|
@@ -1,5 +1,5 @@
|
|
/*
|
|
/*
|
|
- * Copyright 2002-2019 the original author or authors.
|
|
|
|
|
|
+ * Copyright 2002-2020 the original author or authors.
|
|
*
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* you may not use this file except in compliance with the License.
|
|
@@ -222,9 +222,16 @@ public final class OAuth2ResourceServerConfigurer<H extends HttpSecurityBuilder<
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public void init(H http) {
|
|
public void init(H http) {
|
|
|
|
+ validateConfiguration();
|
|
|
|
+
|
|
registerDefaultAccessDeniedHandler(http);
|
|
registerDefaultAccessDeniedHandler(http);
|
|
registerDefaultEntryPoint(http);
|
|
registerDefaultEntryPoint(http);
|
|
registerDefaultCsrfOverride(http);
|
|
registerDefaultCsrfOverride(http);
|
|
|
|
+
|
|
|
|
+ AuthenticationProvider authenticationProvider = getAuthenticationProvider();
|
|
|
|
+ if (authenticationProvider != null) {
|
|
|
|
+ http.authenticationProvider(authenticationProvider);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -232,8 +239,6 @@ public final class OAuth2ResourceServerConfigurer<H extends HttpSecurityBuilder<
|
|
BearerTokenResolver bearerTokenResolver = getBearerTokenResolver();
|
|
BearerTokenResolver bearerTokenResolver = getBearerTokenResolver();
|
|
this.requestMatcher.setBearerTokenResolver(bearerTokenResolver);
|
|
this.requestMatcher.setBearerTokenResolver(bearerTokenResolver);
|
|
|
|
|
|
- validateConfiguration();
|
|
|
|
-
|
|
|
|
AuthenticationManagerResolver resolver = this.authenticationManagerResolver;
|
|
AuthenticationManagerResolver resolver = this.authenticationManagerResolver;
|
|
if (resolver == null) {
|
|
if (resolver == null) {
|
|
AuthenticationManager authenticationManager = getAuthenticationManager(http);
|
|
AuthenticationManager authenticationManager = getAuthenticationManager(http);
|
|
@@ -321,9 +326,9 @@ public final class OAuth2ResourceServerConfigurer<H extends HttpSecurityBuilder<
|
|
return this.decoder;
|
|
return this.decoder;
|
|
}
|
|
}
|
|
|
|
|
|
- AuthenticationManager getAuthenticationManager(H http) {
|
|
|
|
|
|
+ AuthenticationProvider getAuthenticationProvider() {
|
|
if (this.authenticationManager != null) {
|
|
if (this.authenticationManager != null) {
|
|
- return this.authenticationManager;
|
|
|
|
|
|
+ return null;
|
|
}
|
|
}
|
|
|
|
|
|
JwtDecoder decoder = getJwtDecoder();
|
|
JwtDecoder decoder = getJwtDecoder();
|
|
@@ -333,9 +338,13 @@ public final class OAuth2ResourceServerConfigurer<H extends HttpSecurityBuilder<
|
|
JwtAuthenticationProvider provider =
|
|
JwtAuthenticationProvider provider =
|
|
new JwtAuthenticationProvider(decoder);
|
|
new JwtAuthenticationProvider(decoder);
|
|
provider.setJwtAuthenticationConverter(jwtAuthenticationConverter);
|
|
provider.setJwtAuthenticationConverter(jwtAuthenticationConverter);
|
|
- AuthenticationProvider authenticationProvider = postProcess(provider);
|
|
|
|
|
|
+ return postProcess(provider);
|
|
|
|
+ }
|
|
|
|
|
|
- http.authenticationProvider(authenticationProvider);
|
|
|
|
|
|
+ AuthenticationManager getAuthenticationManager(H http) {
|
|
|
|
+ if (this.authenticationManager != null) {
|
|
|
|
+ return this.authenticationManager;
|
|
|
|
+ }
|
|
|
|
|
|
return http.getSharedObject(AuthenticationManager.class);
|
|
return http.getSharedObject(AuthenticationManager.class);
|
|
}
|
|
}
|
|
@@ -391,16 +400,19 @@ public final class OAuth2ResourceServerConfigurer<H extends HttpSecurityBuilder<
|
|
return this.context.getBean(OpaqueTokenIntrospector.class);
|
|
return this.context.getBean(OpaqueTokenIntrospector.class);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ AuthenticationProvider getAuthenticationProvider() {
|
|
|
|
+ if (this.authenticationManager != null) {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+ OpaqueTokenIntrospector introspector = getIntrospector();
|
|
|
|
+ return new OpaqueTokenAuthenticationProvider(introspector);
|
|
|
|
+ }
|
|
|
|
+
|
|
AuthenticationManager getAuthenticationManager(H http) {
|
|
AuthenticationManager getAuthenticationManager(H http) {
|
|
if (this.authenticationManager != null) {
|
|
if (this.authenticationManager != null) {
|
|
return this.authenticationManager;
|
|
return this.authenticationManager;
|
|
}
|
|
}
|
|
|
|
|
|
- OpaqueTokenIntrospector introspector = getIntrospector();
|
|
|
|
- OpaqueTokenAuthenticationProvider provider =
|
|
|
|
- new OpaqueTokenAuthenticationProvider(introspector);
|
|
|
|
- http.authenticationProvider(provider);
|
|
|
|
-
|
|
|
|
return http.getSharedObject(AuthenticationManager.class);
|
|
return http.getSharedObject(AuthenticationManager.class);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -439,6 +451,18 @@ public final class OAuth2ResourceServerConfigurer<H extends HttpSecurityBuilder<
|
|
csrf.ignoringRequestMatchers(this.requestMatcher);
|
|
csrf.ignoringRequestMatchers(this.requestMatcher);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ AuthenticationProvider getAuthenticationProvider() {
|
|
|
|
+ if (this.jwtConfigurer != null) {
|
|
|
|
+ return this.jwtConfigurer.getAuthenticationProvider();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (this.opaqueTokenConfigurer != null) {
|
|
|
|
+ return this.opaqueTokenConfigurer.getAuthenticationProvider();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+
|
|
AuthenticationManager getAuthenticationManager(H http) {
|
|
AuthenticationManager getAuthenticationManager(H http) {
|
|
if (this.jwtConfigurer != null) {
|
|
if (this.jwtConfigurer != null) {
|
|
return this.jwtConfigurer.getAuthenticationManager(http);
|
|
return this.jwtConfigurer.getAuthenticationManager(http);
|