@Override public Mono<Authentication> authenticate(Authentication authentication) { return Mono.defer(() -> { OAuth2AuthorizationCodeAuthenticationToken token = (OAuth2AuthorizationCodeAuthenticationToken) authentication; OAuth2AuthorizationExchangeValidator.validate(token.getAuthorizationExchange()); OAuth2AuthorizationCodeGrantRequest authzRequest = new OAuth2AuthorizationCodeGrantRequest( token.getClientRegistration(), token.getAuthorizationExchange()); return this.accessTokenResponseClient.getTokenResponse(authzRequest) .map(onSuccess(token)); }); }
public OAuth2LoginReactiveAuthenticationManager( ReactiveOAuth2AccessTokenResponseClient<OAuth2AuthorizationCodeGrantRequest> accessTokenResponseClient, ReactiveOAuth2UserService<OAuth2UserRequest, OAuth2User> userService) { Assert.notNull(accessTokenResponseClient, "accessTokenResponseClient cannot be null"); Assert.notNull(userService, "userService cannot be null"); this.authorizationCodeManager = new OAuth2AuthorizationCodeReactiveAuthenticationManager(accessTokenResponseClient); this.userService = userService; }
public OAuth2AuthorizationCodeAuthenticationToken(ClientRegistration clientRegistration, OAuth2AuthorizationExchange authorizationExchange, OAuth2AccessToken accessToken, OAuth2RefreshToken refreshToken, Map<String, Object> additionalParameters) { this(clientRegistration, authorizationExchange); Assert.notNull(accessToken, "accessToken cannot be null"); this.accessToken = accessToken; this.refreshToken = refreshToken; this.setAuthenticated(true); this.additionalParameters.putAll(additionalParameters); }
private Function<OAuth2AccessTokenResponse, OAuth2AuthorizationCodeAuthenticationToken> onSuccess(OAuth2AuthorizationCodeAuthenticationToken token) { return accessTokenResponse -> { ClientRegistration registration = token.getClientRegistration(); OAuth2AuthorizationExchange exchange = token.getAuthorizationExchange(); OAuth2AccessToken accessToken = accessTokenResponse.getAccessToken(); OAuth2RefreshToken refreshToken = accessTokenResponse.getRefreshToken(); return new OAuth2AuthorizationCodeAuthenticationToken(registration, exchange, accessToken, refreshToken, accessTokenResponse.getAdditionalParameters()); }; } }
@Test(expected = IllegalArgumentException.class) public void constructorTokenRequestResponseWhenPrincipalIsNullThenThrowIllegalArgumentException() { new OAuth2LoginAuthenticationToken(this.clientRegistration, this.authorizationExchange, null, this.authorities, this.accessToken); }
@Test public void constructorWhenAuthoritiesIsNullThenCreated() { new OAuth2AuthenticationToken(this.principal, null, this.authorizedClientRegistrationId); }
@Before public void setup() { this.manager = new OAuth2LoginReactiveAuthenticationManager(this.accessTokenResponseClient, this.userService); }
@Test public void constructorWhenAccessTokenResponseClientIsNullThenThrowIllegalArgumentException() { this.exception.expect(IllegalArgumentException.class); new OAuth2LoginAuthenticationProvider(null, this.userService); }
@Test public void setAuthoritiesMapperWhenAuthoritiesMapperIsNullThenThrowIllegalArgumentException() { this.exception.expect(IllegalArgumentException.class); this.authenticationProvider.setAuthoritiesMapper(null); }
@Test(expected = IllegalArgumentException.class) public void constructorTokenRequestResponseWhenAuthorizationExchangeIsNullThenThrowIllegalArgumentException() { new OAuth2LoginAuthenticationToken(this.clientRegistration, null, this.principal, this.authorities, this.accessToken); }
/** * Gets the {@link ReactiveAuthenticationManager} to use. First tries an explicitly configured manager, and * defaults to {@link OAuth2AuthorizationCodeReactiveAuthenticationManager} * * @return the {@link ReactiveAuthenticationManager} to use */ private ReactiveAuthenticationManager getAuthenticationManager() { if (this.authenticationManager == null) { this.authenticationManager = new OAuth2AuthorizationCodeReactiveAuthenticationManager(new WebClientReactiveAuthorizationCodeTokenResponseClient()); } return this.authenticationManager; }
@Test(expected = IllegalArgumentException.class) public void constructorWhenPrincipalIsNullThenThrowIllegalArgumentException() { new OAuth2AuthenticationToken(null, this.authorities, this.authorizedClientRegistrationId); }
@Test(expected = IllegalArgumentException.class) public void constructorTokenRequestResponseWhenClientRegistrationIsNullThenThrowIllegalArgumentException() { new OAuth2LoginAuthenticationToken(null, this.authorizationExchange, this.principal, this.authorities, this.accessToken); }
@Before public void setup() { this.manager = new OAuth2AuthorizationCodeReactiveAuthenticationManager(this.accessTokenResponseClient); }
@Test(expected = IllegalArgumentException.class) public void constructorWhenAuthorizedClientRegistrationIdIsNullThenThrowIllegalArgumentException() { new OAuth2AuthenticationToken(this.principal, this.authorities, null); }
@Test(expected = IllegalArgumentException.class) public void constructorAuthorizationRequestResponseWhenClientRegistrationIsNullThenThrowIllegalArgumentException() { new OAuth2LoginAuthenticationToken(null, this.authorizationExchange); }
@Test(expected = IllegalArgumentException.class) public void constructorAuthorizationRequestResponseWhenAuthorizationExchangeIsNullThenThrowIllegalArgumentException() { new OAuth2LoginAuthenticationToken(this.clientRegistration, null); }
@Test public void constructorTokenRequestResponseWhenAuthoritiesIsNullThenCreated() { new OAuth2LoginAuthenticationToken(this.clientRegistration, this.authorizationExchange, this.principal, null, this.accessToken); }
@Test(expected = IllegalArgumentException.class) public void constructorTokenRequestResponseWhenAccessTokenIsNullThenThrowIllegalArgumentException() { new OAuth2LoginAuthenticationToken(this.clientRegistration, this.authorizationExchange, this.principal, this.authorities, null); }
@Test public void constructorTokenRequestResponseWhenAuthoritiesIsEmptyThenCreated() { new OAuth2LoginAuthenticationToken(this.clientRegistration, this.authorizationExchange, this.principal, Collections.emptyList(), this.accessToken); }