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();
}
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);
}
}
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);
}
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);
}
}
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;
}
Aggregations