use of com.enonic.xp.security.CreateUserParams in project xp by enonic.
the class SecurityServiceImplTest method testGetAllMemberships.
@Test
public void testGetAllMemberships() 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();
final PrincipalKey roleKey1 = PrincipalKey.ofRole("role-a");
final CreateRoleParams createRole = CreateRoleParams.create().roleKey(roleKey1).displayName("Role A").description("Group A Description").build();
securityService.createUser(createUser);
securityService.createGroup(createGroup1);
securityService.createGroup(createGroup2);
securityService.createRole(createRole);
securityService.addRelationship(PrincipalRelationship.from(groupKey1).to(userKey));
securityService.addRelationship(PrincipalRelationship.from(groupKey2).to(groupKey1));
securityService.addRelationship(PrincipalRelationship.from(roleKey1).to(groupKey2));
refresh();
final PrincipalKeys memberships = securityService.getAllMemberships(userKey);
assertTrue(memberships.contains(groupKey1));
assertTrue(memberships.contains(groupKey2));
assertTrue(memberships.contains(roleKey1));
assertEquals(3, memberships.getSize());
});
}
use of com.enonic.xp.security.CreateUserParams in project xp by enonic.
the class SecurityServiceImplTest method testQuery.
@Test
public void testQuery() throws Exception {
runAsAdmin(() -> {
final PrincipalKey userKey1 = PrincipalKey.ofUser(SYSTEM, "User1");
final CreateUserParams createUser1 = CreateUserParams.create().userKey(userKey1).displayName("User 1").email("user1@enonic.com").login("User1").password("123456").build();
refresh();
final PrincipalQuery query = PrincipalQuery.create().idProvider(IdProviderKey.system()).build();
PrincipalQueryResult queryResult = securityService.query(query);
queryResult = securityService.query(query);
assertEquals(2, queryResult.getTotalSize());
final User user1 = securityService.createUser(createUser1);
refresh();
queryResult = securityService.query(query);
assertEquals(3, queryResult.getTotalSize());
assertEquals(user1, queryResult.getPrincipals().getPrincipal(userKey1));
});
}
use of com.enonic.xp.security.CreateUserParams in project xp by enonic.
the class SecurityServiceImplTest method testAuthenticateByEmailPwdWrongPwd.
@Test
public void testAuthenticateByEmailPwdWrongPwd() throws Exception {
runAsAdmin(() -> {
final CreateUserParams createUser = CreateUserParams.create().userKey(PrincipalKey.ofUser(SYSTEM, "User1")).displayName("User 1").email("user1@enonic.com").login("User1").password("fisk").build();
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);
assertFalse(authInfo.isAuthenticated());
});
}
use of com.enonic.xp.security.CreateUserParams in project xp by enonic.
the class SecurityServiceImplTest method testRemoveRelationship.
@Test
public void testRemoveRelationship() throws Exception {
runAsAdmin(() -> {
// set up
final PrincipalKey userKey1 = PrincipalKey.ofUser(SYSTEM, "User1");
final CreateUserParams createUser1 = CreateUserParams.create().userKey(userKey1).displayName("User 1").email("user1@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("user2@enonic.com").login("user2").build();
final PrincipalKey groupKey1 = PrincipalKey.ofGroup(SYSTEM, "Group-a");
final CreateGroupParams createGroup = CreateGroupParams.create().groupKey(groupKey1).displayName("Group A").build();
securityService.createUser(createUser1);
securityService.createUser(createUser2);
securityService.createGroup(createGroup);
refresh();
PrincipalRelationship membership = PrincipalRelationship.from(groupKey1).to(userKey1);
PrincipalRelationship membership2 = PrincipalRelationship.from(groupKey1).to(userKey2);
securityService.addRelationship(membership);
securityService.addRelationship(membership2);
refresh();
// exercise
securityService.removeRelationship(membership);
refresh();
// verify
final PrincipalRelationships relationships = securityService.getRelationships(groupKey1);
assertEquals(1, relationships.getSize());
assertEquals(membership2, relationships.get(0));
});
}
use of com.enonic.xp.security.CreateUserParams 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());
});
}
Aggregations