Search in sources :

Example 1 with Principals

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

the class SecurityServiceImpl method query.

@Override
public UserQueryResult query(final UserQuery query) {
    try {
        final NodeQuery nodeQueryBuilder = UserQueryNodeQueryTranslator.translate(query);
        final FindNodesByQueryResult result = callWithContext(() -> this.nodeService.findByQuery(nodeQueryBuilder));
        final Nodes nodes = callWithContext(() -> this.nodeService.getByIds(result.getNodeIds()));
        final Principals principals = PrincipalNodeTranslator.fromNodes(nodes);
        return UserQueryResult.create().addUsers(principals).totalSize(Ints.checkedCast(result.getTotalHits())).build();
    } catch (NodeNotFoundException e) {
        return UserQueryResult.create().build();
    }
}
Also used : NodeNotFoundException(com.enonic.xp.node.NodeNotFoundException) Principals(com.enonic.xp.security.Principals) FindNodesByQueryResult(com.enonic.xp.node.FindNodesByQueryResult) NodeQuery(com.enonic.xp.node.NodeQuery) Nodes(com.enonic.xp.node.Nodes)

Example 2 with Principals

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

the class SecurityServiceImpl method query.

@Override
public PrincipalQueryResult query(final PrincipalQuery query) {
    try {
        final NodeQuery nodeQueryBuilder = PrincipalQueryNodeQueryTranslator.translate(query);
        final FindNodesByQueryResult result = callWithContext(() -> this.nodeService.findByQuery(nodeQueryBuilder));
        final Nodes nodes = callWithContext(() -> this.nodeService.getByIds(result.getNodeIds()));
        final Principals principals = PrincipalNodeTranslator.fromNodes(nodes);
        return PrincipalQueryResult.create().addPrincipals(principals).totalSize(Ints.checkedCast(result.getTotalHits())).build();
    } catch (NodeNotFoundException e) {
        return PrincipalQueryResult.create().build();
    }
}
Also used : NodeNotFoundException(com.enonic.xp.node.NodeNotFoundException) Principals(com.enonic.xp.security.Principals) FindNodesByQueryResult(com.enonic.xp.node.FindNodesByQueryResult) NodeQuery(com.enonic.xp.node.NodeQuery) Nodes(com.enonic.xp.node.Nodes)

Example 3 with Principals

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

the class AclFilterBuilderFactoryTest method testName.

@Test
public void testName() throws Exception {
    final Principals principals = Principals.from(User.create().email("rmy@enonic.com").login("rmy").displayName("Runar Myklebust").key(PrincipalKey.from("user:system:rmy")).build(), Group.create().key(PrincipalKey.from("group:system:mygroup")).displayName("My group").build());
    final Filter filter = AclFilterBuilderFactory.create(principals.getKeys());
    assertTrue(filter instanceof ValueFilter);
    ValueFilter valueFilter = (ValueFilter) filter;
    assertEquals(2, valueFilter.getValues().size());
}
Also used : Principals(com.enonic.xp.security.Principals) ValueFilter(com.enonic.xp.query.filter.ValueFilter) Filter(com.enonic.xp.query.filter.Filter) ValueFilter(com.enonic.xp.query.filter.ValueFilter) Test(org.junit.jupiter.api.Test)

Example 4 with Principals

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

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

Aggregations

Principals (com.enonic.xp.security.Principals)5 FindNodesByQueryResult (com.enonic.xp.node.FindNodesByQueryResult)2 NodeNotFoundException (com.enonic.xp.node.NodeNotFoundException)2 NodeQuery (com.enonic.xp.node.NodeQuery)2 Nodes (com.enonic.xp.node.Nodes)2 PrincipalKeys (com.enonic.xp.security.PrincipalKeys)2 Filter (com.enonic.xp.query.filter.Filter)1 ValueFilter (com.enonic.xp.query.filter.ValueFilter)1 PrincipalKey (com.enonic.xp.security.PrincipalKey)1 PrincipalRelationship (com.enonic.xp.security.PrincipalRelationship)1 PrincipalRelationships (com.enonic.xp.security.PrincipalRelationships)1 Test (org.junit.jupiter.api.Test)1