use of eu.bcvsolutions.idm.core.model.entity.IdmIdentityContract in project CzechIdMng by bcvsolutions.
the class DefaultIdmIdentityContractServiceUnitTest method testSimpleDisabledPrimeContract.
@Test
public void testSimpleDisabledPrimeContract() {
List<IdmIdentityContract> contracts = new ArrayList<>();
IdmIdentityContract invalidContract = new IdmIdentityContract(UUID.randomUUID());
invalidContract.setMain(true);
invalidContract.setDisabled(true);
IdmIdentityContract mainContract = new IdmIdentityContract(UUID.randomUUID());
mainContract.setMain(true);
contracts.add(invalidContract);
contracts.add(mainContract);
//
when(repository.findAllByIdentity_Id(any(UUID.class), any())).thenReturn(contracts);
when(treeConfiguration.getDefaultType()).thenReturn(null);
//
Assert.assertEquals(mainContract.getId(), service.getPrimeContract(UUID.randomUUID()).getId());
}
use of eu.bcvsolutions.idm.core.model.entity.IdmIdentityContract in project CzechIdMng by bcvsolutions.
the class IdentityRoleAddAuthoritiesProcessor method checkAddedPermissions.
private void checkAddedPermissions(IdmIdentityRoleDto identityRole) {
IdmIdentityContract contract = contractRepository.findOne(identityRole.getIdentityContract());
IdmIdentity identity = contract.getIdentity();
List<IdmIdentityRoleDto> withoutAdded = identityRoleService.findAllByIdentity(identity.getId());
withoutAdded.remove(identityRole);
// represents the final authorities set after role removal
Collection<? extends GrantedAuthority> original = authorityHierarchy.getReachableGrantedAuthorities(authoritiesFactory.getGrantedAuthoritiesForValidRoles(identity.getId(), withoutAdded));
Collection<? extends GrantedAuthority> addedAuthorities = authorityHierarchy.getReachableGrantedAuthorities(authoritiesFactory.getGrantedAuthoritiesForValidRoles(identity.getId(), Collections.singletonList(identityRole)));
if (!authoritiesFactory.containsAllAuthorities(original, addedAuthorities)) {
// authorities were changed, update identity flag
IdmAuthorityChange ac = repository.findOneByIdentity_Id(identity.getId());
if (ac == null) {
ac = new IdmAuthorityChange();
ac.setIdentity(identity);
}
ac.authoritiesChanged();
repository.save(ac);
}
}
use of eu.bcvsolutions.idm.core.model.entity.IdmIdentityContract in project CzechIdMng by bcvsolutions.
the class IdentityRoleDeleteAuthoritiesProcessor method checkRevokedPermissions.
private void checkRevokedPermissions(IdmIdentityRoleDto identityRole) {
IdmIdentityContract contract = contractRepository.findOne(identityRole.getIdentityContract());
IdmIdentity identity = contract.getIdentity();
List<IdmIdentityRoleDto> roles = identityRoleService.findAllByIdentity(identity.getId());
roles.remove(identityRole);
// represents the final authorities set after role removal
Collection<? extends GrantedAuthority> withoutDeleted = authorityHierarchy.getReachableGrantedAuthorities(authoritiesFactory.getGrantedAuthoritiesForValidRoles(identity.getId(), roles));
Collection<? extends GrantedAuthority> deletedAuthorities = authorityHierarchy.getReachableGrantedAuthorities(authoritiesFactory.getGrantedAuthoritiesForValidRoles(identity.getId(), Collections.singletonList(identityRole)));
if (!authoritiesFactory.containsAllAuthorities(withoutDeleted, deletedAuthorities)) {
// authorities were changed, update identity flag
IdmAuthorityChange ac = repository.findOneByIdentity_Id(identity.getId());
if (ac == null) {
ac = new IdmAuthorityChange();
ac.setIdentity(identity);
}
ac.authoritiesChanged();
repository.save(ac);
}
}
use of eu.bcvsolutions.idm.core.model.entity.IdmIdentityContract 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());
return getPredicateWithComparsion(path, castToType(singularAttribute, rule.getValue()), cb, rule.getComparison(), !pass);
} else if (rule.getType() == AutomaticRoleAttributeRuleType.CONTRACT_EAV) {
IdmFormAttributeDto formAttributeDto = formAttributeService.get(rule.getFormAttribute());
//
Object value = getEavValue(rule.getValue(), formAttributeDto.getPersistentType());
//
Subquery<IdmIdentityContractFormValue> subquery = query.subquery(IdmIdentityContractFormValue.class);
Root<IdmIdentityContractFormValue> subRoot = subquery.from(IdmIdentityContractFormValue.class);
subquery.select(subRoot);
//
Path<?> path = subRoot.get(getSingularAttributeForEav(formAttributeDto.getPersistentType()));
//
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);
//
return existsInEav;
} else if (rule.getType() == AutomaticRoleAttributeRuleType.IDENTITY_EAV) {
IdmFormAttributeDto formAttributeDto = formAttributeService.get(rule.getFormAttribute());
//
Object value = getEavValue(rule.getValue(), formAttributeDto.getPersistentType());
//
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()));
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);
//
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()), cb, rule.getComparison(), null)));
//
return getPredicateForConnection(subquery, cb, pass);
} else {
throw new UnsupportedOperationException("Type: " + rule.getType().name() + ", isn't supported for contract rules!");
}
}
Aggregations