Search in sources :

Example 51 with IdmIdentity

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;
}
Also used : IdmIdentityFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityFilter) IdmIdentity(eu.bcvsolutions.idm.core.model.entity.IdmIdentity)

Example 52 with IdmIdentity

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());
}
Also used : IdmIdentityFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityFilter) IdmIdentity(eu.bcvsolutions.idm.core.model.entity.IdmIdentity)

Example 53 with IdmIdentity

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);
    }
}
Also used : DataFilter(eu.bcvsolutions.idm.core.api.dto.filter.DataFilter) IdmIdentityService(eu.bcvsolutions.idm.core.api.service.IdmIdentityService) IdmIdentityFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityFilter) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentity(eu.bcvsolutions.idm.core.model.entity.IdmIdentity) Test(org.junit.Test) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)

Example 54 with IdmIdentity

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));
}
Also used : FilterBuilderFilter(eu.bcvsolutions.idm.core.api.dto.filter.FilterBuilderFilter) FilterBuilderDto(eu.bcvsolutions.idm.core.api.dto.FilterBuilderDto) IdmIdentity(eu.bcvsolutions.idm.core.model.entity.IdmIdentity) Test(org.junit.Test) AbstractUnitTest(eu.bcvsolutions.idm.test.api.AbstractUnitTest)

Example 55 with IdmIdentity

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));
}
Also used : GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmIdentity(eu.bcvsolutions.idm.core.model.entity.IdmIdentity) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

IdmIdentity (eu.bcvsolutions.idm.core.model.entity.IdmIdentity)58 Test (org.junit.Test)44 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)28 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)20 IdmIdentityFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityFilter)18 AbstractUnitTest (eu.bcvsolutions.idm.test.api.AbstractUnitTest)13 Transactional (org.springframework.transaction.annotation.Transactional)11 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)9 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)9 IdmIdentityService (eu.bcvsolutions.idm.core.api.service.IdmIdentityService)7 DataFilter (eu.bcvsolutions.idm.core.api.dto.filter.DataFilter)6 List (java.util.List)6 Autowired (org.springframework.beans.factory.annotation.Autowired)6 IdmIdentityContract (eu.bcvsolutions.idm.core.model.entity.IdmIdentityContract)5 Assert (org.junit.Assert)5 IdmAuthorityChange (eu.bcvsolutions.idm.core.model.entity.IdmAuthorityChange)4 UUID (java.util.UUID)4 Identifiable (eu.bcvsolutions.idm.core.api.domain.Identifiable)3 IdmEntityEventDto (eu.bcvsolutions.idm.core.api.dto.IdmEntityEventDto)3 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)3