Java Code Examples for org.apache.chemistry.opencmis.commons.data.Ace#getPrincipal()

The following examples show how to use org.apache.chemistry.opencmis.commons.data.Ace#getPrincipal() . 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: Converter.java    From document-management-software with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Converts an ACL object with its ACEs
 * 
 * @param acl the acl
 * 
 * @return the CMIS ACL
 */
public static CmisAccessControlListType convert(Acl acl) {
	if (acl == null) {
		return null;
	}

	CmisAccessControlListType result = new CmisAccessControlListType();

	if (acl.getAces() != null) {
		for (Ace ace : acl.getAces()) {
			if (ace == null) {
				continue;
			}

			CmisAccessControlEntryType entry = new CmisAccessControlEntryType();

			if (ace.getPrincipal() != null) {
				CmisAccessControlPrincipalType pincipal = new CmisAccessControlPrincipalType();

				pincipal.setPrincipalId(ace.getPrincipal().getId());
				convertExtension(pincipal, ace.getPrincipal());

				entry.setPrincipal(pincipal);
			}

			entry.setDirect(ace.isDirect());
			entry.getPermission().addAll(ace.getPermissions());

			convertExtension(ace, entry);

			result.getPermission().add(entry);
		}
	}

	// handle extensions
	convertExtension(acl, result);

	return result;
}
 
Example 2
Source File: CMISConnector.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Converts Acl to map and ignore the indirect ACEs
 *
 * @param acl Acl
 * @return Map
 */
private Map<String, Set<String>> convertAclToMap(Acl acl)
{
    Map<String, Set<String>> result = new HashMap<String, Set<String>>();

    if (acl == null || acl.getAces() == null)
    {
        return result;
    }

    for (Ace ace : acl.getAces())
    {
        // don't consider indirect ACEs - we can't change them
        if (!ace.isDirect())
        {
            // ignore
            continue;
        }

        // although a principal must not be null, check it
        if (ace.getPrincipal() == null || ace.getPrincipal().getId() == null)
        {
            // ignore
            continue;
        }

        Set<String> permissions = result.get(ace.getPrincipal().getId());
        if (permissions == null)
        {
            permissions = new HashSet<String>();
            result.put(ace.getPrincipal().getId(), permissions);
        }

        if (ace.getPermissions() != null)
        {
            permissions.addAll(ace.getPermissions());
        }
    }

    return result;
}