Search in sources :

Example 1 with CreateRoleParams

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());
    });
}
Also used : CreateRoleParams(com.enonic.xp.security.CreateRoleParams) Role(com.enonic.xp.security.Role) UpdateRoleParams(com.enonic.xp.security.UpdateRoleParams) AbstractElasticsearchIntegrationTest(com.enonic.xp.repo.impl.elasticsearch.AbstractElasticsearchIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 2 with CreateRoleParams

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);
}
Also used : CreateRoleParams(com.enonic.xp.security.CreateRoleParams)

Example 3 with CreateRoleParams

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());
    });
}
Also used : CreateRoleParams(com.enonic.xp.security.CreateRoleParams) CreateUserParams(com.enonic.xp.security.CreateUserParams) CreateGroupParams(com.enonic.xp.security.CreateGroupParams) PrincipalKeys(com.enonic.xp.security.PrincipalKeys) PrincipalKey(com.enonic.xp.security.PrincipalKey) AbstractElasticsearchIntegrationTest(com.enonic.xp.repo.impl.elasticsearch.AbstractElasticsearchIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 4 with CreateRoleParams

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());
    });
}
Also used : CreateRoleParams(com.enonic.xp.security.CreateRoleParams) Role(com.enonic.xp.security.Role) PrincipalKey(com.enonic.xp.security.PrincipalKey) AbstractElasticsearchIntegrationTest(com.enonic.xp.repo.impl.elasticsearch.AbstractElasticsearchIntegrationTest) Test(org.junit.jupiter.api.Test)

Aggregations

CreateRoleParams (com.enonic.xp.security.CreateRoleParams)4 AbstractElasticsearchIntegrationTest (com.enonic.xp.repo.impl.elasticsearch.AbstractElasticsearchIntegrationTest)3 Test (org.junit.jupiter.api.Test)3 PrincipalKey (com.enonic.xp.security.PrincipalKey)2 Role (com.enonic.xp.security.Role)2 CreateGroupParams (com.enonic.xp.security.CreateGroupParams)1 CreateUserParams (com.enonic.xp.security.CreateUserParams)1 PrincipalKeys (com.enonic.xp.security.PrincipalKeys)1 UpdateRoleParams (com.enonic.xp.security.UpdateRoleParams)1