public void throwIfNotValid() { if (!valid()) { throw new PasswordConfirmationException(getMessageCode(), getEmail()); } }
@RequestMapping(value = {"/.well-known/openid-configuration", "/oauth/token/.well-known/openid-configuration"}) public ResponseEntity<OpenIdConfiguration> getOpenIdConfiguration(HttpServletRequest request) throws URISyntaxException { OpenIdConfiguration conf = new OpenIdConfiguration(getServerContextPath(request), getTokenEndpoint()); return new ResponseEntity<>(conf, OK); }
@Override public String[] getParameterValues(String name) { return getParameterMap().get(name); } };
@Test(expected = BadCredentialsException.class) public void changePasswordFailsForUserIfTheySupplyWrongCurrentPassword() { endpoints.setSecurityContextAccessor(mockSecurityContext(joel)); PasswordChangeRequest change = new PasswordChangeRequest(); change.setPassword("newpassword"); change.setOldPassword("wrongpassword"); endpoints.changePassword(joel.getId(), change); }
@Test public void test_happy_day_password_reset_with_redirect() throws Exception { reset(service); resetPasswordResponse = new ResetPasswordService.ResetPasswordResponse(user, "http://test.com", null); when(service.resetPassword(any(ExpiringCode.class), eq(password))).thenReturn(resetPasswordResponse); happy_day_password_reset(resetPasswordResponse.getRedirectUri()); }
@Test public void test_happy_day_password_reset_with_home_redirect() throws Exception { reset(service); resetPasswordResponse = new ResetPasswordService.ResetPasswordResponse(user, "home", null); when(service.resetPassword(any(ExpiringCode.class), eq(password))).thenReturn(resetPasswordResponse); happy_day_password_reset(""); }
@Test public void test_happy_day_password_reset() throws Exception { happy_day_password_reset(resetPasswordResponse.getRedirectUri()); }
@Bean AccountsController accountsController(AccountCreationService accountCreationService, IdentityProviderProvisioning identityProviderProvisioning) { return new AccountsController(accountCreationService, identityProviderProvisioning); } }
private EmailAccountCreationService initEmailAccountCreationService() { return new EmailAccountCreationService( templateEngine, messageService, codeStore, scimUserProvisioning, clientDetailsService, passwordValidator ); }
public UserInfoEndpointTests() { endpoint.setUserDatabase(userDatabase); }
@Override public ResetPasswordResponse resetPassword(ExpiringCode code, String newPassword) { passwordValidator.validate(newPassword); return changePasswordCodeAuthenticated(code, newPassword); }
@Bean ResetPasswordController resetPasswordController(ResetPasswordService resetPasswordService, MessageService messageService, TemplateEngine mailTemplateEngine, ExpiringCodeStore codeStore, UaaUserDatabase userDatabase) { ResetPasswordController controller = new ResetPasswordController(resetPasswordService, messageService, mailTemplateEngine, codeStore, userDatabase); return controller; } }
@Test public void userCanChangeTheirOwnPasswordIfTheySupplyCorrectCurrentPassword() { endpoints.setSecurityContextAccessor(mockSecurityContext(joel)); PasswordChangeRequest change = new PasswordChangeRequest(); change.setOldPassword("password"); change.setPassword("newpassword"); endpoints.changePassword(joel.getId(), change); }
@Test public void test_happy_day_password_reset_with_null_redirect() throws Exception { reset(service); resetPasswordResponse = new ResetPasswordService.ResetPasswordResponse(user, null, null); when(service.resetPassword(any(ExpiringCode.class), eq(password))).thenReturn(resetPasswordResponse); happy_day_password_reset(resetPasswordResponse.getRedirectUri()); }
@Test(expected = ScimException.class) public void userCantChangeAnotherUsersPassword() { endpoints.setSecurityContextAccessor(mockSecurityContext(joel)); PasswordChangeRequest change = new PasswordChangeRequest(); change.setOldPassword("password"); change.setPassword("newpassword"); endpoints.changePassword(dale.getId(), change); }
@Test(expected = ScimException.class) public void changePasswordRequestFailsForUserWithoutCurrentPassword() { endpoints.setSecurityContextAccessor(mockSecurityContext(joel)); PasswordChangeRequest change = new PasswordChangeRequest(); change.setPassword("newpassword"); endpoints.changePassword(joel.getId(), change); }
@Test(expected = ScimException.class) public void changePasswordRequestFailsForAdminWithoutOwnCurrentPassword() { endpoints.setSecurityContextAccessor(mockSecurityContext(joel)); PasswordChangeRequest change = new PasswordChangeRequest(); change.setPassword("newpassword"); endpoints.changePassword(joel.getId(), change); }
@Test public void passwordIsValidated() throws Exception { endpoints.setSecurityContextAccessor(mockSecurityContext(joel)); PasswordValidator mockPasswordValidator = mock(PasswordValidator.class); endpoints.setPasswordValidator(mockPasswordValidator); PasswordChangeRequest change = new PasswordChangeRequest(); change.setOldPassword("password"); change.setPassword("newpassword"); endpoints.changePassword(joel.getId(), change); verify(mockPasswordValidator).validate("newpassword"); }
@Test public void clientCanChangeUserPasswordWithoutCurrentPassword() { SecurityContextAccessor sca = mockSecurityContext(joel); when(sca.isClient()).thenReturn(true); endpoints.setSecurityContextAccessor(sca); PasswordChangeRequest change = new PasswordChangeRequest(); change.setPassword("newpassword"); endpoints.changePassword(joel.getId(), change); }
@Test public void changePasswordFailsForNewPasswordIsSameAsCurrentPassword() { endpoints.setSecurityContextAccessor(mockSecurityContext(joel)); PasswordChangeRequest change = new PasswordChangeRequest(); change.setPassword("password"); change.setOldPassword("password"); try { endpoints.changePassword(joel.getId(), change); fail(); } catch (InvalidPasswordException e) { assertEquals("Your new password cannot be the same as the old password.", e.getLocalizedMessage()); } }