use of alien4cloud.security.Subject in project alien4cloud by alien4cloud.
the class LocationSecurityService method getSubjectsFromContext.
/**
* Get subjects from context (current user, current user's groups, current environment, application ...)
*
* @param environment the environment from which the request has been made
* @return a map of subject type to subjects' ids
*/
public Map<Subject, Set<String>> getSubjectsFromContext(ApplicationEnvironment environment) {
Map<Subject, Set<String>> subjectsMap = new HashMap<>();
User user = AuthorizationUtil.getCurrentUser();
if (user != null) {
subjectsMap.put(Subject.USER, Sets.newHashSet(user.getUsername()));
Set<String> userGroups = AuthorizationUtil.getUserGroups(user);
subjectsMap.put(Subject.GROUP, userGroups);
}
if (environment != null) {
subjectsMap.put(Subject.ENVIRONMENT, Sets.newHashSet(environment.getId()));
subjectsMap.put(Subject.ENVIRONMENT_TYPE, Sets.newHashSet(environment.getApplicationId() + ":" + environment.getEnvironmentType().toString()));
subjectsMap.put(Subject.APPLICATION, Sets.newHashSet(environment.getApplicationId()));
}
return subjectsMap;
}
use of alien4cloud.security.Subject in project alien4cloud by alien4cloud.
the class AbstractLocationResourcesBatchSecurityController method processRevokeForSubjectType.
private void processRevokeForSubjectType(Subject subjectType, String[] resources, String[] subjects) {
if (ArrayUtils.isEmpty(resources)) {
return;
}
Arrays.stream(resources).forEach(resourceId -> {
AbstractLocationResourceTemplate resourceTemplate = locationResourceService.getOrFail(resourceId);
resourcePermissionService.revokePermission(resourceTemplate, (resource -> locationResourceService.saveResource((AbstractLocationResourceTemplate) resource)), subjectType, subjects);
});
}
use of alien4cloud.security.Subject in project alien4cloud by alien4cloud.
the class AbstractLocationResourcesBatchSecurityController method processGrantForSubjectType.
private void processGrantForSubjectType(Subject subjectType, String orchestratorId, String locationId, String[] resources, String[] subjects) {
if (ArrayUtils.isEmpty(resources)) {
return;
}
Location location = locationService.getLocation(orchestratorId, locationId);
locationSecurityService.grantAuthorizationOnLocationIfNecessary(location, subjectType, subjects);
Arrays.stream(resources).forEach(resourceId -> {
AbstractLocationResourceTemplate resourceTemplate = locationResourceService.getOrFail(resourceId);
// prefer using locationResourceService.saveResource so that the location update date is update.
// This will then trigger a deployment topology update
resourcePermissionService.grantPermission(resourceTemplate, (resource -> locationResourceService.saveResource(location, (AbstractLocationResourceTemplate) resource)), subjectType, subjects);
});
}
Aggregations