use of com.enonic.xp.security.CreateRoleParams in project xp by enonic.
the class SecurityServiceImplTest method testUpdateRole.
@Test
public void testUpdateRole() throws Exception {
runAsAdmin(() -> {
final CreateRoleParams createRole = CreateRoleParams.create().roleKey(PrincipalKey.ofRole("Role-a")).displayName("Role A").build();
final Role role = securityService.createRole(createRole);
final UpdateRoleParams roleUpdate = UpdateRoleParams.create(role).displayName("___Role B___").description("description").build();
final Role updatedRoleResult = securityService.updateRole(roleUpdate);
refresh();
final Role updatedRole = securityService.getRole(role.getKey()).get();
assertEquals("___Role B___", updatedRoleResult.getDisplayName());
assertEquals("___Role B___", updatedRole.getDisplayName());
assertEquals("description", updatedRoleResult.getDescription());
assertEquals("description", updatedRole.getDescription());
});
}
use of com.enonic.xp.security.CreateRoleParams in project xp by enonic.
the class SecurityInitializer method createRoles.
private void createRoles() {
final CreateRoleParams createAdministratorRole = CreateRoleParams.create().roleKey(RoleKeys.ADMIN).displayName("Administrator").build();
addRole(createAdministratorRole);
final CreateRoleParams createAuthenticatedRole = CreateRoleParams.create().roleKey(RoleKeys.AUTHENTICATED).displayName("Authenticated").build();
addRole(createAuthenticatedRole);
final CreateRoleParams createEveryoneRole = CreateRoleParams.create().roleKey(RoleKeys.EVERYONE).displayName("Everyone").build();
addRole(createEveryoneRole);
final CreateRoleParams createAdminLoginRole = CreateRoleParams.create().roleKey(RoleKeys.ADMIN_LOGIN).displayName("Administration Console Login").build();
addRole(createAdminLoginRole);
final CreateRoleParams createUserManagerAppRole = CreateRoleParams.create().roleKey(RoleKeys.USER_MANAGER_APP).displayName("Users App").build();
addRole(createUserManagerAppRole);
final CreateRoleParams createUserManager = CreateRoleParams.create().roleKey(RoleKeys.USER_MANAGER_ADMIN).displayName("Users Administrator").build();
addRole(createUserManager);
final CreateRoleParams createContentManagerAppRole = CreateRoleParams.create().roleKey(RoleKeys.CONTENT_MANAGER_APP).displayName("Content Manager App").build();
addRole(createContentManagerAppRole);
final CreateRoleParams createContentManagerExpert = CreateRoleParams.create().roleKey(RoleKeys.CONTENT_MANAGER_EXPERT).displayName("Content Manager Expert").build();
addRole(createContentManagerExpert);
final CreateRoleParams createContentManager = CreateRoleParams.create().roleKey(RoleKeys.CONTENT_MANAGER_ADMIN).displayName("Content Manager Administrator").build();
addRole(createContentManager);
final CreateRoleParams createAuditLogRole = CreateRoleParams.create().roleKey(RoleKeys.AUDIT_LOG).displayName("Audit Log").build();
addRole(createAuditLogRole);
}
use of com.enonic.xp.security.CreateRoleParams 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.CreateRoleParams 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());
});
}
Aggregations