use of com.enonic.xp.security.PrincipalKey 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.PrincipalKey in project xp by enonic.
the class SecurityServiceImplTest method testCreateRole.
@Test
public void testCreateRole() throws Exception {
runAsAdmin(() -> {
final PrincipalKey roleKey1 = PrincipalKey.ofRole("Role-a");
final CreateRoleParams createRole = CreateRoleParams.create().roleKey(roleKey1).displayName("Role A").description("Group A Description").build();
final PrincipalKey roleKey2 = PrincipalKey.ofRole("role-b");
final CreateRoleParams createRole2 = CreateRoleParams.create().roleKey(roleKey2).displayName("Role B").build();
final Role role1 = securityService.createRole(createRole);
final Role role2 = securityService.createRole(createRole2);
final Role createdRole1 = securityService.getRole(roleKey1).get();
final Role createdRole2 = securityService.getRole(roleKey2).get();
assertEquals("Role A", role1.getDisplayName());
assertEquals("Role A", createdRole1.getDisplayName());
assertEquals("Group A Description", role1.getDescription());
assertEquals("Group A Description", createdRole1.getDescription());
assertEquals("Role B", role2.getDisplayName());
assertEquals("Role B", createdRole2.getDisplayName());
assertNull(role2.getDescription());
assertNull(createdRole2.getDescription());
});
}
use of com.enonic.xp.security.PrincipalKey in project xp by enonic.
the class SecurityServiceImplTest method testRemoveAllRelationships.
@Test
public void testRemoveAllRelationships() 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.removeRelationships(groupKey1);
refresh();
// verify
final PrincipalRelationships relationships = securityService.getRelationships(groupKey1);
assertEquals(0, relationships.getSize());
});
}
use of com.enonic.xp.security.PrincipalKey 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.PrincipalKey in project xp by enonic.
the class SecurityServiceImplTest method testCreateUser.
@Test
public void testCreateUser() 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();
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 User user1 = securityService.createUser(createUser1);
final User user2 = securityService.createUser(createUser2);
refresh();
final User createdUser1 = securityService.getUser(userKey1).get();
final User createdUser2 = securityService.getUser(userKey2).get();
assertEquals("User 1", user1.getDisplayName());
assertEquals("user1@enonic.com", user1.getEmail());
assertEquals("User1", user1.getLogin());
assertEquals("User 1", createdUser1.getDisplayName());
assertEquals("user1@enonic.com", createdUser1.getEmail());
assertEquals("User1", createdUser1.getLogin());
assertEquals("User 2", user2.getDisplayName());
assertEquals("user2@enonic.com", user2.getEmail());
assertEquals("user2", user2.getLogin());
assertEquals("User 2", createdUser2.getDisplayName());
assertEquals("user2@enonic.com", createdUser2.getEmail());
assertEquals("user2", createdUser2.getLogin());
});
}
Aggregations