Search in sources :

Example 6 with IdmAuthorizationPolicyFilter

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

the class DuplicateRoleAuthorizationPolicyProcessor method process.

@Override
public EventResult<IdmRoleDto> process(EntityEvent<IdmRoleDto> event) {
    // newly set role
    IdmRoleDto duplicate = event.getContent();
    // cloned role
    IdmRoleDto originalSource = event.getOriginalSource();
    // just for sure
    Assert.notNull(originalSource.getId(), "Original source identifier is required.");
    // 
    // find current, create new and delete not present authorization policies
    IdmAuthorizationPolicyFilter filter = new IdmAuthorizationPolicyFilter();
    filter.setRoleId(duplicate.getId());
    List<IdmAuthorizationPolicyDto> currentPolicies = Lists.newArrayList(authorizationPolicyService.find(filter, null).getContent());
    // and create new authorization policies
    filter.setRoleId(originalSource.getId());
    authorizationPolicyService.find(filter, null).filter(// find and remove from list => processed
    policy -> findCurrent(currentPolicies, policy) == null).forEach(policy -> {
        policy.setId(null);
        DtoUtils.clearAuditFields(policy);
        policy.setRole(duplicate.getId());
        // 
        EntityEvent<IdmAuthorizationPolicyDto> subEvent = new AuthorizationPolicyEvent(AuthorizationPolicyEventType.CREATE, policy);
        // we want to be sync (same as other, but no reason now)
        subEvent.setPriority(PriorityType.IMMEDIATE);
        // 
        authorizationPolicyService.publish(subEvent, event);
    });
    // 
    // remove not found (~not present in original) policies
    currentPolicies.forEach(policy -> {
        EntityEvent<IdmAuthorizationPolicyDto> subEvent = new AuthorizationPolicyEvent(AuthorizationPolicyEventType.DELETE, policy);
        // we want to be sync (same as other, but no reason now)
        subEvent.setPriority(PriorityType.IMMEDIATE);
        // 
        authorizationPolicyService.publish(subEvent, event);
    });
    // 
    return new DefaultEventResult<>(event, this);
}
Also used : Description(org.springframework.context.annotation.Description) RoleProcessor(eu.bcvsolutions.idm.core.api.event.processor.RoleProcessor) AuthorizationPolicyEvent(eu.bcvsolutions.idm.core.model.event.AuthorizationPolicyEvent) DtoUtils(eu.bcvsolutions.idm.core.api.utils.DtoUtils) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) Autowired(org.springframework.beans.factory.annotation.Autowired) CoreEventProcessor(eu.bcvsolutions.idm.core.api.event.CoreEventProcessor) PriorityType(eu.bcvsolutions.idm.core.api.domain.PriorityType) PersistentType(eu.bcvsolutions.idm.core.eav.api.domain.PersistentType) List(java.util.List) Component(org.springframework.stereotype.Component) IdmAuthorizationPolicyFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmAuthorizationPolicyFilter) Lists(com.google.common.collect.Lists) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmAuthorizationPolicyDto(eu.bcvsolutions.idm.core.api.dto.IdmAuthorizationPolicyDto) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) EventResult(eu.bcvsolutions.idm.core.api.event.EventResult) IdmAuthorizationPolicyService(eu.bcvsolutions.idm.core.api.service.IdmAuthorizationPolicyService) RoleEventType(eu.bcvsolutions.idm.core.model.event.RoleEvent.RoleEventType) EntityEvent(eu.bcvsolutions.idm.core.api.event.EntityEvent) Assert(org.springframework.util.Assert) AuthorizationPolicyEventType(eu.bcvsolutions.idm.core.model.event.AuthorizationPolicyEvent.AuthorizationPolicyEventType) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) IdmAuthorizationPolicyDto(eu.bcvsolutions.idm.core.api.dto.IdmAuthorizationPolicyDto) IdmAuthorizationPolicyFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmAuthorizationPolicyFilter) AuthorizationPolicyEvent(eu.bcvsolutions.idm.core.model.event.AuthorizationPolicyEvent)

Example 7 with IdmAuthorizationPolicyFilter

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

the class DefaultIdmAuthorizationPolicyService method getDefaultPolicies.

@Override
@Transactional(readOnly = true)
public List<IdmAuthorizationPolicyDto> getDefaultPolicies(Class<? extends Identifiable> entityType) {
    IdmRoleDto defaultRole = roleService.getDefaultRole();
    if (defaultRole == null) {
        LOG.debug("Default role not found, no default authorization policies will be added.  Change configuration [{}].", IdmRoleService.PROPERTY_DEFAULT_ROLE);
        return Collections.<IdmAuthorizationPolicyDto>emptyList();
    }
    if (defaultRole.isDisabled()) {
        LOG.debug("Default role [{}] is disabled, no default authorization policies will be added.", defaultRole.getCode());
        return Collections.<IdmAuthorizationPolicyDto>emptyList();
    }
    // 
    UUID defaultRoleId = defaultRole.getId();
    IdmAuthorizationPolicyFilter filter = new IdmAuthorizationPolicyFilter();
    filter.setDisabled(Boolean.FALSE);
    if (entityType != null) {
        // optional
        filter.setAuthorizableType(entityType.getCanonicalName());
    }
    // default role policies
    filter.setRoleId(defaultRoleId);
    List<IdmAuthorizationPolicyDto> defaultPolicies = new ArrayList<>();
    defaultPolicies.addAll(find(filter, null).getContent());
    // all sub roles policies
    roleCompositionService.findAllSubRoles(defaultRoleId).stream().filter(roleComposition -> {
        IdmRoleDto subRole = DtoUtils.getEmbedded(roleComposition, IdmRoleComposition_.sub);
        return !subRole.isDisabled();
    }).forEach(roleComposition -> {
        filter.setRoleId(roleComposition.getSub());
        defaultPolicies.addAll(find(filter, null).getContent());
    });
    // 
    LOG.debug("Found [{}] default policies", defaultPolicies.size());
    // 
    return defaultPolicies;
}
Also used : DtoUtils(eu.bcvsolutions.idm.core.api.utils.DtoUtils) Autowired(org.springframework.beans.factory.annotation.Autowired) SiemLoggerManager(eu.bcvsolutions.idm.core.api.audit.service.SiemLoggerManager) StringUtils(org.apache.commons.lang3.StringUtils) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) CoreGroupPermission(eu.bcvsolutions.idm.core.model.domain.CoreGroupPermission) IdmAuthorizationPolicyFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmAuthorizationPolicyFilter) IdmBasePermission(eu.bcvsolutions.idm.core.security.api.domain.IdmBasePermission) LookupService(eu.bcvsolutions.idm.core.api.service.LookupService) Predicate(javax.persistence.criteria.Predicate) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) IdmAuthorizationPolicyRepository(eu.bcvsolutions.idm.core.model.repository.IdmAuthorizationPolicyRepository) ModuleService(eu.bcvsolutions.idm.core.api.service.ModuleService) EntityEvent(eu.bcvsolutions.idm.core.api.event.EntityEvent) Root(javax.persistence.criteria.Root) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) IdmRole_(eu.bcvsolutions.idm.core.model.entity.IdmRole_) ImmutableMap(com.google.common.collect.ImmutableMap) IdmRoleComposition_(eu.bcvsolutions.idm.core.model.entity.IdmRoleComposition_) AbstractEventableDtoService(eu.bcvsolutions.idm.core.api.service.AbstractEventableDtoService) IdmRoleService(eu.bcvsolutions.idm.core.api.service.IdmRoleService) Set(java.util.Set) DefaultGrantedAuthority(eu.bcvsolutions.idm.core.security.api.domain.DefaultGrantedAuthority) IdmRoleCompositionService(eu.bcvsolutions.idm.core.api.service.IdmRoleCompositionService) UUID(java.util.UUID) IdmAuthorizationPolicy(eu.bcvsolutions.idm.core.model.entity.IdmAuthorizationPolicy) Sets(com.google.common.collect.Sets) GrantedAuthority(org.springframework.security.core.GrantedAuthority) Objects(java.util.Objects) IdmAuthorizationPolicy_(eu.bcvsolutions.idm.core.model.entity.IdmAuthorizationPolicy_) List(java.util.List) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) CoreResultCode(eu.bcvsolutions.idm.core.api.domain.CoreResultCode) IdmAuthorizationPolicyDto(eu.bcvsolutions.idm.core.api.dto.IdmAuthorizationPolicyDto) LocalDate(java.time.LocalDate) Identifiable(eu.bcvsolutions.idm.core.api.domain.Identifiable) IdmAuthorizationPolicyService(eu.bcvsolutions.idm.core.api.service.IdmAuthorizationPolicyService) IdmGroupPermission(eu.bcvsolutions.idm.core.security.api.domain.IdmGroupPermission) Collections(java.util.Collections) EntityEventManager(eu.bcvsolutions.idm.core.api.service.EntityEventManager) AuthorizableType(eu.bcvsolutions.idm.core.security.api.dto.AuthorizableType) Transactional(org.springframework.transaction.annotation.Transactional) Assert(org.springframework.util.Assert) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) ArrayList(java.util.ArrayList) IdmAuthorizationPolicyDto(eu.bcvsolutions.idm.core.api.dto.IdmAuthorizationPolicyDto) IdmAuthorizationPolicyFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmAuthorizationPolicyFilter) UUID(java.util.UUID) Transactional(org.springframework.transaction.annotation.Transactional)

Example 8 with IdmAuthorizationPolicyFilter

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

the class IdmAuthorizationPolicyControllerRestTest method testFindByIdentityId.

@Test
public void testFindByIdentityId() {
    // default role is enabled by default - disable
    String defaultRoleCode = roleConfiguration.getDefaultRoleCode();
    // 
    try {
        // disable default role
        getHelper().setConfigurationValue(RoleConfiguration.PROPERTY_DEFAULT_ROLE, "");
        // 
        // create test data
        IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
        // 
        IdmAuthorizationPolicyFilter filter = new IdmAuthorizationPolicyFilter();
        filter.setIdentityId(identity.getId());
        List<IdmAuthorizationPolicyDto> policies = find(filter);
        Assert.assertTrue(policies.isEmpty());
        // 
        // assign role
        IdmRoleDto role = getHelper().createRole();
        IdmAuthorizationPolicyDto policy = getHelper().createBasePolicy(role.getId(), IdmBasePermission.AUTOCOMPLETE);
        getHelper().createIdentityRole(identity, role);
        // 
        policies = find(filter);
        Assert.assertEquals(1, policies.size());
        Assert.assertTrue(policies.stream().anyMatch(p -> p.getId().equals(policy.getId())));
        // 
        // configure default role
        IdmRoleDto defaultRole = getHelper().createRole();
        IdmAuthorizationPolicyDto defaultPolicy = getHelper().createBasePolicy(defaultRole.getId(), IdmBasePermission.READ);
        getHelper().setConfigurationValue(RoleConfiguration.PROPERTY_DEFAULT_ROLE, defaultRole.getId().toString());
        // 
        policies = find(filter);
        Assert.assertEquals(2, policies.size());
        Assert.assertTrue(policies.stream().anyMatch(p -> p.getId().equals(policy.getId())));
        Assert.assertTrue(policies.stream().anyMatch(p -> p.getId().equals(defaultPolicy.getId())));
    } finally {
        getHelper().setConfigurationValue(RoleConfiguration.PROPERTY_DEFAULT_ROLE, defaultRoleCode);
    }
}
Also used : IdmIdentity(eu.bcvsolutions.idm.core.model.entity.IdmIdentity) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) Autowired(org.springframework.beans.factory.annotation.Autowired) Test(org.junit.Test) RoleConfiguration(eu.bcvsolutions.idm.core.api.config.domain.RoleConfiguration) AuthorizationPolicyByIdentityFilterBuilder(eu.bcvsolutions.idm.core.model.repository.filter.AuthorizationPolicyByIdentityFilterBuilder) StringUtils(org.apache.commons.lang3.StringUtils) AbstractReadWriteDtoControllerRestTest(eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoControllerRestTest) CoreGroupPermission(eu.bcvsolutions.idm.core.model.domain.CoreGroupPermission) List(java.util.List) IdmAuthorizationPolicyFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmAuthorizationPolicyFilter) IdmBasePermission(eu.bcvsolutions.idm.core.security.api.domain.IdmBasePermission) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) AbstractReadWriteDtoController(eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoController) IdmAuthorizationPolicyDto(eu.bcvsolutions.idm.core.api.dto.IdmAuthorizationPolicyDto) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmGroupPermission(eu.bcvsolutions.idm.core.security.api.domain.IdmGroupPermission) Assert(org.junit.Assert) BasePermissionEvaluator(eu.bcvsolutions.idm.core.security.evaluator.BasePermissionEvaluator) IdmRole(eu.bcvsolutions.idm.core.model.entity.IdmRole) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmAuthorizationPolicyDto(eu.bcvsolutions.idm.core.api.dto.IdmAuthorizationPolicyDto) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmAuthorizationPolicyFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmAuthorizationPolicyFilter) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) Test(org.junit.Test) AbstractReadWriteDtoControllerRestTest(eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoControllerRestTest)

Example 9 with IdmAuthorizationPolicyFilter

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

the class IdmAuthorizationPolicyControllerRestTest method testFindByRoleId.

@Test
public void testFindByRoleId() {
    IdmRoleDto roleOne = getHelper().createRole();
    IdmRoleDto roleOther = getHelper().createRole();
    // 
    IdmAuthorizationPolicyDto policyOne = getHelper().createBasePolicy(roleOne.getId(), IdmBasePermission.READ);
    // other
    getHelper().createBasePolicy(roleOther.getId(), IdmBasePermission.UPDATE);
    // 
    // 
    IdmAuthorizationPolicyFilter filter = new IdmAuthorizationPolicyFilter();
    filter.setRoleId(roleOne.getId());
    List<IdmAuthorizationPolicyDto> policies = find(filter);
    Assert.assertEquals(1, policies.size());
    Assert.assertTrue(policies.stream().anyMatch(p -> p.getId().equals(policyOne.getId())));
}
Also used : IdmIdentity(eu.bcvsolutions.idm.core.model.entity.IdmIdentity) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) Autowired(org.springframework.beans.factory.annotation.Autowired) Test(org.junit.Test) RoleConfiguration(eu.bcvsolutions.idm.core.api.config.domain.RoleConfiguration) AuthorizationPolicyByIdentityFilterBuilder(eu.bcvsolutions.idm.core.model.repository.filter.AuthorizationPolicyByIdentityFilterBuilder) StringUtils(org.apache.commons.lang3.StringUtils) AbstractReadWriteDtoControllerRestTest(eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoControllerRestTest) CoreGroupPermission(eu.bcvsolutions.idm.core.model.domain.CoreGroupPermission) List(java.util.List) IdmAuthorizationPolicyFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmAuthorizationPolicyFilter) IdmBasePermission(eu.bcvsolutions.idm.core.security.api.domain.IdmBasePermission) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) AbstractReadWriteDtoController(eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoController) IdmAuthorizationPolicyDto(eu.bcvsolutions.idm.core.api.dto.IdmAuthorizationPolicyDto) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmGroupPermission(eu.bcvsolutions.idm.core.security.api.domain.IdmGroupPermission) Assert(org.junit.Assert) BasePermissionEvaluator(eu.bcvsolutions.idm.core.security.evaluator.BasePermissionEvaluator) IdmRole(eu.bcvsolutions.idm.core.model.entity.IdmRole) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmAuthorizationPolicyDto(eu.bcvsolutions.idm.core.api.dto.IdmAuthorizationPolicyDto) IdmAuthorizationPolicyFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmAuthorizationPolicyFilter) Test(org.junit.Test) AbstractReadWriteDtoControllerRestTest(eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoControllerRestTest)

Example 10 with IdmAuthorizationPolicyFilter

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

the class IdmAuthorizationPolicyControllerRestTest method testFindByGroupPermission.

@Test
public void testFindByGroupPermission() {
    IdmRoleDto role = getHelper().createRole();
    // 
    IdmAuthorizationPolicyDto policyOne = getHelper().createBasePolicy(role.getId(), CoreGroupPermission.IDENTITY, IdmIdentity.class, IdmBasePermission.READ);
    // other
    getHelper().createBasePolicy(role.getId(), CoreGroupPermission.ROLE, IdmRole.class, IdmBasePermission.READ);
    // 
    IdmAuthorizationPolicyFilter filter = new IdmAuthorizationPolicyFilter();
    filter.setRoleId(role.getId());
    filter.setGroupPermission(CoreGroupPermission.IDENTITY.getName());
    List<IdmAuthorizationPolicyDto> policies = find(filter);
    Assert.assertEquals(1, policies.size());
    Assert.assertTrue(policies.stream().anyMatch(p -> p.getId().equals(policyOne.getId())));
}
Also used : IdmIdentity(eu.bcvsolutions.idm.core.model.entity.IdmIdentity) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) Autowired(org.springframework.beans.factory.annotation.Autowired) Test(org.junit.Test) RoleConfiguration(eu.bcvsolutions.idm.core.api.config.domain.RoleConfiguration) AuthorizationPolicyByIdentityFilterBuilder(eu.bcvsolutions.idm.core.model.repository.filter.AuthorizationPolicyByIdentityFilterBuilder) StringUtils(org.apache.commons.lang3.StringUtils) AbstractReadWriteDtoControllerRestTest(eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoControllerRestTest) CoreGroupPermission(eu.bcvsolutions.idm.core.model.domain.CoreGroupPermission) List(java.util.List) IdmAuthorizationPolicyFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmAuthorizationPolicyFilter) IdmBasePermission(eu.bcvsolutions.idm.core.security.api.domain.IdmBasePermission) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) AbstractReadWriteDtoController(eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoController) IdmAuthorizationPolicyDto(eu.bcvsolutions.idm.core.api.dto.IdmAuthorizationPolicyDto) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmGroupPermission(eu.bcvsolutions.idm.core.security.api.domain.IdmGroupPermission) Assert(org.junit.Assert) BasePermissionEvaluator(eu.bcvsolutions.idm.core.security.evaluator.BasePermissionEvaluator) IdmRole(eu.bcvsolutions.idm.core.model.entity.IdmRole) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmAuthorizationPolicyDto(eu.bcvsolutions.idm.core.api.dto.IdmAuthorizationPolicyDto) IdmAuthorizationPolicyFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmAuthorizationPolicyFilter) Test(org.junit.Test) AbstractReadWriteDtoControllerRestTest(eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoControllerRestTest)

Aggregations

IdmAuthorizationPolicyFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmAuthorizationPolicyFilter)19 IdmAuthorizationPolicyDto (eu.bcvsolutions.idm.core.api.dto.IdmAuthorizationPolicyDto)13 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)12 Test (org.junit.Test)11 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)9 List (java.util.List)9 Autowired (org.springframework.beans.factory.annotation.Autowired)9 CoreGroupPermission (eu.bcvsolutions.idm.core.model.domain.CoreGroupPermission)7 IdmRole (eu.bcvsolutions.idm.core.model.entity.IdmRole)7 IdmBasePermission (eu.bcvsolutions.idm.core.security.api.domain.IdmBasePermission)7 IdmIdentity (eu.bcvsolutions.idm.core.model.entity.IdmIdentity)6 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)6 Assert (org.junit.Assert)6 RoleConfiguration (eu.bcvsolutions.idm.core.api.config.domain.RoleConfiguration)5 IdmGroupPermission (eu.bcvsolutions.idm.core.security.api.domain.IdmGroupPermission)5 StringUtils (org.apache.commons.lang3.StringUtils)5 IdmBulkActionDto (eu.bcvsolutions.idm.core.api.bulk.action.dto.IdmBulkActionDto)4 AbstractReadWriteDtoController (eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoController)4 AbstractReadWriteDtoControllerRestTest (eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoControllerRestTest)4 IdmAuthorizationPolicyService (eu.bcvsolutions.idm.core.api.service.IdmAuthorizationPolicyService)4