Search in sources :

Example 1 with Group

use of org.alfresco.rest.api.model.Group 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 Group

use of org.alfresco.rest.api.model.Group in project alfresco-remote-api by Alfresco.

the class GroupsImpl method getGroupsByPersonId.

@Override
public CollectionWithPagingInfo<Group> getGroupsByPersonId(String requestedPersonId, Parameters parameters) {
    // Canonicalize the person ID, performing -me- alias substitution.
    final String personId = people.validatePerson(requestedPersonId);
    // Non-admins can only access their own data
    // TODO: this is also in PeopleImpl.update(personId,personInfo) - refactor?
    boolean isAdmin = authorityService.hasAdminAuthority();
    String currentUserId = AuthenticationUtil.getFullyAuthenticatedUser();
    if (!isAdmin && !currentUserId.equalsIgnoreCase(personId)) {
        // The user is not an admin user and is not attempting to retrieve *their own* details.
        throw new PermissionDeniedException();
    }
    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 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);
    // Get all the authorities for a user, including but not limited to, groups.
    Set<String> userAuthorities = runAsSystem(() -> authorityService.getAuthoritiesForUser(personId));
    final Set<String> rootAuthorities = getAllRootAuthorities(AuthorityType.GROUP);
    // Filter, transform and sort the list of user authorities into
    // a suitable list of AuthorityInfo objects.
    final String finalZoneFilter = zoneFilter;
    final Boolean finalIsRootParam = isRootParam;
    List<AuthorityInfo> groupAuthorities = userAuthorities.stream().filter(a -> a.startsWith(AuthorityType.GROUP.getPrefixString())).filter(a -> isRootPredicate(finalIsRootParam, rootAuthorities, a)).filter(a -> zonePredicate(a, finalZoneFilter)).map(this::getAuthorityInfo).sorted(new AuthorityInfoComparator(sortProp.getFirst(), sortProp.getSecond())).collect(Collectors.toList());
    PagingResults<AuthorityInfo> pagingResult = Util.wrapPagingResults(paging, groupAuthorities);
    // Create response.
    final List<AuthorityInfo> page = pagingResult.getPage();
    int totalItems = pagingResult.getTotalResultCount().getFirst();
    // Transform the page of results into Group objects
    List<Group> groups = page.stream().map(authority -> getGroup(authority, includeParam, rootAuthorities)).collect(Collectors.toList());
    return CollectionWithPagingInfo.asPaged(paging, groups, pagingResult.hasMoreItems(), totalItems);
}
Also used : CannedQueryPageDetails(org.alfresco.query.CannedQueryPageDetails) Arrays(java.util.Arrays) UnsupportedResourceOperationException(org.alfresco.rest.framework.core.exceptions.UnsupportedResourceOperationException) MapBasedQueryWalkerOrSupported(org.alfresco.rest.workflow.api.impl.MapBasedQueryWalkerOrSupported) Query(org.alfresco.rest.framework.resource.parameters.where.Query) AuthorityService(org.alfresco.service.cmr.security.AuthorityService) Paging(org.alfresco.rest.framework.resource.parameters.Paging) AuthenticationUtil.runAsSystem(org.alfresco.repo.security.authentication.AuthenticationUtil.runAsSystem) AbstractList(java.util.AbstractList) HashMap(java.util.HashMap) PagingRequest(org.alfresco.query.PagingRequest) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) WhereClauseParser(org.alfresco.rest.antlr.WhereClauseParser) GroupMember(org.alfresco.rest.api.model.GroupMember) ConstraintViolatedException(org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException) PermissionDeniedException(org.alfresco.rest.framework.core.exceptions.PermissionDeniedException) PagingResults(org.alfresco.query.PagingResults) PermissionService(org.alfresco.service.cmr.security.PermissionService) People(org.alfresco.rest.api.People) Map(java.util.Map) QueryHelper(org.alfresco.rest.framework.resource.parameters.where.QueryHelper) AuthorityDAO(org.alfresco.repo.security.authority.AuthorityDAO) Group(org.alfresco.rest.api.model.Group) Collator(java.text.Collator) UnknownAuthorityException(org.alfresco.repo.security.authority.UnknownAuthorityException) AuthorityType(org.alfresco.service.cmr.security.AuthorityType) Iterator(java.util.Iterator) SortColumn(org.alfresco.rest.framework.resource.parameters.SortColumn) Set(java.util.Set) Pair(org.alfresco.util.Pair) AuthorityInfo(org.alfresco.repo.security.authority.AuthorityInfo) Collectors(java.util.stream.Collectors) EmptyPagingResults(org.alfresco.query.EmptyPagingResults) AlfrescoCollator(org.alfresco.util.AlfrescoCollator) List(java.util.List) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) CollectionWithPagingInfo(org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo) MapBasedQueryWalker(org.alfresco.rest.workflow.api.impl.MapBasedQueryWalker) I18NUtil(org.springframework.extensions.surf.util.I18NUtil) AuthenticationUtil(org.alfresco.repo.security.authentication.AuthenticationUtil) Groups(org.alfresco.rest.api.Groups) NotFoundException(org.alfresco.rest.framework.core.exceptions.NotFoundException) Comparator(java.util.Comparator) Collections(java.util.Collections) AuthorityException(org.alfresco.repo.security.authority.AuthorityException) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) Parameters(org.alfresco.rest.framework.resource.parameters.Parameters) Group(org.alfresco.rest.api.model.Group) Query(org.alfresco.rest.framework.resource.parameters.where.Query) Paging(org.alfresco.rest.framework.resource.parameters.Paging) PermissionDeniedException(org.alfresco.rest.framework.core.exceptions.PermissionDeniedException) AuthorityInfo(org.alfresco.repo.security.authority.AuthorityInfo)

Example 3 with Group

use of org.alfresco.rest.api.model.Group in project alfresco-remote-api by Alfresco.

the class GroupsImpl method getGroup.

private Group getGroup(AuthorityInfo authorityInfo, List<String> includeParam, Set<String> rootAuthorities) {
    if (authorityInfo == null) {
        return null;
    }
    Group group = new Group();
    group.setId(authorityInfo.getAuthorityName());
    // REPO-1743
    String authorityDisplayName = authorityInfo.getAuthorityDisplayName();
    if (authorityDisplayName == null || authorityDisplayName.isEmpty()) {
        authorityDisplayName = authorityService.getAuthorityDisplayName(authorityInfo.getAuthorityName());
    }
    group.setDisplayName(authorityDisplayName);
    group.setIsRoot(isRootAuthority(rootAuthorities, authorityInfo.getAuthorityName()));
    // Optionally include
    if (includeParam != null) {
        if (includeParam.contains(PARAM_INCLUDE_PARENT_IDS)) {
            String authority = authorityInfo.getAuthorityName();
            Set<String> containingAuthorities = Collections.emptySet();
            // is a special case, AuthorityType.EVERYONE is not, and an exception is thrown.
            if (!authority.equalsIgnoreCase(PermissionService.ALL_AUTHORITIES)) {
                containingAuthorities = authorityService.getContainingAuthorities(AuthorityType.GROUP, authority, true);
            }
            group.setParentIds(containingAuthorities);
        }
        if (includeParam.contains(PARAM_INCLUDE_ZONES)) {
            Set<String> authorityZones = authorityService.getAuthorityZones(authorityInfo.getAuthorityName());
            group.setZones(authorityZones);
        }
    }
    return group;
}
Also used : Group(org.alfresco.rest.api.model.Group)

Example 4 with Group

use of org.alfresco.rest.api.model.Group in project alfresco-remote-api by Alfresco.

the class GroupsFilter method getGroupsByPersonId.

@Override
public CollectionWithPagingInfo<Group> getGroupsByPersonId(String requestedPersonId, Parameters parameters) {
    // Canonicalize the person ID, performing -me- alias substitution.
    final String personId = people.validatePerson(requestedPersonId);
    // Non-admins can only access their own data
    // TODO: this is also in PeopleImpl.update(personId,personInfo) - refactor?
    boolean isAdmin = authorityService.hasAdminAuthority();
    String currentUserId = AuthenticationUtil.getFullyAuthenticatedUser();
    if (!isAdmin && !currentUserId.equalsIgnoreCase(personId)) {
        // The user is not an admin user and is not attempting to retrieve *their own* details.
        throw new PermissionDeniedException();
    }
    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) {
            validateListParam(zonesParam, ZONE, MAX_ZONES);
            zoneFilter = zonesParam.get(0);
        }
    }
    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);
    // Get all the authorities for a user, including but not limited to, groups.
    Set<String> userAuthorities = runAsSystem(() -> authorityService.getAuthoritiesForUser(personId));
    final Set<String> rootAuthorities = getAllRootAuthorities(AuthorityType.GROUP);
    // Filter, transform and sort the list of user authorities into
    // a suitable list of AuthorityInfo objects.
    final String finalZoneFilter = zoneFilter;
    final Boolean finalIsRootParam = isRootParam;
    List<AuthorityInfo> groupAuthorities = userAuthorities.stream().filter(a -> a.startsWith(AuthorityType.GROUP.getPrefixString())).filter(a -> isRootPredicate(finalIsRootParam, rootAuthorities, a)).filter(a -> zonePredicate(a, finalZoneFilter)).map(this::getAuthorityInfo).sorted(new AuthorityInfoComparator(sortProp.getFirst(), sortProp.getSecond())).collect(Collectors.toList());
    PagingResults<AuthorityInfo> pagingResult = Util.wrapPagingResults(paging, groupAuthorities);
    // Create response.
    final List<AuthorityInfo> page = pagingResult.getPage();
    int totalItems = pagingResult.getTotalResultCount().getFirst();
    // Transform the page of results into Group objects
    List<Group> groups = page.stream().map(authority -> getGroup(authority, includeParam, rootAuthorities)).collect(Collectors.toList());
    return CollectionWithPagingInfo.asPaged(paging, groups, pagingResult.hasMoreItems(), totalItems);
}
Also used : CannedQueryPageDetails(org.alfresco.query.CannedQueryPageDetails) Arrays(java.util.Arrays) UnsupportedResourceOperationException(org.alfresco.rest.framework.core.exceptions.UnsupportedResourceOperationException) MapBasedQueryWalkerOrSupported(org.alfresco.rest.workflow.api.impl.MapBasedQueryWalkerOrSupported) Query(org.alfresco.rest.framework.resource.parameters.where.Query) AuthorityService(org.alfresco.service.cmr.security.AuthorityService) Paging(org.alfresco.rest.framework.resource.parameters.Paging) AuthenticationUtil.runAsSystem(org.alfresco.repo.security.authentication.AuthenticationUtil.runAsSystem) AbstractList(java.util.AbstractList) HashMap(java.util.HashMap) StringUtils(org.apache.commons.lang3.StringUtils) PagingRequest(org.alfresco.query.PagingRequest) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) WhereClauseParser(org.alfresco.rest.antlr.WhereClauseParser) GroupMember(org.alfresco.rest.api.model.GroupMember) ConstraintViolatedException(org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException) PermissionDeniedException(org.alfresco.rest.framework.core.exceptions.PermissionDeniedException) PagingResults(org.alfresco.query.PagingResults) PermissionService(org.alfresco.service.cmr.security.PermissionService) People(org.alfresco.rest.api.People) Map(java.util.Map) QueryHelper(org.alfresco.rest.framework.resource.parameters.where.QueryHelper) AuthorityDAO(org.alfresco.repo.security.authority.AuthorityDAO) Group(org.alfresco.rest.api.model.Group) Collator(java.text.Collator) UnknownAuthorityException(org.alfresco.repo.security.authority.UnknownAuthorityException) AuthorityType(org.alfresco.service.cmr.security.AuthorityType) SortColumn(org.alfresco.rest.framework.resource.parameters.SortColumn) Set(java.util.Set) Pair(org.alfresco.util.Pair) AuthorityInfo(org.alfresco.repo.security.authority.AuthorityInfo) Collectors(java.util.stream.Collectors) EmptyPagingResults(org.alfresco.query.EmptyPagingResults) AlfrescoCollator(org.alfresco.util.AlfrescoCollator) List(java.util.List) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) CollectionWithPagingInfo(org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo) MapBasedQueryWalker(org.alfresco.rest.workflow.api.impl.MapBasedQueryWalker) I18NUtil(org.springframework.extensions.surf.util.I18NUtil) AuthenticationUtil(org.alfresco.repo.security.authentication.AuthenticationUtil) Groups(org.alfresco.rest.api.Groups) NotFoundException(org.alfresco.rest.framework.core.exceptions.NotFoundException) Comparator(java.util.Comparator) Collections(java.util.Collections) AuthorityException(org.alfresco.repo.security.authority.AuthorityException) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) Parameters(org.alfresco.rest.framework.resource.parameters.Parameters) Group(org.alfresco.rest.api.model.Group) Query(org.alfresco.rest.framework.resource.parameters.where.Query) Paging(org.alfresco.rest.framework.resource.parameters.Paging) PermissionDeniedException(org.alfresco.rest.framework.core.exceptions.PermissionDeniedException) AuthorityInfo(org.alfresco.repo.security.authority.AuthorityInfo)

Example 5 with Group

use of org.alfresco.rest.api.model.Group in project alfresco-remote-api by Alfresco.

the class GroupsFilter method getGroup.

private Group getGroup(AuthorityInfo authorityInfo, List<String> includeParam, Set<String> rootAuthorities) {
    if (authorityInfo == null) {
        return null;
    }
    Group group = new Group();
    group.setId(authorityInfo.getAuthorityName());
    // REPO-1743
    String authorityDisplayName = authorityInfo.getAuthorityDisplayName();
    if (authorityDisplayName == null || authorityDisplayName.isEmpty()) {
        authorityDisplayName = authorityService.getAuthorityDisplayName(authorityInfo.getAuthorityName());
    }
    group.setDisplayName(authorityDisplayName);
    group.setIsRoot(isRootAuthority(rootAuthorities, authorityInfo.getAuthorityName()));
    // Optionally include
    if (includeParam != null) {
        if (includeParam.contains(PARAM_INCLUDE_PARENT_IDS)) {
            String authority = authorityInfo.getAuthorityName();
            Set<String> containingAuthorities = Collections.emptySet();
            // is a special case, AuthorityType.EVERYONE is not, and an exception is thrown.
            if (!authority.equalsIgnoreCase(PermissionService.ALL_AUTHORITIES)) {
                containingAuthorities = authorityService.getContainingAuthorities(AuthorityType.GROUP, authority, true);
            }
            group.setParentIds(containingAuthorities);
        }
        if (includeParam.contains(PARAM_INCLUDE_ZONES)) {
            Set<String> authorityZones = authorityService.getAuthorityZones(authorityInfo.getAuthorityName());
            group.setZones(authorityZones);
        }
    }
    return group;
}
Also used : Group(org.alfresco.rest.api.model.Group)

Aggregations

Group (org.alfresco.rest.api.model.Group)6 EmptyPagingResults (org.alfresco.query.EmptyPagingResults)4 AuthorityInfo (org.alfresco.repo.security.authority.AuthorityInfo)4 UnknownAuthorityException (org.alfresco.repo.security.authority.UnknownAuthorityException)4 Paging (org.alfresco.rest.framework.resource.parameters.Paging)4 AuthorityType (org.alfresco.service.cmr.security.AuthorityType)4 AbstractList (java.util.AbstractList)3 Query (org.alfresco.rest.framework.resource.parameters.where.Query)3 Collator (java.text.Collator)2 ArrayList (java.util.ArrayList)2 Arrays (java.util.Arrays)2 Collections (java.util.Collections)2 Comparator (java.util.Comparator)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Map (java.util.Map)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 CannedQueryPageDetails (org.alfresco.query.CannedQueryPageDetails)2