Search in sources :

Example 41 with IdmRoleFilter

use of eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleFilter in project CzechIdMng by bcvsolutions.

the class DefaultIdmConceptRoleRequestService method toPredicates.

@Override
protected List<Predicate> toPredicates(Root<IdmConceptRoleRequest> root, CriteriaQuery<?> query, CriteriaBuilder builder, IdmConceptRoleRequestFilter filter) {
    List<Predicate> predicates = super.toPredicates(root, query, builder, filter);
    // 
    if (filter.getRoleRequestId() != null) {
        predicates.add(builder.equal(root.get(IdmConceptRoleRequest_.roleRequest).get(IdmRoleRequest_.id), filter.getRoleRequestId()));
    }
    if (filter.getIdentityRoleId() != null) {
        predicates.add(builder.equal(root.get(IdmConceptRoleRequest_.identityRole).get(IdmIdentityRole_.id), filter.getIdentityRoleId()));
    }
    if (filter.getRoleId() != null) {
        predicates.add(builder.equal(root.get(IdmConceptRoleRequest_.role).get(IdmRole_.id), filter.getRoleId()));
    }
    // by role text
    String roleText = filter.getRoleText();
    if (StringUtils.isNotEmpty(roleText)) {
        IdmRoleFilter subFilter = new IdmRoleFilter();
        subFilter.setText(roleText);
        Subquery<IdmRole> subquery = query.subquery(IdmRole.class);
        Root<IdmRole> subRoot = subquery.from(IdmRole.class);
        subquery.select(subRoot);
        Predicate rolePredicate = filterManager.getBuilder(IdmRole.class, IdmRoleFilter.PARAMETER_TEXT).getPredicate(subRoot, subquery, builder, subFilter);
        subquery.where(builder.and(// correlation attr
        builder.equal(root.get(IdmConceptRoleRequest_.role), subRoot), rolePredicate));
        // 
        predicates.add(builder.exists(subquery));
    }
    if (filter.getIdentityContractId() != null) {
        predicates.add(builder.equal(root.get(IdmConceptRoleRequest_.identityContract).get(IdmIdentityContract_.id), filter.getIdentityContractId()));
    }
    if (filter.getAutomaticRole() != null) {
        predicates.add(builder.equal(root.get(IdmConceptRoleRequest_.automaticRole).get(IdmAutomaticRole_.id), filter.getAutomaticRole()));
    }
    if (filter.getOperation() != null) {
        predicates.add(builder.equal(root.get(IdmConceptRoleRequest_.operation), filter.getOperation()));
    }
    if (filter.getState() != null) {
        predicates.add(builder.equal(root.get(IdmConceptRoleRequest_.state), filter.getState()));
    }
    Set<UUID> ids = filter.getIdentityRoleIds();
    if (ids != null && !ids.isEmpty()) {
        predicates.add(root.get(IdmConceptRoleRequest_.identityRole).get(IdmIdentityRole_.id).in(ids));
    }
    if (filter.getRoleEnvironment() != null) {
        predicates.add(builder.equal(root.get(IdmConceptRoleRequest_.role).get(IdmRole_.environment), filter.getRoleEnvironment()));
    }
    List<String> roleEnvironments = filter.getRoleEnvironments();
    if (CollectionUtils.isNotEmpty(roleEnvironments)) {
        predicates.add(root.get(IdmConceptRoleRequest_.role).get(IdmRole_.environment).in(roleEnvironments));
    }
    if (filter.isIdentityRoleIsNull()) {
        predicates.add(builder.isNull(root.get(IdmConceptRoleRequest_.identityRole)));
    }
    // 
    return predicates;
}
Also used : IdmRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleFilter) IdmRole(eu.bcvsolutions.idm.core.model.entity.IdmRole) UUID(java.util.UUID) Predicate(javax.persistence.criteria.Predicate)

Example 42 with IdmRoleFilter

use of eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleFilter in project CzechIdMng by bcvsolutions.

the class DefaultIdmIdentityRoleService method toPredicates.

@Override
protected List<Predicate> toPredicates(Root<IdmIdentityRole> root, CriteriaQuery<?> query, CriteriaBuilder builder, IdmIdentityRoleFilter filter) {
    List<Predicate> predicates = super.toPredicates(root, query, builder, filter);
    // quick - by identity's username
    String text = filter.getText();
    if (StringUtils.isNotEmpty(text)) {
        text = text.toLowerCase();
        predicates.add(builder.like(builder.lower(root.get(IdmIdentityRole_.identityContract).get(IdmIdentityContract_.identity).get(IdmIdentity_.username)), "%" + text + "%"));
    }
    // by role text
    String roleText = filter.getRoleText();
    if (StringUtils.isNotEmpty(roleText)) {
        IdmRoleFilter subFilter = new IdmRoleFilter();
        subFilter.setText(roleText);
        Subquery<IdmRole> subquery = query.subquery(IdmRole.class);
        Root<IdmRole> subRoot = subquery.from(IdmRole.class);
        subquery.select(subRoot);
        // 
        Predicate rolePredicate = filterManager.getBuilder(IdmRole.class, IdmRoleFilter.PARAMETER_TEXT).getPredicate(subRoot, subquery, builder, subFilter);
        // 
        subquery.where(builder.and(// correlation attr
        builder.equal(root.get(IdmIdentityRole_.role), subRoot), rolePredicate));
        // 
        predicates.add(builder.exists(subquery));
    }
    List<UUID> identities = filter.getIdentities();
    if (!identities.isEmpty()) {
        predicates.add(root.get(IdmIdentityRole_.identityContract).get(IdmIdentityContract_.identity).get(IdmIdentity_.id).in(identities));
    }
    List<UUID> roles = filter.getRoles();
    if (!roles.isEmpty()) {
        predicates.add(root.get(IdmIdentityRole_.role).get(IdmRole_.id).in(roles));
    }
    List<String> roleEnvironments = filter.getRoleEnvironments();
    if (CollectionUtils.isNotEmpty(roleEnvironments)) {
        predicates.add(root.get(IdmIdentityRole_.role).get(IdmRole_.environment).in(roleEnvironments));
    }
    UUID roleCatalogueId = filter.getRoleCatalogueId();
    if (roleCatalogueId != null) {
        Subquery<IdmRoleCatalogueRole> roleCatalogueRoleSubquery = query.subquery(IdmRoleCatalogueRole.class);
        Root<IdmRoleCatalogueRole> subRootRoleCatalogueRole = roleCatalogueRoleSubquery.from(IdmRoleCatalogueRole.class);
        roleCatalogueRoleSubquery.select(subRootRoleCatalogueRole);
        roleCatalogueRoleSubquery.where(builder.and(builder.equal(subRootRoleCatalogueRole.get(IdmRoleCatalogueRole_.role), root.get(IdmIdentityRole_.role)), builder.equal(subRootRoleCatalogueRole.get(IdmRoleCatalogueRole_.roleCatalogue).get(AbstractEntity_.id), roleCatalogueId)));
        predicates.add(builder.exists(roleCatalogueRoleSubquery));
    }
    // 
    Boolean valid = filter.getValid();
    if (valid != null) {
        // Only valid identity-role include check on contract validity too
        if (valid) {
            final LocalDate today = LocalDate.now();
            predicates.add(builder.and(RepositoryUtils.getValidPredicate(root, builder, today), RepositoryUtils.getValidPredicate(root.get(IdmIdentityRole_.identityContract), builder, today), builder.equal(root.get(IdmIdentityRole_.identityContract).get(IdmIdentityContract_.disabled), Boolean.FALSE)));
        }
        // Only invalid identity-role
        if (!valid) {
            final LocalDate today = LocalDate.now();
            predicates.add(builder.or(builder.not(RepositoryUtils.getValidPredicate(root, builder, today)), builder.not(RepositoryUtils.getValidPredicate(root.get(IdmIdentityRole_.identityContract), builder, today)), builder.equal(root.get(IdmIdentityRole_.identityContract).get(IdmIdentityContract_.disabled), Boolean.TRUE)));
        }
    }
    // 
    // is automatic role
    Boolean automaticRole = filter.getAutomaticRole();
    if (automaticRole != null) {
        if (automaticRole) {
            predicates.add(builder.isNotNull(root.get(IdmIdentityRole_.automaticRole)));
        } else {
            predicates.add(builder.isNull(root.get(IdmIdentityRole_.automaticRole)));
        }
    }
    // 
    UUID automaticRoleId = filter.getAutomaticRoleId();
    if (automaticRoleId != null) {
        predicates.add(builder.equal(root.get(IdmIdentityRole_.automaticRole).get(IdmAutomaticRole_.id), automaticRoleId));
    }
    // 
    UUID identityContractId = filter.getIdentityContractId();
    if (identityContractId != null) {
        predicates.add(builder.equal(root.get(IdmIdentityRole_.identityContract).get(AbstractEntity_.id), identityContractId));
    }
    // 
    UUID contractPositionId = filter.getContractPositionId();
    if (contractPositionId != null) {
        predicates.add(builder.equal(root.get(IdmIdentityRole_.contractPosition).get(AbstractEntity_.id), contractPositionId));
    }
    // 
    UUID directRoleId = filter.getDirectRoleId();
    if (directRoleId != null) {
        predicates.add(builder.equal(root.get(IdmIdentityRole_.directRole).get(IdmIdentityRole_.id), directRoleId));
    }
    // 
    UUID roleCompositionId = filter.getRoleCompositionId();
    if (roleCompositionId != null) {
        predicates.add(builder.equal(root.get(IdmIdentityRole_.roleComposition).get(IdmRoleComposition_.id), roleCompositionId));
    }
    // 
    // is direct role
    Boolean directRole = filter.getDirectRole();
    if (directRole != null) {
        if (directRole) {
            predicates.add(builder.isNull(root.get(IdmIdentityRole_.directRole)));
        } else {
            predicates.add(builder.isNotNull(root.get(IdmIdentityRole_.directRole)));
        }
    }
    // Role-system
    UUID roleSystemId = filter.getRoleSystemId();
    if (roleSystemId != null) {
        predicates.add(builder.equal(root.get(IdmIdentityRole_.roleSystem), roleSystemId));
    }
    return predicates;
}
Also used : IdmRoleCatalogueRole(eu.bcvsolutions.idm.core.model.entity.IdmRoleCatalogueRole) LocalDate(java.time.LocalDate) Predicate(javax.persistence.criteria.Predicate) IdmRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleFilter) IdmRole(eu.bcvsolutions.idm.core.model.entity.IdmRole) UUID(java.util.UUID)

Example 43 with IdmRoleFilter

use of eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleFilter in project CzechIdMng by bcvsolutions.

the class RoleUniversalSearchType method createFilter.

protected IdmRoleFilter createFilter(String text) {
    IdmRoleFilter filter = new IdmRoleFilter();
    filter.setText(text);
    return filter;
}
Also used : IdmRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleFilter)

Example 44 with IdmRoleFilter

use of eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleFilter in project CzechIdMng by bcvsolutions.

the class RoleByRoleCatalogueEvaluator method getPermissions.

@Override
public Set<String> getPermissions(IdmRole authorizable, AuthorizationPolicy policy) {
    Set<String> permissions = super.getPermissions(authorizable, policy);
    UUID roleCatalogueId = getUuid(policy);
    if (roleCatalogueId == null) {
        return permissions;
    }
    // we try found role by id and role catalogue
    IdmRoleFilter filter = new IdmRoleFilter();
    filter.setId(authorizable.getId());
    filter.setRoleCatalogueId(roleCatalogueId);
    long rolesCount = roleService.count(filter);
    if (rolesCount > 0) {
        permissions.addAll(policy.getPermissions());
    }
    return permissions;
}
Also used : IdmRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleFilter) UUID(java.util.UUID)

Example 45 with IdmRoleFilter

use of eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleFilter in project CzechIdMng by bcvsolutions.

the class RoleDuplicateBulkActionIntegrationTest method testDuplicateRoleOnlyOnTheDifferentEnvironment.

@Test
public void testDuplicateRoleOnlyOnTheDifferentEnvironment() {
    IdmRoleDto role = createRole();
    // create attributes, automatic roles etc.
    createRoleFormAttribute(role, getHelper().createName(), getHelper().createName());
    createAutomaticRole(role, getHelper().createTreeNode());
    createAutomaticRole(role, getHelper().createName());
    // 
    Assert.assertFalse(findAllSubRoles(role).isEmpty());
    Assert.assertFalse(findAutomaticRolesByTree(role).isEmpty());
    Assert.assertFalse(findRoleFormAttributes(role).isEmpty());
    Assert.assertFalse(findAutomaticRolesByAttribute(role).isEmpty());
    // 
    String roleBaseCode = role.getBaseCode();
    // 
    String targetEnvironment = getHelper().createName();
    IdmBulkActionDto bulkAction = findBulkAction(IdmRole.class, RoleDuplicateBulkAction.NAME);
    bulkAction.setIdentifiers(Sets.newHashSet(role.getId()));
    bulkAction.getProperties().put(RoleDuplicateBulkAction.PROPERTY_ENVIRONMENT, targetEnvironment);
    bulkAction.getProperties().put(DuplicateRoleAutomaticByTreeProcessor.PARAMETER_INCLUDE_AUTOMATIC_ROLE, false);
    bulkAction.getProperties().put(DuplicateRoleFormAttributeProcessor.PARAMETER_INCLUDE_ROLE_FORM_ATTRIBUTE, false);
    bulkAction.getProperties().put(DuplicateRoleCompositionProcessor.PARAMETER_INCLUDE_ROLE_COMPOSITION, false);
    IdmBulkActionDto processAction = bulkActionManager.processAction(bulkAction);
    // 
    checkResultLrt(processAction, 1l, null, null);
    IdmRoleFilter filter = new IdmRoleFilter();
    filter.setEnvironment(targetEnvironment);
    List<IdmRoleDto> roles = roleService.find(filter, null).getContent();
    // 
    Assert.assertEquals(1, roles.size());
    IdmRoleDto duplicate = roles.get(0);
    Assert.assertEquals(roleBaseCode, duplicate.getBaseCode());
    Assert.assertEquals(role.getName(), duplicate.getName());
    Assert.assertEquals(role.getDescription(), duplicate.getDescription());
    // 
    Assert.assertTrue(findAllSubRoles(duplicate).isEmpty());
    Assert.assertTrue(findAutomaticRolesByTree(duplicate).isEmpty());
    Assert.assertTrue(findRoleFormAttributes(duplicate).isEmpty());
    Assert.assertTrue(findAutomaticRolesByAttribute(duplicate).isEmpty());
    // 
    role.setDescription(getHelper().createName());
    role = roleService.save(role);
    // 
    processAction = bulkActionManager.processAction(bulkAction);
    // 
    checkResultLrt(processAction, 1l, null, null);
    // 
    roles = roleService.find(filter, null).getContent();
    Assert.assertEquals(1, roles.size());
    duplicate = roles.get(0);
    // on the different environment is updated the first duplicate
    Assert.assertEquals(1, roles.size());
    Assert.assertEquals(role.getDescription(), duplicate.getDescription());
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmBulkActionDto(eu.bcvsolutions.idm.core.api.bulk.action.dto.IdmBulkActionDto) IdmRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleFilter) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) AbstractBulkActionTest(eu.bcvsolutions.idm.test.api.AbstractBulkActionTest) Test(org.junit.Test)

Aggregations

IdmRoleFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleFilter)54 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)46 Test (org.junit.Test)41 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)22 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)17 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)17 IdmRoleCatalogueDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleCatalogueDto)16 SysSyncLogDto (eu.bcvsolutions.idm.acc.dto.SysSyncLogDto)14 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)14 IdmRole (eu.bcvsolutions.idm.core.model.entity.IdmRole)10 IdmFormValueDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto)9 List (java.util.List)9 Assert (org.junit.Assert)9 Autowired (org.springframework.beans.factory.annotation.Autowired)9 SysSyncRoleConfigDto (eu.bcvsolutions.idm.acc.dto.SysSyncRoleConfigDto)8 UUID (java.util.UUID)8 AbstractSysSyncConfigDto (eu.bcvsolutions.idm.acc.dto.AbstractSysSyncConfigDto)7 SysSyncConfigFilter (eu.bcvsolutions.idm.acc.dto.filter.SysSyncConfigFilter)7 CoreGroupPermission (eu.bcvsolutions.idm.core.model.domain.CoreGroupPermission)7 TestHelper (eu.bcvsolutions.idm.test.api.TestHelper)7