|
@@ -102,12 +102,14 @@ import org.springframework.security.oauth2.server.resource.web.server.ServerBear
|
|
import org.springframework.security.web.PortMapper;
|
|
import org.springframework.security.web.PortMapper;
|
|
import org.springframework.security.web.authentication.preauth.x509.SubjectDnX509PrincipalExtractor;
|
|
import org.springframework.security.web.authentication.preauth.x509.SubjectDnX509PrincipalExtractor;
|
|
import org.springframework.security.web.authentication.preauth.x509.X509PrincipalExtractor;
|
|
import org.springframework.security.web.authentication.preauth.x509.X509PrincipalExtractor;
|
|
|
|
+import org.springframework.security.web.server.DefaultServerRedirectStrategy;
|
|
import org.springframework.security.web.server.DelegatingServerAuthenticationEntryPoint;
|
|
import org.springframework.security.web.server.DelegatingServerAuthenticationEntryPoint;
|
|
import org.springframework.security.web.server.DelegatingServerAuthenticationEntryPoint.DelegateEntry;
|
|
import org.springframework.security.web.server.DelegatingServerAuthenticationEntryPoint.DelegateEntry;
|
|
import org.springframework.security.web.server.ExchangeMatcherRedirectWebFilter;
|
|
import org.springframework.security.web.server.ExchangeMatcherRedirectWebFilter;
|
|
import org.springframework.security.web.server.MatcherSecurityWebFilterChain;
|
|
import org.springframework.security.web.server.MatcherSecurityWebFilterChain;
|
|
import org.springframework.security.web.server.SecurityWebFilterChain;
|
|
import org.springframework.security.web.server.SecurityWebFilterChain;
|
|
import org.springframework.security.web.server.ServerAuthenticationEntryPoint;
|
|
import org.springframework.security.web.server.ServerAuthenticationEntryPoint;
|
|
|
|
+import org.springframework.security.web.server.ServerRedirectStrategy;
|
|
import org.springframework.security.web.server.authentication.AnonymousAuthenticationWebFilter;
|
|
import org.springframework.security.web.server.authentication.AnonymousAuthenticationWebFilter;
|
|
import org.springframework.security.web.server.authentication.AuthenticationConverterServerWebExchangeMatcher;
|
|
import org.springframework.security.web.server.authentication.AuthenticationConverterServerWebExchangeMatcher;
|
|
import org.springframework.security.web.server.authentication.AuthenticationWebFilter;
|
|
import org.springframework.security.web.server.authentication.AuthenticationWebFilter;
|
|
@@ -3375,6 +3377,8 @@ public class ServerHttpSecurity {
|
|
|
|
|
|
private ServerOAuth2AuthorizationRequestResolver authorizationRequestResolver;
|
|
private ServerOAuth2AuthorizationRequestResolver authorizationRequestResolver;
|
|
|
|
|
|
|
|
+ private ServerRedirectStrategy authorizationRedirectStrategy;
|
|
|
|
+
|
|
private ServerWebExchangeMatcher authenticationMatcher;
|
|
private ServerWebExchangeMatcher authenticationMatcher;
|
|
|
|
|
|
private ServerAuthenticationSuccessHandler authenticationSuccessHandler;
|
|
private ServerAuthenticationSuccessHandler authenticationSuccessHandler;
|
|
@@ -3547,6 +3551,16 @@ public class ServerHttpSecurity {
|
|
return this;
|
|
return this;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Sets the redirect strategy for Authorization Endpoint redirect URI.
|
|
|
|
+ * @param authorizationRedirectStrategy the redirect strategy
|
|
|
|
+ * @return the {@link OAuth2LoginSpec} for further configuration
|
|
|
|
+ */
|
|
|
|
+ public OAuth2LoginSpec authorizationRedirectStrategy(ServerRedirectStrategy authorizationRedirectStrategy) {
|
|
|
|
+ this.authorizationRedirectStrategy = authorizationRedirectStrategy;
|
|
|
|
+ return this;
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Sets the {@link ServerWebExchangeMatcher matcher} used for determining if the
|
|
* Sets the {@link ServerWebExchangeMatcher matcher} used for determining if the
|
|
* request is an authentication request.
|
|
* request is an authentication request.
|
|
@@ -3581,7 +3595,9 @@ public class ServerHttpSecurity {
|
|
OAuth2AuthorizationRequestRedirectWebFilter oauthRedirectFilter = getRedirectWebFilter();
|
|
OAuth2AuthorizationRequestRedirectWebFilter oauthRedirectFilter = getRedirectWebFilter();
|
|
ServerAuthorizationRequestRepository<OAuth2AuthorizationRequest> authorizationRequestRepository = getAuthorizationRequestRepository();
|
|
ServerAuthorizationRequestRepository<OAuth2AuthorizationRequest> authorizationRequestRepository = getAuthorizationRequestRepository();
|
|
oauthRedirectFilter.setAuthorizationRequestRepository(authorizationRequestRepository);
|
|
oauthRedirectFilter.setAuthorizationRequestRepository(authorizationRequestRepository);
|
|
|
|
+ oauthRedirectFilter.setAuthorizationRedirectStrategy(getAuthorizationRedirectStrategy());
|
|
oauthRedirectFilter.setRequestCache(http.requestCache.requestCache);
|
|
oauthRedirectFilter.setRequestCache(http.requestCache.requestCache);
|
|
|
|
+
|
|
ReactiveAuthenticationManager manager = getAuthenticationManager();
|
|
ReactiveAuthenticationManager manager = getAuthenticationManager();
|
|
AuthenticationWebFilter authenticationFilter = new OAuth2LoginAuthenticationWebFilter(manager,
|
|
AuthenticationWebFilter authenticationFilter = new OAuth2LoginAuthenticationWebFilter(manager,
|
|
authorizedClientRepository);
|
|
authorizedClientRepository);
|
|
@@ -3591,6 +3607,7 @@ public class ServerHttpSecurity {
|
|
authenticationFilter.setAuthenticationSuccessHandler(getAuthenticationSuccessHandler(http));
|
|
authenticationFilter.setAuthenticationSuccessHandler(getAuthenticationSuccessHandler(http));
|
|
authenticationFilter.setAuthenticationFailureHandler(getAuthenticationFailureHandler());
|
|
authenticationFilter.setAuthenticationFailureHandler(getAuthenticationFailureHandler());
|
|
authenticationFilter.setSecurityContextRepository(this.securityContextRepository);
|
|
authenticationFilter.setSecurityContextRepository(this.securityContextRepository);
|
|
|
|
+
|
|
setDefaultEntryPoints(http);
|
|
setDefaultEntryPoints(http);
|
|
http.addFilterAt(oauthRedirectFilter, SecurityWebFiltersOrder.HTTP_BASIC);
|
|
http.addFilterAt(oauthRedirectFilter, SecurityWebFiltersOrder.HTTP_BASIC);
|
|
http.addFilterAt(authenticationFilter, SecurityWebFiltersOrder.AUTHENTICATION);
|
|
http.addFilterAt(authenticationFilter, SecurityWebFiltersOrder.AUTHENTICATION);
|
|
@@ -3737,6 +3754,13 @@ public class ServerHttpSecurity {
|
|
return this.authorizationRequestRepository;
|
|
return this.authorizationRequestRepository;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private ServerRedirectStrategy getAuthorizationRedirectStrategy() {
|
|
|
|
+ if (this.authorizationRedirectStrategy == null) {
|
|
|
|
+ this.authorizationRedirectStrategy = new DefaultServerRedirectStrategy();
|
|
|
|
+ }
|
|
|
|
+ return this.authorizationRedirectStrategy;
|
|
|
|
+ }
|
|
|
|
+
|
|
private ReactiveOAuth2AuthorizedClientService getAuthorizedClientService() {
|
|
private ReactiveOAuth2AuthorizedClientService getAuthorizedClientService() {
|
|
ReactiveOAuth2AuthorizedClientService bean = getBeanOrNull(ReactiveOAuth2AuthorizedClientService.class);
|
|
ReactiveOAuth2AuthorizedClientService bean = getBeanOrNull(ReactiveOAuth2AuthorizedClientService.class);
|
|
if (bean != null) {
|
|
if (bean != null) {
|
|
@@ -3759,6 +3783,8 @@ public class ServerHttpSecurity {
|
|
|
|
|
|
private ServerAuthorizationRequestRepository<OAuth2AuthorizationRequest> authorizationRequestRepository;
|
|
private ServerAuthorizationRequestRepository<OAuth2AuthorizationRequest> authorizationRequestRepository;
|
|
|
|
|
|
|
|
+ private ServerRedirectStrategy authorizationRedirectStrategy;
|
|
|
|
+
|
|
private OAuth2ClientSpec() {
|
|
private OAuth2ClientSpec() {
|
|
}
|
|
}
|
|
|
|
|
|
@@ -3851,6 +3877,23 @@ public class ServerHttpSecurity {
|
|
return this.authorizationRequestRepository;
|
|
return this.authorizationRequestRepository;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Sets the redirect strategy for Authorization Endpoint redirect URI.
|
|
|
|
+ * @param authorizationRedirectStrategy the redirect strategy
|
|
|
|
+ * @return the {@link OAuth2ClientSpec} for further configuration
|
|
|
|
+ */
|
|
|
|
+ public OAuth2ClientSpec authorizationRedirectStrategy(ServerRedirectStrategy authorizationRedirectStrategy) {
|
|
|
|
+ this.authorizationRedirectStrategy = authorizationRedirectStrategy;
|
|
|
|
+ return this;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private ServerRedirectStrategy getAuthorizationRedirectStrategy() {
|
|
|
|
+ if (this.authorizationRedirectStrategy == null) {
|
|
|
|
+ this.authorizationRedirectStrategy = new DefaultServerRedirectStrategy();
|
|
|
|
+ }
|
|
|
|
+ return this.authorizationRedirectStrategy;
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Allows method chaining to continue configuring the {@link ServerHttpSecurity}
|
|
* Allows method chaining to continue configuring the {@link ServerHttpSecurity}
|
|
* @return the {@link ServerHttpSecurity} to continue configuring
|
|
* @return the {@link ServerHttpSecurity} to continue configuring
|
|
@@ -3870,12 +3913,15 @@ public class ServerHttpSecurity {
|
|
if (http.requestCache != null) {
|
|
if (http.requestCache != null) {
|
|
codeGrantWebFilter.setRequestCache(http.requestCache.requestCache);
|
|
codeGrantWebFilter.setRequestCache(http.requestCache.requestCache);
|
|
}
|
|
}
|
|
|
|
+
|
|
OAuth2AuthorizationRequestRedirectWebFilter oauthRedirectFilter = new OAuth2AuthorizationRequestRedirectWebFilter(
|
|
OAuth2AuthorizationRequestRedirectWebFilter oauthRedirectFilter = new OAuth2AuthorizationRequestRedirectWebFilter(
|
|
clientRegistrationRepository);
|
|
clientRegistrationRepository);
|
|
oauthRedirectFilter.setAuthorizationRequestRepository(getAuthorizationRequestRepository());
|
|
oauthRedirectFilter.setAuthorizationRequestRepository(getAuthorizationRequestRepository());
|
|
|
|
+ oauthRedirectFilter.setAuthorizationRedirectStrategy(getAuthorizationRedirectStrategy());
|
|
if (http.requestCache != null) {
|
|
if (http.requestCache != null) {
|
|
oauthRedirectFilter.setRequestCache(http.requestCache.requestCache);
|
|
oauthRedirectFilter.setRequestCache(http.requestCache.requestCache);
|
|
}
|
|
}
|
|
|
|
+
|
|
http.addFilterAt(codeGrantWebFilter, SecurityWebFiltersOrder.OAUTH2_AUTHORIZATION_CODE);
|
|
http.addFilterAt(codeGrantWebFilter, SecurityWebFiltersOrder.OAUTH2_AUTHORIZATION_CODE);
|
|
http.addFilterAt(oauthRedirectFilter, SecurityWebFiltersOrder.HTTP_BASIC);
|
|
http.addFilterAt(oauthRedirectFilter, SecurityWebFiltersOrder.HTTP_BASIC);
|
|
}
|
|
}
|