|
@@ -196,177 +196,178 @@ final class OAuth2ResourceServerBeanDefinitionParser implements BeanDefinitionPa
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-}
|
|
|
-
|
|
|
-final class JwtBeanDefinitionParser implements BeanDefinitionParser {
|
|
|
+ static final class JwtBeanDefinitionParser implements BeanDefinitionParser {
|
|
|
|
|
|
- static final String DECODER_REF = "decoder-ref";
|
|
|
- static final String JWK_SET_URI = "jwk-set-uri";
|
|
|
- static final String JWT_AUTHENTICATION_CONVERTER_REF = "jwt-authentication-converter-ref";
|
|
|
- static final String JWT_AUTHENTICATION_CONVERTER = "jwtAuthenticationConverter";
|
|
|
+ static final String DECODER_REF = "decoder-ref";
|
|
|
+ static final String JWK_SET_URI = "jwk-set-uri";
|
|
|
+ static final String JWT_AUTHENTICATION_CONVERTER_REF = "jwt-authentication-converter-ref";
|
|
|
+ static final String JWT_AUTHENTICATION_CONVERTER = "jwtAuthenticationConverter";
|
|
|
|
|
|
- @Override
|
|
|
- public BeanDefinition parse(Element element, ParserContext pc) {
|
|
|
- validateConfiguration(element, pc);
|
|
|
+ @Override
|
|
|
+ public BeanDefinition parse(Element element, ParserContext pc) {
|
|
|
+ validateConfiguration(element, pc);
|
|
|
|
|
|
- BeanDefinitionBuilder jwtProviderBuilder = BeanDefinitionBuilder
|
|
|
- .rootBeanDefinition(JwtAuthenticationProvider.class);
|
|
|
- jwtProviderBuilder.addConstructorArgValue(getDecoder(element));
|
|
|
- jwtProviderBuilder.addPropertyValue(JWT_AUTHENTICATION_CONVERTER, getJwtAuthenticationConverter(element));
|
|
|
+ BeanDefinitionBuilder jwtProviderBuilder = BeanDefinitionBuilder
|
|
|
+ .rootBeanDefinition(JwtAuthenticationProvider.class);
|
|
|
+ jwtProviderBuilder.addConstructorArgValue(getDecoder(element));
|
|
|
+ jwtProviderBuilder.addPropertyValue(JWT_AUTHENTICATION_CONVERTER, getJwtAuthenticationConverter(element));
|
|
|
|
|
|
- return jwtProviderBuilder.getBeanDefinition();
|
|
|
- }
|
|
|
+ return jwtProviderBuilder.getBeanDefinition();
|
|
|
+ }
|
|
|
|
|
|
- void validateConfiguration(Element element, ParserContext pc) {
|
|
|
- boolean usesDecoder = element.hasAttribute(DECODER_REF);
|
|
|
- boolean usesJwkSetUri = element.hasAttribute(JWK_SET_URI);
|
|
|
+ void validateConfiguration(Element element, ParserContext pc) {
|
|
|
+ boolean usesDecoder = element.hasAttribute(DECODER_REF);
|
|
|
+ boolean usesJwkSetUri = element.hasAttribute(JWK_SET_URI);
|
|
|
|
|
|
- if (usesDecoder == usesJwkSetUri) {
|
|
|
- pc.getReaderContext().error("Please specify either decoder-ref or jwk-set-uri.", element);
|
|
|
+ if (usesDecoder == usesJwkSetUri) {
|
|
|
+ pc.getReaderContext().error("Please specify either decoder-ref or jwk-set-uri.", element);
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- Object getDecoder(Element element) {
|
|
|
- String decoderRef = element.getAttribute(DECODER_REF);
|
|
|
- if (!StringUtils.isEmpty(decoderRef)) {
|
|
|
- return new RuntimeBeanReference(decoderRef);
|
|
|
+ Object getDecoder(Element element) {
|
|
|
+ String decoderRef = element.getAttribute(DECODER_REF);
|
|
|
+ if (!StringUtils.isEmpty(decoderRef)) {
|
|
|
+ return new RuntimeBeanReference(decoderRef);
|
|
|
+ }
|
|
|
+
|
|
|
+ BeanDefinitionBuilder builder = BeanDefinitionBuilder
|
|
|
+ .rootBeanDefinition(NimbusJwtDecoderJwkSetUriFactoryBean.class);
|
|
|
+ builder.addConstructorArgValue(element.getAttribute(JWK_SET_URI));
|
|
|
+ return builder.getBeanDefinition();
|
|
|
}
|
|
|
|
|
|
- BeanDefinitionBuilder builder = BeanDefinitionBuilder
|
|
|
- .rootBeanDefinition(NimbusJwtDecoderJwkSetUriFactoryBean.class);
|
|
|
- builder.addConstructorArgValue(element.getAttribute(JWK_SET_URI));
|
|
|
- return builder.getBeanDefinition();
|
|
|
- }
|
|
|
+ Object getJwtAuthenticationConverter(Element element) {
|
|
|
+ String jwtDecoderRef = element.getAttribute(JWT_AUTHENTICATION_CONVERTER_REF);
|
|
|
+ if (!StringUtils.isEmpty(jwtDecoderRef)) {
|
|
|
+ return new RuntimeBeanReference(jwtDecoderRef);
|
|
|
+ }
|
|
|
|
|
|
- Object getJwtAuthenticationConverter(Element element) {
|
|
|
- String jwtDecoderRef = element.getAttribute(JWT_AUTHENTICATION_CONVERTER_REF);
|
|
|
- if (!StringUtils.isEmpty(jwtDecoderRef)) {
|
|
|
- return new RuntimeBeanReference(jwtDecoderRef);
|
|
|
+ return new JwtAuthenticationConverter();
|
|
|
}
|
|
|
|
|
|
- return new JwtAuthenticationConverter();
|
|
|
- }
|
|
|
+ JwtBeanDefinitionParser() {
|
|
|
+ }
|
|
|
|
|
|
- JwtBeanDefinitionParser() {
|
|
|
}
|
|
|
|
|
|
-}
|
|
|
+ static final class OpaqueTokenBeanDefinitionParser implements BeanDefinitionParser {
|
|
|
|
|
|
-final class OpaqueTokenBeanDefinitionParser implements BeanDefinitionParser {
|
|
|
+ static final String INTROSPECTOR_REF = "introspector-ref";
|
|
|
+ static final String INTROSPECTION_URI = "introspection-uri";
|
|
|
+ static final String CLIENT_ID = "client-id";
|
|
|
+ static final String CLIENT_SECRET = "client-secret";
|
|
|
|
|
|
- static final String INTROSPECTOR_REF = "introspector-ref";
|
|
|
- static final String INTROSPECTION_URI = "introspection-uri";
|
|
|
- static final String CLIENT_ID = "client-id";
|
|
|
- static final String CLIENT_SECRET = "client-secret";
|
|
|
+ @Override
|
|
|
+ public BeanDefinition parse(Element element, ParserContext pc) {
|
|
|
+ validateConfiguration(element, pc);
|
|
|
|
|
|
- @Override
|
|
|
- public BeanDefinition parse(Element element, ParserContext pc) {
|
|
|
- validateConfiguration(element, pc);
|
|
|
+ BeanMetadataElement introspector = getIntrospector(element);
|
|
|
+ BeanDefinitionBuilder opaqueTokenProviderBuilder = BeanDefinitionBuilder
|
|
|
+ .rootBeanDefinition(OpaqueTokenAuthenticationProvider.class);
|
|
|
+ opaqueTokenProviderBuilder.addConstructorArgValue(introspector);
|
|
|
|
|
|
- BeanMetadataElement introspector = getIntrospector(element);
|
|
|
- BeanDefinitionBuilder opaqueTokenProviderBuilder = BeanDefinitionBuilder
|
|
|
- .rootBeanDefinition(OpaqueTokenAuthenticationProvider.class);
|
|
|
- opaqueTokenProviderBuilder.addConstructorArgValue(introspector);
|
|
|
+ return opaqueTokenProviderBuilder.getBeanDefinition();
|
|
|
+ }
|
|
|
|
|
|
- return opaqueTokenProviderBuilder.getBeanDefinition();
|
|
|
- }
|
|
|
+ void validateConfiguration(Element element, ParserContext pc) {
|
|
|
+ boolean usesIntrospector = element.hasAttribute(INTROSPECTOR_REF);
|
|
|
+ boolean usesEndpoint = element.hasAttribute(INTROSPECTION_URI) || element.hasAttribute(CLIENT_ID)
|
|
|
+ || element.hasAttribute(CLIENT_SECRET);
|
|
|
|
|
|
- void validateConfiguration(Element element, ParserContext pc) {
|
|
|
- boolean usesIntrospector = element.hasAttribute(INTROSPECTOR_REF);
|
|
|
- boolean usesEndpoint = element.hasAttribute(INTROSPECTION_URI) || element.hasAttribute(CLIENT_ID)
|
|
|
- || element.hasAttribute(CLIENT_SECRET);
|
|
|
+ if (usesIntrospector == usesEndpoint) {
|
|
|
+ pc.getReaderContext().error("Please specify either introspector-ref or all of "
|
|
|
+ + "introspection-uri, client-id, and client-secret.", element);
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
- if (usesIntrospector == usesEndpoint) {
|
|
|
- pc.getReaderContext().error("Please specify either introspector-ref or all of "
|
|
|
- + "introspection-uri, client-id, and client-secret.", element);
|
|
|
- return;
|
|
|
+ if (usesEndpoint) {
|
|
|
+ if (!(element.hasAttribute(INTROSPECTION_URI) && element.hasAttribute(CLIENT_ID)
|
|
|
+ && element.hasAttribute(CLIENT_SECRET))) {
|
|
|
+ pc.getReaderContext()
|
|
|
+ .error("Please specify introspection-uri, client-id, and client-secret together", element);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- if (usesEndpoint) {
|
|
|
- if (!(element.hasAttribute(INTROSPECTION_URI) && element.hasAttribute(CLIENT_ID)
|
|
|
- && element.hasAttribute(CLIENT_SECRET))) {
|
|
|
- pc.getReaderContext().error("Please specify introspection-uri, client-id, and client-secret together",
|
|
|
- element);
|
|
|
+ BeanMetadataElement getIntrospector(Element element) {
|
|
|
+ String introspectorRef = element.getAttribute(INTROSPECTOR_REF);
|
|
|
+ if (!StringUtils.isEmpty(introspectorRef)) {
|
|
|
+ return new RuntimeBeanReference(introspectorRef);
|
|
|
}
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
- BeanMetadataElement getIntrospector(Element element) {
|
|
|
- String introspectorRef = element.getAttribute(INTROSPECTOR_REF);
|
|
|
- if (!StringUtils.isEmpty(introspectorRef)) {
|
|
|
- return new RuntimeBeanReference(introspectorRef);
|
|
|
- }
|
|
|
+ String introspectionUri = element.getAttribute(INTROSPECTION_URI);
|
|
|
+ String clientId = element.getAttribute(CLIENT_ID);
|
|
|
+ String clientSecret = element.getAttribute(CLIENT_SECRET);
|
|
|
|
|
|
- String introspectionUri = element.getAttribute(INTROSPECTION_URI);
|
|
|
- String clientId = element.getAttribute(CLIENT_ID);
|
|
|
- String clientSecret = element.getAttribute(CLIENT_SECRET);
|
|
|
+ BeanDefinitionBuilder introspectorBuilder = BeanDefinitionBuilder
|
|
|
+ .rootBeanDefinition(NimbusOpaqueTokenIntrospector.class);
|
|
|
+ introspectorBuilder.addConstructorArgValue(introspectionUri);
|
|
|
+ introspectorBuilder.addConstructorArgValue(clientId);
|
|
|
+ introspectorBuilder.addConstructorArgValue(clientSecret);
|
|
|
|
|
|
- BeanDefinitionBuilder introspectorBuilder = BeanDefinitionBuilder
|
|
|
- .rootBeanDefinition(NimbusOpaqueTokenIntrospector.class);
|
|
|
- introspectorBuilder.addConstructorArgValue(introspectionUri);
|
|
|
- introspectorBuilder.addConstructorArgValue(clientId);
|
|
|
- introspectorBuilder.addConstructorArgValue(clientSecret);
|
|
|
+ return introspectorBuilder.getBeanDefinition();
|
|
|
+ }
|
|
|
|
|
|
- return introspectorBuilder.getBeanDefinition();
|
|
|
- }
|
|
|
+ OpaqueTokenBeanDefinitionParser() {
|
|
|
+ }
|
|
|
|
|
|
- OpaqueTokenBeanDefinitionParser() {
|
|
|
}
|
|
|
|
|
|
-}
|
|
|
+ static final class StaticAuthenticationManagerResolver
|
|
|
+ implements AuthenticationManagerResolver<HttpServletRequest> {
|
|
|
|
|
|
-final class StaticAuthenticationManagerResolver implements AuthenticationManagerResolver<HttpServletRequest> {
|
|
|
+ private final AuthenticationManager authenticationManager;
|
|
|
|
|
|
- private final AuthenticationManager authenticationManager;
|
|
|
+ StaticAuthenticationManagerResolver(AuthenticationManager authenticationManager) {
|
|
|
+ this.authenticationManager = authenticationManager;
|
|
|
+ }
|
|
|
|
|
|
- StaticAuthenticationManagerResolver(AuthenticationManager authenticationManager) {
|
|
|
- this.authenticationManager = authenticationManager;
|
|
|
- }
|
|
|
+ @Override
|
|
|
+ public AuthenticationManager resolve(HttpServletRequest context) {
|
|
|
+ return this.authenticationManager;
|
|
|
+ }
|
|
|
|
|
|
- @Override
|
|
|
- public AuthenticationManager resolve(HttpServletRequest context) {
|
|
|
- return this.authenticationManager;
|
|
|
}
|
|
|
|
|
|
-}
|
|
|
+ static final class NimbusJwtDecoderJwkSetUriFactoryBean implements FactoryBean<JwtDecoder> {
|
|
|
|
|
|
-final class NimbusJwtDecoderJwkSetUriFactoryBean implements FactoryBean<JwtDecoder> {
|
|
|
+ private final String jwkSetUri;
|
|
|
|
|
|
- private final String jwkSetUri;
|
|
|
+ NimbusJwtDecoderJwkSetUriFactoryBean(String jwkSetUri) {
|
|
|
+ this.jwkSetUri = jwkSetUri;
|
|
|
+ }
|
|
|
|
|
|
- NimbusJwtDecoderJwkSetUriFactoryBean(String jwkSetUri) {
|
|
|
- this.jwkSetUri = jwkSetUri;
|
|
|
- }
|
|
|
+ @Override
|
|
|
+ public JwtDecoder getObject() {
|
|
|
+ return NimbusJwtDecoder.withJwkSetUri(this.jwkSetUri).build();
|
|
|
+ }
|
|
|
|
|
|
- @Override
|
|
|
- public JwtDecoder getObject() {
|
|
|
- return NimbusJwtDecoder.withJwkSetUri(this.jwkSetUri).build();
|
|
|
- }
|
|
|
+ @Override
|
|
|
+ public Class<?> getObjectType() {
|
|
|
+ return JwtDecoder.class;
|
|
|
+ }
|
|
|
|
|
|
- @Override
|
|
|
- public Class<?> getObjectType() {
|
|
|
- return JwtDecoder.class;
|
|
|
}
|
|
|
|
|
|
-}
|
|
|
-
|
|
|
-final class BearerTokenRequestMatcher implements RequestMatcher {
|
|
|
-
|
|
|
- private final BearerTokenResolver bearerTokenResolver;
|
|
|
+ static final class BearerTokenRequestMatcher implements RequestMatcher {
|
|
|
|
|
|
- BearerTokenRequestMatcher(BearerTokenResolver bearerTokenResolver) {
|
|
|
- Assert.notNull(bearerTokenResolver, "bearerTokenResolver cannot be null");
|
|
|
- this.bearerTokenResolver = bearerTokenResolver;
|
|
|
- }
|
|
|
+ private final BearerTokenResolver bearerTokenResolver;
|
|
|
|
|
|
- @Override
|
|
|
- public boolean matches(HttpServletRequest request) {
|
|
|
- try {
|
|
|
- return this.bearerTokenResolver.resolve(request) != null;
|
|
|
+ BearerTokenRequestMatcher(BearerTokenResolver bearerTokenResolver) {
|
|
|
+ Assert.notNull(bearerTokenResolver, "bearerTokenResolver cannot be null");
|
|
|
+ this.bearerTokenResolver = bearerTokenResolver;
|
|
|
}
|
|
|
- catch (OAuth2AuthenticationException e) {
|
|
|
- return false;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean matches(HttpServletRequest request) {
|
|
|
+ try {
|
|
|
+ return this.bearerTokenResolver.resolve(request) != null;
|
|
|
+ }
|
|
|
+ catch (OAuth2AuthenticationException e) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
|
|
|
}
|