use of com.enonic.xp.security.CreateUserParams in project xp by enonic.
the class SecurityServiceImplTest method testAuthenticateByEmailPwd.
@Test
public void testAuthenticateByEmailPwd() throws Exception {
runAsAdmin(() -> {
final CreateUserParams createUser = CreateUserParams.create().userKey(PrincipalKey.ofUser(SYSTEM, "User1")).displayName("User 1").email("user1@enonic.com").login("User1").password("password").build();
final User user = securityService.createUser(createUser);
refresh();
final EmailPasswordAuthToken authToken = new EmailPasswordAuthToken();
authToken.setEmail("user1@enonic.com");
authToken.setPassword("password");
authToken.setIdProvider(SYSTEM);
final AuthenticationInfo authInfo = securityService.authenticate(authToken);
assertTrue(authInfo.isAuthenticated());
assertEquals(user.getKey(), authInfo.getUser().getKey());
});
}
use of com.enonic.xp.security.CreateUserParams in project xp by enonic.
the class SecurityServiceImplTest method testDeletePrincipalWithoutPermissions.
@Test
public void testDeletePrincipalWithoutPermissions() throws Exception {
final CreateUserParams createUser = CreateUserParams.create().userKey(PrincipalKey.ofUser(SYSTEM, "User1")).displayName("User 1").email("user1@enonic.com").login("User1").build();
runAsAdmin(() -> {
securityService.createUser(createUser);
refresh();
});
assertThrows(PrincipalNotFoundException.class, () -> securityService.deletePrincipal(createUser.getKey()));
}
use of com.enonic.xp.security.CreateUserParams in project xp by enonic.
the class SecurityServiceImplTest method testGetUserMemberships.
@Test
public void testGetUserMemberships() throws Exception {
runAsAdmin(() -> {
final PrincipalKey userKey = PrincipalKey.ofUser(SYSTEM, "User1");
final CreateUserParams createUser = CreateUserParams.create().userKey(userKey).displayName("User 1").email("user1@enonic.com").login("User1").password("123456").build();
final PrincipalKey groupKey1 = PrincipalKey.ofGroup(SYSTEM, "Group-a");
final CreateGroupParams createGroup1 = CreateGroupParams.create().groupKey(groupKey1).displayName("Group A").build();
final PrincipalKey groupKey2 = PrincipalKey.ofGroup(SYSTEM, "group-b");
final CreateGroupParams createGroup2 = CreateGroupParams.create().groupKey(groupKey2).displayName("Group B").build();
securityService.createUser(createUser);
securityService.createGroup(createGroup1);
securityService.createGroup(createGroup2);
securityService.addRelationship(PrincipalRelationship.from(groupKey1).to(userKey));
securityService.addRelationship(PrincipalRelationship.from(groupKey2).to(userKey));
refresh();
final PrincipalKeys memberships = securityService.getMemberships(userKey);
assertTrue(memberships.contains(groupKey1));
assertTrue(memberships.contains(groupKey2));
assertEquals(2, memberships.getSize());
});
}
use of com.enonic.xp.security.CreateUserParams 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.CreateUserParams in project xp by enonic.
the class SecurityServiceImplTest method testAuthenticateByUsernamePwd.
@Test
public void testAuthenticateByUsernamePwd() throws Exception {
runAsAdmin(() -> {
final CreateUserParams createUser = CreateUserParams.create().userKey(PrincipalKey.ofUser(SYSTEM, "User1")).displayName("User 1").email("user1@enonic.com").login("User1").password("runar").build();
final User user = securityService.createUser(createUser);
refresh();
final UsernamePasswordAuthToken authToken = new UsernamePasswordAuthToken();
authToken.setUsername("User1");
authToken.setPassword("runar");
authToken.setIdProvider(SYSTEM);
final AuthenticationInfo authInfo = securityService.authenticate(authToken);
assertTrue(authInfo.isAuthenticated());
assertEquals(user.getKey(), authInfo.getUser().getKey());
});
}
Aggregations