Search in sources :

Example 1 with AuthorizationPolicyEvent

use of eu.bcvsolutions.idm.core.model.event.AuthorizationPolicyEvent in project CzechIdMng by bcvsolutions.

the class DefaultIdmAuthorizationPolicyService method delete.

@Override
@Transactional
public void delete(IdmAuthorizationPolicyDto dto, BasePermission... permissions) {
    checkAccess(getPolicyEntity(dto), permissions);
    // 
    eventManager.process(new AuthorizationPolicyEvent(DELETE, dto));
}
Also used : AuthorizationPolicyEvent(eu.bcvsolutions.idm.core.model.event.AuthorizationPolicyEvent) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with AuthorizationPolicyEvent

use of eu.bcvsolutions.idm.core.model.event.AuthorizationPolicyEvent 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)

Aggregations

AuthorizationPolicyEvent (eu.bcvsolutions.idm.core.model.event.AuthorizationPolicyEvent)2 Lists (com.google.common.collect.Lists)1 PriorityType (eu.bcvsolutions.idm.core.api.domain.PriorityType)1 IdmAuthorizationPolicyDto (eu.bcvsolutions.idm.core.api.dto.IdmAuthorizationPolicyDto)1 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)1 IdmAuthorizationPolicyFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmAuthorizationPolicyFilter)1 CoreEventProcessor (eu.bcvsolutions.idm.core.api.event.CoreEventProcessor)1 DefaultEventResult (eu.bcvsolutions.idm.core.api.event.DefaultEventResult)1 EntityEvent (eu.bcvsolutions.idm.core.api.event.EntityEvent)1 EventResult (eu.bcvsolutions.idm.core.api.event.EventResult)1 RoleProcessor (eu.bcvsolutions.idm.core.api.event.processor.RoleProcessor)1 IdmAuthorizationPolicyService (eu.bcvsolutions.idm.core.api.service.IdmAuthorizationPolicyService)1 DtoUtils (eu.bcvsolutions.idm.core.api.utils.DtoUtils)1 PersistentType (eu.bcvsolutions.idm.core.eav.api.domain.PersistentType)1 IdmFormAttributeDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto)1 AuthorizationPolicyEventType (eu.bcvsolutions.idm.core.model.event.AuthorizationPolicyEvent.AuthorizationPolicyEventType)1 RoleEventType (eu.bcvsolutions.idm.core.model.event.RoleEvent.RoleEventType)1 List (java.util.List)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1 Description (org.springframework.context.annotation.Description)1