Search in sources :

Example 16 with PrincipalKeys

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

the class IssueQueryNodeQueryTranslator method translate.

public static NodeQuery translate(final IssueQuery issueQuery) {
    final NodeQuery.Builder builder = NodeQuery.create();
    final ValueFilter issueCollectionFilter = ValueFilter.create().fieldName(NodeIndexPath.NODE_TYPE.getPath()).addValue(ValueFactory.newString(IssueConstants.ISSUE_NODE_COLLECTION.getName())).build();
    if (issueQuery.isCount()) {
        builder.searchMode(SearchMode.COUNT);
    }
    builder.from(issueQuery.getFrom()).size(issueQuery.getSize()).addQueryFilter(issueCollectionFilter);
    final PrincipalKey creator = issueQuery.getCreator();
    if (creator != null) {
        builder.addQueryFilter(ValueFilter.create().fieldName(CREATOR).addValues(creator.toString()).build());
    }
    final PrincipalKeys approvers = issueQuery.getApprovers();
    if (approvers != null && approvers.isNotEmpty()) {
        builder.addQueryFilter(ValueFilter.create().fieldName(APPROVERS).addValues(approvers.stream().map(PrincipalKey::toString).collect(toList())).build());
    }
    final ContentIds items = issueQuery.getItems();
    if (items != null && items.isNotEmpty()) {
        builder.addQueryFilter(ValueFilter.create().fieldName(PUBLISH_REQUEST_ITEM_ID).addValues(items.stream().map(ContentId::toString).collect(toList())).build());
    }
    final IssueStatus status = issueQuery.getStatus();
    if (status != null) {
        builder.addQueryFilter(ValueFilter.create().fieldName(STATUS).addValues(status.toString()).build());
    }
    final IssueType type = issueQuery.getType();
    if (type != null) {
        final Filter isOfType = ValueFilter.create().fieldName(TYPE).addValues(type.toString()).build();
        if (type == IssueType.STANDARD) {
            final Filter notExists = BooleanFilter.create().mustNot(ExistsFilter.create().fieldName(TYPE).build()).build();
            final Filter isStandard = BooleanFilter.create().should(isOfType).should(notExists).build();
            builder.addQueryFilter(isStandard);
        } else {
            builder.addQueryFilter(isOfType);
        }
    }
    builder.setOrderExpressions(IssueConstants.DEFAULT_CHILD_ORDER.getOrderExpressions());
    return builder.build();
}
Also used : PrincipalKeys(com.enonic.xp.security.PrincipalKeys) ExistsFilter(com.enonic.xp.query.filter.ExistsFilter) ValueFilter(com.enonic.xp.query.filter.ValueFilter) BooleanFilter(com.enonic.xp.query.filter.BooleanFilter) Filter(com.enonic.xp.query.filter.Filter) IssueType(com.enonic.xp.issue.IssueType) NodeQuery(com.enonic.xp.node.NodeQuery) ContentIds(com.enonic.xp.content.ContentIds) ValueFilter(com.enonic.xp.query.filter.ValueFilter) ContentId(com.enonic.xp.content.ContentId) PrincipalKey(com.enonic.xp.security.PrincipalKey) IssueStatus(com.enonic.xp.issue.IssueStatus)

Example 17 with PrincipalKeys

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

the class GetMembershipsHandler method getMemberships.

public List<PrincipalMapper> getMemberships() {
    final PrincipalKeys principalKeys;
    if (transitive) {
        principalKeys = this.securityService.get().getAllMemberships(this.principalKey);
    } else {
        principalKeys = this.securityService.get().getMemberships(this.principalKey);
    }
    final Principals principals = this.securityService.get().getPrincipals(principalKeys);
    return principals.stream().map(PrincipalMapper::new).collect(Collectors.toList());
}
Also used : PrincipalKeys(com.enonic.xp.security.PrincipalKeys) Principals(com.enonic.xp.security.Principals)

Example 18 with PrincipalKeys

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

the class GetMembersHandler method getMembers.

public List<PrincipalMapper> getMembers() {
    final PrincipalRelationships relationships = this.securityService.get().getRelationships(this.principalKey);
    final PrincipalKeys principalKeys = PrincipalKeys.from(relationships.stream().map(PrincipalRelationship::getTo).toArray(PrincipalKey[]::new));
    final Principals principals = this.securityService.get().getPrincipals(principalKeys);
    return principals.stream().map(PrincipalMapper::new).collect(Collectors.toList());
}
Also used : PrincipalKeys(com.enonic.xp.security.PrincipalKeys) PrincipalRelationship(com.enonic.xp.security.PrincipalRelationship) Principals(com.enonic.xp.security.Principals) PrincipalKey(com.enonic.xp.security.PrincipalKey) PrincipalRelationships(com.enonic.xp.security.PrincipalRelationships)

Example 19 with PrincipalKeys

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

the class GetMembersHandlerTest method testGetMembers.

@Test
public void testGetMembers() {
    final Group group = TestDataFixtures.getTestGroup();
    final User user1 = TestDataFixtures.getTestUser();
    final User user2 = TestDataFixtures.getTestUser2();
    final PrincipalKeys principalKeys = PrincipalKeys.from(user1.getKey(), user2.getKey());
    final PrincipalRelationships relationships = PrincipalRelationships.from(PrincipalRelationship.from(group.getKey()).to(user1.getKey()), PrincipalRelationship.from(group.getKey()).to(user2.getKey()));
    Mockito.when(securityService.getRelationships(group.getKey())).thenReturn(relationships);
    Mockito.when(securityService.getPrincipals(principalKeys)).thenReturn(Principals.from(user1, user2));
    runFunction("/test/getMembers-test.js", "getMembers");
}
Also used : Group(com.enonic.xp.security.Group) User(com.enonic.xp.security.User) PrincipalKeys(com.enonic.xp.security.PrincipalKeys) PrincipalRelationships(com.enonic.xp.security.PrincipalRelationships) Test(org.junit.jupiter.api.Test)

Example 20 with PrincipalKeys

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

the class GetMembersHandlerTest method testExamples.

@Test
public void testExamples() {
    final Group group = TestDataFixtures.getTestGroup();
    final User user1 = TestDataFixtures.getTestUser();
    final User user2 = TestDataFixtures.getTestUser2();
    final PrincipalKeys principalKeys = PrincipalKeys.from(user1.getKey(), user2.getKey());
    final PrincipalRelationships relationships = PrincipalRelationships.from(PrincipalRelationship.from(group.getKey()).to(user1.getKey()), PrincipalRelationship.from(group.getKey()).to(user2.getKey()));
    Mockito.when(securityService.getRelationships(group.getKey())).thenReturn(relationships);
    Mockito.when(securityService.getPrincipals(principalKeys)).thenReturn(Principals.from(user1, user2));
    runScript("/lib/xp/examples/auth/getMembers.js");
}
Also used : Group(com.enonic.xp.security.Group) User(com.enonic.xp.security.User) PrincipalKeys(com.enonic.xp.security.PrincipalKeys) PrincipalRelationships(com.enonic.xp.security.PrincipalRelationships) 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