Search in sources :

Example 1 with SysSystemGroupSystem

use of eu.bcvsolutions.idm.acc.entity.SysSystemGroupSystem in project CzechIdMng by bcvsolutions.

the class DefaultSysRoleSystemAttributeService method toPredicates.

@Override
protected List<Predicate> toPredicates(Root<SysRoleSystemAttribute> root, CriteriaQuery<?> query, CriteriaBuilder builder, SysRoleSystemAttributeFilter filter) {
    List<Predicate> predicates = super.toPredicates(root, query, builder, filter);
    if (filter.getRoleSystemId() != null) {
        predicates.add(builder.equal(root.get(SysRoleSystemAttribute_.roleSystem).get(AbstractEntity_.id), filter.getRoleSystemId()));
    }
    if (filter.getSystemId() != null) {
        predicates.add(builder.equal(root.get(SysRoleSystemAttribute_.roleSystem).get(SysRoleSystem_.system).get(AbstractEntity_.id), filter.getSystemId()));
    }
    if (filter.getSystemMappingId() != null) {
        predicates.add(builder.equal(root.get(SysRoleSystemAttribute_.roleSystem).get(SysRoleSystem_.systemMapping).get(AbstractEntity_.id), filter.getSystemMappingId()));
    }
    if (filter.getSchemaAttributeName() != null) {
        predicates.add(builder.equal(root.get(SysRoleSystemAttribute_.systemAttributeMapping).get(SysSystemAttributeMapping_.schemaAttribute).get(SysSchemaAttribute_.name), filter.getSchemaAttributeName()));
    }
    if (filter.getIsUid() != null) {
        predicates.add(builder.equal(root.get(SysRoleSystemAttribute_.uid), filter.getIsUid()));
    }
    if (filter.getSystemAttributeMappingId() != null) {
        predicates.add(builder.equal(root.get(SysRoleSystemAttribute_.systemAttributeMapping).get(AbstractEntity_.id), filter.getSystemAttributeMappingId()));
    }
    // role-system-attributes)
    if (filter.getIdentityId() != null && filter.getAccountId() != null) {
        Subquery<AccIdentityAccount> subquery = query.subquery(AccIdentityAccount.class);
        Root<AccIdentityAccount> subRoot = subquery.from(AccIdentityAccount.class);
        subquery.select(subRoot);
        // Correlation attribute predicate
        Predicate correlationPredicate = builder.equal(subRoot.get(AccIdentityAccount_.identityRole).get(IdmIdentityRole_.role), // Correlation attribute
        root.get(SysRoleSystemAttribute_.roleSystem).get(SysRoleSystem_.role));
        // Identity predicate
        Predicate identityPredicate = builder.equal(subRoot.get(AccIdentityAccount_.identityRole).get(IdmIdentityRole_.identityContract).get(IdmIdentityContract_.identity).get(AbstractEntity_.id), filter.getIdentityId());
        // Account predicate
        Predicate accountPredicate = builder.equal(subRoot.get(AccIdentityAccount_.account).get(AbstractEntity_.id), filter.getAccountId());
        subquery.where(builder.and(correlationPredicate, identityPredicate, accountPredicate));
        predicates.add(builder.exists(subquery));
    }
    // Find override for identity (via identity-role)
    if (filter.getIdentityId() != null && filter.getAccountId() == null) {
        Subquery<IdmIdentityRole> subquery = query.subquery(IdmIdentityRole.class);
        Root<IdmIdentityRole> subRoot = subquery.from(IdmIdentityRole.class);
        subquery.select(subRoot);
        // Correlation attribute predicate
        Predicate correlationPredicate = builder.equal(subRoot.get(IdmIdentityRole_.role), // Correlation attribute
        root.get(SysRoleSystemAttribute_.roleSystem).get(SysRoleSystem_.role));
        // Identity predicate
        Predicate identityPredicate = builder.equal(subRoot.get(IdmIdentityRole_.identityContract).get(IdmIdentityContract_.identity).get(AbstractEntity_.id), filter.getIdentityId());
        subquery.where(builder.and(correlationPredicate, identityPredicate));
        predicates.add(builder.exists(subquery));
    }
    // and role-system is null or if relation is not null, then return override attributes where same role-systems are used.
    if (filter.getRoleSystemRelationForIdentityId() != null) {
        // Query via role:
        Subquery<IdmIdentityRole> subquery = query.subquery(IdmIdentityRole.class);
        Root<IdmIdentityRole> subRoot = subquery.from(IdmIdentityRole.class);
        subquery.select(subRoot);
        // Correlation attribute predicate
        Predicate correlationPredicate = builder.equal(subRoot.get(IdmIdentityRole_.role), // Correlation attribute
        root.get(SysRoleSystemAttribute_.roleSystem).get(SysRoleSystem_.role));
        // Identity predicate
        Predicate identityPredicate = builder.equal(subRoot.get(IdmIdentityRole_.identityContract).get(IdmIdentityContract_.identity).get(AbstractEntity_.id), filter.getRoleSystemRelationForIdentityId());
        // Identity-role predicate
        Predicate identityRolePredicate = builder.isNull(subRoot.get(IdmIdentityRole_.roleSystem));
        subquery.where(builder.and(correlationPredicate, identityPredicate, identityRolePredicate));
        // Query via role-system:
        Subquery<IdmIdentityRole> subqueryViaRoleSystem = query.subquery(IdmIdentityRole.class);
        Root<IdmIdentityRole> subRootViaRoleSystem = subqueryViaRoleSystem.from(IdmIdentityRole.class);
        subqueryViaRoleSystem.select(subRootViaRoleSystem);
        // Correlation attribute predicate
        Predicate correlationPredicateViaRoleSystem = builder.equal(subRootViaRoleSystem.get(IdmIdentityRole_.roleSystem), // Correlation attribute
        root.get(SysRoleSystemAttribute_.roleSystem));
        // Identity predicate
        Predicate identityPredicateViaRoleSystem = builder.equal(subRootViaRoleSystem.get(IdmIdentityRole_.identityContract).get(IdmIdentityContract_.identity).get(AbstractEntity_.id), filter.getRoleSystemRelationForIdentityId());
        subqueryViaRoleSystem.where(builder.and(correlationPredicateViaRoleSystem, identityPredicateViaRoleSystem));
        // Query by role or by role-system
        predicates.add(builder.or(builder.exists(subquery), builder.exists(subqueryViaRoleSystem)));
    }
    // Get role-system-attributes with cross domains groups (using same merge attribute) or attributes where default account creation is disabled.
    if (Boolean.TRUE.equals(filter.getInCrossDomainGroupOrIsNoLogin())) {
        Subquery<SysSystemGroupSystem> subquerySystemGroup = query.subquery(SysSystemGroupSystem.class);
        Root<SysSystemGroupSystem> subRootSystemGroup = subquerySystemGroup.from(SysSystemGroupSystem.class);
        subquerySystemGroup.select(subRootSystemGroup);
        subquerySystemGroup.where(builder.and(builder.equal(subRootSystemGroup.get(SysSystemGroupSystem_.mergeAttribute), // Correlation attribute
        root.get(SysRoleSystemAttribute_.systemAttributeMapping))), builder.equal(subRootSystemGroup.get(SysSystemGroupSystem_.systemGroup).get(SysSystemGroup_.disabled), Boolean.FALSE), builder.equal(subRootSystemGroup.get(SysSystemGroupSystem_.systemGroup).get(SysSystemGroup_.type), SystemGroupType.CROSS_DOMAIN));
        predicates.add(builder.or(builder.equal(root.get(SysRoleSystemAttribute_.roleSystem).get(SysRoleSystem_.createAccountByDefault), Boolean.FALSE), builder.exists(subquerySystemGroup)));
    }
    return predicates;
}
Also used : IdmIdentityRole(eu.bcvsolutions.idm.core.model.entity.IdmIdentityRole) SysSystemGroupSystem(eu.bcvsolutions.idm.acc.entity.SysSystemGroupSystem) AccIdentityAccount(eu.bcvsolutions.idm.acc.entity.AccIdentityAccount) Predicate(javax.persistence.criteria.Predicate)

Aggregations

AccIdentityAccount (eu.bcvsolutions.idm.acc.entity.AccIdentityAccount)1 SysSystemGroupSystem (eu.bcvsolutions.idm.acc.entity.SysSystemGroupSystem)1 IdmIdentityRole (eu.bcvsolutions.idm.core.model.entity.IdmIdentityRole)1 Predicate (javax.persistence.criteria.Predicate)1