use of javax.annotation.Resource in project alien4cloud by alien4cloud.
the class ResourcePermissionEventsListener method deleteGroupPermissionOn.
private void deleteGroupPermissionOn(String groupId, Class<?>... resourceClasses) throws IOException, ClassNotFoundException {
FilterBuilder resourceFilter = FilterBuilders.nestedFilter("groupPermissions", FilterBuilders.termFilter("groupPermissions.key", groupId));
deletePermissions(resourceFilter, groupId, ((resource, subjectId) -> resourcePermissionService.revokePermission(resource, Subject.GROUP, subjectId)), resourceClasses);
}
use of javax.annotation.Resource in project alien4cloud by alien4cloud.
the class ResourcePermissionEventsListener method deleteApplicationPermissionOn.
private void deleteApplicationPermissionOn(String applicationId, Class<?>... resourceClasses) throws IOException, ClassNotFoundException {
FilterBuilder resourceFilter = FilterBuilders.nestedFilter("applicationPermissions", FilterBuilders.termFilter("applicationPermissions.key", applicationId));
deletePermissions(resourceFilter, applicationId, ((resource, subjectId) -> resourcePermissionService.revokePermission(resource, Subject.APPLICATION, subjectId)), resourceClasses);
}
use of javax.annotation.Resource in project alien4cloud by alien4cloud.
the class ResourcePermissionEventsListener method deleteEnvironmentTypePermissionOn.
private void deleteEnvironmentTypePermissionOn(String environmentId, Class<?>... resourceClasses) throws IOException, ClassNotFoundException {
FilterBuilder resourceFilter = FilterBuilders.nestedFilter("environmentTypePermissions", FilterBuilders.termFilter("environmentTypePermissions.key", environmentId));
deletePermissions(resourceFilter, environmentId, ((resource, subjectId) -> resourcePermissionService.revokePermission(resource, Subject.ENVIRONMENT_TYPE, subjectId)), resourceClasses);
}
use of javax.annotation.Resource in project alien4cloud by alien4cloud.
the class ResourcePermissionService method grantAuthorizedEnvironmentsAndEnvTypesPerApplication.
public void grantAuthorizedEnvironmentsAndEnvTypesPerApplication(AbstractSecurityEnabledResource resource, String[] applicationsToAdd, String[] environmentsToAdd, String[] environmentTypesToAdd) {
List<String> envIds = Lists.newArrayList();
IResourceSaver noSave = null;
if (ArrayUtils.isNotEmpty(applicationsToAdd)) {
grantPermission(resource, noSave, Subject.APPLICATION, applicationsToAdd);
// when an app is added, all eventual existing env authorizations are removed
for (String applicationToAddId : applicationsToAdd) {
ApplicationEnvironment[] aes = applicationEnvironmentService.getByApplicationId(applicationToAddId);
for (ApplicationEnvironment ae : aes) {
envIds.add(ae.getId());
}
}
if (!envIds.isEmpty()) {
revokePermission(resource, noSave, Subject.ENVIRONMENT, envIds.toArray(new String[envIds.size()]));
}
// remove all all eventual existing env type authorizations
Set<String> envTypes = Sets.newHashSet();
for (String applicationToAddId : applicationsToAdd) {
for (EnvironmentType envType : EnvironmentType.values()) {
envTypes.add(applicationToAddId + ":" + envType.toString());
}
}
if (!envTypes.isEmpty()) {
revokePermission(resource, noSave, Subject.ENVIRONMENT_TYPE, envTypes.toArray(new String[envTypes.size()]));
}
}
if (ArrayUtils.isNotEmpty(environmentsToAdd)) {
List<String> envToAddSet = Arrays.stream(environmentsToAdd).filter(env -> !envIds.contains(env)).collect(Collectors.toList());
grantPermission(resource, noSave, Subject.ENVIRONMENT, envToAddSet.toArray(new String[envToAddSet.size()]));
}
if (ArrayUtils.isNotEmpty(environmentTypesToAdd)) {
grantPermission(resource, noSave, Subject.ENVIRONMENT_TYPE, environmentTypesToAdd);
}
alienDAO.save(resource);
}
use of javax.annotation.Resource 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