use of org.cloudfoundry.identity.uaa.scim.ScimMeta 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.ScimMeta 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.ScimMeta in project uaa by cloudfoundry.
the class ScimGroupRowMapper method mapRow.
@Override
public ScimGroup mapRow(ResultSet rs, int rowNum) throws SQLException {
int pos = 1;
String id = rs.getString(pos++);
String name = rs.getString(pos++);
String description = rs.getString(pos++);
Date created = rs.getTimestamp(pos++);
Date modified = rs.getTimestamp(pos++);
int version = rs.getInt(pos++);
String zoneId = rs.getString(pos++);
ScimGroup group = new ScimGroup(id, name, zoneId);
group.setDescription(description);
ScimMeta meta = new ScimMeta(created, modified, version);
group.setMeta(meta);
return group;
}
use of org.cloudfoundry.identity.uaa.scim.ScimMeta in project uaa by cloudfoundry.
the class PasswordResetEndpointTest method changingAPasswordForUnverifiedUser.
@Test
void changingAPasswordForUnverifiedUser() throws Exception {
ExpiringCode code = new ExpiringCode("secret_code", new Timestamp(System.currentTimeMillis() + UaaResetPasswordService.PASSWORD_RESET_LIFETIME), "{\"user_id\":\"eyedee\",\"username\":\"user@example.com\",\"passwordModifiedTime\":null,\"client_id\":\"\",\"redirect_uri\":\"\"}", null);
when(mockExpiringCodeStore.retrieveCode("secret_code", currentZoneId)).thenReturn(code);
ScimUser scimUser = new ScimUser("eyedee", "user@example.com", "User", "Man");
scimUser.setMeta(new ScimMeta(new Date(System.currentTimeMillis() - (1000 * 60 * 60 * 24)), new Date(System.currentTimeMillis() - (1000 * 60 * 60 * 24)), 0));
scimUser.addEmail("user@example.com");
scimUser.setVerified(false);
when(mockScimUserProvisioning.retrieve("eyedee", currentZoneId)).thenReturn(scimUser);
ExpiringCode autologinCode = new ExpiringCode("autologin-code", new Timestamp(System.currentTimeMillis() + 5 * 60 * 1000), "data", AUTOLOGIN.name());
when(mockExpiringCodeStore.generateCode(anyString(), any(Timestamp.class), eq(AUTOLOGIN.name()), anyString())).thenReturn(autologinCode);
MockHttpServletRequestBuilder post = post("/password_change").contentType(APPLICATION_JSON).content("{\"code\":\"secret_code\",\"new_password\":\"new_secret\"}").accept(APPLICATION_JSON);
SecurityContextHolder.getContext().setAuthentication(new MockAuthentication());
mockMvc.perform(post).andExpect(status().isOk()).andExpect(jsonPath("$.user_id").value("eyedee")).andExpect(jsonPath("$.username").value("user@example.com"));
verify(mockScimUserProvisioning).changePassword("eyedee", null, "new_secret", currentZoneId);
verify(mockScimUserProvisioning).verifyUser(scimUser.getId(), -1, currentZoneId);
}
use of org.cloudfoundry.identity.uaa.scim.ScimMeta in project uaa by cloudfoundry.
the class PasswordResetEndpointTest method creatingAPasswordResetWithAUsernameContainingSpecialCharacters.
@Test
void creatingAPasswordResetWithAUsernameContainingSpecialCharacters() throws Exception {
ScimUser user = new ScimUser("id001", "user\"'@example.com", null, null);
user.setMeta(new ScimMeta(yesterday, yesterday, 0));
user.setPasswordLastModified(yesterday);
user.addEmail("user\"'@example.com");
when(mockScimUserProvisioning.retrieveByUsernameAndOriginAndZone(eq("user\"'@example.com"), eq(OriginKeys.UAA), eq(currentZoneId))).thenReturn(Collections.singletonList(user));
PasswordChange change = new PasswordChange("id001", "user\"'@example.com", yesterday, null, null);
when(mockExpiringCodeStore.generateCode(eq(JsonUtils.writeValueAsString(change)), any(Timestamp.class), anyString(), anyString())).thenReturn(new ExpiringCode("secret_code", new Timestamp(System.currentTimeMillis() + UaaResetPasswordService.PASSWORD_RESET_LIFETIME), JsonUtils.writeValueAsString(change), null));
MockHttpServletRequestBuilder post = post("/password_resets").contentType(APPLICATION_JSON).content("user\"'@example.com").accept(APPLICATION_JSON);
mockMvc.perform(post).andExpect(status().isCreated()).andExpect(content().string(containsString("\"code\":\"secret_code\""))).andExpect(content().string(containsString("\"user_id\":\"id001\"")));
when(mockScimUserProvisioning.retrieveByUsernameAndOriginAndZone(eq("user\"'@example.com"), eq(OriginKeys.UAA), eq(currentZoneId))).thenReturn(Collections.emptyList());
user.setOrigin(OriginKeys.LDAP);
when(mockScimUserProvisioning.retrieveByUsernameAndZone(eq("user\"'@example.com"), eq(currentZoneId))).thenReturn(Collections.singletonList(user));
post = post("/password_resets").contentType(APPLICATION_JSON).content("user\"'@example.com").accept(APPLICATION_JSON);
mockMvc.perform(post).andExpect(status().isConflict());
}
Aggregations