Search in sources :

Example 6 with NotFoundException

use of org.alfresco.rest.framework.core.exceptions.NotFoundException in project alfresco-remote-api by Alfresco.

the class NodesImpl method resolveNodeByPath.

protected NodeRef resolveNodeByPath(final NodeRef parentNodeRef, String path, boolean checkForCompanyHome) {
    final List<String> pathElements = getPathElements(path);
    if (!pathElements.isEmpty() && checkForCompanyHome) {
    /*
            if (nodeService.getRootNode(parentNodeRef.getStoreRef()).equals(parentNodeRef))
            {
                // special case
                NodeRef chNodeRef = repositoryHelper.getCompanyHome();
                String chName = (String) nodeService.getProperty(chNodeRef, ContentModel.PROP_NAME);
                if (chName.equals(pathElements.get(0)))
                {
                    pathElements = pathElements.subList(1, pathElements.size());
                    parentNodeRef = chNodeRef;
                }
            }
            */
    }
    FileInfo fileInfo = null;
    try {
        if (!pathElements.isEmpty()) {
            fileInfo = fileFolderService.resolveNamePath(parentNodeRef, pathElements);
        } else {
            fileInfo = fileFolderService.getFileInfo(parentNodeRef);
            if (fileInfo == null) {
                throw new EntityNotFoundException(parentNodeRef.getId());
            }
        }
    } catch (FileNotFoundException fnfe) {
        // convert checked exception
        throw new NotFoundException("The entity with relativePath: " + path + " was not found.");
    } catch (AccessDeniedException ade) {
        // return 404 instead of 403 (as per security review - uuid vs path)
        throw new NotFoundException("The entity with relativePath: " + path + " was not found.");
    }
    return fileInfo.getNodeRef();
}
Also used : AccessDeniedException(org.alfresco.repo.security.permissions.AccessDeniedException) FileInfo(org.alfresco.service.cmr.model.FileInfo) FileNotFoundException(org.alfresco.service.cmr.model.FileNotFoundException) NotFoundException(org.alfresco.rest.framework.core.exceptions.NotFoundException) FileNotFoundException(org.alfresco.service.cmr.model.FileNotFoundException) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException)

Example 7 with NotFoundException

use of org.alfresco.rest.framework.core.exceptions.NotFoundException in project alfresco-remote-api by Alfresco.

the class DeletedNodesImpl method restoreArchivedNode.

@Override
public Node restoreArchivedNode(String archivedId, NodeTargetAssoc nodeTargetAssoc) {
    // First check the node is valid and has been archived.
    NodeRef validatedNodeRef = nodes.validateNode(StoreRef.STORE_REF_ARCHIVE_SPACESSTORE, archivedId);
    RestoreNodeReport restored = null;
    if (nodeTargetAssoc != null) {
        NodeRef targetNodeRef = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, nodeTargetAssoc.getTargetParentId());
        QName assocType = nodes.getAssocType(nodeTargetAssoc.getAssocType());
        restored = nodeArchiveService.restoreArchivedNode(validatedNodeRef, targetNodeRef, assocType, null);
    } else {
        restored = nodeArchiveService.restoreArchivedNode(validatedNodeRef);
    }
    switch(restored.getStatus()) {
        case SUCCESS:
            return nodes.getFolderOrDocumentFullInfo(restored.getRestoredNodeRef(), null, null, null, null);
        case FAILURE_PERMISSION:
            throw new PermissionDeniedException();
        case FAILURE_INTEGRITY:
            throw new IntegrityException("Restore failed due to an integrity error", null);
        case FAILURE_DUPLICATE_CHILD_NODE_NAME:
            throw new ConstraintViolatedException("Name already exists in target");
        case FAILURE_INVALID_ARCHIVE_NODE:
            throw new EntityNotFoundException(archivedId);
        case FAILURE_INVALID_PARENT:
            throw new NotFoundException("Invalid parent id " + restored.getTargetParentNodeRef());
        default:
            throw new ApiException("Unable to restore node " + archivedId);
    }
}
Also used : RestoreNodeReport(org.alfresco.repo.node.archive.RestoreNodeReport) NodeRef(org.alfresco.service.cmr.repository.NodeRef) QName(org.alfresco.service.namespace.QName) IntegrityException(org.alfresco.repo.node.integrity.IntegrityException) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) NotFoundException(org.alfresco.rest.framework.core.exceptions.NotFoundException) PermissionDeniedException(org.alfresco.rest.framework.core.exceptions.PermissionDeniedException) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) ConstraintViolatedException(org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException) ApiException(org.alfresco.rest.framework.core.exceptions.ApiException)

Example 8 with NotFoundException

use of org.alfresco.rest.framework.core.exceptions.NotFoundException in project alfresco-remote-api by Alfresco.

the class GroupsFilter method deleteGroupMembership.

public void deleteGroupMembership(String groupId, String groupMemberId) {
    validateGroupId(groupId, false);
    // Not allowed to modify a GROUP_EVERYONE member.
    if (PermissionService.ALL_AUTHORITIES.equals(groupId)) {
        throw new ConstraintViolatedException(ERR_MSG_MODIFY_FIXED_AUTHORITY);
    }
    validateGroupMemberId(groupMemberId);
    // Verify if groupMemberId is member of groupId
    AuthorityType authorityType = AuthorityType.getAuthorityType(groupMemberId);
    Set<String> parents = authorityService.getContainingAuthorities(AuthorityType.GROUP, groupMemberId, true);
    if (!parents.contains(groupId)) {
        throw new NotFoundException(groupMemberId + " is not member of " + groupId);
    }
    authorityService.removeAuthority(groupId, groupMemberId);
}
Also used : AuthorityType(org.alfresco.service.cmr.security.AuthorityType) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) NotFoundException(org.alfresco.rest.framework.core.exceptions.NotFoundException) ConstraintViolatedException(org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException)

Example 9 with NotFoundException

use of org.alfresco.rest.framework.core.exceptions.NotFoundException in project alfresco-remote-api by Alfresco.

the class BaseSSOAuthenticationFilter method doFilter.

/*
     * (non-Javadoc)
     * @see org.alfresco.repo.web.filter.beans.DependencyInjectedFilter#doFilter(javax.servlet.ServletContext,
     * javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain)
     */
public void doFilter(ServletContext context, ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
    // Get the publicapi.container bean.
    ApplicationContext appContext = WebApplicationContextUtils.getRequiredWebApplicationContext(context);
    RuntimeContainer container = (RuntimeContainer) appContext.getBean("publicapi.container");
    // Get the HTTP request/response
    HttpServletRequest req = (HttpServletRequest) request;
    Match match = null;
    try {
        match = container.getRegistry().findWebScript(req.getMethod(), getScriptUrl(req));
    } catch (NotFoundException | IllegalArgumentException Ex) {
        getLogger().debug(req.getMethod() + " " + getScriptUrl(req) + "not found in Public API Container.");
    }
    // If a filter up the chain has marked the request as not requiring auth then respect it
    if (request.getAttribute(NO_AUTH_REQUIRED) != null) {
        if (getLogger().isTraceEnabled()) {
            getLogger().trace("Authentication not required (filter), chaining ...");
        }
        chain.doFilter(request, response);
    } else // check the authentication required - if none then we don't want any of the filters down the chain to require any authentication checks
    if ((match != null) && (match.getWebScript() != null) && (RequiredAuthentication.none == match.getWebScript().getDescription().getRequiredAuthentication())) {
        if (getLogger().isDebugEnabled()) {
            getLogger().debug("Found webscript with no authentication - set NO_AUTH_REQUIRED flag.");
        }
        req.setAttribute(NO_AUTH_REQUIRED, Boolean.TRUE);
        chain.doFilter(request, response);
    } else if (authenticateRequest(context, (HttpServletRequest) request, (HttpServletResponse) response)) {
        chain.doFilter(request, response);
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ApplicationContext(org.springframework.context.ApplicationContext) NotFoundException(org.alfresco.rest.framework.core.exceptions.NotFoundException) RuntimeContainer(org.springframework.extensions.webscripts.RuntimeContainer) Match(org.springframework.extensions.webscripts.Match)

Example 10 with NotFoundException

use of org.alfresco.rest.framework.core.exceptions.NotFoundException in project alfresco-remote-api by Alfresco.

the class PublicApiDeclarativeRegistry method findWebScript.

/* (non-Javadoc)
     * @see org.alfresco.web.scripts.Registry#findWebScript(java.lang.String, java.lang.String)
     */
public Match findWebScript(String method, String uri) {
    Match match;
    HttpMethod httpMethod = HttpMethod.valueOf(method);
    if (HttpMethod.GET.equals(httpMethod)) {
        if (uri.equals(PublicApiTenantWebScriptServletRequest.NETWORKS_PATH)) {
            Map<String, String> templateVars = new HashMap<>();
            templateVars.put("apiScope", "public");
            templateVars.put("apiVersion", "1");
            templateVars.put("apiName", "networks");
            match = new Match("", templateVars, "", getNetworksWebScript);
        } else if (uri.equals(PublicApiTenantWebScriptServletRequest.NETWORK_PATH)) {
            Map<String, String> templateVars = new HashMap<>();
            templateVars.put("apiScope", "public");
            templateVars.put("apiVersion", "1");
            templateVars.put("apiName", "network");
            match = new Match("", templateVars, "", getNetworkWebScript);
        } else {
            match = super.findWebScript(method, uri);
            if (match == null) {
                return null;
            }
            Map<String, String> templateVars = match.getTemplateVars();
            ResourceWithMetadata rwm = getResourceWithMetadataOrNull(templateVars, httpMethod);
            if (rwm != null) {
                Class<? extends ResourceAction> resAction = null;
                final Map<String, String> resourceVars = locator.parseTemplateVars(templateVars);
                final String entityId = resourceVars.get(ResourceLocator.ENTITY_ID);
                final String relationshipId = resourceVars.get(ResourceLocator.RELATIONSHIP_ID);
                switch(rwm.getMetaData().getType()) {
                    case ENTITY:
                        if (StringUtils.isNotBlank(entityId)) {
                            if (EntityResourceAction.ReadById.class.isAssignableFrom(rwm.getResource().getClass())) {
                                resAction = EntityResourceAction.ReadById.class;
                            }
                        } else {
                            if (EntityResourceAction.Read.class.isAssignableFrom(rwm.getResource().getClass())) {
                                resAction = EntityResourceAction.Read.class;
                            }
                        }
                        break;
                    case PROPERTY:
                        if (StringUtils.isNotBlank(entityId)) {
                            if (BinaryResourceAction.Read.class.isAssignableFrom(rwm.getResource().getClass())) {
                                resAction = BinaryResourceAction.Read.class;
                            } else if (RelationshipResourceBinaryAction.Read.class.isAssignableFrom(rwm.getResource().getClass())) {
                                resAction = RelationshipResourceBinaryAction.Read.class;
                            }
                        }
                        break;
                    case RELATIONSHIP:
                        if (StringUtils.isNotBlank(relationshipId)) {
                            if (RelationshipResourceAction.ReadById.class.isAssignableFrom(rwm.getResource().getClass())) {
                                resAction = RelationshipResourceAction.ReadById.class;
                            }
                        } else {
                            if (RelationshipResourceAction.Read.class.isAssignableFrom(rwm.getResource().getClass())) {
                                resAction = RelationshipResourceAction.Read.class;
                            }
                        }
                        break;
                    default:
                        break;
                }
                final boolean noAuth = (resAction != null && rwm.getMetaData().isNoAuth(resAction));
                if (noAuth) {
                    // override match with noAuth
                    match = overrideMatch(match);
                }
            }
        }
    } else if (HttpMethod.POST.equals(httpMethod)) {
        match = super.findWebScript(method, uri);
        if (match != null) {
            ResourceWithMetadata rwm = getResourceWithMetadataOrNull(match.getTemplateVars(), httpMethod);
            if (rwm != null) {
                Class<? extends ResourceAction> resAction = null;
                Boolean noAuth = null;
                switch(rwm.getMetaData().getType()) {
                    case ENTITY:
                        if (EntityResourceAction.Create.class.isAssignableFrom(rwm.getResource().getClass())) {
                            resAction = EntityResourceAction.Create.class;
                        } else if (EntityResourceAction.CreateWithResponse.class.isAssignableFrom(rwm.getResource().getClass())) {
                            resAction = EntityResourceAction.CreateWithResponse.class;
                        }
                        break;
                    case RELATIONSHIP:
                        if (RelationshipResourceAction.Create.class.isAssignableFrom(rwm.getResource().getClass())) {
                            resAction = RelationshipResourceAction.Create.class;
                        } else if (RelationshipResourceAction.CreateWithResponse.class.isAssignableFrom(rwm.getResource().getClass())) {
                            resAction = RelationshipResourceAction.CreateWithResponse.class;
                        }
                        break;
                    case OPERATION:
                        noAuth = rwm.getMetaData().isNoAuth(null);
                        break;
                    default:
                        break;
                }
                if (noAuth == null) {
                    noAuth = (resAction != null && rwm.getMetaData().isNoAuth(resAction));
                }
                if (noAuth) {
                    // override match with noAuth
                    match = overrideMatch(match);
                }
            }
        }
    } else {
        match = super.findWebScript(method, uri);
    }
    if (match == null) {
        throw new NotFoundException(NotFoundException.DEFAULT_MESSAGE_ID, new String[] { uri });
    }
    return match;
}
Also used : EntityResourceAction(org.alfresco.rest.framework.resource.actions.interfaces.EntityResourceAction) HashMap(java.util.HashMap) NotFoundException(org.alfresco.rest.framework.core.exceptions.NotFoundException) RelationshipResourceBinaryAction(org.alfresco.rest.framework.resource.actions.interfaces.RelationshipResourceBinaryAction) RelationshipResourceAction(org.alfresco.rest.framework.resource.actions.interfaces.RelationshipResourceAction) HashMap(java.util.HashMap) Map(java.util.Map) ResourceWithMetadata(org.alfresco.rest.framework.core.ResourceWithMetadata) HttpMethod(org.springframework.http.HttpMethod) RelationshipResourceAction(org.alfresco.rest.framework.resource.actions.interfaces.RelationshipResourceAction) EntityResourceAction(org.alfresco.rest.framework.resource.actions.interfaces.EntityResourceAction) ResourceAction(org.alfresco.rest.framework.resource.actions.interfaces.ResourceAction) BinaryResourceAction(org.alfresco.rest.framework.resource.actions.interfaces.BinaryResourceAction)

Aggregations

NotFoundException (org.alfresco.rest.framework.core.exceptions.NotFoundException)24 ConstraintViolatedException (org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException)11 EntityNotFoundException (org.alfresco.rest.framework.core.exceptions.EntityNotFoundException)9 NodeRef (org.alfresco.service.cmr.repository.NodeRef)9 InvalidArgumentException (org.alfresco.rest.framework.core.exceptions.InvalidArgumentException)8 DisabledServiceException (org.alfresco.rest.framework.core.exceptions.DisabledServiceException)6 ResourceWithMetadata (org.alfresco.rest.framework.core.ResourceWithMetadata)4 ApiException (org.alfresco.rest.framework.core.exceptions.ApiException)4 StaleEntityException (org.alfresco.rest.framework.core.exceptions.StaleEntityException)4 ContentData (org.alfresco.service.cmr.repository.ContentData)4 IntegrityException (org.alfresco.repo.node.integrity.IntegrityException)3 PermissionDeniedException (org.alfresco.rest.framework.core.exceptions.PermissionDeniedException)3 QName (org.alfresco.service.namespace.QName)3 Test (org.junit.Test)3 File (java.io.File)2 InputStream (java.io.InputStream)2 Serializable (java.io.Serializable)2 Date (java.util.Date)2 HashMap (java.util.HashMap)2 RenditionDefinition2 (org.alfresco.repo.rendition2.RenditionDefinition2)2