Search in sources :

Example 1 with IdmRoleFilter

use of eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleFilter in project CzechIdMng by bcvsolutions.

the class DefaultAuthorizationManagerIntegrationTest method testPredicate.

@Test
public void testPredicate() {
    loginAsAdmin(InitTestData.TEST_USER_1);
    // prepare role
    IdmRoleDto role = helper.createRole();
    helper.createUuidPolicy(role.getId(), role.getId(), IdmBasePermission.READ);
    helper.createBasePolicy(role.getId(), IdmBasePermission.AUTOCOMPLETE);
    // prepare identity
    IdmIdentityDto identity = helper.createIdentity();
    identity.setPassword(new GuardedString("heslo"));
    identityService.save(identity);
    // assign role
    helper.createIdentityRole(identity, role);
    logout();
    // 
    // empty without login
    IdmRoleFilter filter = new IdmRoleFilter();
    assertEquals(0, roleService.find(filter, null, IdmBasePermission.READ).getTotalElements());
    assertEquals(0, roleService.find(filter, null, IdmBasePermission.AUTOCOMPLETE).getTotalElements());
    // 
    try {
        loginService.login(new LoginDto(identity.getUsername(), identity.getPassword()));
        // 
        // evaluate	access
        assertEquals(1, roleService.find(filter, null, IdmBasePermission.READ).getTotalElements());
        assertEquals(roleService.find(null).getTotalElements(), roleService.find(filter, null, IdmBasePermission.AUTOCOMPLETE).getTotalElements());
    } finally {
        logout();
    }
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleFilter) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) LoginDto(eu.bcvsolutions.idm.core.security.api.dto.LoginDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 2 with IdmRoleFilter

use of eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleFilter in project CzechIdMng by bcvsolutions.

the class RoleDuplicateBulkActionIntegrationTest method testDuplicateRoleOnlyOnTheSameEnvironment.

@Test
public void testDuplicateRoleOnlyOnTheSameEnvironment() {
    IdmRoleDto role = createRole();
    // create attributes, automatic roles etc.
    createRoleFormAttribute(role, getHelper().createName(), getHelper().createName());
    createAutomaticRole(role, getHelper().createTreeNode());
    createAutomaticRole(role, getHelper().createName());
    // 
    Assert.assertFalse(findAllSubRoles(role).isEmpty());
    Assert.assertFalse(findAutomaticRolesByTree(role).isEmpty());
    Assert.assertFalse(findRoleFormAttributes(role).isEmpty());
    Assert.assertFalse(findAutomaticRolesByAttribute(role).isEmpty());
    // 
    String roleBaseCode = role.getBaseCode();
    // 
    IdmBulkActionDto bulkAction = findBulkAction(IdmRole.class, RoleDuplicateBulkAction.NAME);
    bulkAction.setIdentifiers(Sets.newHashSet(role.getId()));
    bulkAction.getProperties().put(DuplicateRoleAutomaticByTreeProcessor.PARAMETER_INCLUDE_AUTOMATIC_ROLE, false);
    bulkAction.getProperties().put(DuplicateRoleFormAttributeProcessor.PARAMETER_INCLUDE_ROLE_FORM_ATTRIBUTE, false);
    bulkAction.getProperties().put(DuplicateRoleCompositionProcessor.PARAMETER_INCLUDE_ROLE_COMPOSITION, false);
    IdmBulkActionDto processAction = bulkActionManager.processAction(bulkAction);
    // 
    checkResultLrt(processAction, 1l, null, null);
    IdmRoleFilter filter = new IdmRoleFilter();
    filter.setEnvironment(role.getEnvironment());
    List<IdmRoleDto> roles = roleService.find(filter, null).getContent();
    IdmRoleDto duplicate = roles.stream().filter(r -> r.getBaseCode().startsWith(roleBaseCode) && !r.getBaseCode().equals(roleBaseCode)).findFirst().get();
    Assert.assertNotNull(duplicate);
    Assert.assertEquals(duplicate.getName(), role.getName());
    Assert.assertEquals(duplicate.getDescription(), role.getDescription());
    // 
    Assert.assertTrue(findAllSubRoles(duplicate).isEmpty());
    Assert.assertTrue(findAutomaticRolesByTree(duplicate).isEmpty());
    Assert.assertTrue(findRoleFormAttributes(duplicate).isEmpty());
    Assert.assertTrue(findAutomaticRolesByAttribute(duplicate).isEmpty());
    // 
    role.setDescription(getHelper().createName());
    // 
    processAction = bulkActionManager.processAction(bulkAction);
    // 
    checkResultLrt(processAction, 1l, null, null);
    // 
    filter = new IdmRoleFilter();
    filter.setProperty(IdmRole_.name.getName());
    filter.setValue(role.getName());
    roles = roleService.find(filter, null).getContent();
    // on the same environment is created the second duplicate
    Assert.assertEquals(3, roles.size());
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmBulkActionDto(eu.bcvsolutions.idm.core.api.bulk.action.dto.IdmBulkActionDto) IdmRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleFilter) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) AbstractBulkActionTest(eu.bcvsolutions.idm.test.api.AbstractBulkActionTest) Test(org.junit.Test)

Example 3 with IdmRoleFilter

use of eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleFilter in project CzechIdMng by bcvsolutions.

the class RoleDuplicateBulkActionIntegrationTest method testDuplicateRoleOnTheSameEnvironmentWithComposition.

/**
 * Sub roles are used the same as on parent
 */
@Test
public void testDuplicateRoleOnTheSameEnvironmentWithComposition() {
    IdmRoleDto role = createRole();
    List<IdmRoleCompositionDto> subRoles = findAllSubRoles(role);
    Assert.assertFalse(subRoles.isEmpty());
    // 
    String roleBaseCode = role.getBaseCode();
    // 
    IdmBulkActionDto bulkAction = findBulkAction(IdmRole.class, RoleDuplicateBulkAction.NAME);
    bulkAction.setIdentifiers(Sets.newHashSet(role.getId()));
    bulkAction.getProperties().put(DuplicateRoleCompositionProcessor.PARAMETER_INCLUDE_ROLE_COMPOSITION, true);
    IdmBulkActionDto processAction = bulkActionManager.processAction(bulkAction);
    // 
    checkResultLrt(processAction, 1l, null, null);
    IdmRoleFilter filter = new IdmRoleFilter();
    filter.setEnvironment(role.getEnvironment());
    List<IdmRoleDto> roles = roleService.find(filter, null).getContent();
    IdmRoleDto duplicate = roles.stream().filter(r -> r.getBaseCode().startsWith(roleBaseCode) && !r.getBaseCode().equals(roleBaseCode)).findFirst().get();
    // 
    List<IdmRoleCompositionDto> duplicateSubRoles = findAllSubRoles(duplicate);
    Assert.assertFalse(duplicateSubRoles.isEmpty());
    Assert.assertEquals(subRoles.size(), duplicateSubRoles.size());
    Assert.assertTrue(duplicateSubRoles.stream().allMatch(s -> subRoles.stream().anyMatch(r -> r.getSub().equals(s.getSub()))));
}
Also used : IdmRoleTreeNodeFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleTreeNodeFilter) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) IdmTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto) Autowired(org.springframework.beans.factory.annotation.Autowired) FormService(eu.bcvsolutions.idm.core.eav.api.service.FormService) CodeableEvaluator(eu.bcvsolutions.idm.core.security.evaluator.CodeableEvaluator) IdmAutomaticRoleAttributeDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto) CoreGroupPermission(eu.bcvsolutions.idm.core.model.domain.CoreGroupPermission) IdmAuthorizationPolicyFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmAuthorizationPolicyFilter) IdmAutomaticRoleAttributeRuleDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeRuleDto) After(org.junit.After) TransactionContextHolder(eu.bcvsolutions.idm.core.api.domain.TransactionContextHolder) IdmRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleFilter) IdmEntityStateService(eu.bcvsolutions.idm.core.api.service.IdmEntityStateService) AutomaticRoleAttributeRuleType(eu.bcvsolutions.idm.core.api.domain.AutomaticRoleAttributeRuleType) IdmIdentity(eu.bcvsolutions.idm.core.model.entity.IdmIdentity) IdmIdentityContractService(eu.bcvsolutions.idm.core.api.service.IdmIdentityContractService) IdmTreeType(eu.bcvsolutions.idm.core.model.entity.IdmTreeType) DuplicateRoleAutomaticByTreeProcessor(eu.bcvsolutions.idm.core.model.event.processor.role.DuplicateRoleAutomaticByTreeProcessor) IdmRoleCompositionService(eu.bcvsolutions.idm.core.api.service.IdmRoleCompositionService) UUID(java.util.UUID) DuplicateRoleFormAttributeProcessor(eu.bcvsolutions.idm.core.model.event.processor.role.DuplicateRoleFormAttributeProcessor) Sets(com.google.common.collect.Sets) IdmEntityStateDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto) List(java.util.List) DuplicateRoleCompositionProcessor(eu.bcvsolutions.idm.core.model.event.processor.role.DuplicateRoleCompositionProcessor) IdmAutomaticRoleAttributeRuleService(eu.bcvsolutions.idm.core.api.service.IdmAutomaticRoleAttributeRuleService) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmAutomaticRoleAttributeService(eu.bcvsolutions.idm.core.api.service.IdmAutomaticRoleAttributeService) IdmRole(eu.bcvsolutions.idm.core.model.entity.IdmRole) IdmRoleFormAttributeDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleFormAttributeDto) IdmRoleTreeNodeService(eu.bcvsolutions.idm.core.api.service.IdmRoleTreeNodeService) IdmRoleCompositionDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleCompositionDto) AbstractBulkActionTest(eu.bcvsolutions.idm.test.api.AbstractBulkActionTest) DuplicateRoleAuthorizationPolicyProcessor(eu.bcvsolutions.idm.core.model.event.processor.role.DuplicateRoleAuthorizationPolicyProcessor) PersistentType(eu.bcvsolutions.idm.core.eav.api.domain.PersistentType) IdmBasePermission(eu.bcvsolutions.idm.core.security.api.domain.IdmBasePermission) OperationResultDto(eu.bcvsolutions.idm.core.api.dto.OperationResultDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) IdmRoleFormAttributeFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleFormAttributeFilter) Before(org.junit.Before) IdmIdentityRoleService(eu.bcvsolutions.idm.core.api.service.IdmIdentityRoleService) IdmRole_(eu.bcvsolutions.idm.core.model.entity.IdmRole_) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmRoleService(eu.bcvsolutions.idm.core.api.service.IdmRoleService) OperationState(eu.bcvsolutions.idm.core.api.domain.OperationState) Test(org.junit.Test) IdmCodeList(eu.bcvsolutions.idm.core.eav.entity.IdmCodeList) IdmRoleFormAttributeService(eu.bcvsolutions.idm.core.api.service.IdmRoleFormAttributeService) ConfigurationMap(eu.bcvsolutions.idm.core.api.domain.ConfigurationMap) IdmRoleTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto) IdmAutomaticRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmAutomaticRoleFilter) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) IdmTreeNode(eu.bcvsolutions.idm.core.model.entity.IdmTreeNode) IdmBulkActionDto(eu.bcvsolutions.idm.core.api.bulk.action.dto.IdmBulkActionDto) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmAuthorizationPolicyDto(eu.bcvsolutions.idm.core.api.dto.IdmAuthorizationPolicyDto) AutomaticRoleAttributeRuleComparison(eu.bcvsolutions.idm.core.api.domain.AutomaticRoleAttributeRuleComparison) IdmIdentity_(eu.bcvsolutions.idm.core.model.entity.IdmIdentity_) IdmAuthorizationPolicyService(eu.bcvsolutions.idm.core.api.service.IdmAuthorizationPolicyService) Assert(org.junit.Assert) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmBulkActionDto(eu.bcvsolutions.idm.core.api.bulk.action.dto.IdmBulkActionDto) IdmRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleFilter) IdmRoleCompositionDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleCompositionDto) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) AbstractBulkActionTest(eu.bcvsolutions.idm.test.api.AbstractBulkActionTest) Test(org.junit.Test)

Example 4 with IdmRoleFilter

use of eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleFilter in project CzechIdMng by bcvsolutions.

the class RoleDuplicateBulkActionIntegrationTest method testDuplicateRoleOnlyOnTheSameEnvironmentGivenAsProperty.

@Test
public void testDuplicateRoleOnlyOnTheSameEnvironmentGivenAsProperty() {
    IdmRoleDto role = createRole();
    // create attributes, automatic roles etc.
    createRoleFormAttribute(role, getHelper().createName(), getHelper().createName());
    createAutomaticRole(role, getHelper().createTreeNode());
    createAutomaticRole(role, getHelper().createName());
    // 
    Assert.assertFalse(findAllSubRoles(role).isEmpty());
    Assert.assertFalse(findAutomaticRolesByTree(role).isEmpty());
    Assert.assertFalse(findRoleFormAttributes(role).isEmpty());
    Assert.assertFalse(findAutomaticRolesByAttribute(role).isEmpty());
    // 
    String roleBaseCode = role.getBaseCode();
    // 
    String targetEnvironment = role.getEnvironment();
    IdmBulkActionDto bulkAction = findBulkAction(IdmRole.class, RoleDuplicateBulkAction.NAME);
    bulkAction.setIdentifiers(Sets.newHashSet(role.getId()));
    bulkAction.getProperties().put(RoleDuplicateBulkAction.PROPERTY_ENVIRONMENT, targetEnvironment);
    bulkAction.getProperties().put(DuplicateRoleAutomaticByTreeProcessor.PARAMETER_INCLUDE_AUTOMATIC_ROLE, false);
    bulkAction.getProperties().put(DuplicateRoleFormAttributeProcessor.PARAMETER_INCLUDE_ROLE_FORM_ATTRIBUTE, false);
    bulkAction.getProperties().put(DuplicateRoleCompositionProcessor.PARAMETER_INCLUDE_ROLE_COMPOSITION, false);
    IdmBulkActionDto processAction = bulkActionManager.processAction(bulkAction);
    // 
    checkResultLrt(processAction, 1l, null, null);
    IdmRoleFilter filter = new IdmRoleFilter();
    filter.setEnvironment(targetEnvironment);
    List<IdmRoleDto> roles = roleService.find(filter, null).getContent();
    IdmRoleDto duplicate = roles.stream().filter(r -> r.getBaseCode().startsWith(roleBaseCode) && !r.getBaseCode().equals(roleBaseCode)).findFirst().get();
    Assert.assertEquals(role.getName(), duplicate.getName());
    Assert.assertEquals(role.getDescription(), duplicate.getDescription());
    // 
    Assert.assertTrue(findAllSubRoles(duplicate).isEmpty());
    Assert.assertTrue(findAutomaticRolesByTree(duplicate).isEmpty());
    Assert.assertTrue(findRoleFormAttributes(duplicate).isEmpty());
    Assert.assertTrue(findAutomaticRolesByAttribute(duplicate).isEmpty());
    // 
    role.setDescription(getHelper().createName());
    // 
    processAction = bulkActionManager.processAction(bulkAction);
    // 
    checkResultLrt(processAction, 1l, null, null);
    // 
    filter = new IdmRoleFilter();
    filter.setProperty(IdmRole_.name.getName());
    filter.setValue(role.getName());
    roles = roleService.find(filter, null).getContent();
    // on the same environment is created the second duplicate
    Assert.assertEquals(3, roles.size());
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmBulkActionDto(eu.bcvsolutions.idm.core.api.bulk.action.dto.IdmBulkActionDto) IdmRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleFilter) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) AbstractBulkActionTest(eu.bcvsolutions.idm.test.api.AbstractBulkActionTest) Test(org.junit.Test)

Example 5 with IdmRoleFilter

use of eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleFilter in project CzechIdMng by bcvsolutions.

the class RoleDeleteBulkActionIntegrationTest method processBulkActionByFilter.

@Test
public void processBulkActionByFilter() {
    String testDescription = "bulkActionName" + System.currentTimeMillis();
    List<IdmRoleDto> roles = this.createRoles(5);
    for (IdmRoleDto role : roles) {
        role.setDescription(testDescription);
        role = roleService.save(role);
    }
    IdmRoleFilter filter = new IdmRoleFilter();
    filter.setValue(testDescription);
    filter.setProperty(IdmRole_.description.getName());
    List<IdmRoleDto> checkIdentities = roleService.find(filter, null).getContent();
    assertEquals(5, checkIdentities.size());
    IdmBulkActionDto bulkAction = this.findBulkAction(IdmRole.class, RoleDeleteBulkAction.NAME);
    bulkAction.setTransformedFilter(filter);
    bulkAction.setFilter(toMap(filter));
    IdmBulkActionDto processAction = bulkActionManager.processAction(bulkAction);
    checkResultLrt(processAction, 5l, null, null);
    for (IdmRoleDto role : roles) {
        IdmRoleDto dto = roleService.get(role.getId());
        assertNull(dto);
    }
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmBulkActionDto(eu.bcvsolutions.idm.core.api.bulk.action.dto.IdmBulkActionDto) IdmRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleFilter) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) AbstractBulkActionTest(eu.bcvsolutions.idm.test.api.AbstractBulkActionTest) Test(org.junit.Test)

Aggregations

IdmRoleFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleFilter)54 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)46 Test (org.junit.Test)41 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)22 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)17 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)17 IdmRoleCatalogueDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleCatalogueDto)16 SysSyncLogDto (eu.bcvsolutions.idm.acc.dto.SysSyncLogDto)14 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)14 IdmRole (eu.bcvsolutions.idm.core.model.entity.IdmRole)10 IdmFormValueDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto)9 List (java.util.List)9 Assert (org.junit.Assert)9 Autowired (org.springframework.beans.factory.annotation.Autowired)9 SysSyncRoleConfigDto (eu.bcvsolutions.idm.acc.dto.SysSyncRoleConfigDto)8 UUID (java.util.UUID)8 AbstractSysSyncConfigDto (eu.bcvsolutions.idm.acc.dto.AbstractSysSyncConfigDto)7 SysSyncConfigFilter (eu.bcvsolutions.idm.acc.dto.filter.SysSyncConfigFilter)7 CoreGroupPermission (eu.bcvsolutions.idm.core.model.domain.CoreGroupPermission)7 TestHelper (eu.bcvsolutions.idm.test.api.TestHelper)7