org.apache.chemistry.opencmis.commons.impl.dataobjects.AccessControlPrincipalDataImpl Java Examples

The following examples show how to use org.apache.chemistry.opencmis.commons.impl.dataobjects.AccessControlPrincipalDataImpl. 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 security policies
 * @param isExact if the specification is exact
 * 
 * @return the converted ACL
 */
public static Acl convert(CmisAccessControlListType acl, Boolean isExact) {
	if (acl == null) {
		return null;
	}

	AccessControlListImpl result = new AccessControlListImpl();

	List<Ace> aces = new ArrayList<Ace>();
	for (CmisAccessControlEntryType entry : acl.getPermission()) {
		if (entry == null) {
			continue;
		}

		AccessControlEntryImpl ace = new AccessControlEntryImpl();
		ace.setDirect(entry.isDirect());
		ace.setPermissions(entry.getPermission());
		AccessControlPrincipalDataImpl principal = new AccessControlPrincipalDataImpl(
				entry.getPrincipal() == null ? null : entry.getPrincipal().getPrincipalId());
		convertExtension(entry.getPrincipal(), principal);
		ace.setPrincipal(principal);

		// handle extensions
		convertExtension(entry, ace);

		aces.add(ace);
	}

	result.setAces(aces);

	result.setExact(isExact);

	// handle extensions
	convertExtension(acl, result);

	return result;
}
 
Example #2
Source File: LDRepository.java    From document-management-software with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
	 * Compiles the ACL for a file or folder
	 * 
	 * @param object the persistent object
	 * 
	 * @return the ACL
	 */
	private Acl compileAcl(PersistentObject object) {
		AccessControlListImpl result = new AccessControlListImpl();
		result.setAces(new ArrayList<Ace>());

		for (Map.Entry<String, Boolean> ue : userMap.entrySet()) {
			// create principal
//			AccessControlPrincipalDataImpl principal = new AccessControlPrincipalDataImpl();
//			principal.setPrincipalId(ue.getKey());
			
			// create principal
			AccessControlPrincipalDataImpl principal = new AccessControlPrincipalDataImpl(ue.getKey());

			// create ACE
			AccessControlEntryImpl entry = new AccessControlEntryImpl();
			entry.setPrincipal(principal);
			entry.setPermissions(new ArrayList<String>());
			entry.getPermissions().add(CMIS_READ);

			if (!ue.getValue().booleanValue() && checkPermission(object, null, Permission.WRITE)
					&& !(object instanceof Folder && ((Folder) object).getType() == Folder.TYPE_WORKSPACE)) {

				entry.getPermissions().add(CMIS_WRITE);
				entry.getPermissions().add(CMIS_ALL);
			}

			entry.setDirect(true);

			// add ACE
			result.getAces().add(entry);
		}

		return result;
	}
 
Example #3
Source File: CMISConnector.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Filter acl to ignore inherited ACEs
 *
 * @param nodeRef NodeRef
 * @param acl Acl
 * @return Acl
 */
protected Acl excludeInheritedAces(NodeRef nodeRef, Acl acl)
{

    List<Ace> newAces = new ArrayList<Ace>();
    Acl allACLs = getACL(nodeRef, false);

    Map<String, Set<String>> originalsAcls = convertAclToMap(allACLs);
    Map<String, Set<String>> newAcls = convertAclToMap(acl);

    // iterate through the original ACEs
    for (Map.Entry<String, Set<String>> ace : originalsAcls.entrySet())
    {

        // add permissions
        Set<String> addPermissions = newAcls.get(ace.getKey());
        if (addPermissions != null)
        {
            ace.getValue().addAll(addPermissions);
        }

        // create new ACE
        if (!ace.getValue().isEmpty())
        {
            newAces.add(new AccessControlEntryImpl(new AccessControlPrincipalDataImpl(ace
                    .getKey()), new ArrayList<String>(ace.getValue())));
        }
    }

    return new AccessControlListImpl(newAces);
}
 
Example #4
Source File: CMISDataCreatorTest.java    From SearchServices with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void testCreate()
{
    Session session = getSession("admin", "admin");
    
    String folderName = getRootFolderName();
    Folder root = session.getRootFolder();
    
    Map<String, Object> properties = new HashMap<String, Object>();
    properties.put(PropertyIds.OBJECT_TYPE_ID, "cmis:folder");
    properties.put(PropertyIds.NAME, folderName);

    // create the folder
    Folder newFolder = root.createFolder(properties);
    
    for(int i = 0; i < 50; i++)
    {
        AccessControlPrincipalDataImpl principal = new AccessControlPrincipalDataImpl("user"+i);
        List<String> permissions = new ArrayList<String>(1);
        permissions.add(BasicPermissions.READ);
        List<Ace> addAces = new ArrayList<Ace>(1);
        addAces.add(new AccessControlEntryImpl(principal, permissions));
        newFolder.addAcl(addAces, AclPropagation.PROPAGATE);
        
        Map<String, Object> updateProperties = new HashMap<String, Object>();
        updateProperties.put("cm:title", "Update title "+i);
        newFolder.updateProperties(properties);
        
        if(i % 10 == 0)
        {
            System.out.println("@ "+i);
        }
    }
    ItemIterable<QueryResult> result = session.query("select * from cmis:folder", false);
    assertTrue(result.getTotalNumItems() > 0);
    
    result = session.query("select * from cmis:folder where cmis:name = '"+folderName+"'", false);
    assertTrue(result.getTotalNumItems() > 0);
    
}
 
Example #5
Source File: CMISDataCreatorTest.java    From SearchServices with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void testCreateLots() throws Exception
{
    Session session = getSession("admin", "admin");
    
    Folder root = session.getRootFolder();
    String folderNameBase = getRootFolderName();

    
    Map<String, Object> properties = new HashMap<String, Object>();
    properties.put(PropertyIds.OBJECT_TYPE_ID, "cmis:folder");
    properties.put(PropertyIds.NAME, folderNameBase);
    
    Folder base = root.createFolder(properties);
    for(int i = 0; i < 10; i++)
    {
       AccessControlPrincipalDataImpl principal = new AccessControlPrincipalDataImpl(""+i+i+i);
       List<String> permissions = new ArrayList<String>(1);
       permissions.add(BasicPermissions.ALL);
       List<Ace> addAces = new ArrayList<Ace>(1);
       addAces.add(new AccessControlEntryImpl(principal, permissions));
       base.addAcl(addAces, AclPropagation.PROPAGATE);
    }
    
    
    Thread last = null;
    
    for(int i = 0; i < 10; i++)
    {
        Creator creator = new Creator(base.getPath(), i);
        Thread thread = new Thread(creator);
        thread.start();
        last = thread;
    }
    
    if(last != null)
    {
        last.join();
    }
  
    ItemIterable<QueryResult> result = session.query("select * from cmis:folder", false);
    assertTrue(result.getTotalNumItems() > 0);
    
    //result = session.query("select * from cmis:folder where cmis:name = '"+folderName+"'", false);
    //assertTrue(result.getTotalNumItems() > 0);
    
}