use of eu.bcvsolutions.idm.core.model.entity.IdmIdentity in project CzechIdMng by bcvsolutions.
the class SubordinatesEvaluator method getPredicate.
@Override
public Predicate getPredicate(Root<IdmIdentity> root, CriteriaQuery<?> query, CriteriaBuilder builder, AuthorizationPolicy policy, BasePermission... permission) {
if (!hasPermission(policy, permission)) {
return null;
}
if (!securityService.isAuthenticated()) {
return null;
}
IdmIdentityFilter filter = new IdmIdentityFilter();
filter.setSubordinatesFor(securityService.getAuthentication().getCurrentIdentity().getId());
//
return filterManager.getBuilder(IdmIdentity.class, IdmIdentityFilter.PARAMETER_SUBORDINATES_FOR).getPredicate(root, query, builder, filter);
}
use of eu.bcvsolutions.idm.core.model.entity.IdmIdentity in project CzechIdMng by bcvsolutions.
the class DefaultFormServiceIntegrationTest method testOwnerWithoutId.
@Test(expected = IllegalArgumentException.class)
public void testOwnerWithoutId() {
// unpersisted identity
Identifiable owner = new IdmIdentity();
formService.getValues(owner);
}
use of eu.bcvsolutions.idm.core.model.entity.IdmIdentity in project CzechIdMng by bcvsolutions.
the class DefaultFormServiceIntegrationTest method testFillFormValues.
@Test
public void testFillFormValues() {
Identifiable owner = getHelper().createIdentity((GuardedString) null);
//
// create definition one
IdmFormAttributeDto attributeDefinitionOne = new IdmFormAttributeDto();
attributeDefinitionOne.setCode(getHelper().createName());
attributeDefinitionOne.setName(attributeDefinitionOne.getCode());
attributeDefinitionOne.setPersistentType(PersistentType.TEXT);
IdmFormDefinitionDto formDefinitionOne = formService.createDefinition(IdmIdentity.class.getCanonicalName(), getHelper().createName(), Lists.newArrayList(attributeDefinitionOne));
attributeDefinitionOne = formDefinitionOne.getMappedAttributeByCode(attributeDefinitionOne.getCode());
//
// create definition two
IdmFormAttributeDto attributeDefinitionTwo = new IdmFormAttributeDto();
attributeDefinitionTwo.setCode(getHelper().createName());
attributeDefinitionTwo.setName(attributeDefinitionTwo.getCode());
attributeDefinitionTwo.setPersistentType(PersistentType.TEXT);
IdmFormDefinitionDto formDefinitionTwo = formService.createDefinition(IdmIdentity.class.getCanonicalName(), getHelper().createName(), Lists.newArrayList(attributeDefinitionTwo));
attributeDefinitionTwo = formDefinitionTwo.getMappedAttributeByCode(attributeDefinitionTwo.getCode());
//
IdmFormValueDto value1 = new IdmFormValueDto(attributeDefinitionOne);
value1.setValue(FORM_VALUE_ONE);
IdmFormValueDto value2 = new IdmFormValueDto(attributeDefinitionTwo);
value2.setValue(FORM_VALUE_TWO);
formService.saveValues(owner, formDefinitionOne, Lists.newArrayList(value1));
formService.saveValues(owner, formDefinitionTwo, Lists.newArrayList(value2));
assertEquals(FORM_VALUE_ONE, formService.getValues(owner, formDefinitionOne).get(0).getStringValue());
assertEquals(FORM_VALUE_TWO, formService.getValues(owner, formDefinitionTwo).get(0).getStringValue());
//
// create second owner
Identifiable owner2 = getHelper().createIdentity((GuardedString) null);
assertEquals(0, formService.getValues(owner2, formDefinitionOne).size());
assertEquals(1, formService.getValues(owner, formDefinitionOne).size());
assertEquals(1, formService.getValues(owner, formDefinitionTwo).size());
identityService.deleteById(owner2.getId());
// TODO: remove this test? - not exists entity has to be given
assertEquals(0, formService.getValues(new IdmIdentity((UUID) owner2.getId()), formDefinitionOne).size());
assertEquals(1, formService.getValues(owner, formDefinitionOne).size());
assertEquals(1, formService.getValues(owner, formDefinitionTwo).size());
formService.deleteValues(owner, formDefinitionOne);
assertEquals(0, formService.getValues(owner, formDefinitionOne).size());
assertEquals(1, formService.getValues(owner, formDefinitionTwo).size());
assertEquals(FORM_VALUE_TWO, formService.getValues(owner, formDefinitionTwo).get(0).getStringValue());
identityService.deleteById(owner.getId());
assertEquals(0, formService.getValues(new IdmIdentity((UUID) owner.getId()), formDefinitionOne).size());
assertEquals(0, formService.getValues(new IdmIdentity((UUID) owner.getId()), formDefinitionTwo).size());
}
use of eu.bcvsolutions.idm.core.model.entity.IdmIdentity in project CzechIdMng by bcvsolutions.
the class IdentityFilterTest method testManagersForFilter.
@Test
public void testManagersForFilter() {
FilterBuilder<IdmIdentity, DataFilter> filterBuilderSubordinates = filterManager.getBuilder(IdmIdentity.class, IdmIdentityFilter.PARAMETER_SUBORDINATES_FOR);
FilterBuilder<IdmIdentity, DataFilter> filterBuilderManagers = filterManager.getBuilder(IdmIdentity.class, IdmIdentityFilter.PARAMETER_MANAGERS_FOR);
FilterBuilder<IdmIdentityContract, DataFilter> filterBuilderContractByManager = filterManager.getBuilder(IdmIdentityContract.class, IdmIdentityContractFilter.PARAMETER_SUBORDINATES_FOR);
Assert.assertEquals(DefaultManagersFilter.FILTER_NAME, filterBuilderManagers.getId());
Assert.assertEquals(DefaultSubordinatesFilter.FILTER_NAME, filterBuilderSubordinates.getId());
Assert.assertEquals(DefaultContractByManagerFilter.FILTER_NAME, filterBuilderContractByManager.getId());
Assert.assertFalse(filterBuilderSubordinates.isDisabled());
Assert.assertFalse(filterBuilderManagers.isDisabled());
Assert.assertFalse(filterBuilderContractByManager.isDisabled());
//
IdmIdentityDto person = getIdmIdentity("ThisIsTestName009", "ThisIsTestName009", "ThisIsTestName009@gemail.eu", "000000009", false);
IdmIdentityDto manager = getIdmIdentity("ThisIsTestName010", "ThisIsTestName010", "ThisIsTestName010@gemail.eu", "000000010", false);
IdmTreeTypeDto type1 = getHelper().createTreeType();
IdmTreeNodeDto node2 = getHelper().createTreeNode(type1, null);
IdmTreeNodeDto node1 = getHelper().createTreeNode(type1, node2);
getHelper().createContract(manager, node2);
getHelper().createContract(person, node1);
//
IdmIdentityFilter filter = new IdmIdentityFilter();
filter.setIncludeGuarantees(false);
filter.setManagersFor(person.getId());
filter.setManagersByTreeType(type1.getId());
List<IdmIdentityDto> results = identityService.find(filter, null).getContent();
Assert.assertEquals(1, results.size());
Assert.assertEquals(manager.getId(), results.get(0).getId());
}
use of eu.bcvsolutions.idm.core.model.entity.IdmIdentity in project CzechIdMng by bcvsolutions.
the class ReadAccountByIdentityEvaluator method getPredicate.
@Override
public Predicate getPredicate(Root<AccAccount> root, CriteriaQuery<?> query, CriteriaBuilder builder, AuthorizationPolicy policy, BasePermission... permission) {
UUID currentId = securityService.getCurrentId();
if (!hasAuthority(currentId, policy, permission) || !securityService.isAuthenticated()) {
return null;
}
// System identity account subquery
Subquery<AccIdentityAccount> subquery = query.subquery(AccIdentityAccount.class);
Root<AccIdentityAccount> subRoot = subquery.from(AccIdentityAccount.class);
subquery.select(subRoot);
// Identity subquery
Subquery<IdmIdentity> subqueryIdentity = query.subquery(IdmIdentity.class);
Root<IdmIdentity> subRootIdentity = subqueryIdentity.from(IdmIdentity.class);
subqueryIdentity.select(subRootIdentity);
// Subselect for identity
subqueryIdentity.where(builder.and(authorizationManager.getPredicate(subRootIdentity, query, builder, permission), builder.equal(subRootIdentity, subRoot.get(AccIdentityAccount_.identity))));
// Subselect for identity account
subquery.where(//
builder.and(builder.equal(root, subRoot.get(AccIdentityAccount_.account)), builder.exists(subqueryIdentity)));
//
return builder.exists(subquery);
}
Aggregations