use of eu.bcvsolutions.idm.core.model.entity.IdmIdentity in project CzechIdMng by bcvsolutions.
the class SubordinateContractEvaluator method getPermissions.
@Override
public Set<String> getPermissions(IdmIdentityContract entity, AuthorizationPolicy policy) {
Set<String> permissions = super.getPermissions(entity, policy);
if (entity == null || !securityService.isAuthenticated()) {
return permissions;
}
IdmIdentity identity = entity.getIdentity();
if (identity == null) {
// new contract is saved together with idenitity - identity is not created now.
return permissions;
}
IdmIdentityFilter filter = new IdmIdentityFilter();
// required - filter is registered to this property
filter.setManagersFor(identity.getId());
filter.setManagersByContract(entity.getId());
filter.setUsername(securityService.getUsername());
boolean isManager = identityService.findIds(filter, PageRequest.of(0, 1)).getTotalElements() > 0;
if (isManager) {
permissions.addAll(policy.getPermissions());
}
return permissions;
}
use of eu.bcvsolutions.idm.core.model.entity.IdmIdentity in project CzechIdMng by bcvsolutions.
the class AbstractWorkingPositionFilterIntegrationTest method testSubordinatesBuilder.
protected void testSubordinatesBuilder(FilterBuilder<IdmIdentity, IdmIdentityFilter> builder) {
IdmIdentityFilter filter = new IdmIdentityFilter();
filter.setSubordinatesFor(managerOne.getId());
filter.setIncludeGuarantees(false);
List<IdmIdentity> subordinates = builder.find(filter, null).getContent();
assertTrue(contains(subordinates, subordinateOne));
assertEquals(1, subordinates.size());
//
filter = new IdmIdentityFilter();
filter.setSubordinatesFor(managerOne.getId());
filter.setIncludeGuarantees(true);
subordinates = builder.find(filter, null).getContent();
assertTrue(contains(subordinates, subordinateOne));
assertTrue(contains(subordinates, subordinateThree));
assertEquals(2, subordinates.size());
//
filter = new IdmIdentityFilter();
filter.setSubordinatesFor(managerOne.getId());
filter.setSubordinatesByTreeType(structureOne.getId());
subordinates = builder.find(filter, null).getContent();
assertEquals(1, subordinates.size());
assertTrue(contains(subordinates, subordinateOne));
//
filter = new IdmIdentityFilter();
filter.setSubordinatesFor(guaranteeFour.getId());
subordinates = builder.find(filter, null).getContent();
assertEquals(2, subordinates.size());
assertTrue(contains(subordinates, subordinateOne));
assertTrue(contains(subordinates, subordinateTwo));
//
filter = new IdmIdentityFilter();
filter.setSubordinatesFor(invalidManagerExpiredContract.getId());
subordinates = builder.find(filter, null).getContent();
assertTrue(subordinates.isEmpty());
}
use of eu.bcvsolutions.idm.core.model.entity.IdmIdentity in project CzechIdMng by bcvsolutions.
the class DefaultFilterManagerIntegrationTest method testDisableSubordinatesBuilder.
@Test
public void testDisableSubordinatesBuilder() {
IdmIdentityDto subordinate = getHelper().createIdentity((GuardedString) null);
IdmIdentityDto manager = getHelper().createIdentity((GuardedString) null);
getHelper().createContractGuarantee(getHelper().getPrimeContract(subordinate.getId()).getId(), manager.getId());
//
FilterBuilder<IdmIdentity, DataFilter> filter = filterManager.getBuilder(IdmIdentity.class, IdmIdentityFilter.PARAMETER_SUBORDINATES_FOR);
String enabledPropertyName = filter.getConfigurationPropertyName(ConfigurationService.PROPERTY_ENABLED);
String implProperty = filter.getConfigurationPropertyName(ConfigurationService.PROPERTY_IMPLEMENTATION);
String currentFilterBeanName = filter.getConfigurationValue(ConfigurationService.PROPERTY_IMPLEMENTATION);
//
Assert.assertNotNull(filter);
Assert.assertFalse(filter.isDisabled());
IdmIdentityFilter identityFilter = new IdmIdentityFilter();
identityFilter.setSubordinatesFor(manager.getId());
identityFilter.setIncludeGuarantees(true);
List<IdmIdentityDto> subordinates = getHelper().getService(IdmIdentityService.class).find(identityFilter, null).getContent();
Assert.assertEquals(1, subordinates.size());
Assert.assertEquals(subordinate.getId(), subordinates.get(0).getId());
//
try {
configurationService.setBooleanValue(enabledPropertyName, false);
//
filter = filterManager.getBuilder(IdmIdentity.class, IdmIdentityFilter.PARAMETER_SUBORDINATES_FOR);
Assert.assertNotNull(filter);
Assert.assertTrue(filter.isDisabled());
//
subordinates = getHelper().getService(IdmIdentityService.class).find(identityFilter, null).getContent();
Assert.assertTrue(subordinates.isEmpty());
//
// configure different filter - should be disabled to
configurationService.setValue(implProperty, GuaranteeSubordinatesFilter.BEAN_NAME);
filter = filterManager.getBuilder(IdmIdentity.class, IdmIdentityFilter.PARAMETER_SUBORDINATES_FOR);
//
Assert.assertNotNull(filter);
Assert.assertTrue(filter.isDisabled());
Assert.assertEquals(GuaranteeSubordinatesFilter.BEAN_NAME, filter.getConfigurationValue(ConfigurationService.PROPERTY_IMPLEMENTATION));
//
subordinates = getHelper().getService(IdmIdentityService.class).find(identityFilter, null).getContent();
Assert.assertTrue(subordinates.isEmpty());
} finally {
configurationService.setBooleanValue(enabledPropertyName, true);
configurationService.setValue(implProperty, currentFilterBeanName);
}
}
use of eu.bcvsolutions.idm.core.model.entity.IdmIdentity in project CzechIdMng by bcvsolutions.
the class DefaultFilterManagerUnitTest method testFindByText.
@SuppressWarnings("serial")
@Test
public void testFindByText() {
FilterBuilderDto dto = new FilterBuilderDto();
dto.setName("test-x");
dto.setDescription("x-Test-x");
dto.setEntityClass(IdmIdentity.class);
dto.setFilterBuilderClass(IdmIdentityService.class);
//
FilterBuilderFilter filter = new FilterBuilderFilter();
filter.setText("tesT-");
Assert.assertTrue(manager.passFilter(dto, filter));
filter.setText("x-tesT");
Assert.assertTrue(manager.passFilter(dto, filter));
filter.setText("xtesT");
Assert.assertFalse(manager.passFilter(dto, filter));
dto.setDescription(null);
filter.setText("x-t");
Assert.assertFalse(manager.passFilter(dto, filter));
filter.setText("ident");
Assert.assertTrue(manager.passFilter(dto, filter));
filter.setText("service");
Assert.assertTrue(manager.passFilter(dto, filter));
//
// inline classes with null cannonical name
dto.setFilterBuilderClass((new IdmIdentity() {
}).getClass());
Assert.assertFalse(manager.passFilter(dto, filter));
filter.setText("ident");
Assert.assertTrue(manager.passFilter(dto, filter));
}
use of eu.bcvsolutions.idm.core.model.entity.IdmIdentity in project CzechIdMng by bcvsolutions.
the class DefaultIdmConfidentialStorageIntegrationTest method testUnpersistedOwnerWithId.
@Test
@Transactional
public void testUnpersistedOwnerWithId() {
String storageKeyOne = getHelper().createName();
// unpersisted identity
IdmIdentity owner = new IdmIdentity(UUID.randomUUID());
Assert.assertNull(confidentalStorage.get(owner.getId(), IdmIdentity.class, storageKeyOne));
}
Aggregations