OAuth2LoginAuthenticationFilter requires collaborators

Fixes gh-4661
This commit is contained in:
Joe Grandja 2017-10-29 04:41:13 -04:00
parent 5a7466512e
commit 6fbd435bdf
3 changed files with 24 additions and 31 deletions

View File

@ -70,9 +70,7 @@ public final class OAuth2LoginConfigurer<B extends HttpSecurityBuilder<B>> exten
private final UserInfoEndpointConfig userInfoEndpointConfig = new UserInfoEndpointConfig();
public OAuth2LoginConfigurer() {
super(new OAuth2LoginAuthenticationFilter(
OAuth2LoginAuthenticationFilter.DEFAULT_FILTER_PROCESSES_URI),
OAuth2LoginAuthenticationFilter.DEFAULT_FILTER_PROCESSES_URI);
super();
}
public OAuth2LoginConfigurer<B> clients(ClientRegistrationRepository clientRegistrationRepository) {
@ -217,6 +215,14 @@ public final class OAuth2LoginConfigurer<B extends HttpSecurityBuilder<B>> exten
@Override
public void init(B http) throws Exception {
OAuth2LoginAuthenticationFilter authenticationFilter =
new OAuth2LoginAuthenticationFilter(
OAuth2LoginAuthenticationFilter.DEFAULT_FILTER_PROCESSES_URI,
this.getClientRegistrationRepository(),
this.getAuthorizedClientService());
this.setAuthenticationFilter(authenticationFilter);
this.loginProcessingUrl(OAuth2LoginAuthenticationFilter.DEFAULT_FILTER_PROCESSES_URI);
super.init(http);
AuthorizationGrantTokenExchanger<OAuth2AuthorizationCodeGrantRequest> authorizationCodeTokenExchanger =
@ -282,16 +288,14 @@ public final class OAuth2LoginConfigurer<B extends HttpSecurityBuilder<B>> exten
}
http.addFilter(this.postProcess(authorizationRequestFilter));
OAuth2LoginAuthenticationFilter authorizationResponseFilter = this.getAuthenticationFilter();
OAuth2LoginAuthenticationFilter authenticationFilter = this.getAuthenticationFilter();
if (this.redirectionEndpointConfig.authorizationResponseBaseUri != null) {
authorizationResponseFilter.setFilterProcessesUrl(this.redirectionEndpointConfig.authorizationResponseBaseUri);
authenticationFilter.setFilterProcessesUrl(this.redirectionEndpointConfig.authorizationResponseBaseUri);
}
authorizationResponseFilter.setClientRegistrationRepository(this.getClientRegistrationRepository());
if (this.authorizationEndpointConfig.authorizationRequestRepository != null) {
authorizationResponseFilter.setAuthorizationRequestRepository(
authenticationFilter.setAuthorizationRequestRepository(
this.authorizationEndpointConfig.authorizationRequestRepository);
}
authorizationResponseFilter.setAuthorizedClientService(this.getAuthorizedClientService());
super.configure(http);
}

View File

@ -85,19 +85,19 @@ public class OAuth2LoginAuthenticationFilter extends AbstractAuthenticationProce
private AuthorizationRequestRepository<OAuth2AuthorizationRequest> authorizationRequestRepository =
new HttpSessionOAuth2AuthorizationRequestRepository();
public OAuth2LoginAuthenticationFilter() {
this(DEFAULT_FILTER_PROCESSES_URI);
public OAuth2LoginAuthenticationFilter(ClientRegistrationRepository clientRegistrationRepository,
OAuth2AuthorizedClientService<OAuth2AuthorizedClient> authorizedClientService) {
this(DEFAULT_FILTER_PROCESSES_URI, clientRegistrationRepository, authorizedClientService);
}
public OAuth2LoginAuthenticationFilter(String filterProcessesUrl) {
public OAuth2LoginAuthenticationFilter(String filterProcessesUrl,
ClientRegistrationRepository clientRegistrationRepository,
OAuth2AuthorizedClientService<OAuth2AuthorizedClient> authorizedClientService) {
super(filterProcessesUrl);
}
@Override
public void afterPropertiesSet() {
super.afterPropertiesSet();
Assert.notNull(this.clientRegistrationRepository, "clientRegistrationRepository cannot be null");
Assert.notNull(this.authorizedClientService, "authorizedClientService cannot be null");
Assert.notNull(clientRegistrationRepository, "clientRegistrationRepository cannot be null");
Assert.notNull(authorizedClientService, "authorizedClientService cannot be null");
this.clientRegistrationRepository = clientRegistrationRepository;
this.authorizedClientService = authorizedClientService;
}
@Override
@ -143,16 +143,6 @@ public class OAuth2LoginAuthenticationFilter extends AbstractAuthenticationProce
return oauth2Authentication;
}
public final void setClientRegistrationRepository(ClientRegistrationRepository clientRegistrationRepository) {
Assert.notNull(clientRegistrationRepository, "clientRegistrationRepository cannot be null");
this.clientRegistrationRepository = clientRegistrationRepository;
}
public final void setAuthorizedClientService(OAuth2AuthorizedClientService<OAuth2AuthorizedClient> authorizedClientService) {
Assert.notNull(authorizedClientService, "authorizedClientService cannot be null");
this.authorizedClientService = authorizedClientService;
}
public final void setAuthorizationRequestRepository(AuthorizationRequestRepository<OAuth2AuthorizationRequest> authorizationRequestRepository) {
Assert.notNull(authorizationRequestRepository, "authorizationRequestRepository cannot be null");
this.authorizationRequestRepository = authorizationRequestRepository;

View File

@ -188,10 +188,9 @@ public class OAuth2LoginAuthenticationFilterTests {
ClientRegistrationRepository clientRegistrationRepository = TestUtil.clientRegistrationRepository(clientRegistrations);
OAuth2LoginAuthenticationFilter filter = new OAuth2LoginAuthenticationFilter();
filter.setClientRegistrationRepository(clientRegistrationRepository);
OAuth2LoginAuthenticationFilter filter = new OAuth2LoginAuthenticationFilter(
clientRegistrationRepository, mock(OAuth2AuthorizedClientService.class));
filter.setAuthenticationManager(authenticationManager);
filter.setAuthorizedClientService(mock(OAuth2AuthorizedClientService.class));
return filter;
}