Java Code Examples for org.alfresco.service.cmr.security.AuthorityType#equals()

The following examples show how to use org.alfresco.service.cmr.security.AuthorityType#equals() . 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: AuthorityDAOImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void listAuthorities(AuthorityType type, String name, Set<String> authorities, boolean parents, boolean recursive)
{
    AuthorityType localType = AuthorityType.getAuthorityType(name);
    if (localType.equals(AuthorityType.GUEST))
    {
        // Nothing to do
    }
    else
    {
        NodeRef ref = getAuthorityOrNull(name);
        
        if (ref != null)
        {
            listAuthorities(type, ref, authorities, parents, recursive, false);
        }
        else if (!localType.equals(AuthorityType.USER))
        {
            // Don't worry about missing person objects. It might be the system user or a user yet to be
            // auto-created
            throw new UnknownAuthorityException("An authority was not found for " + name);
        }
    }
}
 
Example 2
Source File: AuthorityDAOImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
public PagingResults<String> getAuthorities(AuthorityType type, String zoneName, String displayNameFilter, boolean sortByDisplayName, boolean sortAscending, PagingRequest pagingRequest)
{
    checkGetAuthorityParams(type, zoneName, pagingRequest);
    
    if ((zoneName == null) && (type.equals(AuthorityType.USER)))
    {
        return getUserAuthoritiesImpl(displayNameFilter, sortByDisplayName, sortAscending, pagingRequest);
    }
    
    return getAuthoritiesImpl(type, getContainerRef(zoneName), displayNameFilter, (sortByDisplayName ? GetAuthoritiesCannedQuery.DISPLAY_NAME : null), sortAscending, pagingRequest, new PagingResultsString());
}
 
Example 3
Source File: AuthorityDAOImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
private Set<String> getRootAuthoritiesUnderContainer(NodeRef container, AuthorityType type)
{
    if (type != null && type.equals(AuthorityType.USER))
    {
        return Collections.<String> emptySet();
    }
    Collection<ChildAssociationRef> childRefs = nodeService.getChildAssocsWithoutParentAssocsOfType(container, ContentModel.ASSOC_MEMBER);
    Set<String> authorities = new TreeSet<String>();
    for (ChildAssociationRef childRef : childRefs)
    {
        addAuthorityNameIfMatches(authorities, childRef.getQName().getLocalName(), type);
    }
    return authorities;
}
 
Example 4
Source File: GetAuthoritiesCannedQuery.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
private boolean includeFilter(AuthorityInfo auth, AuthorityType type, Pattern nameFilter)
    {
        String authName = auth.getAuthorityName();
        
        AuthorityType authType = AuthorityType.getAuthorityType(authName);
        if ((authName == null) || ((type != null) && (! type.equals(authType))))
        {
            // exclude by type
            return false;
        }
        
        if (nameFilter == null)
        {
            return true;
        }
        
        String displayName = auth.getAuthorityDisplayName();
        if (displayName != null && nameFilter.matcher(displayName).find())
        {
            return true;
        }
//        To match on just displayName use the following.
//        if (displayName != null)
//        {
//            return nameFilter.matcher(displayName).find();
//        }
        
        if (authType.isPrefixed())
        {
            authName = authName.substring(authType.getPrefixString().length());
        }
        
        return (nameFilter.matcher(authName).find());
    }
 
Example 5
Source File: People.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Get Contained Authorities
 * 
 * @param container  authority containers
 * @param type       authority type to filter by
 * @param recurse    recurse into sub-containers
 * 
 * @return contained authorities
 */
private Object[] getContainedAuthorities(ScriptNode container, AuthorityType type, boolean recurse)
{
    Object[] members = null;
    
    if (container.getQNameType().equals(ContentModel.TYPE_AUTHORITY_CONTAINER))
    {
        String groupName = (String)container.getProperties().get(ContentModel.PROP_AUTHORITY_NAME);
        Set<String> authorities = authorityService.getContainedAuthorities(type, groupName, !recurse);
        members = new Object[authorities.size()];
        int i = 0;
        for (String authority : authorities)
        {
            AuthorityType authorityType = AuthorityType.getAuthorityType(authority);
            if (authorityType.equals(AuthorityType.GROUP))
            {
                ScriptNode group = getGroup(authority);
                if (group != null)
                {
                    members[i++] = group; 
                }
            }
            else if (authorityType.equals(AuthorityType.USER))
            {
                ScriptNode person = getPerson(authority);
                if (person != null)
                {
                    members[i++] = person; 
                }
            }
        }
    }
    
    return members != null ? members : new Object[0];
}
 
Example 6
Source File: People.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Get Contained Authorities
 * 
 * @param container  authority containers
 * @param type       authority type to filter by
 * @param recurse    recurse into sub-containers
 * 
 * @return contained authorities
 */
private List<TemplateNode> getContainedAuthorities(TemplateNode container, AuthorityType type, boolean recurse)
{
    List<TemplateNode> members = null;
    
    if (container.getType().equals(ContentModel.TYPE_AUTHORITY_CONTAINER))
    {
        String groupName = (String)container.getProperties().get(ContentModel.PROP_AUTHORITY_NAME);
        Set<String> authorities = authorityService.getContainedAuthorities(type, groupName, !recurse);
        members = new ArrayList<TemplateNode>(authorities.size());
        for (String authority : authorities)
        {
            AuthorityType authorityType = AuthorityType.getAuthorityType(authority);
            if (authorityType.equals(AuthorityType.GROUP))
            {
                TemplateNode group = getGroup(authority);
                if (group != null)
                {
                    members.add(group);
                }
            }
            else if (authorityType.equals(AuthorityType.USER))
            {
                TemplateNode person = getPerson(authority);
                if (person != null)
                {
                    members.add(person);
                }
            }
        }
    }
    
    return members != null ? members : Collections.<TemplateNode>emptyList();
}
 
Example 7
Source File: AuthorityDAOImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void addAuthority(Collection<String> parentNames, String childName)
{
    Set<NodeRef> parentRefs = new HashSet<NodeRef>(parentNames.size() * 2);
    AuthorityType authorityType = AuthorityType.getAuthorityType(childName);
    boolean isUser = authorityType.equals(AuthorityType.USER);
    boolean notUserOrGroup = !isUser && !authorityType.equals(AuthorityType.GROUP);
    for (String parentName : parentNames)
    {
        NodeRef parentRef = getAuthorityOrNull(parentName);
        if (parentRef == null)
        {
            throw new UnknownAuthorityException("An authority was not found for " + parentName);
        }
        if (notUserOrGroup
                && !(authorityType.equals(AuthorityType.ROLE) && AuthorityType.getAuthorityType(parentName).equals(
                        AuthorityType.ROLE)))
        {
            throw new AlfrescoRuntimeException("Authorities of the type " + authorityType
                    + " may not be added to other authorities");
        }
        childAuthorityCache.remove(parentRef);
        parentRefs.add(parentRef);
    }
    NodeRef childRef = getAuthorityOrNull(childName);

    if (childRef == null)
    {
        throw new UnknownAuthorityException("An authority was not found for " + childName);
    }

    // Normalize the user name if necessary
    if (isUser)
    {
        childName = (String) nodeService.getProperty(childRef, ContentModel.PROP_USERNAME);
    }

    nodeService.addChild(parentRefs, childRef, ContentModel.ASSOC_MEMBER, QName.createQName("cm", childName,
            namespacePrefixResolver));
    if (isUser)
    {
        userAuthorityCache.remove(childName);
    }
    else
    {
        userAuthorityCache.clear();
        authorityBridgeTableCache.refresh();
    }
}