use of org.cloudfoundry.identity.uaa.scim.exception.InvalidPasswordException in project uaa by cloudfoundry.
the class UaaChangePasswordServiceTest method testChangePasswordWithInvalidNewPassword.
@Test(expected = InvalidPasswordException.class)
public void testChangePasswordWithInvalidNewPassword() {
doThrow(new InvalidPasswordException("")).when(passwordValidator).validate("invPawd");
subject.changePassword("username", "currentPassword", "invPawd");
}
use of org.cloudfoundry.identity.uaa.scim.exception.InvalidPasswordException in project uaa by cloudfoundry.
the class UaaResetPasswordServiceTests method resetPassword_ForcedChange_NewPasswordSameAsOld.
@Test
void resetPassword_ForcedChange_NewPasswordSameAsOld() {
String userId = "user-id";
ScimUser user = new ScimUser(userId, "username", "firstname", "lastname");
user.setMeta(new ScimMeta(new Date(), new Date(), 0));
user.setPrimaryEmail("foo@example.com");
when(scimUserProvisioning.retrieve(userId, currentZoneId)).thenReturn(user);
when(scimUserProvisioning.checkPasswordMatches("user-id", "password", currentZoneId)).thenThrow(new InvalidPasswordException("Your new password cannot be the same as the old password.", UNPROCESSABLE_ENTITY));
assertThrows(InvalidPasswordException.class, () -> uaaResetPasswordService.resetUserPassword(userId, "password"));
}
use of org.cloudfoundry.identity.uaa.scim.exception.InvalidPasswordException in project uaa by cloudfoundry.
the class UaaResetPasswordServiceTests method resetPassword_forcedChange_must_verify_password_policy.
@Test
void resetPassword_forcedChange_must_verify_password_policy() {
String userId = "user-id";
ScimUser user = new ScimUser(userId, "username", "firstname", "lastname");
user.setMeta(new ScimMeta(new Date(), new Date(), 0));
user.setPrimaryEmail("foo@example.com");
when(scimUserProvisioning.retrieve(userId, currentZoneId)).thenReturn(user);
doThrow(new InvalidPasswordException("Password cannot contain whitespace characters.")).when(passwordValidator).validate("new password");
assertThrowsWithMessageThat(InvalidPasswordException.class, () -> uaaResetPasswordService.resetUserPassword(userId, "new password"), containsString("Password cannot contain whitespace characters."));
}
use of org.cloudfoundry.identity.uaa.scim.exception.InvalidPasswordException in project uaa by cloudfoundry.
the class ScimUserEndpointsTests method setUpAfterSeeding.
void setUpAfterSeeding(final IdentityZone identityZone) {
this.identityZone = identityZone;
identityZoneManager.setCurrentIdentityZone(this.identityZone);
this.identityZone.getConfig().getUserConfig().setDefaultGroups(Collections.singletonList("uaa.user"));
this.mockApprovalStore = mock(ApprovalStore.class);
jdbcScimUserProvisioning.setQueryConverter(filterConverter);
mockJdbcIdentityProviderProvisioning = mock(JdbcIdentityProviderProvisioning.class);
mockJdbcUserGoogleMfaCredentialsProvisioning = mock(JdbcUserGoogleMfaCredentialsProvisioning.class);
mockPasswordValidator = mock(PasswordValidator.class);
ApplicationEventPublisher mockApplicationEventPublisher = mock(ApplicationEventPublisher.class);
doThrow(new InvalidPasswordException("Password must be at least 1 characters in length.")).when(mockPasswordValidator).validate(null);
doThrow(new InvalidPasswordException("Password must be at least 1 characters in length.")).when(mockPasswordValidator).validate(eq(""));
jdbcScimGroupProvisioning.createOrGet(new ScimGroup(null, "uaa.user", identityZone.getId()), identityZone.getId());
joel = jdbcScimUserProvisioning.createUser(joel, "password", identityZone.getId());
dale = jdbcScimUserProvisioning.createUser(dale, "password", identityZone.getId());
spiedScimGroupMembershipManager = spy(scimGroupMembershipManager);
scimUserEndpoints = new ScimUserEndpoints(new IdentityZoneManagerImpl(), new IsSelfCheck(null), jdbcScimUserProvisioning, mockJdbcIdentityProviderProvisioning, null, statuses, mockPasswordValidator, null, mockJdbcUserGoogleMfaCredentialsProvisioning, mockApprovalStore, spiedScimGroupMembershipManager, 5);
}
use of org.cloudfoundry.identity.uaa.scim.exception.InvalidPasswordException in project uaa by cloudfoundry.
the class ChangePasswordController method changePassword.
@RequestMapping(value = "/change_password.do", method = POST)
public String changePassword(Model model, @RequestParam("current_password") String currentPassword, @RequestParam("new_password") String newPassword, @RequestParam("confirm_password") String confirmPassword, HttpServletResponse response, HttpServletRequest request) {
PasswordConfirmationValidation validation = new PasswordConfirmationValidation(newPassword, confirmPassword);
if (!validation.valid()) {
model.addAttribute("message_code", validation.getMessageCode());
response.setStatus(HttpStatus.UNPROCESSABLE_ENTITY.value());
return "change_password";
}
SecurityContext securityContext = SecurityContextHolder.getContext();
Authentication authentication = securityContext.getAuthentication();
String username = authentication.getName();
try {
changePasswordService.changePassword(username, currentPassword, newPassword);
request.getSession().invalidate();
request.getSession(true);
if (authentication instanceof UaaAuthentication) {
UaaAuthentication uaaAuthentication = (UaaAuthentication) authentication;
uaaAuthentication.setAuthenticatedTime(System.currentTimeMillis());
uaaAuthentication.setAuthenticationDetails(new UaaAuthenticationDetails(request));
}
securityContext.setAuthentication(authentication);
return "redirect:profile";
} catch (BadCredentialsException e) {
model.addAttribute("message_code", "unauthorized");
} catch (InvalidPasswordException e) {
model.addAttribute("message", e.getMessagesAsOneString());
}
response.setStatus(HttpStatus.UNPROCESSABLE_ENTITY.value());
return "change_password";
}
Aggregations