Java Code Examples for org.apache.chemistry.opencmis.commons.data.Acl#getAces()

The following examples show how to use org.apache.chemistry.opencmis.commons.data.Acl#getAces() . 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 5 votes vote down vote up
/**
 * Sets the given ACL.
 */
public void applyACL(NodeRef nodeRef, TypeDefinitionWrapper type, Acl aces)
{
    boolean hasAces = (aces != null) && (aces.getAces() != null) && !aces.getAces().isEmpty();

    if (!hasAces && !permissionService.getInheritParentPermissions(nodeRef))
    {
        return;
    }

    if (!type.getTypeDefinition(false).isControllableAcl())
    {
        throw new CmisConstraintException("Object is not ACL controllable!");
    }

    // remove all permissions
    permissionService.deletePermissions(nodeRef);

    // set new permissions
    for (Ace ace : aces.getAces())
    {
        String principalId = ace.getPrincipalId();
        if (CMIS_USER.equals(principalId))
        {
            principalId = AuthenticationUtil.getFullyAuthenticatedUser();
        }

        List<String> permissions = translatePermissionsFromCMIS(ace.getPermissions());
        for (String permission : permissions)
        {
            permissionService.setPermission(nodeRef, principalId, permission, true);
        }
    }
}
 
Example 3
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;
}
 
Example 4
Source File: AlfrescoCmisServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public String createRelationship(
        String repositoryId, Properties properties, List<String> policies, Acl addAces,
        Acl removeAces, ExtensionsData extension)
{
    checkRepositoryId(repositoryId);

    // get type
    String objectTypeId = connector.getObjectTypeIdProperty(properties);
    final TypeDefinitionWrapper type = connector.getTypeForCreate(objectTypeId, BaseTypeId.CMIS_RELATIONSHIP);

    // get source object
    String sourceId = connector.getSourceIdProperty(properties);
    CMISNodeInfo sourceInfo = getOrCreateNodeInfo(sourceId, "Source");

    if (!sourceInfo.isVariant(CMISObjectVariant.CURRENT_VERSION) && !sourceInfo.isVariant(CMISObjectVariant.FOLDER) && !sourceInfo.isVariant(CMISObjectVariant.ITEM))
    {
        throw new CmisInvalidArgumentException("Source is not the latest version of a document, a folder or an item object!");
    }

    final NodeRef sourceNodeRef = sourceInfo.getNodeRef();

    // get target object
    String targetId = connector.getTargetIdProperty(properties);
    CMISNodeInfo targetInfo = getOrCreateNodeInfo(targetId, "Target");

    if (!targetInfo.isVariant(CMISObjectVariant.CURRENT_VERSION) && !targetInfo.isVariant(CMISObjectVariant.FOLDER) && !targetInfo.isVariant(CMISObjectVariant.ITEM))
    {
        throw new CmisInvalidArgumentException(
                "Target is not the latest version of a document, a folder or an item object!!");
    }

    final NodeRef targetNodeRef = targetInfo.getNodeRef();

    // check policies and ACLs
    if ((policies != null) && (!policies.isEmpty()))
    {
        throw new CmisConstraintException("Relationships are not policy controllable!");
    }

    if ((addAces != null) && (addAces.getAces() != null) && (!addAces.getAces().isEmpty()))
    {
        throw new CmisConstraintException("Relationships are not ACL controllable!");
    }

    if ((removeAces != null) && (removeAces.getAces() != null) && (!removeAces.getAces().isEmpty()))
    {
        throw new CmisConstraintException("Relationships are not ACL controllable!");
    }

    // create relationship
    // ALF-10085 : disable auditing behaviour for this use case
    boolean wasEnabled = connector.disableBehaviour(ContentModel.ASPECT_AUDITABLE, sourceNodeRef);        // Lasts for txn
    try
    {
        AssociationRef assocRef = connector.getNodeService().createAssociation(
                sourceNodeRef, targetNodeRef, type.getAlfrescoClass());

        return CMISConnector.ASSOC_ID_PREFIX + assocRef.getId();
    }
    finally
    {
        if(wasEnabled)
        {
            connector.enableBehaviour(ContentModel.ASPECT_AUDITABLE, sourceNodeRef);
        }
    }
}