Search in sources :

Example 21 with PermissionDeniedException

use of org.alfresco.rest.framework.core.exceptions.PermissionDeniedException 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 22 with PermissionDeniedException

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

the class SiteMembershipRequestsImpl method rejectSiteMembershipRequest.

@Override
public void rejectSiteMembershipRequest(String siteId, String inviteeId, SiteMembershipRejection siteMembershipRejection) {
    SiteInfo siteInfo = sites.validateSite(siteId);
    if (siteInfo == null) {
        throw new EntityNotFoundException(siteId);
    }
    // set the site id to the short name (to deal with case sensitivity issues with
    // using the siteId from the url)
    siteId = siteInfo.getShortName();
    // Validate invitation.
    Invitation invitation = getSiteInvitation(inviteeId, siteId);
    if (invitation == null || !(invitation instanceof ModeratedInvitation)) {
        throw new RelationshipResourceNotFoundException(siteId, inviteeId);
    }
    ModeratedInvitation moderatedInvitation = (ModeratedInvitation) invitation;
    ResourceType resourceType = moderatedInvitation.getResourceType();
    if (!resourceType.equals(ResourceType.WEB_SITE) || !SiteVisibility.MODERATED.equals(siteInfo.getVisibility())) {
        // note: security, no indication that this has a different visibility
        throw new RelationshipResourceNotFoundException(siteId, inviteeId);
    }
    String reason = null;
    if (siteMembershipRejection != null && !(siteMembershipRejection.getComment() == null || siteMembershipRejection.getComment().isEmpty())) {
        reason = siteMembershipRejection.getComment();
    }
    try {
        invitationService.reject(invitation.getInviteId(), reason);
    } catch (InvitationExceptionForbidden ex) {
        throw new PermissionDeniedException();
    }
}
Also used : RelationshipResourceNotFoundException(org.alfresco.rest.framework.core.exceptions.RelationshipResourceNotFoundException) SiteInfo(org.alfresco.service.cmr.site.SiteInfo) ModeratedInvitation(org.alfresco.service.cmr.invitation.ModeratedInvitation) Invitation(org.alfresco.service.cmr.invitation.Invitation) ModeratedInvitation(org.alfresco.service.cmr.invitation.ModeratedInvitation) InvitationExceptionForbidden(org.alfresco.service.cmr.invitation.InvitationExceptionForbidden) ResourceType(org.alfresco.service.cmr.invitation.Invitation.ResourceType) PermissionDeniedException(org.alfresco.rest.framework.core.exceptions.PermissionDeniedException) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException)

Example 23 with PermissionDeniedException

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

the class NodeVersionsRelation method delete.

@Override
@WebApiDescription(title = "Delete version")
public void delete(String nodeId, String versionId, Parameters parameters) {
    Version v = findVersion(nodeId, versionId);
    // live (aka versioned) nodeRef
    NodeRef nodeRef = v.getVersionedNodeRef();
    if (sr.getPermissionService().hasPermission(nodeRef, PermissionService.DELETE) != AccessStatus.ALLOWED) {
        throw new PermissionDeniedException("Cannot delete version");
    }
    versionService.deleteVersion(nodeRef, v);
    Map<QName, Serializable> props = sr.getNodeService().getProperties(nodeRef);
    if (props.get(ContentModel.PROP_VERSION_LABEL) == null) {
        // note: alternatively, the client can remove the "cm:versionable" aspect (if permissions allow) to clear the version history and disable versioning
        throw new IntegrityException("Cannot delete last version (did you mean to disable versioning instead ?) [" + nodeId + "," + versionId + "]", null);
    /*
            if (props.get(ContentModel.PROP_VERSION_TYPE) != null)
            {
                // minor fix up to versionable aspect - ie. remove versionType
                behaviourFilter.disableBehaviour(nodeRef, ContentModel.ASPECT_VERSIONABLE);
                behaviourFilter.disableBehaviour(nodeRef, ContentModel.ASPECT_AUDITABLE);
                try
                {
                    sr.getNodeService().removeProperty(nodeRef, ContentModel.PROP_VERSION_TYPE);
                }
                finally
                {
                    behaviourFilter.enableBehaviour(nodeRef, ContentModel.ASPECT_AUDITABLE);
                    behaviourFilter.enableBehaviour(nodeRef, ContentModel.ASPECT_VERSIONABLE);
                }
            }
            */
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) Serializable(java.io.Serializable) Version(org.alfresco.service.cmr.version.Version) QName(org.alfresco.service.namespace.QName) IntegrityException(org.alfresco.repo.node.integrity.IntegrityException) PermissionDeniedException(org.alfresco.rest.framework.core.exceptions.PermissionDeniedException) WebApiDescription(org.alfresco.rest.framework.WebApiDescription)

Example 24 with PermissionDeniedException

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

the class AuthenticationsImpl method createTicket.

@Override
public LoginTicketResponse createTicket(LoginTicket loginRequest, Parameters parameters) {
    validateLoginRequest(loginRequest);
    try {
        // get ticket
        authenticationService.authenticate(loginRequest.getUserId(), loginRequest.getPassword().toCharArray());
        LoginTicketResponse response = new LoginTicketResponse();
        response.setUserId(loginRequest.getUserId());
        response.setId(authenticationService.getCurrentTicket());
        return response;
    } catch (AuthenticationException e) {
        throw new PermissionDeniedException("Login failed");
    } finally {
        AuthenticationUtil.clearCurrentSecurityContext();
    }
}
Also used : LoginTicketResponse(org.alfresco.rest.api.model.LoginTicketResponse) AuthenticationException(org.alfresco.repo.security.authentication.AuthenticationException) PermissionDeniedException(org.alfresco.rest.framework.core.exceptions.PermissionDeniedException)

Example 25 with PermissionDeniedException

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

the class DeploymentsImpl method getDeployment.

@Override
public Deployment getDeployment(String deploymentId) {
    // Only admin-user is allowed to get deployments
    if (!authorityService.isAdminAuthority(AuthenticationUtil.getRunAsUser())) {
        throw new PermissionDeniedException();
    }
    RepositoryService repositoryService = activitiProcessEngine.getRepositoryService();
    DeploymentQuery query = repositoryService.createDeploymentQuery().deploymentId(deploymentId);
    if (tenantService.isEnabled() && deployWorkflowsInTenant) {
        query.processDefinitionKeyLike("@" + TenantUtil.getCurrentDomain() + "@%");
    }
    org.activiti.engine.repository.Deployment deployment = null;
    try {
        deployment = query.singleResult();
    } catch (ActivitiException e) {
        // The next exception will cause a response status 400: Bad request
        throw new InvalidArgumentException("Invalid deployment id: " + deploymentId);
    }
    if (deployment == null) {
        // The next exception will cause a response status 404: Not found
        throw new EntityNotFoundException(deploymentId);
    }
    Deployment deploymentRest = new Deployment(deployment);
    return deploymentRest;
}
Also used : DeploymentQuery(org.activiti.engine.repository.DeploymentQuery) ActivitiException(org.activiti.engine.ActivitiException) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) Deployment(org.alfresco.rest.workflow.api.model.Deployment) PermissionDeniedException(org.alfresco.rest.framework.core.exceptions.PermissionDeniedException) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) RepositoryService(org.activiti.engine.RepositoryService)

Aggregations

PermissionDeniedException (org.alfresco.rest.framework.core.exceptions.PermissionDeniedException)26 EntityNotFoundException (org.alfresco.rest.framework.core.exceptions.EntityNotFoundException)16 InvalidArgumentException (org.alfresco.rest.framework.core.exceptions.InvalidArgumentException)13 NodeRef (org.alfresco.service.cmr.repository.NodeRef)13 ConstraintViolatedException (org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException)11 IntegrityException (org.alfresco.repo.node.integrity.IntegrityException)6 NotFoundException (org.alfresco.rest.framework.core.exceptions.NotFoundException)6 QName (org.alfresco.service.namespace.QName)6 Serializable (java.io.Serializable)5 HashMap (java.util.HashMap)5 ArrayList (java.util.ArrayList)4 ApiException (org.alfresco.rest.framework.core.exceptions.ApiException)4 HashSet (java.util.HashSet)3 AuthenticationException (org.alfresco.repo.security.authentication.AuthenticationException)3 AccessDeniedException (org.alfresco.repo.security.permissions.AccessDeniedException)3 DisabledServiceException (org.alfresco.rest.framework.core.exceptions.DisabledServiceException)3 InsufficientStorageException (org.alfresco.rest.framework.core.exceptions.InsufficientStorageException)3 RelationshipResourceNotFoundException (org.alfresco.rest.framework.core.exceptions.RelationshipResourceNotFoundException)3 UnsupportedResourceOperationException (org.alfresco.rest.framework.core.exceptions.UnsupportedResourceOperationException)3 DuplicateChildNodeNameException (org.alfresco.service.cmr.repository.DuplicateChildNodeNameException)3