Browse Source

Fixed final field warnings in opaque token introspectors

Ashley Scopes 4 năm trước cách đây
mục cha
commit
e9d5bbba34

+ 5 - 5
oauth2/oauth2-resource-server/src/main/java/org/springframework/security/oauth2/server/resource/introspection/NimbusOpaqueTokenIntrospector.java

@@ -61,13 +61,13 @@ import org.springframework.web.client.RestTemplate;
  */
 public class NimbusOpaqueTokenIntrospector implements OpaqueTokenIntrospector {
 
-	private final Log logger = LogFactory.getLog(getClass());
+	private static final String AUTHORITY_PREFIX = "SCOPE_";
 
-	private Converter<String, RequestEntity<?>> requestEntityConverter;
+	private final Log logger = LogFactory.getLog(getClass());
 
-	private RestOperations restOperations;
+	private final RestOperations restOperations;
 
-	private final String authorityPrefix = "SCOPE_";
+	private Converter<String, RequestEntity<?>> requestEntityConverter;
 
 	/**
 	 * Creates a {@code OpaqueTokenAuthenticationProvider} with the provided parameters
@@ -258,7 +258,7 @@ public class NimbusOpaqueTokenIntrospector implements OpaqueTokenIntrospector {
 			List<String> scopes = Collections.unmodifiableList(response.getScope().toStringList());
 			claims.put(OAuth2TokenIntrospectionClaimNames.SCOPE, scopes);
 			for (String scope : scopes) {
-				authorities.add(new SimpleGrantedAuthority(this.authorityPrefix + scope));
+				authorities.add(new SimpleGrantedAuthority(AUTHORITY_PREFIX + scope));
 			}
 		}
 		return new OAuth2IntrospectionAuthenticatedPrincipal(claims, authorities);

+ 3 - 3
oauth2/oauth2-resource-server/src/main/java/org/springframework/security/oauth2/server/resource/introspection/NimbusReactiveOpaqueTokenIntrospector.java

@@ -57,14 +57,14 @@ import org.springframework.web.reactive.function.client.WebClient;
  */
 public class NimbusReactiveOpaqueTokenIntrospector implements ReactiveOpaqueTokenIntrospector {
 
+	private static final String AUTHORITY_PREFIX = "SCOPE_";
+
 	private final Log logger = LogFactory.getLog(getClass());
 
 	private final URI introspectionUri;
 
 	private final WebClient webClient;
 
-	private String authorityPrefix = "SCOPE_";
-
 	/**
 	 * Creates a {@code OpaqueTokenReactiveAuthenticationManager} with the provided
 	 * parameters
@@ -227,7 +227,7 @@ public class NimbusReactiveOpaqueTokenIntrospector implements ReactiveOpaqueToke
 			claims.put(OAuth2TokenIntrospectionClaimNames.SCOPE, scopes);
 
 			for (String scope : scopes) {
-				authorities.add(new SimpleGrantedAuthority(this.authorityPrefix + scope));
+				authorities.add(new SimpleGrantedAuthority(AUTHORITY_PREFIX + scope));
 			}
 		}
 		return new OAuth2IntrospectionAuthenticatedPrincipal(claims, authorities);

+ 5 - 5
oauth2/oauth2-resource-server/src/main/java/org/springframework/security/oauth2/server/resource/introspection/SpringOpaqueTokenIntrospector.java

@@ -57,16 +57,16 @@ import org.springframework.web.client.RestTemplate;
  */
 public class SpringOpaqueTokenIntrospector implements OpaqueTokenIntrospector {
 
-	private final Log logger = LogFactory.getLog(getClass());
+	private static final String AUTHORITY_PREFIX = "SCOPE_";
 
 	private static final ParameterizedTypeReference<Map<String, Object>> STRING_OBJECT_MAP = new ParameterizedTypeReference<Map<String, Object>>() {
 	};
 
-	private Converter<String, RequestEntity<?>> requestEntityConverter;
+	private final Log logger = LogFactory.getLog(getClass());
 
-	private RestOperations restOperations;
+	private final RestOperations restOperations;
 
-	private final String authorityPrefix = "SCOPE_";
+	private Converter<String, RequestEntity<?>> requestEntityConverter;
 
 	/**
 	 * Creates a {@code OpaqueTokenAuthenticationProvider} with the provided parameters
@@ -216,7 +216,7 @@ public class SpringOpaqueTokenIntrospector implements OpaqueTokenIntrospector {
 			if (v instanceof String) {
 				Collection<String> scopes = Arrays.asList(((String) v).split(" "));
 				for (String scope : scopes) {
-					authorities.add(new SimpleGrantedAuthority(this.authorityPrefix + scope));
+					authorities.add(new SimpleGrantedAuthority(AUTHORITY_PREFIX + scope));
 				}
 				return scopes;
 			}

+ 3 - 3
oauth2/oauth2-resource-server/src/main/java/org/springframework/security/oauth2/server/resource/introspection/SpringReactiveOpaqueTokenIntrospector.java

@@ -51,6 +51,8 @@ import org.springframework.web.reactive.function.client.WebClient;
  */
 public class SpringReactiveOpaqueTokenIntrospector implements ReactiveOpaqueTokenIntrospector {
 
+	private static final String AUTHORITY_PREFIX = "SCOPE_";
+
 	private static final ParameterizedTypeReference<Map<String, Object>> STRING_OBJECT_MAP = new ParameterizedTypeReference<Map<String, Object>>() {
 	};
 
@@ -58,8 +60,6 @@ public class SpringReactiveOpaqueTokenIntrospector implements ReactiveOpaqueToke
 
 	private final WebClient webClient;
 
-	private String authorityPrefix = "SCOPE_";
-
 	/**
 	 * Creates a {@code OpaqueTokenReactiveAuthenticationManager} with the provided
 	 * parameters
@@ -171,7 +171,7 @@ public class SpringReactiveOpaqueTokenIntrospector implements ReactiveOpaqueToke
 			if (v instanceof String) {
 				Collection<String> scopes = Arrays.asList(((String) v).split(" "));
 				for (String scope : scopes) {
-					authorities.add(new SimpleGrantedAuthority(this.authorityPrefix + scope));
+					authorities.add(new SimpleGrantedAuthority(AUTHORITY_PREFIX + scope));
 				}
 				return scopes;
 			}