Java Code Examples for org.alfresco.service.cmr.security.AuthorityType#GROUP

The following examples show how to use org.alfresco.service.cmr.security.AuthorityType#GROUP . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AuthorityNameConstraint.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
protected void evaluateSingleValue(Object value)
{
    // ensure that the value can be converted to a String
    String checkValue = null;
    try
    {
        checkValue = DefaultTypeConverter.INSTANCE.convert(String.class, value);
    }
    catch (TypeConversionException e)
    {
        throw new ConstraintException(ERR_NON_STRING, value);
    }
    
    AuthorityType type = AuthorityType.getAuthorityType(checkValue);
    if((type != AuthorityType.GROUP) && (type != AuthorityType.ROLE))
    {
        throw new ConstraintException(ERR_INVALID_AUTHORITY_NAME, value, type);
    }
}
 
Example 2
Source File: GroupsImpl.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 6 votes vote down vote up
private AuthorityType getAuthorityType(String memberType)
{
    AuthorityType authorityType = null;
    if (memberType != null && !memberType.isEmpty())
    {
        switch (memberType)
        {
        case PARAM_MEMBER_TYPE_GROUP:
            authorityType = AuthorityType.GROUP;
            break;
        case PARAM_MEMBER_TYPE_PERSON:
            authorityType = AuthorityType.USER;
            break;
        default:
            throw new InvalidArgumentException("MemberType is invalid (expected eg. GROUP, PERSON)");
        }
    }
    return authorityType;
}
 
Example 3
Source File: AuthorityServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public PagingResults<AuthorityInfo> getAuthoritiesInfo(AuthorityType type, String zoneName, String displayNameFilter, String sortBy, boolean sortAscending, PagingRequest pagingRequest)
{
    ParameterCheck.mandatory("pagingRequest", pagingRequest);
    ParameterCheck.mandatory("type", type);
    
    if (type != AuthorityType.USER && type != AuthorityType.GROUP && type != AuthorityType.ROLE)
    {
        throw new UnsupportedOperationException("Unexpected authority type: "+type);
    }
    return authorityDAO.getAuthoritiesInfo(type, zoneName, displayNameFilter, sortBy, sortAscending, pagingRequest);
}
 
Example 4
Source File: AuthorityServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void checkTypeIsMutable(AuthorityType type)
{
    if((type == AuthorityType.GROUP) || (type == AuthorityType.ROLE))
    {
        return;
    }
    else
    {
        throw new AuthorityException("Trying to modify a fixed authority");
    }
}
 
Example 5
Source File: AuthorityServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public Set<String> findAuthorities(AuthorityType type, String parentAuthority, boolean immediate, String displayNamePattern, String zoneName)
{
    if (type == null || type == AuthorityType.GROUP || type == AuthorityType.USER)
    {
        return authorityDAO.findAuthorities(type, parentAuthority, immediate, displayNamePattern, zoneName);
    }
    else
    {
        throw new UnsupportedOperationException();
    }
}
 
Example 6
Source File: AuthorityServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
private boolean isGroup(AuthorityType authorityType)
{
    return AuthorityType.GROUP == authorityType || AuthorityType.EVERYONE == authorityType;
}
 
Example 7
Source File: AuthorityDAOImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * @param parentNodeRef         the parent authority
 * @return                      Returns authorities reachable by the {@link ContentModel#ASSOC_MEMBER} association
 */
private Pair<Map<NodeRef, String>, List<NodeRef>> getChildAuthorities(NodeRef parentNodeRef)
{
    Pair<Map<NodeRef,String>, List<NodeRef>> result = childAuthorityCache.get(parentNodeRef);
    if (result == null)
    {
        List<ChildAssociationRef> cars = nodeService.getChildAssocs(
                parentNodeRef,
                ContentModel.ASSOC_MEMBER,
                RegexQNamePattern.MATCH_ALL,
                false);
        if (cars.isEmpty())
        {
            // ALF-17702: BM-0013: Soak: Run 02: getCachedChildAuthorities is not caching results
            //            Don't return here.  We need to cache the miss.
            result = new Pair<Map<NodeRef, String>, List<NodeRef>>(Collections.<NodeRef, String> emptyMap(),
                    Collections.<NodeRef> emptyList());
        }
        else
        {
            Map<NodeRef,String> lookup = new HashMap<NodeRef, String>(cars.size() * 2);
            List<NodeRef> parents = new LinkedList<NodeRef>();
            for (ChildAssociationRef car : cars)
            {
                NodeRef memberNodeRef = car.getChildRef();
                String memberName = getPooledName(car.getQName().getLocalName());
                lookup.put(memberNodeRef, memberName);
                AuthorityType authorityType = AuthorityType.getAuthorityType(memberName);
                if (authorityType == AuthorityType.GROUP || authorityType == AuthorityType.ROLE)
                {
                    parents.add(memberNodeRef);
                }
            }
            result = new Pair<Map<NodeRef, String>, List<NodeRef>>(lookup, parents);
        }
        // Cache whatever we have
        if(!TransactionalResourceHelper.getSet(PARENTS_OF_DELETING_CHILDREN_SET_RESOURCE).contains(parentNodeRef))
        {
            childAuthorityCache.put(parentNodeRef, result);
        }
    }
    return result;
}
 
Example 8
Source File: SiteServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * @see org.alfresco.service.cmr.site.SiteService#removeMembership(java.lang.String, java.lang.String)
 */
public void removeMembership(final String shortName, final String authorityName)
{
    final NodeRef siteNodeRef = getSiteNodeRef(shortName);
    if (siteNodeRef == null)
    {
       throw new SiteDoesNotExistException(shortName);
    }

    // TODO what do we do about the user if they are in a group that has
    // rights to the site?

    // Get the current user
    String currentUserName = AuthenticationUtil.getFullyAuthenticatedUser();

    // Get the user current role
    final String role = getMembersRole(shortName, authorityName);
    if (role != null)
    {
        // Check that we are not about to remove the last site manager
        checkLastManagerRemoval(shortName, authorityName, role);
        
        // If ...
        // -- the current user has change permissions rights on the site
        // or
        // -- the user is ourselves
        if ((currentUserName.equals(authorityName) == true) || isSiteAdmin(currentUserName) ||
            (permissionService.hasPermission(siteNodeRef, PermissionService.CHANGE_PERMISSIONS) == AccessStatus.ALLOWED))
        {
            // Run as system user
            AuthenticationUtil.runAs(
                new AuthenticationUtil.RunAsWork<Object>()
                {
                    public Object doWork() throws Exception
                    {
                        // Remove the user from the current permission
                        // group
                        String currentGroup = getSiteRoleGroup(shortName, role, true);
                        authorityService.removeAuthority(currentGroup, authorityName);
                        
                        return null;
                    }
                }, AuthenticationUtil.SYSTEM_USER_NAME);

            // Raise events
            AuthorityType authorityType = AuthorityType.getAuthorityType(authorityName);
            if (authorityType == AuthorityType.USER)
            {
                activityService.postActivity(
                        ActivityType.SITE_USER_REMOVED, shortName,
                        ACTIVITY_TOOL, getActivityUserData(authorityName, ""), authorityName);
            }
            else if (authorityType == AuthorityType.GROUP)
            {
                String authorityDisplayName = authorityService.getAuthorityDisplayName(authorityName);
                activityService.postActivity(
                        ActivityType.SITE_GROUP_REMOVED, shortName,
                        ACTIVITY_TOOL, getActivityGroupData(authorityDisplayName, ""));
            }
        }
        else
        {
            // Throw an exception
            throw new SiteServiceException(MSG_CAN_NOT_REMOVE_MSHIP, new Object[]{shortName});
        }
    } 
    else
    {
        // Throw an exception
        throw new SiteServiceException(MSG_CAN_NOT_REMOVE_MSHIP, new Object[]{shortName});
    }
}
 
Example 9
Source File: SiteServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * @see org.alfresco.service.cmr.site.SiteService#setMembership(java.lang.String,
 *      java.lang.String, java.lang.String)
 */
public void setMembership(final String shortName, 
                          final String authorityName,
                          final String role)
{
    final NodeRef siteNodeRef = getSiteNodeRef(shortName);
    if (siteNodeRef == null)
    {
       throw new SiteDoesNotExistException(shortName);
    }

    // Get the user's current role
    final String currentRole = getMembersRole(shortName, authorityName);

    // Do nothing if the role of the user is not being changed
    if (currentRole == null || role.equals(currentRole) == false)
    {
        // TODO if this is the only site manager do not down grade their
        // permissions
        if(canAddMember(shortName, authorityName, role))
        {
            // Check that we are not about to remove the last site manager
            checkLastManagerRemoval(shortName, authorityName, currentRole);
            
            // Run as system user
            AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork<Object>()
            {
                public Object doWork() throws Exception
                {
                    if (currentRole != null)
                    {
                        // Remove the user from the current
                        // permission group
                        String currentGroup = getSiteRoleGroup(shortName, currentRole, true);
                        authorityService.removeAuthority(currentGroup, authorityName);
                    }

                    // Add the user to the new permission group
                    String newGroup = getSiteRoleGroup(shortName, role, true);
                    authorityService.addAuthority(newGroup, authorityName);

                    return null;
                }

            }, AuthenticationUtil.SYSTEM_USER_NAME);

            AuthorityType authorityType = AuthorityType.getAuthorityType(authorityName);
            String authorityDisplayName = authorityName;
            if (authorityType == AuthorityType.GROUP)
            {
                authorityDisplayName = authorityService.getAuthorityDisplayName(authorityName);
            }

            if (currentRole == null)
            {
                if (authorityType == AuthorityType.USER)
                {
                    activityService.postActivity(
                            ActivityType.SITE_USER_JOINED, shortName,
                            ACTIVITY_TOOL, getActivityUserData(authorityDisplayName, role), authorityName);
                } 
                else if (authorityType == AuthorityType.GROUP)
                { 
                    activityService.postActivity(
                            ActivityType.SITE_GROUP_ADDED, shortName,
                            ACTIVITY_TOOL, getActivityGroupData(authorityDisplayName, role));                   
                }
            }
            else
            {
                if (authorityType == AuthorityType.USER)
                {
                    activityService.postActivity(
                            ActivityType.SITE_USER_ROLE_UPDATE, shortName,
                            ACTIVITY_TOOL, getActivityUserData(authorityDisplayName, role));
                } 
                else if (authorityType == AuthorityType.GROUP)
                {
                    activityService.postActivity(
                            ActivityType.SITE_GROUP_ROLE_UPDATE, shortName,
                            ACTIVITY_TOOL, getActivityGroupData(authorityDisplayName, role));
                }
            }
        } 
        else
        {
            // Raise a permission exception
            throw new SiteServiceException(MSG_CAN_NOT_CHANGE_MSHIP, new Object[]{shortName});
        }
    }
}
 
Example 10
Source File: GroupsImpl.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 4 votes vote down vote up
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);
}