use of eu.bcvsolutions.idm.core.model.entity.IdmRoleGuaranteeRole in project CzechIdMng by bcvsolutions.
the class RoleGuaranteeEvaluator method getPredicate.
@Override
public Predicate getPredicate(Root<IdmRole> root, CriteriaQuery<?> query, CriteriaBuilder builder, AuthorizationPolicy policy, BasePermission... permission) {
AbstractAuthentication authentication = securityService.getAuthentication();
if (authentication == null || authentication.getCurrentIdentity() == null) {
return null;
}
//
if (hasPermission(policy, permission)) {
//
// by identity
Subquery<IdmRoleGuarantee> subquery = query.subquery(IdmRoleGuarantee.class);
Root<IdmRoleGuarantee> subRoot = subquery.from(IdmRoleGuarantee.class);
subquery.select(subRoot);
subquery.where(builder.and(// correlation attr
builder.equal(subRoot.get(IdmRoleGuarantee_.role), root), builder.equal(subRoot.get(IdmRoleGuarantee_.guarantee).get(AbstractEntity_.id), authentication.getCurrentIdentity().getId())));
//
// by role - currently logged identity has a role
Subquery<IdmRoleGuaranteeRole> subqueryGuaranteeRole = query.subquery(IdmRoleGuaranteeRole.class);
Root<IdmRoleGuaranteeRole> subRootGuaranteeRole = subqueryGuaranteeRole.from(IdmRoleGuaranteeRole.class);
subqueryGuaranteeRole.select(subRootGuaranteeRole);
//
// assigned roles
Subquery<IdmRole> subqueryIdentityRole = query.subquery(IdmRole.class);
Root<IdmIdentityRole> subrootIdentityRole = subqueryIdentityRole.from(IdmIdentityRole.class);
subqueryIdentityRole.select(subrootIdentityRole.get(IdmIdentityRole_.role));
final LocalDate today = LocalDate.now();
subqueryIdentityRole.where(builder.and(builder.equal(subrootIdentityRole.get(IdmIdentityRole_.identityContract).get(IdmIdentityContract_.identity).get(IdmIdentity_.id), authentication.getCurrentIdentity().getId()), RepositoryUtils.getValidPredicate(subrootIdentityRole, builder, today), RepositoryUtils.getValidPredicate(subrootIdentityRole.get(IdmIdentityRole_.identityContract), builder, today), builder.equal(subrootIdentityRole.get(IdmIdentityRole_.identityContract).get(IdmIdentityContract_.disabled), Boolean.FALSE)));
//
subqueryGuaranteeRole.where(builder.and(// correlation attr
builder.equal(subRootGuaranteeRole.get(IdmRoleGuaranteeRole_.role), root), subRootGuaranteeRole.get(IdmRoleGuaranteeRole_.guaranteeRole).in(subqueryIdentityRole)));
//
return builder.or(builder.exists(subquery), builder.exists(subqueryGuaranteeRole));
}
return null;
}
use of eu.bcvsolutions.idm.core.model.entity.IdmRoleGuaranteeRole in project CzechIdMng by bcvsolutions.
the class RoleByGuaranteeFilter method getPredicate.
@Override
public Predicate getPredicate(Root<IdmRole> root, AbstractQuery<?> query, CriteriaBuilder builder, IdmRoleFilter filter) {
UUID guaranteeId = filter.getGuaranteeId();
if (guaranteeId == null) {
return null;
}
// guarante by identity
Subquery<IdmRoleGuarantee> subquery = query.subquery(IdmRoleGuarantee.class);
Root<IdmRoleGuarantee> subRoot = subquery.from(IdmRoleGuarantee.class);
subquery.select(subRoot);
subquery.where(builder.and(// correlation attr
builder.equal(subRoot.get(IdmRoleGuarantee_.role), root), builder.equal(subRoot.get(IdmRoleGuarantee_.guarantee).get(IdmIdentity_.id), guaranteeId)));
// guarantee by role - identity has assigned role
Subquery<UUID> subqueryIdentityRole = query.subquery(UUID.class);
Root<IdmIdentityRole> subRootIdentityRole = subqueryIdentityRole.from(IdmIdentityRole.class);
subqueryIdentityRole.select(subRootIdentityRole.get(IdmIdentityRole_.role).get(IdmRole_.id));
subqueryIdentityRole.where(builder.and(builder.equal(subRootIdentityRole.get(IdmIdentityRole_.identityContract).get(IdmIdentityContract_.identity).get(IdmIdentity_.id), guaranteeId), RepositoryUtils.getValidPredicate(subRootIdentityRole, builder)));
//
Subquery<IdmRoleGuaranteeRole> subqueryRole = query.subquery(IdmRoleGuaranteeRole.class);
Root<IdmRoleGuaranteeRole> subRootRole = subqueryRole.from(IdmRoleGuaranteeRole.class);
subqueryRole.select(subRootRole);
subqueryRole.where(builder.and(// correlation attr
builder.equal(subRootRole.get(IdmRoleGuaranteeRole_.role), root), subRootRole.get(IdmRoleGuaranteeRole_.guaranteeRole).get(IdmRole_.id).in(subqueryIdentityRole)));
return builder.or(builder.exists(subquery), builder.exists(subqueryRole));
}
use of eu.bcvsolutions.idm.core.model.entity.IdmRoleGuaranteeRole in project CzechIdMng by bcvsolutions.
the class IdentityGuaranteesForRoleFilter method getPredicate.
@Override
public Predicate getPredicate(Root<IdmIdentity> root, AbstractQuery<?> query, CriteriaBuilder builder, IdmIdentityFilter filter) {
UUID guaranteesForRole = filter.getGuaranteesForRole();
if (guaranteesForRole == null) {
return null;
}
String guaranteeType = filter.getGuaranteeType();
// guarantee for role can be defined as identity
Subquery<IdmRoleGuarantee> subqueryIdentity = query.subquery(IdmRoleGuarantee.class);
Root<IdmRoleGuarantee> subRootIdentity = subqueryIdentity.from(IdmRoleGuarantee.class);
subqueryIdentity.select(subRootIdentity);
subqueryIdentity.where(StringUtils.isNotEmpty(guaranteeType) ? builder.and(builder.equal(subRootIdentity.get(IdmRoleGuarantee_.role).get(IdmRole_.id), guaranteesForRole), builder.equal(subRootIdentity.get(IdmRoleGuarantee_.type), guaranteeType), // corelation
builder.equal(subRootIdentity.get(IdmRoleGuarantee_.guarantee), root)) : builder.and(builder.equal(subRootIdentity.get(IdmRoleGuarantee_.role).get(IdmRole_.id), guaranteesForRole), // corelation
builder.equal(subRootIdentity.get(IdmRoleGuarantee_.guarantee), root)));
// guarantee for role can be defined as identity with role assigned
Subquery<UUID> subqueryRole = query.subquery(UUID.class);
Root<IdmRoleGuaranteeRole> subRootRole = subqueryRole.from(IdmRoleGuaranteeRole.class);
subqueryRole.select(subRootRole.get(IdmRoleGuaranteeRole_.guaranteeRole).get(IdmRole_.id));
subqueryRole.where(StringUtils.isNotEmpty(guaranteeType) ? builder.and(builder.equal(subRootRole.get(IdmRoleGuaranteeRole_.role).get(IdmRole_.id), guaranteesForRole), builder.equal(subRootRole.get(IdmRoleGuaranteeRole_.type), guaranteeType)) : builder.and(builder.equal(subRootRole.get(IdmRoleGuaranteeRole_.role).get(IdmRole_.id), guaranteesForRole)));
Subquery<UUID> subqueryIdentityRole = query.subquery(UUID.class);
Root<IdmIdentityRole> subRootIdentityRole = subqueryIdentityRole.from(IdmIdentityRole.class);
subqueryIdentityRole.select(subRootIdentityRole.get(IdmIdentityRole_.role).get(IdmRole_.id));
subqueryIdentityRole.where(builder.and(// correlation
builder.equal(subRootIdentityRole.get(IdmIdentityRole_.identityContract).get(IdmIdentityContract_.identity), root), RepositoryUtils.getValidPredicate(subRootIdentityRole, builder), subRootIdentityRole.get(IdmIdentityRole_.role).get(IdmRole_.id).in(subqueryRole)));
//
return builder.or(builder.exists(subqueryIdentity), builder.exists(subqueryIdentityRole));
}
Aggregations