Search in sources :

Example 1 with AuthorityType

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

the class GroupsImpl method createGroupMember.

@Override
public GroupMember createGroupMember(String groupId, GroupMember groupMember) {
    validateGroupId(groupId, false);
    // Not allowed to modify a GROUP_EVERYONE member.
    if (PermissionService.ALL_AUTHORITIES.equals(groupId)) {
        throw new ConstraintViolatedException(ERR_MSG_MODIFY_FIXED_AUTHORITY);
    }
    validateGroupMember(groupMember);
    AuthorityType authorityType = getAuthorityType(groupMember.getMemberType());
    if (!authorityService.authorityExists(groupMember.getId())) {
        throw new EntityNotFoundException(groupMember.getId());
    }
    AuthorityType existingAuthorityType = AuthorityType.getAuthorityType(groupMember.getId());
    if (existingAuthorityType != authorityType) {
        throw new IllegalArgumentException("Incorrect group member type, " + (AuthorityType.USER.equals(existingAuthorityType) ? Groups.PARAM_MEMBER_TYPE_PERSON : existingAuthorityType) + " exists with the given id");
    }
    authorityService.addAuthority(groupId, groupMember.getId());
    String authority = authorityService.getName(authorityType, groupMember.getId());
    return getGroupMember(authority);
}
Also used : AuthorityType(org.alfresco.service.cmr.security.AuthorityType) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) ConstraintViolatedException(org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException)

Example 2 with AuthorityType

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

the class GroupsImpl method deleteGroupMembership.

public void deleteGroupMembership(String groupId, String groupMemberId) {
    validateGroupId(groupId, false);
    // Not allowed to modify a GROUP_EVERYONE member.
    if (PermissionService.ALL_AUTHORITIES.equals(groupId)) {
        throw new ConstraintViolatedException(ERR_MSG_MODIFY_FIXED_AUTHORITY);
    }
    validateGroupMemberId(groupMemberId);
    // Verify if groupMemberId is member of groupId
    AuthorityType authorityType = AuthorityType.getAuthorityType(groupMemberId);
    Set<String> parents = authorityService.getContainingAuthorities(AuthorityType.GROUP, groupMemberId, true);
    if (!parents.contains(groupId)) {
        throw new NotFoundException(groupMemberId + " is not member of " + groupId);
    }
    authorityService.removeAuthority(groupId, groupMemberId);
}
Also used : AuthorityType(org.alfresco.service.cmr.security.AuthorityType) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) NotFoundException(org.alfresco.rest.framework.core.exceptions.NotFoundException) ConstraintViolatedException(org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException)

Example 3 with AuthorityType

use of org.alfresco.service.cmr.security.AuthorityType 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 4 with AuthorityType

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

the class EmailSpaceUsersDialog 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 {
    // get the space ref this mail applies to
    NodeRef spaceRef = getSpace().getNodeRef();
    // calculate the 'from' email address
    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();
    }
    Set<String> mailedAuthorities = new HashSet<String>(usersGroups.size());
    // walk the list of users/groups to notify - handle duplicates along the way
    for (Map node : usersGroups) {
        String authority = (String) node.get(PROP_USERNAME);
        boolean selected = (Boolean) node.get(PROP_SELECTED);
        // if User, email then, else if Group get all members and email them
        AuthorityType authType = AuthorityType.getAuthorityType(authority);
        if (authType.equals(AuthorityType.USER)) {
            if (selected == true && this.getPersonService().personExists(authority)) {
                if (mailedAuthorities.contains(authority) == false) {
                    this.mailHelper.notifyUser(this.getPersonService().getPerson(authority), spaceRef, from, (String) node.get(PROP_ROLES));
                    mailedAuthorities.add(authority);
                }
            }
        } else if (authType.equals(AuthorityType.GROUP)) {
            // is the group expanded? if so we'll deal with the child authorities instead
            boolean expanded = (Boolean) node.get(PROP_EXPANDED);
            if (expanded == false && selected == true) {
                // 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) {
                        if (mailedAuthorities.contains(userAuth) == false) {
                            this.mailHelper.notifyUser(this.getPersonService().getPerson(userAuth), spaceRef, from, (String) node.get(PROP_ROLES));
                            mailedAuthorities.add(userAuth);
                        }
                    }
                }
            }
        }
    }
    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) HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Example 5 with AuthorityType

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

the class BaseInviteUsersWizard method addAuthorityWithRole.

/**
 * Add an authority with the specified role to the list managed by this wizard.
 *
 * @param authority        Authority to add (cannot be null)
 * @param role             Role for the authorities (cannot be null)
 */
public void addAuthorityWithRole(String authority, String role) {
    // only add if authority not already present in the list with same role
    boolean foundExisting = false;
    for (int n = 0; n < this.userGroupRoles.size(); n++) {
        UserGroupRole wrapper = this.userGroupRoles.get(n);
        if (authority.equals(wrapper.getAuthority()) && (!this.allowDuplicateAuthorities || role.equals(wrapper.getRole()))) {
            foundExisting = true;
            break;
        }
    }
    if (foundExisting == false) {
        StringBuilder label = new StringBuilder(64);
        // build a display label showing the user and their role for the space
        AuthorityType authType = AuthorityType.getAuthorityType(authority);
        if (authType == AuthorityType.GUEST || authType == AuthorityType.USER) {
            if (authType == AuthorityType.GUEST || getPersonService().personExists(authority) == true) {
                // found a User authority
                label.append(buildLabelForUserAuthorityRole(authority, role));
            }
        } else {
            // found a group authority
            label.append(buildLabelForGroupAuthorityRole(authority, role));
        }
        this.userGroupRoles.add(new UserGroupRole(authority, role, label.toString()));
    }
}
Also used : AuthorityType(org.alfresco.service.cmr.security.AuthorityType)

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