use of eu.bcvsolutions.idm.vs.dto.filter.VsSystemImplementerFilter in project CzechIdMng by bcvsolutions.
the class SystemDeleteProcessor method process.
@Override
public EventResult<SysSystemDto> process(EntityEvent<SysSystemDto> event) {
SysSystemDto system = event.getContent();
Assert.notNull(system);
//
// If exists unresolved vs request, then is not possible to delete
// system
VsRequestFilter requestFilter = new VsRequestFilter();
requestFilter.setSystemId(system.getId());
requestFilter.setState(VsRequestState.IN_PROGRESS);
if (requestService.find(requestFilter, null).getTotalElements() > 0) {
throw new ResultCodeException(VsResultCode.VS_SYSTEM_DELETE_FAILED_HAS_REQUEST, ImmutableMap.of("system", system.getName()));
}
// Delete archived vs requests
requestFilter = new VsRequestFilter();
requestFilter.setSystemId(system.getId());
requestFilter.setOnlyArchived(Boolean.TRUE);
requestService.find(requestFilter, null).forEach(entity -> {
requestService.delete(entity);
});
// Delete vs account
VsAccountFilter accountFilter = new VsAccountFilter();
accountFilter.setSystemId(system.getId());
accountService.find(accountFilter, null).forEach(entity -> {
accountService.delete(entity);
});
// Delete vs account form definition
if (system.getConnectorKey() != null) {
String virtualSystemKey = MessageFormat.format("{0}:systemId={1}", system.getConnectorKey().getFullName(), system.getId());
IdmFormDefinitionDto definition = this.formDefinitionService.findOneByTypeAndCode(VsAccount.class.getName(), virtualSystemKey);
if (definition != null) {
formDefinitionService.delete(definition);
}
}
// Delete vs implementers
VsSystemImplementerFilter implementerFilter = new VsSystemImplementerFilter();
implementerFilter.setSystemId(system.getId());
systemImplementerService.find(implementerFilter, null).forEach(entity -> {
systemImplementerService.delete(entity);
});
return new DefaultEventResult<>(event, this);
}
use of eu.bcvsolutions.idm.vs.dto.filter.VsSystemImplementerFilter in project CzechIdMng by bcvsolutions.
the class BasicVirtualConnector method updateSystemImplementers.
/**
* Update identity and role implementers relations
*
* @param virtualConfiguration
* @param systemId
*/
private void updateSystemImplementers(BasicVirtualConfiguration virtualConfiguration, UUID systemId) {
VsSystemImplementerFilter systemImplementerFilter = new VsSystemImplementerFilter();
systemImplementerFilter.setSystemId(systemId);
List<VsSystemImplementerDto> systemImplementers = systemImplementerService.find(systemImplementerFilter, null).getContent();
// Load implementers from config
List<IdmIdentityDto> implementersFromConfig = this.loadImplementers(virtualConfiguration.getImplementers());
// Load roles from config
List<IdmRoleDto> rolesFromConfig = this.loadImplementerRoles(virtualConfiguration.getImplementerRoles(), implementersFromConfig);
List<VsSystemImplementerDto> systemImplementersToAdd = new ArrayList<>();
// Search system-implementers to delete (for identity)
List<VsSystemImplementerDto> systemImplementersToDelete = systemImplementers.stream().filter(sysImplementer -> {
return sysImplementer.getIdentity() != null && !implementersFromConfig.contains(new IdmIdentityDto(sysImplementer.getIdentity()));
}).collect(Collectors.toList());
// Search implementers to add (for identity)
List<IdmIdentityDto> implementersToAdd = implementersFromConfig.stream().filter(implementer -> {
return !systemImplementers.stream().filter(sysImplementer -> {
return implementer.getId().equals(sysImplementer.getIdentity());
}).findFirst().isPresent();
}).collect(Collectors.toList());
implementersToAdd.forEach(identity -> {
VsSystemImplementerDto sysImpl = new VsSystemImplementerDto();
sysImpl.setIdentity(identity.getId());
sysImpl.setSystem(systemId);
systemImplementersToAdd.add(sysImpl);
});
// Search system-implementers to delete (for role)
systemImplementersToDelete.addAll(systemImplementers.stream().filter(sysImplementer -> {
return sysImplementer.getRole() != null && !rolesFromConfig.contains(new IdmRoleDto(sysImplementer.getRole()));
}).collect(Collectors.toList()));
// Search implementers to add (for role)
List<IdmRoleDto> rolesToAdd = rolesFromConfig.stream().filter(implementer -> {
return !systemImplementers.stream().filter(sysImplementer -> {
return implementer.getId().equals(sysImplementer.getRole());
}).findFirst().isPresent();
}).collect(Collectors.toList());
rolesToAdd.forEach(role -> {
VsSystemImplementerDto sysImpl = new VsSystemImplementerDto();
sysImpl.setRole(role.getId());
sysImpl.setSystem(systemId);
systemImplementersToAdd.add(sysImpl);
});
// Save changes (add new and remove old)
systemImplementerService.saveAll(systemImplementersToAdd);
systemImplementersToDelete.forEach(sysImpl -> {
systemImplementerService.delete(sysImpl);
});
}
use of eu.bcvsolutions.idm.vs.dto.filter.VsSystemImplementerFilter in project CzechIdMng by bcvsolutions.
the class VsRequestByImplementerEvaluator method getPermissions.
@Override
public Set<String> getPermissions(VsRequest authorizable, AuthorizationPolicy policy) {
Set<String> permissions = super.getPermissions(authorizable, policy);
if (authorizable == null || authorizable.getSystem() == null || !securityService.isAuthenticated()) {
return permissions;
}
VsSystemImplementerFilter systemImplementerFilter = new VsSystemImplementerFilter();
systemImplementerFilter.setSystemId(authorizable.getSystem().getId());
List<VsSystemImplementerDto> implemnters = systemImplementerService.find(systemImplementerFilter, null).getContent();
UUID currentId = securityService.getCurrentId();
// Find all valid roles (includes check on contract validity)
Set<UUID> roles = //
identityRoleService.findValidRole(currentId, null).getContent().stream().map(//
IdmIdentityRoleDto::getRole).collect(Collectors.toSet());
for (VsSystemImplementerDto implementer : implemnters) {
if (implementer.getIdentity() != null && implementer.getIdentity().equals(currentId)) {
permissions.addAll(policy.getPermissions());
break;
}
if (implementer.getRole() != null && roles.contains(implementer.getRole())) {
permissions.addAll(policy.getPermissions());
break;
}
}
return permissions;
}
use of eu.bcvsolutions.idm.vs.dto.filter.VsSystemImplementerFilter in project CzechIdMng by bcvsolutions.
the class DefaultVsSystemImplementerService method findRequestImplementers.
@Override
public List<IdmIdentityDto> findRequestImplementers(UUID vsSystemId) {
if (vsSystemId == null) {
return null;
}
VsSystemImplementerFilter filter = new VsSystemImplementerFilter();
filter.setSystemId(vsSystemId);
List<VsSystemImplementerDto> requestImplementers = this.find(filter, null).getContent();
Set<IdmIdentityDto> identities = //
requestImplementers.stream().filter(//
sysImp -> sysImp.getIdentity() != null).map(//
VsSystemImplementerDto::getIdentity).map(//
identityService::get).collect(Collectors.toSet());
// Add identities from all roles
Set<UUID> roles = //
requestImplementers.stream().filter(//
sysImp -> sysImp.getRole() != null).map(//
VsSystemImplementerDto::getRole).collect(Collectors.toSet());
roles.forEach(role -> {
identities.addAll(identityService.findValidByRole(role));
});
return new ArrayList<>(identities);
}
Aggregations