Search in sources :

Example 86 with NotFoundException

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);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ResourceResolver(org.springframework.web.servlet.resource.ResourceResolver) Resource(org.springframework.core.io.Resource) NotFoundException(alien4cloud.exception.NotFoundException) ResourceResolverChain(org.springframework.web.servlet.resource.ResourceResolverChain) ServletWebRequest(org.springframework.web.context.request.ServletWebRequest) Map(java.util.Map)

Example 87 with NotFoundException

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();
}
Also used : MetaPropConfiguration(alien4cloud.model.common.MetaPropConfiguration) NotFoundException(alien4cloud.exception.NotFoundException) Audit(alien4cloud.audit.annotation.Audit) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 88 with NotFoundException

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;
}
Also used : NotFoundException(alien4cloud.exception.NotFoundException)

Aggregations

NotFoundException (alien4cloud.exception.NotFoundException)88 NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)17 PropertyDefinition (org.alien4cloud.tosca.model.definitions.PropertyDefinition)12 Map (java.util.Map)10 Workflow (org.alien4cloud.tosca.model.workflow.Workflow)10 AlreadyExistException (alien4cloud.exception.AlreadyExistException)9 AbstractPropertyValue (org.alien4cloud.tosca.model.definitions.AbstractPropertyValue)9 Capability (org.alien4cloud.tosca.model.templates.Capability)9 NodeType (org.alien4cloud.tosca.model.types.NodeType)9 ApplicationEnvironment (alien4cloud.model.application.ApplicationEnvironment)8 SubstitutionTarget (org.alien4cloud.tosca.model.templates.SubstitutionTarget)8 Topology (org.alien4cloud.tosca.model.templates.Topology)7 Deployment (alien4cloud.model.deployment.Deployment)6 ApiOperation (io.swagger.annotations.ApiOperation)6 RelationshipTemplate (org.alien4cloud.tosca.model.templates.RelationshipTemplate)6 CapabilityType (org.alien4cloud.tosca.model.types.CapabilityType)6 InvalidNameException (alien4cloud.exception.InvalidNameException)5 DeploymentTopology (alien4cloud.model.deployment.DeploymentTopology)5 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)5 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)5