Search in sources :

Example 21 with PrincipalKeys

use of com.enonic.xp.security.PrincipalKeys 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 22 with PrincipalKeys

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

the class GetMembershipsHandlerTest method testGetUserMemberships.

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

Example 23 with PrincipalKeys

use of com.enonic.xp.security.PrincipalKeys 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

PrincipalKeys (com.enonic.xp.security.PrincipalKeys)23 PrincipalKey (com.enonic.xp.security.PrincipalKey)10 Test (org.junit.jupiter.api.Test)10 Group (com.enonic.xp.security.Group)7 PrincipalRelationships (com.enonic.xp.security.PrincipalRelationships)4 ControllerScript (com.enonic.xp.portal.controller.ControllerScript)3 CreateGroupParams (com.enonic.xp.security.CreateGroupParams)3 CreateUserParams (com.enonic.xp.security.CreateUserParams)3 PrincipalRelationship (com.enonic.xp.security.PrincipalRelationship)3 AdminToolDescriptor (com.enonic.xp.admin.tool.AdminToolDescriptor)2 PropertyTree (com.enonic.xp.data.PropertyTree)2 NodeQuery (com.enonic.xp.node.NodeQuery)2 UpdateNodeParams (com.enonic.xp.node.UpdateNodeParams)2 ResourceKey (com.enonic.xp.resource.ResourceKey)2 Principals (com.enonic.xp.security.Principals)2 Role (com.enonic.xp.security.Role)2 User (com.enonic.xp.security.User)2 AccessControlList (com.enonic.xp.security.acl.AccessControlList)2 IdProviderAccessControlList (com.enonic.xp.security.acl.IdProviderAccessControlList)2 AdminToolDescriptors (com.enonic.xp.admin.tool.AdminToolDescriptors)1