@Test public void getAllowUpdateLogin() { when(request.getCookies()).thenReturn(new Cookie[] {new Cookie(AUTHENTICATION_COOKIE_NAME, "{\"allowUpdateLogin\":\"true\"}")}); Optional<Boolean> allowLoginUpdate = underTest.getAllowUpdateLogin(request); assertThat(allowLoginUpdate).isNotEmpty(); assertThat(allowLoginUpdate.get()).isTrue(); }
@Test public void getAllowUpdateLogin_is_empty_when_no_value() { when(request.getCookies()).thenReturn(new Cookie[] {new Cookie(AUTHENTICATION_COOKIE_NAME, "{}")}); Optional<Boolean> allowLoginUpdate = underTest.getAllowUpdateLogin(request); assertThat(allowLoginUpdate).isEmpty(); }
@Test public void getAllowUpdateLogin_is_empty_when_no_cookie() { when(request.getCookies()).thenReturn(new Cookie[] {}); Optional<Boolean> allowLoginUpdate = underTest.getAllowUpdateLogin(request); assertThat(allowLoginUpdate).isEmpty(); }
@Test public void authenticate_with_allow_login_update() { when(oAuthParameters.getAllowUpdateLogin(request)).thenReturn(Optional.of(true)); OAuth2IdentityProvider.CallbackContext callback = newCallbackContext(); callback.authenticate(USER_IDENTITY); assertThat(userIdentityAuthenticator.isAuthenticated()).isTrue(); assertThat(userIdentityAuthenticator.getAuthenticatorParameters().getUpdateLoginStrategy()).isEqualTo(UpdateLoginStrategy.ALLOW); }
@Test public void authenticate_without_allowing_login_update() { when(oAuthParameters.getAllowUpdateLogin(request)).thenReturn(Optional.of(false)); OAuth2IdentityProvider.CallbackContext callback = newCallbackContext(); callback.authenticate(USER_IDENTITY); assertThat(userIdentityAuthenticator.isAuthenticated()).isTrue(); assertThat(userIdentityAuthenticator.getAuthenticatorParameters().getUpdateLoginStrategy()).isEqualTo(UpdateLoginStrategy.WARN); }
@Override public void authenticate(UserIdentity userIdentity) { Boolean allowEmailShift = oAuthParameters.getAllowEmailShift(request).orElse(false); Boolean allowUpdateLogin = oAuthParameters.getAllowUpdateLogin(request).orElse(false); UserDto userDto = userRegistrar.register( UserRegistration.builder() .setUserIdentity(userIdentity) .setProvider(identityProvider) .setSource(AuthenticationEvent.Source.oauth2(identityProvider)) .setExistingEmailStrategy(allowEmailShift ? ExistingEmailStrategy.ALLOW : ExistingEmailStrategy.WARN) .setUpdateLoginStrategy(allowUpdateLogin ? UpdateLoginStrategy.ALLOW : UpdateLoginStrategy.WARN) .build()); jwtHttpHandler.generateToken(userDto, request, response); threadLocalUserSession.set(userSessionFactory.create(userDto)); } }
@Override public void authenticate(UserIdentity userIdentity) { Boolean allowEmailShift = oAuthParameters.getAllowEmailShift(request).orElse(false); Boolean allowUpdateLogin = oAuthParameters.getAllowUpdateLogin(request).orElse(false); UserDto userDto = userIdentityAuthenticator.authenticate( UserIdentityAuthenticatorParameters.builder() .setUserIdentity(userIdentity) .setProvider(identityProvider) .setSource(AuthenticationEvent.Source.oauth2(identityProvider)) .setExistingEmailStrategy(allowEmailShift ? ExistingEmailStrategy.ALLOW : ExistingEmailStrategy.WARN) .setUpdateLoginStrategy(allowUpdateLogin ? UpdateLoginStrategy.ALLOW : UpdateLoginStrategy.WARN) .build()); jwtHttpHandler.generateToken(userDto, request, response); threadLocalUserSession.set(userSessionFactory.create(userDto)); } }