use of javax.annotation.Resource in project alien4cloud by alien4cloud.
the class AbstractLocationResourcesSecurityController method revokeGroupAccess.
/**
* Revoke the group's authorisation to access the location resource
*
* @param locationId The id of the location.
* @param groupId The authorized group.
* @return A {@link Void} {@link RestResponse}.
*/
@ApiOperation(value = "Revoke the group's authorisation to access the location", notes = "Only user with ADMIN role can revoke access to the location.")
@RequestMapping(value = "/groups/{groupId}", method = RequestMethod.DELETE, produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("hasAuthority('ADMIN')")
@Audit
public synchronized RestResponse<List<GroupDTO>> revokeGroupAccess(@PathVariable String orchestratorId, @PathVariable String locationId, @PathVariable String resourceId, @PathVariable String groupId) {
AbstractLocationResourceTemplate resourceTemplate = locationResourceService.getOrFail(resourceId);
resourcePermissionService.revokePermission(resourceTemplate, (resource -> locationResourceService.saveResource((AbstractLocationResourceTemplate) resource)), Subject.GROUP, groupId);
List<GroupDTO> groups = GroupDTO.convert(resourcePermissionService.getAuthorizedGroups(resourceTemplate));
return RestResponseBuilder.<List<GroupDTO>>builder().data(groups).build();
}
use of javax.annotation.Resource in project alien4cloud by alien4cloud.
the class ServiceSecurityController method getAuthorizedEnvironmentsPerApplication.
/**
* List all environments per application authorised to access the location.
*
* @return list of all environments per application.
*/
@ApiOperation(value = "List all applications, environments and environment types authorized to access the service resource", notes = "Only user with ADMIN role can list authorized applications, environments and environment types for the location.")
@RequestMapping(value = "/environmentsPerApplication", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("hasAuthority('ADMIN')")
public RestResponse<List<ApplicationEnvironmentAuthorizationDTO>> getAuthorizedEnvironmentsPerApplication(@PathVariable String serviceId) {
ServiceResource service = serviceResourceService.getOrFail(serviceId);
List<Application> applicationsRelatedToEnvironment = Lists.newArrayList();
List<Application> applicationsRelatedToEnvironmentType = Lists.newArrayList();
List<ApplicationEnvironment> environments = Lists.newArrayList();
List<String> environmentTypes = Lists.newArrayList();
List<Application> applications = Lists.newArrayList();
if (service.getEnvironmentPermissions() != null && service.getEnvironmentPermissions().size() > 0) {
environments = alienDAO.findByIds(ApplicationEnvironment.class, service.getEnvironmentPermissions().keySet().toArray(new String[service.getEnvironmentPermissions().size()]));
Set<String> environmentApplicationIds = environments.stream().map(ae -> ae.getApplicationId()).collect(Collectors.toSet());
applicationsRelatedToEnvironment = alienDAO.findByIds(Application.class, environmentApplicationIds.toArray(new String[environmentApplicationIds.size()]));
}
if (service.getEnvironmentTypePermissions() != null && service.getEnvironmentTypePermissions().size() > 0) {
environmentTypes.addAll(service.getEnvironmentTypePermissions().keySet());
Set<String> environmentTypeApplicationIds = Sets.newHashSet();
for (String envType : safe(service.getEnvironmentTypePermissions()).keySet()) {
environmentTypeApplicationIds.add(envType.split(":")[0]);
}
applicationsRelatedToEnvironmentType = alienDAO.findByIds(Application.class, environmentTypeApplicationIds.toArray(new String[environmentTypeApplicationIds.size()]));
}
if (service.getApplicationPermissions() != null && service.getApplicationPermissions().size() > 0) {
applications = alienDAO.findByIds(Application.class, service.getApplicationPermissions().keySet().toArray(new String[service.getApplicationPermissions().size()]));
}
List<ApplicationEnvironmentAuthorizationDTO> result = ApplicationEnvironmentAuthorizationDTO.buildDTOs(applicationsRelatedToEnvironment, applicationsRelatedToEnvironmentType, environments, applications, environmentTypes);
return RestResponseBuilder.<List<ApplicationEnvironmentAuthorizationDTO>>builder().data(result).build();
}
use of javax.annotation.Resource in project alien4cloud by alien4cloud.
the class ServiceSecurityController method revokeApplicationAccess.
/**
*****************************************************************************************************************************
*
* SECURITY ON APPLICATIONS
*
******************************************************************************************************************************
*/
/**
* Revoke the application's authorisation to access the location (including all related environments and environment types).
*
* @param serviceId The id of the location.
* @param applicationId The authorized application.
* @return A {@link Void} {@link RestResponse}.
*/
@ApiOperation(value = "Revoke the application's authorisation to access the service resource", notes = "Only user with ADMIN role can revoke access to the location.")
@RequestMapping(value = "/applications/{applicationId}", method = RequestMethod.DELETE, produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("hasAuthority('ADMIN')")
@Audit
public synchronized RestResponse<Void> revokeApplicationAccess(@PathVariable String serviceId, @PathVariable String applicationId) {
ServiceResource service = serviceResourceService.getOrFail(serviceId);
resourcePermissionService.revokePermission(service, Subject.APPLICATION, applicationId);
// remove all environments related to this application
ApplicationEnvironment[] aes = applicationEnvironmentService.getByApplicationId(applicationId);
String[] envIds = Arrays.stream(aes).map(ae -> ae.getId()).toArray(String[]::new);
resourcePermissionService.revokePermission(service, Subject.ENVIRONMENT, envIds);
// remove all environments types related to this application
Set<String> envTypeIds = Sets.newHashSet();
for (String envType : safe(service.getEnvironmentTypePermissions()).keySet()) {
if (envType.contains(applicationId)) {
envTypeIds.add(envType);
}
}
resourcePermissionService.revokePermission(service, Subject.ENVIRONMENT_TYPE, envTypeIds.toArray(new String[envTypeIds.size()]));
return RestResponseBuilder.<Void>builder().build();
}
use of javax.annotation.Resource in project tomee by apache.
the class ResourceInjector method visitField.
public final void visitField(final Field field, final Annotation annotation) {
assert annotation instanceof Resource : annotation;
Resource res = (Resource) annotation;
String name = getFieldNameForResource(res, field);
Class<?> type = getResourceType(res, field);
Object resource = resolveResource(name, type);
if (resource == null && "".equals(res.name())) {
resource = resolveResource(null, type);
}
if (resource != null) {
injectField(field, resource);
} else {
LOG.log(Level.INFO, "RESOURCE_RESOLVE_FAILED", name);
}
}
use of javax.annotation.Resource in project cxf by apache.
the class PolicyEngineImpl method setBus.
@Resource
public final void setBus(Bus b) {
if (this.bus == b) {
// avoid bus init twice through injection
return;
}
bus = b;
addBusInterceptors();
FactoryBeanListenerManager fblm = bus.getExtension(FactoryBeanListenerManager.class);
if (fblm != null) {
for (FactoryBeanListener l : fblm.getListeners()) {
if (l instanceof PolicyAnnotationListener) {
return;
}
}
fblm.addListener(new PolicyAnnotationListener(bus));
}
}
Aggregations