use of alien4cloud.exception.NotFoundException in project alien4cloud by alien4cloud.
the class StaticResourcesConfiguration method addResourceHandlers.
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
String prefix = "file:///";
// resource locations must be full path and not relatives
String absToscaRepo = prefix.concat(safeGetRealPath(toscaRepo)).concat("/");
String absPluginUi = prefix.concat(safeGetRealPath(pluginsUi)).concat("/");
log.info("Serving {} as tosca repo content.", absToscaRepo);
log.info("Serving {} as plugin ui content.", absPluginUi);
registry.addResourceHandler("/static/tosca/{csarName:.+}/{csarVersion:.+}/**").addResourceLocations(absToscaRepo).resourceChain(false).addResolver(new ResourceResolver() {
@Override
public Resource resolveResource(HttpServletRequest request, String requestPath, List<? extends Resource> locations, ResourceResolverChain chain) {
log.debug("Resolving editor resource");
// check security for the requested topology file.
ServletWebRequest webRequest = new ServletWebRequest(request);
Map uriTemplateVars = (Map) webRequest.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE, 0);
String csarName = (String) uriTemplateVars.get("csarName");
String csarVersion = (String) uriTemplateVars.get("csarVersion");
if (csarAuthorizationFilter == null || csarService == null) {
// not initialized as master
throw new NotFoundException("Only master nodes can provide editor static resources.");
} else {
csarAuthorizationFilter.checkReadAccess(csarService.getOrFail(csarName, csarVersion));
}
// let the usual resolving
return chain.resolveResource(request, csarName + "/" + csarVersion + "/" + requestPath, locations);
}
@Override
public String resolveUrlPath(String resourceUrlPath, List<? extends Resource> locations, ResourceResolverChain chain) {
return chain.resolveUrlPath(resourceUrlPath, locations);
}
});
registry.addResourceHandler(PLUGIN_STATIC_ENDPOINT + "**").addResourceLocations(absPluginUi);
}
use of alien4cloud.exception.NotFoundException in project alien4cloud by alien4cloud.
the class TagConfigurationController method removeConfiguration.
@ApiOperation(value = "Remove tag configuration.")
@RequestMapping(value = "/{tagConfigurationId}", method = RequestMethod.DELETE, produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("hasAuthority('ADMIN')")
@Audit
public RestResponse<Void> removeConfiguration(@PathVariable String tagConfigurationId) {
MetaPropConfiguration configuration = dao.findById(MetaPropConfiguration.class, tagConfigurationId);
if (configuration == null) {
throw new NotFoundException("Configuration is not found");
}
switch(configuration.getTarget().toString()) {
case "application":
removeMetaPropertyFromResources(Application.class, dao, configuration);
break;
case "location":
removeMetaPropertyFromResources(Location.class, dao, configuration);
break;
// TODO : case environment
default:
break;
}
dao.delete(MetaPropConfiguration.class, tagConfigurationId);
return RestResponseBuilder.<Void>builder().build();
}
use of alien4cloud.exception.NotFoundException in project alien4cloud by alien4cloud.
the class ResourceRoleService method formatRole.
/**
* Clean the role string
*
* @param resource The resource for which to format a role string.
* @param role The role string to check and format.
* @return The formatted and checked role string. An exception is thrown in case the role is not a valid role for the given resource.
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
private String formatRole(ISecuredResource resource, String role) {
if (role == null || role.toString().trim().isEmpty()) {
throw new NotFoundException("Resource Role [" + role + "] is empty");
}
String goodRoleToAdd = role.toString().toUpperCase();
try {
Class enumClass = resource.roleEnum();
Enum.valueOf(enumClass, goodRoleToAdd);
} catch (IllegalArgumentException e) {
throw new NotFoundException("Resource role [" + role + "] cannot be found", e);
}
return goodRoleToAdd;
}
Aggregations