Search in sources :

Example 1 with UnknownAuthorityException

use of org.alfresco.repo.security.authority.UnknownAuthorityException in project alfresco-remote-api by Alfresco.

the class GroupsImpl method getGroups.

public CollectionWithPagingInfo<Group> getGroups(final Parameters parameters) {
    final List<String> includeParam = parameters.getInclude();
    Paging paging = parameters.getPaging();
    // Retrieve sort column. This is limited for now to sort column due to
    // v0 api implementation. Should be improved in the future.
    Pair<String, Boolean> sortProp = getGroupsSortProp(parameters);
    // Parse where clause properties.
    Query q = parameters.getQuery();
    Boolean isRootParam = null;
    String zoneFilter = null;
    if (q != null) {
        GroupsQueryWalker propertyWalker = new GroupsQueryWalker();
        QueryHelper.walk(q, propertyWalker);
        isRootParam = propertyWalker.getIsRoot();
        List<String> zonesParam = propertyWalker.getZones();
        if (zonesParam != null) {
            validateZonesParam(zonesParam);
            zoneFilter = zonesParam.get(0);
        }
    }
    final AuthorityType authorityType = AuthorityType.GROUP;
    final Set<String> rootAuthorities = getAllRootAuthorities(authorityType);
    PagingResults<AuthorityInfo> pagingResult;
    try {
        pagingResult = getAuthoritiesInfo(authorityType, isRootParam, zoneFilter, rootAuthorities, sortProp, paging);
    } catch (UnknownAuthorityException e) {
        // Non-existent zone
        pagingResult = new EmptyPagingResults<>();
    }
    // Create response.
    final List<AuthorityInfo> page = pagingResult.getPage();
    int totalItems = pagingResult.getTotalResultCount().getFirst();
    List<Group> groups = new AbstractList<Group>() {

        @Override
        public Group get(int index) {
            AuthorityInfo authorityInfo = page.get(index);
            return getGroup(authorityInfo, includeParam, rootAuthorities);
        }

        @Override
        public int size() {
            return page.size();
        }
    };
    return CollectionWithPagingInfo.asPaged(paging, groups, pagingResult.hasMoreItems(), totalItems);
}
Also used : AbstractList(java.util.AbstractList) Group(org.alfresco.rest.api.model.Group) Query(org.alfresco.rest.framework.resource.parameters.where.Query) Paging(org.alfresco.rest.framework.resource.parameters.Paging) AuthorityType(org.alfresco.service.cmr.security.AuthorityType) AuthorityInfo(org.alfresco.repo.security.authority.AuthorityInfo) UnknownAuthorityException(org.alfresco.repo.security.authority.UnknownAuthorityException) EmptyPagingResults(org.alfresco.query.EmptyPagingResults)

Example 2 with UnknownAuthorityException

use of org.alfresco.repo.security.authority.UnknownAuthorityException in project alfresco-remote-api by Alfresco.

the class SiteMembershipRequestsImpl method approveSiteMembershipRequest.

@Override
public void approveSiteMembershipRequest(String siteId, String inviteeId, SiteMembershipApproval siteMembershipApproval) {
    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);
    }
    try {
        invitationService.approve(invitation.getInviteId(), "");
    } catch (InvitationExceptionForbidden ex) {
        throw new PermissionDeniedException();
    }
    // approval role differs from default one.
    if (siteMembershipApproval != null && !(siteMembershipApproval.getRole() == null || siteMembershipApproval.getRole().isEmpty())) {
        String role = siteMembershipApproval.getRole();
        // Check if role chosen by moderator differs from the invite role.
        if (!moderatedInvitation.getRoleName().equals(role)) {
            String currentUserId = AuthenticationUtil.getFullyAuthenticatedUser();
            // Update invitation with new role.
            try {
                addSiteMembership(invitation.getInviteeUserName(), siteId, role, currentUserId);
            } catch (UnknownAuthorityException e) {
                logger.debug("addSiteMember:  UnknownAuthorityException " + siteId + " person " + invitation.getInviteId() + " role " + role);
                throw new InvalidArgumentException("Unknown role '" + role + "'");
            }
        }
    }
}
Also used : RelationshipResourceNotFoundException(org.alfresco.rest.framework.core.exceptions.RelationshipResourceNotFoundException) SiteInfo(org.alfresco.service.cmr.site.SiteInfo) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) 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) UnknownAuthorityException(org.alfresco.repo.security.authority.UnknownAuthorityException)

Example 3 with UnknownAuthorityException

use of org.alfresco.repo.security.authority.UnknownAuthorityException in project alfresco-remote-api by Alfresco.

the class SitesImpl method addSiteMember.

public SiteMember addSiteMember(String siteId, SiteMember siteMember) {
    String personId = people.validatePerson(siteMember.getPersonId());
    SiteInfo siteInfo = validateSite(siteId);
    if (siteInfo == null) {
        // site does not exist
        logger.debug("addSiteMember:  site does not exist " + siteId + " person " + personId);
        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();
    String role = siteMember.getRole();
    if (role == null) {
        logger.debug("addSiteMember:  Must provide a role " + siteMember);
        throw new InvalidArgumentException("Must provide a role");
    }
    if (siteService.isMember(siteId, personId)) {
        logger.debug("addSiteMember:  " + personId + " is already a member of site " + siteId);
        throw new ConstraintViolatedException(personId + " is already a member of site " + siteId);
    }
    if (!siteService.canAddMember(siteId, personId, role)) {
        logger.debug("addSiteMember:  PermissionDeniedException " + siteId + " person " + personId + " role " + role);
        throw new PermissionDeniedException();
    }
    try {
        siteService.setMembership(siteId, personId, role);
    } catch (UnknownAuthorityException e) {
        logger.debug("addSiteMember:  UnknownAuthorityException " + siteId + " person " + personId + " role " + role);
        throw new InvalidArgumentException("Unknown role '" + role + "'");
    }
    return siteMember;
}
Also used : SiteInfo(org.alfresco.service.cmr.site.SiteInfo) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) PermissionDeniedException(org.alfresco.rest.framework.core.exceptions.PermissionDeniedException) FilterPropString(org.alfresco.repo.node.getchildren.FilterPropString) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) ConstraintViolatedException(org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException) UnknownAuthorityException(org.alfresco.repo.security.authority.UnknownAuthorityException)

Example 4 with UnknownAuthorityException

use of org.alfresco.repo.security.authority.UnknownAuthorityException in project alfresco-remote-api by Alfresco.

the class SitesImpl method updateSiteMember.

public SiteMember updateSiteMember(String siteId, SiteMember siteMember) {
    String siteMemberId = siteMember.getPersonId();
    if (siteMemberId == null) {
        throw new InvalidArgumentException("Member id is null");
    }
    siteMemberId = people.validatePerson(siteMemberId);
    SiteInfo siteInfo = validateSite(siteId);
    if (siteInfo == null) {
        // site does not exist
        throw new EntityNotFoundException(siteId);
    }
    siteId = siteInfo.getShortName();
    String siteRole = siteMember.getRole();
    if (siteRole == null) {
        throw new InvalidArgumentException("Must provide a role");
    }
    /* MNT-10551 : fix */
    if (!siteService.isMember(siteId, siteMember.getPersonId())) {
        throw new InvalidArgumentException("User is not a member of the site");
    }
    try {
        siteService.setMembership(siteId, siteMember.getPersonId(), siteRole);
    } catch (UnknownAuthorityException e) {
        throw new InvalidArgumentException("Unknown role '" + siteRole + "'");
    }
    return siteMember;
}
Also used : SiteInfo(org.alfresco.service.cmr.site.SiteInfo) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) FilterPropString(org.alfresco.repo.node.getchildren.FilterPropString) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) UnknownAuthorityException(org.alfresco.repo.security.authority.UnknownAuthorityException)

Example 5 with UnknownAuthorityException

use of org.alfresco.repo.security.authority.UnknownAuthorityException in project alfresco-remote-api by Alfresco.

the class GroupsFilter method getGroups.

public CollectionWithPagingInfo<Group> getGroups(final Parameters parameters) {
    Paging paging = parameters.getPaging();
    // Retrieve sort column. This is limited for now to sort column due to
    // v0 api implementation. Should be improved in the future.
    Pair<String, Boolean> sortProp = getGroupsSortProp(parameters);
    // Parse where clause properties.
    GroupsFilter groupsFilters = getGroupsFilterFromQueryParameters(parameters.getQuery());
    final AuthorityType authorityType = AuthorityType.GROUP;
    final Set<String> rootAuthorities = getAllRootAuthorities(authorityType);
    PagingResults<AuthorityInfo> pagingResult;
    try {
        pagingResult = getAuthoritiesInfo(authorityType, groupsFilters, rootAuthorities, sortProp, paging);
    } catch (UnknownAuthorityException e) {
        // Non-existent zone
        pagingResult = new EmptyPagingResults<>();
    }
    List<Group> groups = createGroupsResponse(pagingResult.getPage(), parameters.getInclude(), rootAuthorities);
    int totalItems = pagingResult.getTotalResultCount().getFirst();
    return CollectionWithPagingInfo.asPaged(paging, groups, pagingResult.hasMoreItems(), totalItems);
}
Also used : Group(org.alfresco.rest.api.model.Group) Paging(org.alfresco.rest.framework.resource.parameters.Paging) AuthorityType(org.alfresco.service.cmr.security.AuthorityType) AuthorityInfo(org.alfresco.repo.security.authority.AuthorityInfo) UnknownAuthorityException(org.alfresco.repo.security.authority.UnknownAuthorityException) EmptyPagingResults(org.alfresco.query.EmptyPagingResults)

Aggregations

UnknownAuthorityException (org.alfresco.repo.security.authority.UnknownAuthorityException)5 EntityNotFoundException (org.alfresco.rest.framework.core.exceptions.EntityNotFoundException)3 InvalidArgumentException (org.alfresco.rest.framework.core.exceptions.InvalidArgumentException)3 SiteInfo (org.alfresco.service.cmr.site.SiteInfo)3 EmptyPagingResults (org.alfresco.query.EmptyPagingResults)2 FilterPropString (org.alfresco.repo.node.getchildren.FilterPropString)2 AuthorityInfo (org.alfresco.repo.security.authority.AuthorityInfo)2 Group (org.alfresco.rest.api.model.Group)2 PermissionDeniedException (org.alfresco.rest.framework.core.exceptions.PermissionDeniedException)2 Paging (org.alfresco.rest.framework.resource.parameters.Paging)2 AuthorityType (org.alfresco.service.cmr.security.AuthorityType)2 AbstractList (java.util.AbstractList)1 ConstraintViolatedException (org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException)1 RelationshipResourceNotFoundException (org.alfresco.rest.framework.core.exceptions.RelationshipResourceNotFoundException)1 Query (org.alfresco.rest.framework.resource.parameters.where.Query)1 Invitation (org.alfresco.service.cmr.invitation.Invitation)1 ResourceType (org.alfresco.service.cmr.invitation.Invitation.ResourceType)1 InvitationExceptionForbidden (org.alfresco.service.cmr.invitation.InvitationExceptionForbidden)1 ModeratedInvitation (org.alfresco.service.cmr.invitation.ModeratedInvitation)1