Search in sources :

Example 1 with VsSystemImplementer

use of eu.bcvsolutions.idm.vs.entity.VsSystemImplementer in project CzechIdMng by bcvsolutions.

the class VsRequestByImplementerEvaluator method getPredicate.

@Override
public Predicate getPredicate(Root<VsRequest> root, CriteriaQuery<?> query, CriteriaBuilder builder, AuthorizationPolicy policy, BasePermission... permission) {
    UUID currentId = securityService.getCurrentId();
    if (!hasAuthority(currentId, policy, permission) || !securityService.isAuthenticated()) {
        return null;
    }
    // Find all valid roles (includes check on contract validity)
    Set<UUID> roles = // 
    identityRoleService.findValidRole(currentId, null).getContent().stream().map(// 
    IdmIdentityRoleDto::getRole).collect(Collectors.toSet());
    if (roles.isEmpty()) {
        roles.add(UUID.randomUUID());
    }
    // System implementer subquery
    Subquery<VsSystemImplementer> subquery = query.subquery(VsSystemImplementer.class);
    Root<VsSystemImplementer> subRoot = subquery.from(VsSystemImplementer.class);
    subquery.select(subRoot);
    subquery.where(// 
    builder.and(// 
    builder.equal(root.get(VsRequest_.system), subRoot.get(VsSystemImplementer_.system)), // correlation attribute
    builder.or(builder.equal(subRoot.get(VsSystemImplementer_.identity).get(IdmIdentity_.id), currentId), subRoot.get(VsSystemImplementer_.role).get(IdmRole_.id).in(roles))));
    // 
    return builder.exists(subquery);
}
Also used : VsSystemImplementer(eu.bcvsolutions.idm.vs.entity.VsSystemImplementer) UUID(java.util.UUID)

Aggregations

VsSystemImplementer (eu.bcvsolutions.idm.vs.entity.VsSystemImplementer)1 UUID (java.util.UUID)1