Search in sources :

Example 76 with PrincipalKey

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

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

the class SetPermissionsHandler method validPrincipals.

private boolean validPrincipals() {
    boolean valid = true;
    for (PrincipalKey principal : permissions.getAllPrincipals()) {
        if (!principalExists(principal)) {
            LOG.warn("Principal not found: " + principal);
            valid = false;
        }
    }
    return valid;
}
Also used : PrincipalKey(com.enonic.xp.security.PrincipalKey)

Example 78 with PrincipalKey

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

the class ContextMapper method serializePrincipals.

private void serializePrincipals(final MapGenerator gen, final PrincipalKeys keys) {
    if (keys == null) {
        return;
    }
    gen.array("principals");
    for (final PrincipalKey key : keys) {
        gen.value(key.toString());
    }
    gen.end();
}
Also used : PrincipalKey(com.enonic.xp.security.PrincipalKey)

Example 79 with PrincipalKey

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

the class ServiceHandlerTest method testForbiddenService.

@Test
public void testForbiddenService() throws Exception {
    final DescriptorKey serviceDescriptorKey = DescriptorKey.from("demo:test");
    final Set<PrincipalKey> allowedPrincipals = Collections.singleton(PrincipalKey.from("role:system.admin"));
    final ServiceDescriptor serviceDescriptor = ServiceDescriptor.create().key(serviceDescriptorKey).setAllowedPrincipals(allowedPrincipals).build();
    Mockito.when(this.serviceDescriptorService.getByKey(serviceDescriptorKey)).thenReturn(serviceDescriptor);
    this.request.setEndpointPath("/_/service/demo/test");
    boolean forbiddenErrorThrown = false;
    try {
        this.handler.handle(this.request, PortalResponse.create().build(), null);
    } catch (WebException e) {
        if (HttpStatus.UNAUTHORIZED == e.getStatus()) {
            forbiddenErrorThrown = true;
        }
    }
    assertTrue(forbiddenErrorThrown);
}
Also used : WebException(com.enonic.xp.web.WebException) ServiceDescriptor(com.enonic.xp.service.ServiceDescriptor) DescriptorKey(com.enonic.xp.page.DescriptorKey) PrincipalKey(com.enonic.xp.security.PrincipalKey) BaseHandlerTest(com.enonic.xp.web.handler.BaseHandlerTest) Test(org.junit.jupiter.api.Test)

Aggregations

PrincipalKey (com.enonic.xp.security.PrincipalKey)79 Test (org.junit.jupiter.api.Test)47 PropertyTree (com.enonic.xp.data.PropertyTree)21 AbstractElasticsearchIntegrationTest (com.enonic.xp.repo.impl.elasticsearch.AbstractElasticsearchIntegrationTest)15 User (com.enonic.xp.security.User)15 CreateUserParams (com.enonic.xp.security.CreateUserParams)12 PrincipalKeys (com.enonic.xp.security.PrincipalKeys)12 Instant (java.time.Instant)12 Node (com.enonic.xp.node.Node)10 DescriptorKey (com.enonic.xp.page.DescriptorKey)10 CreateGroupParams (com.enonic.xp.security.CreateGroupParams)8 PrincipalRelationship (com.enonic.xp.security.PrincipalRelationship)8 Context (com.enonic.xp.context.Context)7 NodeId (com.enonic.xp.node.NodeId)7 NodeQuery (com.enonic.xp.node.NodeQuery)7 ScheduledJob (com.enonic.xp.scheduler.ScheduledJob)7 IdProviderKey (com.enonic.xp.security.IdProviderKey)7 Group (com.enonic.xp.security.Group)6 AccessControlList (com.enonic.xp.security.acl.AccessControlList)6 AuthenticationInfo (com.enonic.xp.security.auth.AuthenticationInfo)6