use of eu.bcvsolutions.idm.vs.dto.VsSystemImplementerDto 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.VsSystemImplementerDto 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.VsSystemImplementerDto 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