Search in sources :

Example 6 with Role

use of com.enonic.xp.security.Role in project xp by enonic.

the class ModifyRoleHandlerTest method invokeUpdate.

private Role invokeUpdate(final UpdateRoleParams params) {
    final RoleEditor editor = params.getEditor();
    assertNotNull(editor);
    final Role role = TestDataFixtures.getTestRole();
    final EditableRole editable = new EditableRole(role);
    editor.edit(editable);
    return editable.build();
}
Also used : Role(com.enonic.xp.security.Role) EditableRole(com.enonic.xp.security.EditableRole) RoleEditor(com.enonic.xp.security.RoleEditor) EditableRole(com.enonic.xp.security.EditableRole)

Example 7 with Role

use of com.enonic.xp.security.Role in project xp by enonic.

the class GetMembershipsHandlerTest method testExamples.

@Test
public void testExamples() {
    final Role role = TestDataFixtures.getTestRole();
    final Group group = TestDataFixtures.getTestGroup();
    final PrincipalKeys principalKeys = PrincipalKeys.from(role.getKey(), group.getKey());
    Mockito.when(securityService.getMemberships(PrincipalKey.from("user:myIdProvider:userId"))).thenReturn(principalKeys);
    Mockito.when(securityService.getPrincipals(principalKeys)).thenReturn(Principals.from(role, group));
    runScript("/lib/xp/examples/auth/getMemberships.js");
}
Also used : Role(com.enonic.xp.security.Role) Group(com.enonic.xp.security.Group) PrincipalKeys(com.enonic.xp.security.PrincipalKeys) Test(org.junit.jupiter.api.Test)

Example 8 with Role

use of com.enonic.xp.security.Role in project xp by enonic.

the class GetMembershipsHandlerTest method testGetUserMembershipsWithRoleAndGroup.

@Test
public void testGetUserMembershipsWithRoleAndGroup() {
    final Role role = TestDataFixtures.getTestRole();
    final Group group = TestDataFixtures.getTestGroup();
    final PrincipalKeys principalKeys = PrincipalKeys.from(role.getKey(), group.getKey());
    Mockito.when(securityService.getMemberships(PrincipalKey.from("user:myIdProvider:userId"))).thenReturn(principalKeys);
    Mockito.when(securityService.getPrincipals(principalKeys)).thenReturn(Principals.from(role, group));
    runFunction("/test/getMemberships-test.js", "getUserMembershipsWithRoleAndGroup");
}
Also used : Role(com.enonic.xp.security.Role) Group(com.enonic.xp.security.Group) PrincipalKeys(com.enonic.xp.security.PrincipalKeys) Test(org.junit.jupiter.api.Test)

Aggregations

Role (com.enonic.xp.security.Role)8 Test (org.junit.jupiter.api.Test)4 Node (com.enonic.xp.node.Node)2 AbstractElasticsearchIntegrationTest (com.enonic.xp.repo.impl.elasticsearch.AbstractElasticsearchIntegrationTest)2 CreateRoleParams (com.enonic.xp.security.CreateRoleParams)2 Group (com.enonic.xp.security.Group)2 PrincipalKey (com.enonic.xp.security.PrincipalKey)2 PrincipalKeys (com.enonic.xp.security.PrincipalKeys)2 UpdateRoleParams (com.enonic.xp.security.UpdateRoleParams)2 CreateNodeParams (com.enonic.xp.node.CreateNodeParams)1 NodeAlreadyExistAtPathException (com.enonic.xp.node.NodeAlreadyExistAtPathException)1 NodeIdExistsException (com.enonic.xp.node.NodeIdExistsException)1 UpdateNodeParams (com.enonic.xp.node.UpdateNodeParams)1 ProjectRole (com.enonic.xp.project.ProjectRole)1 EditableRole (com.enonic.xp.security.EditableRole)1 PrincipalAlreadyExistsException (com.enonic.xp.security.PrincipalAlreadyExistsException)1 PrincipalNotFoundException (com.enonic.xp.security.PrincipalNotFoundException)1 RoleEditor (com.enonic.xp.security.RoleEditor)1 Preconditions (com.google.common.base.Preconditions)1