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();
}
}
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();
}
}
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());
}
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());
}
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());
}
Aggregations