use of eu.bcvsolutions.idm.core.model.entity.IdmIdentity in project CzechIdMng by bcvsolutions.
the class IdentityGuaranteesForRoleFilterIntegrationTest method testFindGuaranteesByTypeInIdentityAndRole.
@Test
public void testFindGuaranteesByTypeInIdentityAndRole() {
// prepare data
String guaranteeType = getHelper().createName();
IdmIdentityDto identityOne = getHelper().createIdentity((GuardedString) null);
IdmIdentityDto identityTwo = getHelper().createIdentity((GuardedString) null);
IdmIdentityDto identityThree = getHelper().createIdentity((GuardedString) null);
IdmRoleDto role = getHelper().createRole();
IdmRoleDto roleGuarantee = getHelper().createRole();
getHelper().createRoleGuarantee(role, identityOne, guaranteeType);
getHelper().createRoleGuaranteeRole(role, roleGuarantee, guaranteeType);
getHelper().createIdentityRole(identityThree, roleGuarantee);
getHelper().createIdentityRole(identityTwo, role);
//
IdmIdentityFilter dataFilter = new IdmIdentityFilter();
dataFilter.setGuaranteesForRole(role.getId());
dataFilter.setGuaranteeType(guaranteeType);
List<IdmIdentity> identities = filter.find(dataFilter, null).getContent();
//
Assert.assertEquals(2, identities.size());
Assert.assertTrue(identities.stream().anyMatch(i -> i.getId().equals(identityOne.getId())));
Assert.assertTrue(identities.stream().anyMatch(i -> i.getId().equals(identityThree.getId())));
}
use of eu.bcvsolutions.idm.core.model.entity.IdmIdentity in project CzechIdMng by bcvsolutions.
the class IdentityGuaranteesForRoleFilterIntegrationTest method testFindWithGuaranteeType.
@Test
public void testFindWithGuaranteeType() {
// prepare data
String guaranteeType = getHelper().createName();
IdmIdentityDto identityOne = getHelper().createIdentity((GuardedString) null);
IdmIdentityDto identityTwo = getHelper().createIdentity((GuardedString) null);
IdmIdentityDto identityThree = getHelper().createIdentity((GuardedString) null);
IdmRoleDto role = getHelper().createRole();
IdmRoleDto roleGuarantee = getHelper().createRole();
getHelper().createRoleGuarantee(role, identityOne, guaranteeType);
getHelper().createRoleGuaranteeRole(role, roleGuarantee, guaranteeType);
getHelper().createIdentityRole(identityThree, roleGuarantee);
getHelper().createIdentityRole(identityTwo, role);
//
IdmIdentityFilter dataFilter = new IdmIdentityFilter();
dataFilter.setGuaranteesForRole(role.getId());
List<IdmIdentity> identities = filter.find(dataFilter, null).getContent();
//
Assert.assertEquals(2, identities.size());
Assert.assertTrue(identities.stream().anyMatch(i -> i.getId().equals(identityOne.getId())));
Assert.assertTrue(identities.stream().anyMatch(i -> i.getId().equals(identityThree.getId())));
}
use of eu.bcvsolutions.idm.core.model.entity.IdmIdentity in project CzechIdMng by bcvsolutions.
the class PhoneIdentityFilterBuilderIntegrationTest method testFindIdentityByPhone.
@Test
public void testFindIdentityByPhone() {
// prepare data
IdmIdentityDto identityOne = new IdmIdentityDto(getHelper().createName());
identityOne.setPhone(getHelper().createName().substring(0, 30));
identityOne = identityService.save(identityOne);
IdmIdentityDto identityTwo = new IdmIdentityDto(getHelper().createName());
identityTwo.setPhone(getHelper().createName().substring(0, 30));
identityTwo = identityService.save(identityTwo);
//
IdmIdentityFilter dataFilter = new IdmIdentityFilter();
dataFilter.setPhone(identityOne.getPhone());
List<IdmIdentity> identities = filter.find(dataFilter, null).getContent();
//
assertEquals(1, identities.size());
assertEquals(identityOne.getId(), identities.get(0).getId());
//
dataFilter.setPhone(identityTwo.getPhone());
identities = filter.find(dataFilter, null).getContent();
assertEquals(1, identities.size());
assertEquals(identityTwo.getId(), identities.get(0).getId());
}
use of eu.bcvsolutions.idm.core.model.entity.IdmIdentity in project CzechIdMng by bcvsolutions.
the class DefaultIdmAutomaticRoleAttributeService method getPredicateForRuleByContract.
/**
* Return predicate for given rule by contract
*
* @param rule
* @param root
* @param query
* @param cb
* @return
*/
private Predicate getPredicateForRuleByContract(IdmAutomaticRoleAttributeRuleDto rule, Root<IdmIdentityContract> root, CriteriaQuery<?> query, CriteriaBuilder cb, boolean pass) {
//
Metamodel metamodel = entityManager.getMetamodel();
if (rule.getType() == AutomaticRoleAttributeRuleType.CONTRACT) {
SingularAttribute<? super IdmIdentityContract, ?> singularAttribute = metamodel.entity(IdmIdentityContract.class).getSingularAttribute(rule.getAttributeName());
Path<Object> path = root.get(singularAttribute.getName());
// role will be added and wich roles will be removed.
return getPredicateWithComparsion(path, castToType(singularAttribute, rule.getValue(), rule.getComparison()), cb, rule.getComparison(), !pass);
} else if (rule.getType() == AutomaticRoleAttributeRuleType.CONTRACT_EAV) {
IdmFormAttributeDto formAttributeDto = formAttributeService.get(rule.getFormAttribute());
AutomaticRoleAttributeRuleComparison comparison = rule.getComparison();
// Cast given value to specific persistent type
// For is empty and is not empty comparison is returned null even if value exists
Object value = getFormValue(rule.getValue(), formAttributeDto, comparison);
//
// For contract form attribute was composed only one subquery
Subquery<IdmIdentityContractFormValue> subquery = query.subquery(IdmIdentityContractFormValue.class);
Root<IdmIdentityContractFormValue> subRoot = subquery.from(IdmIdentityContractFormValue.class);
subquery.select(subRoot);
//
Path<?> path = subRoot.get(getSingularAttributeForEav(formAttributeDto.getPersistentType()));
// Is empty comparison has specific behavior because form value isn't empty, but value doesn't exist
if (comparison == AutomaticRoleAttributeRuleComparison.IS_EMPTY) {
subquery.where(cb.or(// Predicate for check if value exists
getPredicateForNullFormAttributeIdentityContract(root, query, cb, formAttributeDto), cb.and(cb.equal(subRoot.get(IdmIdentityContractFormValue_.owner), root), cb.equal(subRoot.get(IdmIdentityContractFormValue_.formAttribute).get(AbstractFormValue_.id), formAttributeDto.getId()), getPredicateWithComparsion(path, null, cb, rule.getComparison(), null))));
if (pass) {
return cb.not(cb.exists(subquery));
}
return cb.exists(subquery);
}
//
subquery.where(cb.and(cb.equal(subRoot.get(IdmIdentityContractFormValue_.owner), root), cb.equal(subRoot.get(IdmIdentityContractFormValue_.formAttribute).get(AbstractFormValue_.id), formAttributeDto.getId()), getPredicateWithComparsion(path, value, cb, rule.getComparison(), null)));
//
Predicate existsInEav = getPredicateForConnection(subquery, cb, pass, formAttributeDto.isMultiple());
// For comparison with not is required also check null values
if (comparison == AutomaticRoleAttributeRuleComparison.NOT_CONTAINS || comparison == AutomaticRoleAttributeRuleComparison.NOT_END_WITH || comparison == AutomaticRoleAttributeRuleComparison.NOT_EQUALS || comparison == AutomaticRoleAttributeRuleComparison.NOT_START_WITH) {
if (pass) {
existsInEav = cb.or(existsInEav, cb.not(getPredicateForNullFormAttributeIdentityContract(root, query, cb, formAttributeDto)));
} else {
existsInEav = cb.and(existsInEav, getPredicateForNullFormAttributeIdentityContract(root, query, cb, formAttributeDto));
}
}
//
return existsInEav;
} else if (rule.getType() == AutomaticRoleAttributeRuleType.IDENTITY_EAV) {
IdmFormAttributeDto formAttributeDto = formAttributeService.get(rule.getFormAttribute());
AutomaticRoleAttributeRuleComparison comparison = rule.getComparison();
// Cast given value to specific persistent type
// For is empty and is not empty comparison is returned null even if value exists
Object value = getFormValue(rule.getValue(), formAttributeDto, comparison);
//
// Rules for identity form values must contains two subquery identity -> identity eav
Subquery<IdmIdentity> subquery = query.subquery(IdmIdentity.class);
Root<IdmIdentity> subRoot = subquery.from(IdmIdentity.class);
subquery.select(subRoot);
//
Subquery<IdmIdentityFormValue> subQueryIdentityEav = query.subquery(IdmIdentityFormValue.class);
Root<IdmIdentityFormValue> subRootIdentityEav = subQueryIdentityEav.from(IdmIdentityFormValue.class);
subQueryIdentityEav.select(subRootIdentityEav);
//
Path<?> path = subRootIdentityEav.get(getSingularAttributeForEav(formAttributeDto.getPersistentType()));
// Is empty comparison has specific behavior because form value isn't empty, but value doesn't exist
if (comparison == AutomaticRoleAttributeRuleComparison.IS_EMPTY) {
subquery.where(cb.and(cb.equal(root.get(IdmIdentityContract_.identity), subRoot), cb.or(cb.exists(subQueryIdentityEav.where(cb.and(cb.equal(subRootIdentityEav.get(IdmIdentityFormValue_.owner), subRoot), cb.equal(subRootIdentityEav.get(IdmIdentityFormValue_.formAttribute).get(AbstractFormValue_.id), formAttributeDto.getId()), getPredicateWithComparsion(path, null, cb, rule.getComparison(), null)))), // Predicate for check if value exists
getPredicateForNullFormAttributeIdentity(subRoot, subquery, cb, formAttributeDto))));
//
if (pass) {
return cb.not(cb.exists(subquery));
}
return cb.exists(subquery);
}
//
subQueryIdentityEav.where(cb.and(cb.equal(subRootIdentityEav.get(IdmIdentityFormValue_.owner), subRoot), cb.equal(root.get(IdmIdentityContract_.identity), subRoot), cb.equal(subRootIdentityEav.get(IdmIdentityFormValue_.formAttribute).get(AbstractFormValue_.id), formAttributeDto.getId()), getPredicateWithComparsion(path, value, cb, rule.getComparison(), null)));
Predicate existsInEav = getPredicateForConnection(subQueryIdentityEav, cb, pass, formAttributeDto.isMultiple());
// For comparison with not is required also check null values
if (comparison == AutomaticRoleAttributeRuleComparison.NOT_CONTAINS || comparison == AutomaticRoleAttributeRuleComparison.NOT_END_WITH || comparison == AutomaticRoleAttributeRuleComparison.NOT_EQUALS || comparison == AutomaticRoleAttributeRuleComparison.NOT_START_WITH) {
if (pass) {
existsInEav = cb.or(existsInEav, cb.not(getPredicateForNullFormAttributeIdentity(subRoot, subquery, cb, formAttributeDto)));
} else {
existsInEav = cb.and(existsInEav, getPredicateForNullFormAttributeIdentity(subRoot, subquery, cb, formAttributeDto));
}
}
//
subquery.where(cb.and(cb.equal(subRoot.get(IdmIdentity_.id), root.get(IdmIdentityContract_.identity).get(AbstractEntity_.id)), existsInEav));
//
return cb.exists(subquery);
} else if (rule.getType() == AutomaticRoleAttributeRuleType.IDENTITY) {
Subquery<IdmIdentity> subquery = query.subquery(IdmIdentity.class);
Root<IdmIdentity> subRoot = subquery.from(IdmIdentity.class);
subquery.select(subRoot);
//
SingularAttribute<? super IdmIdentity, ?> singularAttribute = metamodel.entity(IdmIdentity.class).getSingularAttribute(rule.getAttributeName());
Path<Object> path = subRoot.get(singularAttribute.getName());
//
subquery.where(// correlation attr
cb.and(// correlation attr
cb.equal(subRoot.get(IdmIdentity_.id), root.get(IdmIdentityContract_.identity).get(AbstractEntity_.id)), getPredicateWithComparsion(path, castToType(singularAttribute, rule.getValue(), rule.getComparison()), cb, rule.getComparison(), null)));
//
return getPredicateForConnection(subquery, cb, pass, false);
} else {
throw new UnsupportedOperationException("Type: " + rule.getType().name() + ", isn't supported for contract rules!");
}
}
use of eu.bcvsolutions.idm.core.model.entity.IdmIdentity in project CzechIdMng by bcvsolutions.
the class RoleRequestByIdentityEvaluator method getPermissions.
@Override
public Set<String> getPermissions(IdmRoleRequest entity, AuthorizationPolicy policy) {
Set<String> permissions = super.getPermissions(entity, policy);
// Add permissions, when CHANGEPERMISSION or CANBEREQUESTED is available on at least one contract of selected identity.
IdmIdentity applicant = entity.getApplicant();
if (applicant != null) {
IdmIdentityContractFilter filter = new IdmIdentityContractFilter();
filter.setEvaluatePermissionOperator(PermissionContext.OPERATOR_OR);
filter.setIdentity(applicant.getId());
//
if (contractService.count(filter, ContractBasePermission.CHANGEPERMISSION, ContractBasePermission.CANBEREQUESTED) > 0) {
permissions.add(IdmBasePermission.READ.getName());
permissions.add(IdmBasePermission.CREATE.getName());
permissions.add(IdmBasePermission.UPDATE.getName());
permissions.add(IdmBasePermission.DELETE.getName());
}
}
return permissions;
}
Aggregations