diff --git a/config/src/main/java/org/springframework/security/config/annotation/web/configurers/oauth2/client/OAuth2LoginConfigurer.java b/config/src/main/java/org/springframework/security/config/annotation/web/configurers/oauth2/client/OAuth2LoginConfigurer.java index ea410026d3..592acb1e2a 100644 --- a/config/src/main/java/org/springframework/security/config/annotation/web/configurers/oauth2/client/OAuth2LoginConfigurer.java +++ b/config/src/main/java/org/springframework/security/config/annotation/web/configurers/oauth2/client/OAuth2LoginConfigurer.java @@ -52,15 +52,17 @@ public final class OAuth2LoginConfigurer> exten private final AuthorizationCodeRequestRedirectFilterConfigurer authorizationCodeRequestRedirectFilterConfigurer; private final AuthorizationCodeAuthenticationFilterConfigurer authorizationCodeAuthenticationFilterConfigurer; - private final AuthorizationEndpointConfig authorizationEndpoint; - private final RedirectionEndpointConfig redirectionEndpoint; + private final AuthorizationEndpointConfig authorizationEndpointConfig; + private final TokenEndpointConfig tokenEndpointConfig; + private final RedirectionEndpointConfig redirectionEndpointConfig; private final UserInfoEndpointConfig userInfoEndpointConfig; public OAuth2LoginConfigurer() { this.authorizationCodeRequestRedirectFilterConfigurer = new AuthorizationCodeRequestRedirectFilterConfigurer<>(); this.authorizationCodeAuthenticationFilterConfigurer = new AuthorizationCodeAuthenticationFilterConfigurer<>(); - this.authorizationEndpoint = new AuthorizationEndpointConfig(); - this.redirectionEndpoint = new RedirectionEndpointConfig(); + this.authorizationEndpointConfig = new AuthorizationEndpointConfig(); + this.tokenEndpointConfig = new TokenEndpointConfig(); + this.redirectionEndpointConfig = new RedirectionEndpointConfig(); this.userInfoEndpointConfig = new UserInfoEndpointConfig(); } @@ -76,14 +78,6 @@ public final class OAuth2LoginConfigurer> exten return this; } - public OAuth2LoginConfigurer authorizationCodeTokenExchanger( - AuthorizationGrantTokenExchanger authorizationCodeTokenExchanger) { - - Assert.notNull(authorizationCodeTokenExchanger, "authorizationCodeTokenExchanger cannot be null"); - this.authorizationCodeAuthenticationFilterConfigurer.authorizationCodeTokenExchanger(authorizationCodeTokenExchanger); - return this; - } - public OAuth2LoginConfigurer userAuthoritiesMapper(GrantedAuthoritiesMapper userAuthoritiesMapper) { Assert.notNull(userAuthoritiesMapper, "userAuthoritiesMapper cannot be null"); this.authorizationCodeAuthenticationFilterConfigurer.userAuthoritiesMapper(userAuthoritiesMapper); @@ -103,7 +97,7 @@ public final class OAuth2LoginConfigurer> exten } public AuthorizationEndpointConfig authorizationEndpoint() { - return this.authorizationEndpoint; + return this.authorizationEndpointConfig; } public class AuthorizationEndpointConfig { @@ -128,8 +122,30 @@ public final class OAuth2LoginConfigurer> exten } } + public TokenEndpointConfig tokenEndpoint() { + return this.tokenEndpointConfig; + } + + public class TokenEndpointConfig { + + private TokenEndpointConfig() { + } + + public TokenEndpointConfig authorizationCodeTokenExchanger( + AuthorizationGrantTokenExchanger authorizationCodeTokenExchanger) { + + Assert.notNull(authorizationCodeTokenExchanger, "authorizationCodeTokenExchanger cannot be null"); + OAuth2LoginConfigurer.this.authorizationCodeAuthenticationFilterConfigurer.authorizationCodeTokenExchanger(authorizationCodeTokenExchanger); + return this; + } + + public OAuth2LoginConfigurer and() { + return OAuth2LoginConfigurer.this; + } + } + public RedirectionEndpointConfig redirectionEndpoint() { - return this.redirectionEndpoint; + return this.redirectionEndpointConfig; } public class RedirectionEndpointConfig { diff --git a/samples/boot/oauth2login/src/integration-test/java/org/springframework/security/samples/OAuth2LoginApplicationTests.java b/samples/boot/oauth2login/src/integration-test/java/org/springframework/security/samples/OAuth2LoginApplicationTests.java index def112f0bd..d69192b4a2 100644 --- a/samples/boot/oauth2login/src/integration-test/java/org/springframework/security/samples/OAuth2LoginApplicationTests.java +++ b/samples/boot/oauth2login/src/integration-test/java/org/springframework/security/samples/OAuth2LoginApplicationTests.java @@ -366,7 +366,9 @@ public class OAuth2LoginApplicationTests { .anyRequest().authenticated() .and() .oauth2Login() - .authorizationCodeTokenExchanger(this.mockAuthorizationCodeTokenExchanger()) + .tokenEndpoint() + .authorizationCodeTokenExchanger(this.mockAuthorizationCodeTokenExchanger()) + .and() .userInfoEndpoint() .userInfoService(this.mockUserInfoService()); }