private ReactiveAuthenticationManager authenticationManager() { OidcAuthorizationCodeReactiveAuthenticationManager oidc = new OidcAuthorizationCodeReactiveAuthenticationManager(tokenResponseClient, userService); oidc.setJwtDecoderFactory(jwtDecoderFactory()); return oidc; }
@Before public void setup() { this.manager = new OidcAuthorizationCodeReactiveAuthenticationManager(this.accessTokenResponseClient, this.userService); }
@Before public void setUp() { this.idTokenDecoderFactory = new ReactiveOidcIdTokenDecoderFactory(); }
@Test public void constructorWhenUserServiceIsNullThenThrowIllegalArgumentException() { this.exception.expect(IllegalArgumentException.class); new OidcAuthorizationCodeAuthenticationProvider(this.accessTokenResponseClient, null); }
@Test public void setAuthoritiesMapperWhenAuthoritiesMapperIsNullThenThrowIllegalArgumentException() { this.exception.expect(IllegalArgumentException.class); this.authenticationProvider.setAuthoritiesMapper(null); }
private Collection<OAuth2Error> validateIdToken() { Jwt idToken = new Jwt("token123", this.issuedAt, this.expiresAt, this.headers, this.claims); OidcIdTokenValidator validator = new OidcIdTokenValidator(this.registration.build()); validator.setClockSkew(this.clockSkew); return validator.validate(idToken).getErrors(); } }
@Test public void setJwtDecoderFactoryWhenNullThenIllegalArgumentException() { assertThatThrownBy(() -> this.manager.setJwtDecoderFactory(null)) .isInstanceOf(IllegalArgumentException.class); }
@Test public void authenticationWhenStateDoesNotMatchThenOAuth2AuthenticationException() { this.authorizationResponseBldr.state("notmatch"); assertThatThrownBy(() -> this.manager.authenticate(loginToken()).block()) .isInstanceOf(OAuth2AuthenticationException.class); }
@Test public void setJwtDecoderFactoryWhenNullThenThrowIllegalArgumentException() { this.exception.expect(IllegalArgumentException.class); this.authenticationProvider.setJwtDecoderFactory(null); }
@Before public void setUp() { this.idTokenDecoderFactory = new OidcIdTokenDecoderFactory(); }
@Test public void setJwtValidatorFactoryWhenNullThenThrowIllegalArgumentException() { assertThatThrownBy(() -> this.idTokenDecoderFactory.setJwtValidatorFactory(null)) .isInstanceOf(IllegalArgumentException.class); }
@Test public void createDecoderWhenClientRegistrationNullThenThrowIllegalArgumentException() { assertThatThrownBy(() -> this.idTokenDecoderFactory.createDecoder(null)) .isInstanceOf(IllegalArgumentException.class); }
@Test public void createDecoderWhenClientRegistrationNullThenThrowIllegalArgumentException() { assertThatThrownBy(() -> this.idTokenDecoderFactory.createDecoder(null)) .isInstanceOf(IllegalArgumentException.class); }
@Test public void setJwtValidatorFactoryWhenNullThenThrowIllegalArgumentException() { assertThatThrownBy(() -> this.idTokenDecoderFactory.setJwtValidatorFactory(null)) .isInstanceOf(IllegalArgumentException.class); }
@Test public void supportsWhenTypeOAuth2LoginAuthenticationTokenThenReturnTrue() { assertThat(this.authenticationProvider.supports(OAuth2LoginAuthenticationToken.class)).isTrue(); }
private void setUpIdToken(Map<String, Object> claims) { Instant issuedAt = Instant.now(); Instant expiresAt = Instant.from(issuedAt).plusSeconds(3600); this.setUpIdToken(claims, issuedAt, expiresAt); }
@Test public void constructorWhenNullUserServiceThenIllegalArgumentException() { this.userService = null; assertThatThrownBy(() -> new OidcAuthorizationCodeReactiveAuthenticationManager(this.accessTokenResponseClient, this.userService)) .isInstanceOf(IllegalArgumentException.class); }
@Test public void constructorWhenAccessTokenResponseClientIsNullThenThrowIllegalArgumentException() { this.exception.expect(IllegalArgumentException.class); new OidcAuthorizationCodeAuthenticationProvider(null, this.userService); }
@Test public void authenticationWhenNotOidcThenEmpty() { this.registration.scope("notopenid"); assertThat(this.manager.authenticate(loginToken()).block()).isNull(); }
@Test public void authenticationWhenErrorThenOAuth2AuthenticationException() { this.authorizationResponseBldr = OAuth2AuthorizationResponse .error("error") .state("state"); assertThatThrownBy(() -> this.manager.authenticate(loginToken()).block()) .isInstanceOf(OAuth2AuthenticationException.class); }