Search in sources :

Example 6 with AuthorityType

use of org.alfresco.service.cmr.security.AuthorityType in project acs-community-packaging by Alfresco.

the class BaseInviteUsersWizard method finishImpl.

/**
 * @see org.alfresco.web.bean.dialog.BaseDialogBean#finishImpl(javax.faces.context.FacesContext, java.lang.String)
 */
@Override
protected String finishImpl(FacesContext context, String outcome) throws Exception {
    User user = Application.getCurrentUser(context);
    String from = (String) this.getNodeService().getProperty(user.getPerson(), ContentModel.PROP_EMAIL);
    if (from == null || from.length() == 0) {
        // if the user does not have an email address get the default one from the config service
        from = Application.getClientConfig(context).getFromEmailAddress();
    }
    // get the Space to apply changes too
    NodeRef nodeRef = this.getNode().getNodeRef();
    // set permissions for each user and send them a mail
    for (int i = 0; i < this.userGroupRoles.size(); i++) {
        UserGroupRole userGroupRole = this.userGroupRoles.get(i);
        String authority = userGroupRole.getAuthority();
        // find the selected permission ref from it's name and apply for the specified user
        Set<String> perms = getPermissionsForType();
        for (String permission : perms) {
            if (userGroupRole.getRole().equals(permission)) {
                this.getPermissionService().setPermission(nodeRef, authority, permission, true);
                break;
            }
        }
        // Create the mail message for sending to each User
        if (NOTIFY_YES.equals(this.notify)) {
            // if User, email then, else if Group get all members and email them
            AuthorityType authType = AuthorityType.getAuthorityType(authority);
            if (authType.equals(AuthorityType.USER)) {
                if (this.getPersonService().personExists(authority) == true) {
                    this.mailHelper.notifyUser(this.getPersonService().getPerson(authority), nodeRef, from, userGroupRole.getRole());
                }
            } else if (authType.equals(AuthorityType.GROUP)) {
                // else notify all members of the group
                Set<String> users = this.getAuthorityService().getContainedAuthorities(AuthorityType.USER, authority, false);
                for (String userAuth : users) {
                    if (this.getPersonService().personExists(userAuth) == true) {
                        this.mailHelper.notifyUser(this.getPersonService().getPerson(userAuth), nodeRef, from, userGroupRole.getRole());
                    }
                }
            }
        }
    }
    // reset max users flag
    this.maxUsersReturned = false;
    return outcome;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) AuthorityType(org.alfresco.service.cmr.security.AuthorityType) User(org.alfresco.web.bean.repository.User) TreeSet(java.util.TreeSet) LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set)

Example 7 with AuthorityType

use of org.alfresco.service.cmr.security.AuthorityType in project alfresco-remote-api by Alfresco.

the class GroupsImpl method getAuthoritiesInfo.

private PagingResults<AuthorityInfo> getAuthoritiesInfo(AuthorityType authorityType, Boolean isRootParam, String zoneFilter, Set<String> rootAuthorities, Pair<String, Boolean> sortProp, Paging paging) {
    PagingResults<AuthorityInfo> pagingResult;
    if (isRootParam != null) {
        List<AuthorityInfo> groupList;
        if (isRootParam) {
            // Limit the post processing work by using the already loaded
            // list of root authorities.
            List<AuthorityInfo> authorities = rootAuthorities.stream().map(this::getAuthorityInfo).filter(auth -> zonePredicate(auth.getAuthorityName(), zoneFilter)).collect(Collectors.toList());
            groupList = new ArrayList<>(rootAuthorities.size());
            groupList.addAll(authorities);
            // Post process sorting - this should be moved to service
            // layer. It is done here because sorting is not supported at
            // service layer.
            AuthorityInfoComparator authorityComparator = new AuthorityInfoComparator(sortProp.getFirst(), sortProp.getSecond());
            Collections.sort(groupList, authorityComparator);
        } else {
            PagingRequest pagingNoMaxItems = new PagingRequest(CannedQueryPageDetails.DEFAULT_PAGE_SIZE);
            // Get authorities using canned query but without using
            // the requested paginating now because we need to filter out
            // the root authorities.
            PagingResults<AuthorityInfo> nonPagingResult = authorityService.getAuthoritiesInfo(authorityType, zoneFilter, null, sortProp.getFirst(), sortProp.getSecond(), pagingNoMaxItems);
            // Post process filtering - this should be moved to service
            // layer. It is done here because filtering by "isRoot" is not
            // supported at service layer.
            groupList = nonPagingResult.getPage();
            if (groupList != null) {
                for (Iterator<AuthorityInfo> i = groupList.iterator(); i.hasNext(); ) {
                    AuthorityInfo authorityInfo = i.next();
                    if (!isRootParam.equals(isRootAuthority(rootAuthorities, authorityInfo.getAuthorityName()))) {
                        i.remove();
                    }
                }
            }
        }
        // Post process paging - this should be moved to service layer.
        pagingResult = Util.wrapPagingResults(paging, groupList);
    } else {
        PagingRequest pagingRequest = Util.getPagingRequest(paging);
        // Get authorities using canned query.
        pagingResult = authorityService.getAuthoritiesInfo(authorityType, zoneFilter, null, sortProp.getFirst(), sortProp.getSecond(), pagingRequest);
    }
    return pagingResult;
}
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) AuthorityInfo(org.alfresco.repo.security.authority.AuthorityInfo) PagingRequest(org.alfresco.query.PagingRequest)

Example 8 with AuthorityType

use of org.alfresco.service.cmr.security.AuthorityType in project alfresco-remote-api by Alfresco.

the class GroupsImpl method getGroupMember.

private GroupMember getGroupMember(AuthorityInfo authorityInfo) {
    if (authorityInfo == null) {
        return null;
    }
    GroupMember groupMember = new GroupMember();
    groupMember.setId(authorityInfo.getAuthorityName());
    String authorityDisplayName = authorityInfo.getAuthorityDisplayName();
    if (authorityDisplayName == null || authorityDisplayName.isEmpty()) {
        authorityDisplayName = authorityService.getAuthorityDisplayName(authorityInfo.getAuthorityName());
    }
    groupMember.setDisplayName(authorityDisplayName);
    String memberType = null;
    AuthorityType authorityType = AuthorityType.getAuthorityType(authorityInfo.getAuthorityName());
    switch(authorityType) {
        case GROUP:
            memberType = PARAM_MEMBER_TYPE_GROUP;
            break;
        case USER:
            memberType = PARAM_MEMBER_TYPE_PERSON;
            break;
        default:
    }
    groupMember.setMemberType(memberType);
    return groupMember;
}
Also used : GroupMember(org.alfresco.rest.api.model.GroupMember) AuthorityType(org.alfresco.service.cmr.security.AuthorityType)

Example 9 with AuthorityType

use of org.alfresco.service.cmr.security.AuthorityType in project alfresco-remote-api by Alfresco.

the class GroupsImpl method getGroupMembers.

public CollectionWithPagingInfo<GroupMember> getGroupMembers(String groupId, final Parameters parameters) {
    validateGroupId(groupId, false);
    // Not allowed to list all members.
    if (PermissionService.ALL_AUTHORITIES.equals(groupId)) {
        throw new UnsupportedResourceOperationException();
    }
    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);
    AuthorityType authorityType = null;
    // Parse where clause properties.
    Query q = parameters.getQuery();
    if (q != null) {
        MapBasedQueryWalkerOrSupported propertyWalker = new MapBasedQueryWalkerOrSupported(LIST_GROUP_MEMBERS_QUERY_PROPERTIES, null);
        QueryHelper.walk(q, propertyWalker);
        String memberTypeStr = propertyWalker.getProperty(PARAM_MEMBER_TYPE, WhereClauseParser.EQUALS, String.class);
        authorityType = getAuthorityType(memberTypeStr);
    }
    PagingResults<AuthorityInfo> pagingResult = getAuthoritiesInfo(authorityType, groupId, sortProp, paging);
    // Create response.
    final List<AuthorityInfo> page = pagingResult.getPage();
    int totalItems = pagingResult.getTotalResultCount().getFirst();
    List<GroupMember> groupMembers = new AbstractList<GroupMember>() {

        @Override
        public GroupMember get(int index) {
            AuthorityInfo authorityInfo = page.get(index);
            return getGroupMember(authorityInfo);
        }

        @Override
        public int size() {
            return page.size();
        }
    };
    return CollectionWithPagingInfo.asPaged(paging, groupMembers, pagingResult.hasMoreItems(), totalItems);
}
Also used : AbstractList(java.util.AbstractList) GroupMember(org.alfresco.rest.api.model.GroupMember) Query(org.alfresco.rest.framework.resource.parameters.where.Query) UnsupportedResourceOperationException(org.alfresco.rest.framework.core.exceptions.UnsupportedResourceOperationException) Paging(org.alfresco.rest.framework.resource.parameters.Paging) AuthorityType(org.alfresco.service.cmr.security.AuthorityType) AuthorityInfo(org.alfresco.repo.security.authority.AuthorityInfo) MapBasedQueryWalkerOrSupported(org.alfresco.rest.workflow.api.impl.MapBasedQueryWalkerOrSupported)

Aggregations

AuthorityType (org.alfresco.service.cmr.security.AuthorityType)9 AbstractList (java.util.AbstractList)3 Set (java.util.Set)3 AuthorityInfo (org.alfresco.repo.security.authority.AuthorityInfo)3 GroupMember (org.alfresco.rest.api.model.GroupMember)3 ConstraintViolatedException (org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException)3 EntityNotFoundException (org.alfresco.rest.framework.core.exceptions.EntityNotFoundException)3 Paging (org.alfresco.rest.framework.resource.parameters.Paging)3 Query (org.alfresco.rest.framework.resource.parameters.where.Query)3 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Map (java.util.Map)2 EmptyPagingResults (org.alfresco.query.EmptyPagingResults)2 UnknownAuthorityException (org.alfresco.repo.security.authority.UnknownAuthorityException)2 Group (org.alfresco.rest.api.model.Group)2 NotFoundException (org.alfresco.rest.framework.core.exceptions.NotFoundException)2 UnsupportedResourceOperationException (org.alfresco.rest.framework.core.exceptions.UnsupportedResourceOperationException)2 MapBasedQueryWalkerOrSupported (org.alfresco.rest.workflow.api.impl.MapBasedQueryWalkerOrSupported)2 Collator (java.text.Collator)1 ArrayList (java.util.ArrayList)1