use of com.enonic.xp.security.CreateGroupParams 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.CreateGroupParams in project xp by enonic.
the class SecurityServiceImplTest method testAddRelationship.
@Test
public void testAddRelationship() 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);
PrincipalRelationship membership = PrincipalRelationship.from(groupKey1).to(userKey1);
PrincipalRelationship membership2 = PrincipalRelationship.from(groupKey1).to(userKey2);
// exercise
securityService.addRelationship(membership);
securityService.addRelationship(membership2);
securityService.addRelationship(membership);
refresh();
// verify
final PrincipalRelationships relationships = securityService.getRelationships(groupKey1);
assertEquals(2, relationships.getSize());
assertEquals(membership, relationships.get(0));
assertEquals(membership2, relationships.get(1));
});
}
Aggregations