Search in sources :

Example 1 with Acl

use of org.apache.chemistry.opencmis.commons.data.Acl in project alfresco-remote-api by Alfresco.

the class TestRemovePermissions method testRemoveAllPermissions_ATOMPUB_11.

@Test
public void testRemoveAllPermissions_ATOMPUB_11() {
    Folder testFolder = null;
    try {
        Session session = getATOMPUB_11_Session();
        if (session == null) {
            fail("ATOMPUB 1.1 session cannot be null");
        }
        testFolder = createFolder(session, "testRemoveAllPermissions_ATOMPUB_11");
        List<Ace> acl = create2TestACLs(session);
        // adding new ACE
        testFolder.addAcl(acl, AclPropagation.PROPAGATE);
        Acl allacl = session.getAcl(session.createObjectId(testFolder.getId()), false);
        int oldSize = allacl.getAces().size();
        // Removing ALL ACEs
        Acl newAcl = testFolder.removeAcl(allacl.getAces(), AclPropagation.PROPAGATE);
        int newsize = newAcl.getAces().size();
        System.out.println("Old ace size -->" + oldSize);
        System.out.println("New ace size --> " + newsize);
        assertTrue(newsize == oldSize - acl.size());
    } catch (Exception ex) {
        fail(ex.getMessage());
    } finally {
        if (testFolder != null) {
            testFolder.delete();
        }
    }
}
Also used : Ace(org.apache.chemistry.opencmis.commons.data.Ace) Acl(org.apache.chemistry.opencmis.commons.data.Acl) Folder(org.apache.chemistry.opencmis.client.api.Folder) Session(org.apache.chemistry.opencmis.client.api.Session) Test(org.junit.Test)

Example 2 with Acl

use of org.apache.chemistry.opencmis.commons.data.Acl in project copper-cms by PogeyanOSS.

the class ObjectActor method createDocument.

private JSONObject createDocument(PostRequest request) throws CmisInvalidArgumentException, CmisConstraintException, IllegalArgumentException, CmisRuntimeException {
    String permission = request.getUserObject().getPermission();
    String principalId = request.getUserObject().getUserDN();
    IUserGroupObject[] groupsId = request.getUserObject().getGroups();
    if (!Helpers.getGroupPermission(permission, groupsId)) {
        throw new CmisRuntimeException(request.getUserName() + " is not authorized to applyAcl.");
    }
    String folderId = request.getObjectId() != null ? request.getObjectId() : null;
    VersioningState versioningState = request.getEnumParameter(QueryGetRequest.PARAM_VERSIONIG_STATE, VersioningState.class);
    // String token = request.getParameter(request.PARAM_TOKEN);
    boolean succinct = request.getBooleanParameter(QueryGetRequest.CONTROL_SUCCINCT, false);
    DateTimeFormat dateTimeFormat = request.getDateTimeFormatParameter();
    Properties prop = CmisPropertyConverter.Impl.createNewProperties(request.getPropertyData(), request.getRepositoryId());
    Acl aclImp = CmisUtils.Object.getAcl(request.getAddAcl(), principalId, permission);
    String newObjectId = null;
    if (request.getContentStream() == null) {
        newObjectId = CmisObjectService.Impl.createDocument(request.getRepositoryId(), prop, folderId, null, versioningState, request.getPolicies(), aclImp, request.getRemoveAcl(), request.getUserObject().getUserDN());
    } else {
        newObjectId = CmisObjectService.Impl.createDocument(request.getRepositoryId(), prop, folderId, request.getContentStream(), versioningState, request.getPolicies(), aclImp, request.getRemoveAcl(), request.getUserObject().getUserDN());
    }
    ObjectData object = CmisObjectService.Impl.getSimpleObject(request.getRepositoryId(), newObjectId, request.getUserObject().getUserDN(), BaseTypeId.CMIS_DOCUMENT);
    if (object == null) {
        MetricsInputs.markUploadErrorMeter();
        throw new CmisRuntimeException("New document is null!");
    }
    // return object
    JSONObject jsonObject = JSONConverter.convert(object, CmisTypeCacheService.get(request.getRepositoryId()), JSONConverter.PropertyMode.CHANGE, succinct, dateTimeFormat);
    return jsonObject;
}
Also used : IUserGroupObject(com.pogeyan.cmis.api.auth.IUserGroupObject) CmisRuntimeException(org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException) JSONObject(org.apache.chemistry.opencmis.commons.impl.json.JSONObject) ObjectData(org.apache.chemistry.opencmis.commons.data.ObjectData) VersioningState(org.apache.chemistry.opencmis.commons.enums.VersioningState) Acl(org.apache.chemistry.opencmis.commons.data.Acl) Properties(org.apache.chemistry.opencmis.commons.data.Properties) DateTimeFormat(org.apache.chemistry.opencmis.commons.enums.DateTimeFormat)

Example 3 with Acl

use of org.apache.chemistry.opencmis.commons.data.Acl in project copper-cms by PogeyanOSS.

the class ObjectActor method createFolders.

private JSONObject createFolders(PostRequest request) throws CmisObjectNotFoundException, IllegalArgumentException, CmisInvalidArgumentException, CmisRuntimeException {
    String folderId = request.getObjectId() != null ? request.getObjectId() : null;
    String permission = request.getUserObject().getPermission();
    String principalId = request.getUserObject().getUserDN();
    IUserGroupObject[] groupsId = request.getUserObject().getGroups();
    if (!Helpers.getGroupPermission(permission, groupsId)) {
        throw new CmisRuntimeException(request.getUserName() + " is not authorized to applyAcl.");
    }
    boolean succinct = request.getBooleanParameter(QueryGetRequest.CONTROL_SUCCINCT, false);
    DateTimeFormat dateTimeFormat = request.getDateTimeFormatParameter();
    Properties prop = CmisPropertyConverter.Impl.createNewProperties(request.getPropertyData(), request.getRepositoryId());
    Acl aclImp = CmisUtils.Object.getAcl(request.getAddAcl(), principalId, permission);
    String newObjectId = CmisObjectService.Impl.createFolder(request.getRepositoryId(), folderId, prop, request.getPolicies(), aclImp, request.getRemoveAcl(), request.getUserObject().getUserDN());
    ObjectData object = CmisObjectService.Impl.getSimpleObject(request.getRepositoryId(), newObjectId, request.getUserObject().getUserDN(), BaseTypeId.CMIS_FOLDER);
    if (object == null) {
        throw new CmisRuntimeException("New folder is null!");
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("createFolder complete with id: {}", object.getId());
    }
    JSONObject jsonObject = JSONConverter.convert(object, CmisTypeCacheService.get(request.getRepositoryId()), JSONConverter.PropertyMode.CHANGE, succinct, dateTimeFormat);
    return jsonObject;
}
Also used : IUserGroupObject(com.pogeyan.cmis.api.auth.IUserGroupObject) CmisRuntimeException(org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException) JSONObject(org.apache.chemistry.opencmis.commons.impl.json.JSONObject) ObjectData(org.apache.chemistry.opencmis.commons.data.ObjectData) Acl(org.apache.chemistry.opencmis.commons.data.Acl) Properties(org.apache.chemistry.opencmis.commons.data.Properties) DateTimeFormat(org.apache.chemistry.opencmis.commons.enums.DateTimeFormat)

Example 4 with Acl

use of org.apache.chemistry.opencmis.commons.data.Acl in project copper-cms by PogeyanOSS.

the class ObjectActor method createDocumentFromSource.

private JSONObject createDocumentFromSource(PostRequest request) throws CmisInvalidArgumentException, CmisConstraintException, CmisObjectNotFoundException, CmisRuntimeException {
    String permission = request.getUserObject().getPermission();
    String principalId = request.getUserObject().getUserDN();
    IUserGroupObject[] groups = request.getUserObject().getGroups();
    if (!Helpers.getGroupPermission(permission, groups)) {
        throw new CmisRuntimeException(request.getUserName() + " is not authorized to applyAcl.");
    }
    String folderId = request.getObjectId() != null ? request.getObjectId() : null;
    VersioningState versioningState = request.getEnumParameter(QueryGetRequest.PARAM_VERSIONIG_STATE, VersioningState.class);
    // String token = request.getParameter(request.PARAM_TOKEN);
    boolean succinct = request.getBooleanParameter(QueryGetRequest.CONTROL_SUCCINCT, false);
    DateTimeFormat dateTimeFormat = request.getDateTimeFormatParameter();
    String sourceId = request.getParameter(QueryGetRequest.PARAM_SOURCE_ID);
    Acl aclImp = CmisUtils.Object.getAcl(request.getAddAcl(), principalId, permission);
    ObjectData sourceDoc = CmisObjectService.Impl.getSimpleObject(request.getRepositoryId(), sourceId, request.getUserName(), BaseTypeId.CMIS_DOCUMENT);
    PropertyData<?> sourceTypeId = sourceDoc.getProperties().getProperties().get(PropertyIds.OBJECT_TYPE_ID);
    if (sourceTypeId == null || sourceTypeId.getFirstValue() == null) {
        throw new CmisRuntimeException("Source object has no type!?!");
    }
    Properties prop = CmisPropertyConverter.Impl.createNewProperties(request.getPropertyData(), request.getRepositoryId());
    String newObjectId = CmisObjectService.Impl.createDocumentFromSource(request.getRepositoryId(), sourceId, prop, folderId, versioningState, request.getPolicies(), aclImp, request.getRemoveAcl(), request.getUserObject().getUserDN());
    ObjectData object = CmisObjectService.Impl.getSimpleObject(request.getRepositoryId(), newObjectId, request.getUserObject().getUserDN(), BaseTypeId.CMIS_DOCUMENT);
    if (object == null) {
        throw new CmisRuntimeException("New document is null!");
    }
    // return object
    JSONObject jsonObject = JSONConverter.convert(object, null, JSONConverter.PropertyMode.CHANGE, succinct, dateTimeFormat);
    return jsonObject;
}
Also used : IUserGroupObject(com.pogeyan.cmis.api.auth.IUserGroupObject) CmisRuntimeException(org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException) JSONObject(org.apache.chemistry.opencmis.commons.impl.json.JSONObject) ObjectData(org.apache.chemistry.opencmis.commons.data.ObjectData) VersioningState(org.apache.chemistry.opencmis.commons.enums.VersioningState) Acl(org.apache.chemistry.opencmis.commons.data.Acl) Properties(org.apache.chemistry.opencmis.commons.data.Properties) DateTimeFormat(org.apache.chemistry.opencmis.commons.enums.DateTimeFormat)

Example 5 with Acl

use of org.apache.chemistry.opencmis.commons.data.Acl in project copper-cms by PogeyanOSS.

the class AclActor method getAcl.

private JSONObject getAcl(QueryGetRequest t) throws CmisObjectNotFoundException, CmisRuntimeException {
    String permission = t.getUserObject().getPermission();
    if (!Helpers.checkingUserPremission(permission, "get")) {
        throw new CmisRuntimeException(t.getUserName() + " is not authorized to applyAcl.");
    }
    String objectId = t.getObjectId();
    Boolean onlyBasicPermissions = t.getBooleanParameter(QueryGetRequest.PARAM_ONLY_BASIC_PERMISSIONS);
    Acl objectAcl = CmisAclServices.Impl.getAcl(t.getRepositoryId(), objectId, onlyBasicPermissions, null, null, t.getUserObject().getUserDN());
    if (objectAcl == null) {
        throw new CmisRuntimeException("object acl is null!");
    }
    JSONObject jsonObject = JSONConverter.convert(objectAcl);
    return jsonObject;
}
Also used : CmisRuntimeException(org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException) JSONObject(org.apache.chemistry.opencmis.commons.impl.json.JSONObject) Acl(org.apache.chemistry.opencmis.commons.data.Acl) CapabilityAcl(org.apache.chemistry.opencmis.commons.enums.CapabilityAcl)

Aggregations

Acl (org.apache.chemistry.opencmis.commons.data.Acl)14 CmisRuntimeException (org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException)8 JSONObject (org.apache.chemistry.opencmis.commons.impl.json.JSONObject)8 IUserGroupObject (com.pogeyan.cmis.api.auth.IUserGroupObject)6 Ace (org.apache.chemistry.opencmis.commons.data.Ace)6 ObjectData (org.apache.chemistry.opencmis.commons.data.ObjectData)6 Properties (org.apache.chemistry.opencmis.commons.data.Properties)6 DateTimeFormat (org.apache.chemistry.opencmis.commons.enums.DateTimeFormat)6 Folder (org.apache.chemistry.opencmis.client.api.Folder)5 Session (org.apache.chemistry.opencmis.client.api.Session)4 CapabilityAcl (org.apache.chemistry.opencmis.commons.enums.CapabilityAcl)3 Test (org.junit.Test)3 ArrayList (java.util.ArrayList)2 VersioningState (org.apache.chemistry.opencmis.commons.enums.VersioningState)2 Document (org.apache.chemistry.opencmis.client.api.Document)1 AccessControlListImpl (org.apache.chemistry.opencmis.commons.impl.dataobjects.AccessControlListImpl)1 CmisTestResult (org.apache.chemistry.opencmis.tck.CmisTestResult)1