Search in sources :

Example 6 with InvalidSharedIdException

use of org.alfresco.service.cmr.quickshare.InvalidSharedIdException in project alfresco-remote-api by Alfresco.

the class QuickShareLinksImpl method readById.

/**
 * Returns limited metadata regarding the shared (content) link.
 * <p>
 * Note: does *not* require authenticated access for (public) shared link.
 */
public QuickShareLink readById(final String sharedId, final Parameters parameters) {
    checkEnabled();
    try {
        Pair<String, NodeRef> pair = quickShareService.getTenantNodeRefFromSharedId(sharedId);
        String networkTenantDomain = pair.getFirst();
        return TenantUtil.runAsSystemTenant(new TenantUtil.TenantRunAsWork<QuickShareLink>() {

            public QuickShareLink doWork() throws Exception {
                // note: assume noAuth here (rather than rely on getRunAsUser which will be null in non-MT)
                return getQuickShareInfo(sharedId, true, parameters.getInclude());
            }
        }, networkTenantDomain);
    } catch (InvalidSharedIdException ex) {
        logger.warn("Unable to find: " + sharedId);
        throw new EntityNotFoundException(sharedId);
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) InvalidSharedIdException(org.alfresco.service.cmr.quickshare.InvalidSharedIdException) TenantUtil(org.alfresco.repo.tenant.TenantUtil) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) QuickShareLink(org.alfresco.rest.api.model.QuickShareLink) PermissionDeniedException(org.alfresco.rest.framework.core.exceptions.PermissionDeniedException) QuickShareLinkExpiryActionException(org.alfresco.repo.quickshare.QuickShareLinkExpiryActionException) AccessDeniedException(org.alfresco.repo.security.permissions.AccessDeniedException) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) InvalidSharedIdException(org.alfresco.service.cmr.quickshare.InvalidSharedIdException) ConstraintViolatedException(org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException) DisabledServiceException(org.alfresco.rest.framework.core.exceptions.DisabledServiceException) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException)

Example 7 with InvalidSharedIdException

use of org.alfresco.service.cmr.quickshare.InvalidSharedIdException in project alfresco-remote-api by Alfresco.

the class QuickShareLinksImpl method delete.

/**
 * Delete the shared link.
 * <p>
 * Once deleted, the shared link will no longer exist hence get/download will no longer work (ie. return 404).
 * If the link is later re-created then a new unique shared id will be generated.
 * <p>
 * Requires authenticated access.
 *
 * @param sharedId String id of the quick share
 */
public void delete(String sharedId, Parameters parameters) {
    checkEnabled();
    checkValidShareId(sharedId);
    try {
        NodeRef nodeRef = quickShareService.getTenantNodeRefFromSharedId(sharedId).getSecond();
        String sharedByUserId = (String) nodeService.getProperty(nodeRef, QuickShareModel.PROP_QSHARE_SHAREDBY);
        if (!quickShareService.canDeleteSharedLink(nodeRef, sharedByUserId)) {
            throw new PermissionDeniedException("Can't perform unshare action: " + sharedId);
        }
        quickShareService.unshareContent(sharedId);
    } catch (InvalidSharedIdException ex) {
        logger.warn("Unable to find: " + sharedId);
        throw new EntityNotFoundException(sharedId);
    } catch (InvalidNodeRefException inre) {
        logger.warn("Unable to find: " + sharedId + " [" + inre.getNodeRef() + "]");
        throw new EntityNotFoundException(sharedId);
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) InvalidSharedIdException(org.alfresco.service.cmr.quickshare.InvalidSharedIdException) PermissionDeniedException(org.alfresco.rest.framework.core.exceptions.PermissionDeniedException) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException)

Example 8 with InvalidSharedIdException

use of org.alfresco.service.cmr.quickshare.InvalidSharedIdException in project alfresco-remote-api by Alfresco.

the class QuickShareLinksImpl method getRendition.

@Override
public Rendition getRendition(String sharedId, String renditionId) {
    checkEnabled();
    checkValidShareId(sharedId);
    try {
        Pair<String, NodeRef> pair = quickShareService.getTenantNodeRefFromSharedId(sharedId);
        String networkTenantDomain = pair.getFirst();
        final NodeRef nodeRef = pair.getSecond();
        return TenantUtil.runAsSystemTenant(() -> {
            Parameters params = getParamsWithCreatedStatus();
            return renditions.getRendition(nodeRef, renditionId, params);
        }, networkTenantDomain);
    } catch (InvalidSharedIdException ex) {
        logger.warn("Unable to find: " + sharedId);
        throw new EntityNotFoundException(sharedId);
    } catch (InvalidNodeRefException inre) {
        logger.warn("Unable to find: " + sharedId + " [" + inre.getNodeRef() + "]");
        throw new EntityNotFoundException(sharedId);
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) InvalidSharedIdException(org.alfresco.service.cmr.quickshare.InvalidSharedIdException) Parameters(org.alfresco.rest.framework.resource.parameters.Parameters) SearchParameters(org.alfresco.service.cmr.search.SearchParameters) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException)

Example 9 with InvalidSharedIdException

use of org.alfresco.service.cmr.quickshare.InvalidSharedIdException in project alfresco-remote-api by Alfresco.

the class QuickShareLinksImpl method getQuickShareInfo.

private QuickShareLink getQuickShareInfo(NodeRef nodeRef, Map<String, Object> map, boolean noAuth, List<String> includeParam) {
    String sharedId = (String) map.get("sharedId");
    try {
        Map<QName, Serializable> nodeProps = nodeService.getProperties(nodeRef);
        ContentData cd = (ContentData) nodeProps.get(ContentModel.PROP_CONTENT);
        String mimeType = cd.getMimetype();
        String mimeTypeName = mimeTypeService.getDisplaysByMimetype().get(mimeType);
        ContentInfo contentInfo = new ContentInfo(mimeType, mimeTypeName, cd.getSize(), cd.getEncoding());
        Map<String, UserInfo> mapUserInfo = new HashMap<>(2);
        // note: if noAuth mode then don't return userids (to limit disclosure and be consistent with v0 internal)
        boolean displayNameOnly = noAuth;
        UserInfo modifiedByUser = Node.lookupUserInfo((String) nodeProps.get(ContentModel.PROP_MODIFIER), mapUserInfo, personService, displayNameOnly);
        // TODO review - should we return sharedByUser for authenticated users only ?? (not exposed by V0 but needed for "find")
        String sharedByUserId = (String) nodeProps.get(QuickShareModel.PROP_QSHARE_SHAREDBY);
        UserInfo sharedByUser = Node.lookupUserInfo(sharedByUserId, mapUserInfo, personService, displayNameOnly);
        QuickShareLink qs = new QuickShareLink(sharedId, nodeRef.getId());
        qs.setName((String) map.get("name"));
        qs.setTitle((String) map.get("title"));
        qs.setDescription((String) map.get("description"));
        qs.setContent(contentInfo);
        qs.setModifiedAt((Date) map.get("modified"));
        qs.setModifiedByUser(modifiedByUser);
        qs.setSharedByUser(sharedByUser);
        qs.setExpiresAt((Date) map.get("expiryDate"));
        // note: if noAuth mode then do not return allowable operations (eg. but can be optionally returned when finding shared links)
        if (!noAuth) {
            if (includeParam.contains(PARAM_INCLUDE_ALLOWABLEOPERATIONS)) {
                if (quickShareService.canDeleteSharedLink(nodeRef, sharedByUserId)) {
                    // the allowable operations for the shared link
                    qs.setAllowableOperations(Collections.singletonList(Nodes.OP_DELETE));
                }
                Node doc = nodes.getFolderOrDocument(nodeRef, null, null, includeParam, null);
                List<String> allowableOps = doc.getAllowableOperations();
                // the allowable operations for the actual file being shared
                qs.setAllowableOperationsOnTarget(allowableOps);
            }
            // in noAuth mode we don't return the path info
            if (includeParam.contains(PARAM_INCLUDE_PATH)) {
                qs.setPath(nodes.lookupPathInfo(nodeRef, null));
            }
        }
        return qs;
    } catch (InvalidSharedIdException ex) {
        logger.warn("Unable to find: " + sharedId);
        throw new EntityNotFoundException(sharedId);
    } catch (InvalidNodeRefException inre) {
        logger.warn("Unable to find: " + sharedId + " [" + inre.getNodeRef() + "]");
        throw new EntityNotFoundException(sharedId);
    }
}
Also used : Serializable(java.io.Serializable) InvalidSharedIdException(org.alfresco.service.cmr.quickshare.InvalidSharedIdException) HashMap(java.util.HashMap) QName(org.alfresco.service.namespace.QName) Node(org.alfresco.rest.api.model.Node) UserInfo(org.alfresco.rest.api.model.UserInfo) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) ContentData(org.alfresco.service.cmr.repository.ContentData) ContentInfo(org.alfresco.rest.api.model.ContentInfo) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException) QuickShareLink(org.alfresco.rest.api.model.QuickShareLink)

Example 10 with InvalidSharedIdException

use of org.alfresco.service.cmr.quickshare.InvalidSharedIdException in project alfresco-remote-api by Alfresco.

the class QuickShareContentGet method execute.

@Override
public void execute(final WebScriptRequest req, final WebScriptResponse res) throws IOException {
    if (!isEnabled()) {
        throw new WebScriptException(HttpServletResponse.SC_FORBIDDEN, "QuickShare is disabled system-wide");
    }
    // create map of template vars (params)
    final Map<String, String> params = req.getServiceMatch().getTemplateVars();
    final String sharedId = params.get("shared_id");
    if (sharedId == null) {
        throw new WebScriptException(HttpServletResponse.SC_BAD_REQUEST, "A valid sharedId must be specified !");
    }
    try {
        Pair<String, NodeRef> pair = quickShareSerivce.getTenantNodeRefFromSharedId(sharedId);
        final String tenantDomain = pair.getFirst();
        final NodeRef nodeRef = pair.getSecond();
        TenantUtil.runAsSystemTenant(new TenantRunAsWork<Void>() {

            public Void doWork() throws Exception {
                if (!nodeService.getAspects(nodeRef).contains(QuickShareModel.ASPECT_QSHARE)) {
                    throw new InvalidNodeRefException(nodeRef);
                }
                executeImpl(nodeRef, params, req, res, null);
                return null;
            }
        }, tenantDomain);
        if (logger.isDebugEnabled()) {
            logger.debug("QuickShare - retrieved content: " + sharedId + " [" + nodeRef + "]");
        }
    } catch (InvalidSharedIdException ex) {
        logger.error("Unable to find: " + sharedId);
        throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Unable to find: " + sharedId);
    } catch (InvalidNodeRefException inre) {
        logger.error("Unable to find: " + sharedId + " [" + inre.getNodeRef() + "]");
        throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Unable to find: " + sharedId);
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) InvalidSharedIdException(org.alfresco.service.cmr.quickshare.InvalidSharedIdException) WebScriptException(org.springframework.extensions.webscripts.WebScriptException) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException) InvalidSharedIdException(org.alfresco.service.cmr.quickshare.InvalidSharedIdException) IOException(java.io.IOException) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException) WebScriptException(org.springframework.extensions.webscripts.WebScriptException)

Aggregations

InvalidSharedIdException (org.alfresco.service.cmr.quickshare.InvalidSharedIdException)11 InvalidNodeRefException (org.alfresco.service.cmr.repository.InvalidNodeRefException)11 NodeRef (org.alfresco.service.cmr.repository.NodeRef)8 EntityNotFoundException (org.alfresco.rest.framework.core.exceptions.EntityNotFoundException)7 WebScriptException (org.springframework.extensions.webscripts.WebScriptException)4 HashMap (java.util.HashMap)3 QuickShareLink (org.alfresco.rest.api.model.QuickShareLink)2 PermissionDeniedException (org.alfresco.rest.framework.core.exceptions.PermissionDeniedException)2 Parameters (org.alfresco.rest.framework.resource.parameters.Parameters)2 SearchParameters (org.alfresco.service.cmr.search.SearchParameters)2 IOException (java.io.IOException)1 Serializable (java.io.Serializable)1 QuickShareLinkExpiryActionException (org.alfresco.repo.quickshare.QuickShareLinkExpiryActionException)1 QuickShareEmailRequest (org.alfresco.repo.quickshare.QuickShareServiceImpl.QuickShareEmailRequest)1 AccessDeniedException (org.alfresco.repo.security.permissions.AccessDeniedException)1 TenantUtil (org.alfresco.repo.tenant.TenantUtil)1 ContentInfo (org.alfresco.rest.api.model.ContentInfo)1 Node (org.alfresco.rest.api.model.Node)1 UserInfo (org.alfresco.rest.api.model.UserInfo)1 ConstraintViolatedException (org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException)1