Skip to content

Commit 7550907

Browse files
committed
Polish OAuth2AccessTokenResponse converters
Since these converters no longer have a direct reference to the HTTP stack, it would be better to move them into another package. Also, now that the converters are public, we should follow the prevailing converter naming convention, which is to call it STConverter for an implementation of Converter<S, T>.
1 parent 704f986 commit 7550907

File tree

5 files changed

+44
-43
lines changed

5 files changed

+44
-43
lines changed
Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,19 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package org.springframework.security.oauth2.core.http.converter;
16+
package org.springframework.security.oauth2.core.endpoint;
17+
18+
import java.util.Arrays;
19+
import java.util.Collections;
20+
import java.util.HashSet;
21+
import java.util.LinkedHashMap;
22+
import java.util.Map;
23+
import java.util.Set;
1724

1825
import org.springframework.core.convert.converter.Converter;
1926
import org.springframework.security.oauth2.core.OAuth2AccessToken;
20-
import org.springframework.security.oauth2.core.endpoint.OAuth2AccessTokenResponse;
21-
import org.springframework.security.oauth2.core.endpoint.OAuth2ParameterNames;
2227
import org.springframework.util.StringUtils;
2328

24-
import java.util.*;
25-
2629
/**
2730
* A {@link Converter} that converts the provided
2831
* OAuth 2.0 Access Token Response parameters to an {@link OAuth2AccessTokenResponse}.
@@ -31,7 +34,7 @@
3134
* @author Nikita Konev
3235
* @since 5.3
3336
*/
34-
public final class OAuth2AccessTokenResponseConverter implements Converter<Map<String, String>, OAuth2AccessTokenResponse> {
37+
public final class MapOAuth2AccessTokenResponseConverter implements Converter<Map<String, String>, OAuth2AccessTokenResponse> {
3538
private static final Set<String> TOKEN_RESPONSE_PARAMETER_NAMES = new HashSet<>(Arrays.asList(
3639
OAuth2ParameterNames.ACCESS_TOKEN,
3740
OAuth2ParameterNames.EXPIRES_IN,
Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,17 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package org.springframework.security.oauth2.core.http.converter;
17-
18-
import org.springframework.core.convert.converter.Converter;
19-
import org.springframework.security.oauth2.core.endpoint.OAuth2AccessTokenResponse;
20-
import org.springframework.security.oauth2.core.endpoint.OAuth2ParameterNames;
21-
import org.springframework.util.CollectionUtils;
22-
import org.springframework.util.StringUtils;
16+
package org.springframework.security.oauth2.core.endpoint;
2317

2418
import java.time.Instant;
2519
import java.time.temporal.ChronoUnit;
2620
import java.util.HashMap;
2721
import java.util.Map;
2822

23+
import org.springframework.core.convert.converter.Converter;
24+
import org.springframework.util.CollectionUtils;
25+
import org.springframework.util.StringUtils;
26+
2927
/**
3028
* A {@link Converter} that converts the provided {@link OAuth2AccessTokenResponse}
3129
* to a {@code Map} representation of the OAuth 2.0 Access Token Response parameters.
@@ -34,7 +32,7 @@
3432
* @author Nikita Konev
3533
* @since 5.3
3634
*/
37-
public final class OAuth2AccessTokenResponseParametersConverter implements Converter<OAuth2AccessTokenResponse, Map<String, String>> {
35+
public final class OAuth2AccessTokenResponseMapConverter implements Converter<OAuth2AccessTokenResponse, Map<String, String>> {
3836

3937
@Override
4038
public Map<String, String> convert(OAuth2AccessTokenResponse tokenResponse) {

oauth2/oauth2-core/src/main/java/org/springframework/security/oauth2/core/http/converter/OAuth2AccessTokenResponseHttpMessageConverter.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
*/
1616
package org.springframework.security.oauth2.core.http.converter;
1717

18+
import java.nio.charset.Charset;
19+
import java.nio.charset.StandardCharsets;
20+
import java.util.Map;
21+
1822
import org.springframework.core.ParameterizedTypeReference;
1923
import org.springframework.core.convert.converter.Converter;
2024
import org.springframework.http.HttpInputMessage;
@@ -25,13 +29,11 @@
2529
import org.springframework.http.converter.HttpMessageConverter;
2630
import org.springframework.http.converter.HttpMessageNotReadableException;
2731
import org.springframework.http.converter.HttpMessageNotWritableException;
32+
import org.springframework.security.oauth2.core.endpoint.MapOAuth2AccessTokenResponseConverter;
2833
import org.springframework.security.oauth2.core.endpoint.OAuth2AccessTokenResponse;
34+
import org.springframework.security.oauth2.core.endpoint.OAuth2AccessTokenResponseMapConverter;
2935
import org.springframework.util.Assert;
3036

31-
import java.nio.charset.Charset;
32-
import java.nio.charset.StandardCharsets;
33-
import java.util.Map;
34-
3537
/**
3638
* A {@link HttpMessageConverter} for an {@link OAuth2AccessTokenResponse OAuth 2.0 Access Token Response}.
3739
*
@@ -49,10 +51,10 @@ public class OAuth2AccessTokenResponseHttpMessageConverter extends AbstractHttpM
4951
private GenericHttpMessageConverter<Object> jsonMessageConverter = HttpMessageConverters.getJsonMessageConverter();
5052

5153
protected Converter<Map<String, String>, OAuth2AccessTokenResponse> tokenResponseConverter =
52-
new OAuth2AccessTokenResponseConverter();
54+
new MapOAuth2AccessTokenResponseConverter();
5355

5456
protected Converter<OAuth2AccessTokenResponse, Map<String, String>> tokenResponseParametersConverter =
55-
new OAuth2AccessTokenResponseParametersConverter();
57+
new OAuth2AccessTokenResponseMapConverter();
5658

5759
public OAuth2AccessTokenResponseHttpMessageConverter() {
5860
super(DEFAULT_CHARSET, MediaType.APPLICATION_JSON, new MediaType("application", "*+json"));
Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,32 +13,32 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package org.springframework.security.oauth2.core.http.converter;
16+
package org.springframework.security.oauth2.core.endpoint;
17+
18+
import java.time.Duration;
19+
import java.util.HashMap;
20+
import java.util.Map;
21+
import java.util.Set;
1722

1823
import org.junit.Assert;
1924
import org.junit.Before;
2025
import org.junit.Test;
26+
2127
import org.springframework.security.oauth2.core.OAuth2AccessToken;
2228
import org.springframework.security.oauth2.core.OAuth2RefreshToken;
23-
import org.springframework.security.oauth2.core.endpoint.OAuth2AccessTokenResponse;
24-
25-
import java.time.Duration;
26-
import java.util.HashMap;
27-
import java.util.Map;
28-
import java.util.Set;
2929

3030
/**
31-
* Tests for {@link OAuth2AccessTokenResponseConverter}.
31+
* Tests for {@link MapOAuth2AccessTokenResponseConverter}.
3232
*
3333
* @author Nikita Konev
3434
*/
35-
public class OAuth2AccessTokenResponseConverterTest {
35+
public class MapOAuth2AccessTokenResponseConverterTest {
3636

37-
private OAuth2AccessTokenResponseConverter messageConverter;
37+
private MapOAuth2AccessTokenResponseConverter messageConverter;
3838

3939
@Before
4040
public void setup() {
41-
this.messageConverter = new OAuth2AccessTokenResponseConverter();
41+
this.messageConverter = new MapOAuth2AccessTokenResponseConverter();
4242
}
4343

4444

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,33 +13,31 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package org.springframework.security.oauth2.core.http.converter;
17-
18-
import org.junit.Assert;
19-
import org.junit.Before;
20-
import org.junit.Test;
21-
import org.springframework.security.oauth2.core.OAuth2AccessToken;
22-
import org.springframework.security.oauth2.core.endpoint.OAuth2AccessTokenResponse;
16+
package org.springframework.security.oauth2.core.endpoint;
2317

2418
import java.util.HashMap;
2519
import java.util.HashSet;
2620
import java.util.Map;
2721
import java.util.Set;
2822

29-
import static org.junit.Assert.*;
23+
import org.junit.Assert;
24+
import org.junit.Before;
25+
import org.junit.Test;
26+
27+
import org.springframework.security.oauth2.core.OAuth2AccessToken;
3028

3129
/**
32-
* Tests for {@link OAuth2AccessTokenResponseParametersConverter}.
30+
* Tests for {@link OAuth2AccessTokenResponseMapConverter}.
3331
*
3432
* @author Nikita Konev
3533
*/
36-
public class OAuth2AccessTokenResponseParametersConverterTest {
34+
public class OAuth2AccessTokenResponseMapConverterTest {
3735

38-
private OAuth2AccessTokenResponseParametersConverter messageConverter;
36+
private OAuth2AccessTokenResponseMapConverter messageConverter;
3937

4038
@Before
4139
public void setup() {
42-
this.messageConverter = new OAuth2AccessTokenResponseParametersConverter();
40+
this.messageConverter = new OAuth2AccessTokenResponseMapConverter();
4341
}
4442

4543

0 commit comments

Comments
 (0)