use of eu.bcvsolutions.idm.core.model.entity.IdmRoleComposition_ in project CzechIdMng by bcvsolutions.
the class AddNewRoleCompositionTaskExecutor method getItemsToProcess.
/**
* Returns superior roles, which should be processed
*/
@Override
public Page<IdmRoleDto> getItemsToProcess(Pageable pageable) {
IdmRoleCompositionDto roleComposition = roleCompositionService.get(roleCompositionId);
Assert.notNull(roleComposition, "Role composition is required.");
//
List<IdmRoleDto> superiorRoles = roleCompositionService.findAllSuperiorRoles(roleComposition.getSub()).stream().map(composition -> {
return DtoUtils.getEmbedded(composition, IdmRoleComposition_.superior, IdmRoleDto.class);
}).collect(Collectors.toList());
return new PageImpl<>(superiorRoles);
}
use of eu.bcvsolutions.idm.core.model.entity.IdmRoleComposition_ 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;
}
use of eu.bcvsolutions.idm.core.model.entity.IdmRoleComposition_ in project CzechIdMng by bcvsolutions.
the class DefaultIdmRoleCompositionService method findAllSubRoles.
private void findAllSubRoles(List<IdmRoleCompositionDto> results, List<IdmRoleCompositionDto> parents, UUID superiorId, BasePermission... permission) {
IdmRoleCompositionFilter filter = new IdmRoleCompositionFilter();
filter.setSuperiorId(superiorId);
//
find(filter, null, permission).stream().filter(// cyclic composition in the first level is ignored
subRole -> !subRole.getSuperior().equals(subRole.getSub())).forEach(subRole -> {
if (!// duplicate composition is enabled, but from different superior role => is not cycle, is duplicate but ok
parents.stream().map(IdmRoleCompositionDto::getSuperior).anyMatch(superior -> superior.equals(subRole.getSub()))) {
results.add(subRole);
List<IdmRoleCompositionDto> lineParents = Lists.newArrayList(parents);
lineParents.add(subRole);
//
IdmRoleDto subRoleDto = DtoUtils.getEmbedded(subRole, IdmRoleComposition_.sub);
if (subRoleDto.getChildrenCount() > 0) {
findAllSubRoles(results, lineParents, subRole.getSub(), permission);
}
}
});
}
use of eu.bcvsolutions.idm.core.model.entity.IdmRoleComposition_ in project CzechIdMng by bcvsolutions.
the class DefaultIdmAuthorizationPolicyService method getDefaultAuthorities.
@Override
@Transactional(readOnly = true)
public Set<GrantedAuthority> getDefaultAuthorities(UUID identityId) {
IdmRoleDto defaultRole = roleService.getDefaultRole();
if (defaultRole == null) {
LOG.debug("Default role not found, no default authorities will be added. Change configuration [{}].", IdmRoleService.PROPERTY_DEFAULT_ROLE);
return Collections.<GrantedAuthority>emptySet();
}
if (defaultRole.isDisabled()) {
LOG.debug("Default role [{}] is disabled, no default authorities will be added.", defaultRole.getCode());
return Collections.<GrantedAuthority>emptySet();
}
//
UUID defaultRoleId = defaultRole.getId();
Set<GrantedAuthority> defaultAuthorities = new HashSet<>();
// default role authorities
defaultAuthorities.addAll(getEnabledRoleAuthorities(identityId, defaultRoleId));
// all sub roles authorities
roleCompositionService.findAllSubRoles(defaultRoleId).stream().filter(roleComposition -> {
IdmRoleDto subRole = DtoUtils.getEmbedded(roleComposition, IdmRoleComposition_.sub);
return !subRole.isDisabled();
}).forEach(roleComposition -> {
defaultAuthorities.addAll(getEnabledRoleAuthorities(identityId, roleComposition.getSub()));
});
//
LOG.debug("Found [{}] default authorities", defaultAuthorities.size());
return defaultAuthorities;
}
use of eu.bcvsolutions.idm.core.model.entity.IdmRoleComposition_ in project CzechIdMng by bcvsolutions.
the class DuplicateRoleCompositionProcessor method process.
@Override
@SuppressWarnings("unchecked")
public EventResult<IdmRoleDto> process(EntityEvent<IdmRoleDto> event) {
IdmRoleDto cloned = event.getContent();
IdmRoleDto originalSource = event.getOriginalSource();
//
Map<String, Serializable> props = resolveProperties(event);
Set<UUID> processedRoles = (Set<UUID>) props.get(RoleEvent.PROPERTY_PROCESSED_ROLES);
processedRoles.add(cloned.getId());
//
// find and clone business role composition
// clone roles recursively
Set<String> processedSubRoles = new HashSet<>();
Map<String, IdmRoleCompositionDto> currentSubRoles = new HashMap<>();
roleCompositionService.findDirectSubRoles(cloned.getId()).forEach(composition -> {
IdmRoleDto subRole = DtoUtils.getEmbedded(composition, IdmRoleComposition_.sub);
currentSubRoles.put(subRole.getCode(), composition);
});
//
roleCompositionService.findDirectSubRoles(originalSource.getId()).stream().filter(composition -> {
return includeComposition(event, composition);
}).forEach(composition -> {
// find sub role on the target environment
IdmRoleDto subRole = DtoUtils.getEmbedded(composition, IdmRoleComposition_.sub);
IdmRoleDto targetRole = roleService.getByBaseCodeAndEnvironment(subRole.getBaseCode(), cloned.getEnvironment());
//
if (targetRole != null || duplicateRecursively(event, subRole, targetRole)) {
if (targetRole == null) {
// new clone
targetRole = prepareRole(subRole.getBaseCode(), cloned.getEnvironment());
}
if (targetRole != null && subRole.getId().equals(targetRole.getId())) {
LOG.debug("Role [{}] is duplicated on the same environment - skipping recursion for the same roles", targetRole.getCode());
} else if (targetRole != null && processedRoles.contains(targetRole.getId())) {
LOG.debug("Role [{}] was already processed by other business role composition - cycle, skipping", targetRole.getCode());
} else {
//
// clone / update
EntityEvent<IdmRoleDto> subEvent = new RoleEvent(RoleEventType.DUPLICATE, targetRole, props);
// original source is the cloned role
subEvent.setOriginalSource(subRole);
// we want to be sync
subEvent.setPriority(PriorityType.IMMEDIATE);
EventContext<IdmRoleDto> resultSubRole = roleService.publish(subEvent, event);
targetRole = resultSubRole.getContent();
}
//
// create the composition (or check composition exists)
// find exists
processedSubRoles.add(targetRole.getCode());
if (!currentSubRoles.containsKey(targetRole.getCode())) {
IdmRoleCompositionDto cloneComposition = new IdmRoleCompositionDto(cloned.getId(), targetRole.getId());
EntityEvent<IdmRoleCompositionDto> createCompositionEvent = new RoleCompositionEvent(RoleCompositionEventType.CREATE, cloneComposition);
// we want to be sync
createCompositionEvent.setPriority(PriorityType.IMMEDIATE);
roleCompositionService.publish(createCompositionEvent, event);
}
}
});
//
// remove unprocessed sub roles, which was removed in surce role
currentSubRoles.entrySet().stream().filter(entry -> {
return !processedSubRoles.contains(entry.getKey());
}).filter(entry -> {
return includeComposition(event, entry.getValue());
}).forEach(entry -> {
// dirty flag role composition only - will be processed after parent action ends
IdmEntityStateDto stateDeleted = new IdmEntityStateDto();
stateDeleted.setEvent(event.getId());
stateDeleted.setSuperOwnerId(cloned.getId());
stateDeleted.setResult(new OperationResultDto.Builder(OperationState.RUNNING).setModel(new DefaultResultModel(CoreResultCode.DELETED)).build());
entityStateManager.saveState(entry.getValue(), stateDeleted);
});
//
return new DefaultEventResult<>(event, this);
}
Aggregations