use of com.enonic.xp.security.UpdateUserParams in project xp by enonic.
the class ModifyProfileHandlerTest method keep_original_value_types_when_not_touched.
@Test
public void keep_original_value_types_when_not_touched() {
final User user = TestDataFixtures.getTestUserWithProfile();
Mockito.when(securityService.getUser(Mockito.any())).thenReturn(Optional.of(user));
Mockito.when(this.securityService.updateUser(Mockito.isA(UpdateUserParams.class))).thenAnswer(invocationOnMock -> {
final User editedUser = invokeUpdate((UpdateUserParams) invocationOnMock.getArguments()[0], user);
final PropertySet profile = editedUser.getProfile().getSet("myApp");
assertTrue(profile.getProperty("untouchedString").getType().equals(ValueTypes.STRING));
assertTrue(profile.getProperty("untouchedBoolean").getType().equals(ValueTypes.BOOLEAN));
assertTrue(profile.getProperty("untouchedDouble").getType().equals(ValueTypes.DOUBLE));
assertTrue(profile.getProperty("untouchedLong").getType().equals(ValueTypes.LONG));
assertTrue(profile.getProperty("untouchedLink").getType().equals(ValueTypes.LINK));
assertTrue(profile.getProperty("untouchedInstant").getType().equals(ValueTypes.DATE_TIME));
assertTrue(profile.getProperty("untouchedGeoPoint").getType().equals(ValueTypes.GEO_POINT));
assertTrue(profile.getProperty("untouchedLocalDate").getType().equals(ValueTypes.LOCAL_DATE));
assertTrue(profile.getProperty("untouchedReference").getType().equals(ValueTypes.REFERENCE));
assertTrue(profile.getProperty("untouchedBinaryRef").getType().equals(ValueTypes.BINARY_REFERENCE));
return editedUser;
});
runScript("/test/modifyProfile-test.js");
}
use of com.enonic.xp.security.UpdateUserParams in project xp by enonic.
the class SecurityServiceImplTest method testUpdateUserDuplicatedEmailWithEditor.
@Test
public void testUpdateUserDuplicatedEmailWithEditor() {
try {
runAsAdmin(() -> {
final PrincipalKey userKey1 = PrincipalKey.ofUser(SYSTEM, "User1");
final CreateUserParams createUser1 = CreateUserParams.create().userKey(userKey1).displayName("User 1").email("same_email@enonic.com").login("User1").password("123456").build();
final PrincipalKey userKey2 = PrincipalKey.ofUser(SYSTEM, "user2");
final CreateUserParams createUser2 = CreateUserParams.create().userKey(userKey2).displayName("User 2").email("same_email@enonic.com").login("user2").build();
final User user1 = securityService.createUser(createUser1);
securityService.createUser(createUser2);
final UpdateUserParams updateUserParams = UpdateUserParams.create(user1).editor(editableUser -> editableUser.email = "same_email@enonic.com").build();
securityService.updateUser(updateUserParams);
refresh();
});
fail("Expected exception");
} catch (IllegalArgumentException e) {
assertEquals("A user with email 'same_email@enonic.com' already exists in id provider 'system'", e.getMessage());
}
}
use of com.enonic.xp.security.UpdateUserParams in project xp by enonic.
the class SecurityServiceImplTest method testUpdateUserDuplicatedEmail.
@Test
public void testUpdateUserDuplicatedEmail() {
try {
runAsAdmin(() -> {
final PrincipalKey userKey1 = PrincipalKey.ofUser(SYSTEM, "User1");
final CreateUserParams createUser1 = CreateUserParams.create().userKey(userKey1).displayName("User 1").email("same_email@enonic.com").login("User1").password("123456").build();
final PrincipalKey userKey2 = PrincipalKey.ofUser(SYSTEM, "user2");
final CreateUserParams createUser2 = CreateUserParams.create().userKey(userKey2).displayName("User 2").email("same_email@enonic.com").login("user2").build();
final User user1 = securityService.createUser(createUser1);
securityService.createUser(createUser2);
final UpdateUserParams updateUserParams = UpdateUserParams.create(user1).email("same_email@enonic.com").build();
securityService.updateUser(updateUserParams);
refresh();
});
fail("Expected exception");
} catch (IllegalArgumentException e) {
assertEquals("A user with email 'same_email@enonic.com' already exists in id provider 'system'", e.getMessage());
}
}
use of com.enonic.xp.security.UpdateUserParams in project xp by enonic.
the class SecurityServiceImplTest method testUpdateUser.
@Test
public void testUpdateUser() throws Exception {
runAsAdmin(() -> {
final CreateUserParams createUser = CreateUserParams.create().userKey(PrincipalKey.ofUser(SYSTEM, "User1")).displayName("User 1").email("user1@enonic.com").login("User1").build();
final User user = securityService.createUser(createUser);
refresh();
final UpdateUserParams updateUserParams = UpdateUserParams.create(user).email("u2@enonic.net").build();
final User updateUserResult = securityService.updateUser(updateUserParams);
refresh();
final User updatedUser = securityService.getUser(user.getKey()).get();
assertEquals("u2@enonic.net", updateUserResult.getEmail());
assertEquals("u2@enonic.net", updatedUser.getEmail());
assertEquals("User1", updatedUser.getLogin());
assertEquals("User 1", updatedUser.getDisplayName());
assertEquals(PrincipalKey.ofUser(SYSTEM, "User1"), updatedUser.getKey());
});
}
use of com.enonic.xp.security.UpdateUserParams in project xp by enonic.
the class ModifyProfileHandler method execute.
public PropertyTreeMapper execute() {
final Optional<User> user = this.securityService.get().getUser(this.key);
if (user.isPresent()) {
final UpdateUserParams params = UpdateUserParams.create().userKey(this.key).editor(this::newProfileEditor).build();
final User updatedUser = this.securityService.get().updateUser(params);
final PropertyTree updatedProfile = updatedUser.getProfile();
return createPropertyTreeMapper(updatedProfile, false);
}
return null;
}
Aggregations