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));
}
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);
}
Aggregations