Search in sources :

Example 6 with CallContext

use of org.apache.chemistry.opencmis.commons.server.CallContext in project alfresco-repository by Alfresco.

the class CMISTest method testModelAvailability.

/**
 * Test for MNT-10537.
 */
@Test
public void testModelAvailability() throws Exception {
    final WorkflowDeployer testWorkflowDeployer = new WorkflowDeployer();
    // setup dependencies
    testWorkflowDeployer.setTransactionService(transactionService);
    testWorkflowDeployer.setWorkflowService(workflowService);
    testWorkflowDeployer.setWorkflowAdminService(workflowAdminService);
    testWorkflowDeployer.setAuthenticationContext(authenticationContext);
    testWorkflowDeployer.setDictionaryDAO(dictionaryDAO);
    testWorkflowDeployer.setTenantAdminService(tenantAdminService);
    testWorkflowDeployer.setTenantService(tenantService);
    testWorkflowDeployer.setNodeService(nodeService);
    testWorkflowDeployer.setNamespaceService(namespaceService);
    testWorkflowDeployer.setSearchService(searchService);
    // populate workflow parameters
    java.util.Properties props = new java.util.Properties();
    props.setProperty(WorkflowDeployer.ENGINE_ID, "activiti");
    props.setProperty(WorkflowDeployer.LOCATION, "activiti/testCustomActiviti.bpmn20.xml");
    props.setProperty(WorkflowDeployer.MIMETYPE, "text/xml");
    props.setProperty(WorkflowDeployer.REDEPLOY, Boolean.FALSE.toString());
    List<java.util.Properties> definitions = new ArrayList<java.util.Properties>(1);
    definitions.add(props);
    testWorkflowDeployer.setWorkflowDefinitions(definitions);
    List<String> models = new ArrayList<String>(1);
    models.add("activiti/testWorkflowModel.xml");
    testWorkflowDeployer.setModels(models);
    // deploy test workflow
    RetryingTransactionHelper txnHelper = transactionService.getRetryingTransactionHelper();
    txnHelper.setForceWritable(true);
    txnHelper.doInTransaction(new RetryingTransactionCallback<Object>() {

        @Override
        public Object execute() throws Throwable {
            return AuthenticationUtil.runAs(new RunAsWork<Object>() {

                public Object doWork() {
                    testWorkflowDeployer.init();
                    return null;
                }
            }, AuthenticationUtil.getSystemUserName());
        }
    }, false, true);
    org.alfresco.service.cmr.dictionary.TypeDefinition startTaskTypeDefinition = this.dictionaryService.getType(TEST_START_TASK);
    org.alfresco.service.cmr.dictionary.TypeDefinition workflowTaskTypeDefinition = this.dictionaryService.getType(TEST_WORKFLOW_TASK);
    // check that workflow types were correctly bootstrapped
    assertNotNull(startTaskTypeDefinition);
    assertNotNull(workflowTaskTypeDefinition);
    // caches are refreshed asynchronously
    Thread.sleep(5000);
    // check that loaded model is available via CMIS API
    CallContext context = new SimpleCallContext("admin", "admin", CmisVersion.CMIS_1_1);
    CmisService service = factory.getService(context);
    try {
        List<RepositoryInfo> repositories = service.getRepositoryInfos(null);
        assertTrue(repositories.size() > 0);
        List<TypeDefinitionContainer> container = service.getTypeDescendants(repositories.get(0).getId(), null, new BigInteger("-1"), true, null);
        assertTrue("Workflow model haven't been loaded", container.toString().contains("testwf:startTaskVarScriptAssign"));
    } finally {
        service.close();
    }
}
Also used : WorkflowDeployer(org.alfresco.repo.workflow.WorkflowDeployer) RetryingTransactionHelper(org.alfresco.repo.transaction.RetryingTransactionHelper) RunAsWork(org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork) TenantRunAsWork(org.alfresco.repo.tenant.TenantUtil.TenantRunAsWork) ArrayList(java.util.ArrayList) Properties(org.apache.chemistry.opencmis.commons.data.Properties) TypeDefinitionContainer(org.apache.chemistry.opencmis.commons.definitions.TypeDefinitionContainer) RepositoryInfo(org.apache.chemistry.opencmis.commons.data.RepositoryInfo) CallContext(org.apache.chemistry.opencmis.commons.server.CallContext) CmisService(org.apache.chemistry.opencmis.commons.server.CmisService) BigInteger(java.math.BigInteger) UnfileObject(org.apache.chemistry.opencmis.commons.enums.UnfileObject) VersionableAspectTest(org.alfresco.repo.version.VersionableAspectTest) Test(org.junit.Test)

Example 7 with CallContext

use of org.apache.chemistry.opencmis.commons.server.CallContext in project alfresco-repository by Alfresco.

the class CMISTest method testIsLatestMajorVersionMNT10868.

/**
 * MNT-10868 CMIS: Incorrect value of Latest Major version on Versions and Properties tabs.
 */
@Test
public void testIsLatestMajorVersionMNT10868() {
    CallContext context = new SimpleCallContext("admin", "admin", CmisVersion.CMIS_1_0);
    String repositoryId = null;
    AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
    CmisService cmisService = factory.getService(context);
    try {
        // get repository id
        List<RepositoryInfo> repositories = cmisService.getRepositoryInfos(null);
        assertTrue(repositories.size() > 0);
        RepositoryInfo repo = repositories.get(0);
        repositoryId = repo.getId();
        final String folderName = "testfolder" + GUID.generate();
        final String docName = "testdoc.txt" + GUID.generate();
        final FileInfo fileInfo = transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<FileInfo>() {

            @Override
            public FileInfo execute() throws Throwable {
                NodeRef companyHomeNodeRef = repositoryHelper.getCompanyHome();
                FileInfo folderInfo = fileFolderService.create(companyHomeNodeRef, folderName, ContentModel.TYPE_FOLDER);
                nodeService.setProperty(folderInfo.getNodeRef(), ContentModel.PROP_NAME, folderName);
                FileInfo fileInfo = fileFolderService.create(folderInfo.getNodeRef(), docName, ContentModel.TYPE_CONTENT);
                nodeService.setProperty(fileInfo.getNodeRef(), ContentModel.PROP_NAME, docName);
                nodeService.addAspect(fileInfo.getNodeRef(), ContentModel.ASPECT_VERSIONABLE, null);
                return fileInfo;
            }
        });
        ObjectData objectData = cmisService.getObjectByPath(repositoryId, "/" + folderName + "/" + docName, null, true, IncludeRelationships.NONE, null, false, true, null);
        PropertyData<?> pd = getPropIsLatestMajorVersion(objectData);
        if (pd != null) {
            assertTrue("The CMISDictionaryModel.PROP_IS_LATEST_MAJOR_VERSION should be true as major version was created", (Boolean) pd.getValues().get(0));
        }
        nodeService.setProperty(fileInfo.getNodeRef(), ContentModel.PROP_TITLE, docName);
        // Create minor version
        transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<Object>() {

            public Object execute() throws Throwable {
                // get an updating writer
                ContentWriter writer = contentService.getWriter(fileInfo.getNodeRef(), ContentModel.PROP_CONTENT, true);
                writer.setMimetype("text/plain");
                writer.putContent("New Version");
                return null;
            }
        });
        objectData = cmisService.getObjectByPath(repositoryId, "/" + folderName + "/" + docName, null, true, IncludeRelationships.NONE, null, false, true, null);
        pd = getPropIsLatestMajorVersion(objectData);
        if (pd != null) {
            assertFalse("The CMISDictionaryModel.PROP_IS_LATEST_MAJOR_VERSION should be false as minor version was created", (Boolean) pd.getValues().get(0));
        }
    } finally {
        cmisService.close();
    }
}
Also used : RepositoryInfo(org.apache.chemistry.opencmis.commons.data.RepositoryInfo) ObjectData(org.apache.chemistry.opencmis.commons.data.ObjectData) CallContext(org.apache.chemistry.opencmis.commons.server.CallContext) NodeRef(org.alfresco.service.cmr.repository.NodeRef) ContentWriter(org.alfresco.service.cmr.repository.ContentWriter) CmisService(org.apache.chemistry.opencmis.commons.server.CmisService) FileInfo(org.alfresco.service.cmr.model.FileInfo) UnfileObject(org.apache.chemistry.opencmis.commons.enums.UnfileObject) VersionableAspectTest(org.alfresco.repo.version.VersionableAspectTest) Test(org.junit.Test)

Example 8 with CallContext

use of org.apache.chemistry.opencmis.commons.server.CallContext in project iaf by ibissource.

the class CmisUtils method populateCmisAttributes.

public static void populateCmisAttributes(PipeLineSession session) {
    CallContext callContext = (CallContext) session.get(CMIS_CALLCONTEXT_KEY);
    if (callContext != null) {
        session.put(CMIS_VERSION_KEY, callContext.getCmisVersion());
        session.put(CMIS_BINDING_KEY, callContext.getBinding());
        if ("basic".equalsIgnoreCase(CMIS_SECURITYHANDLER)) {
            HttpServletRequest request = (HttpServletRequest) callContext.get(CallContext.HTTP_SERVLET_REQUEST);
            session.setSecurityHandler(new HttpSecurityHandler(request));
        } else if ("wsse".equalsIgnoreCase(CMIS_SECURITYHANDLER)) {
            session.setSecurityHandler(new CmisSecurityHandler(callContext));
        }
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) CmisSecurityHandler(nl.nn.adapterframework.extensions.cmis.server.CmisSecurityHandler) HttpSecurityHandler(nl.nn.adapterframework.http.HttpSecurityHandler) CallContext(org.apache.chemistry.opencmis.commons.server.CallContext)

Example 9 with CallContext

use of org.apache.chemistry.opencmis.commons.server.CallContext in project alfresco-repository by Alfresco.

the class CMISTest method testCheckIn.

/**
 * Test for MNT-9203.
 */
@Test
public void testCheckIn() {
    String repositoryId = null;
    ObjectData objectData = null;
    Holder<String> objectId = null;
    CallContext context = new SimpleCallContext("admin", "admin", CmisVersion.CMIS_1_0);
    final String folderName = "testfolder." + GUID.generate();
    final String docName = "testdoc.txt." + GUID.generate();
    final String customModel = "cmistest.model";
    final QName testCustomTypeQName = QName.createQName(customModel, "sop");
    final QName authorisedByQname = QName.createQName(customModel, "authorisedBy");
    AuthenticationUtil.pushAuthentication();
    AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
    try {
        final FileInfo fileInfo = transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<FileInfo>() {

            @Override
            public FileInfo execute() throws Throwable {
                NodeRef companyHomeNodeRef = repositoryHelper.getCompanyHome();
                FileInfo folderInfo = fileFolderService.create(companyHomeNodeRef, folderName, ContentModel.TYPE_FOLDER);
                nodeService.setProperty(folderInfo.getNodeRef(), ContentModel.PROP_NAME, folderName);
                FileInfo fileInfo = fileFolderService.create(folderInfo.getNodeRef(), docName, testCustomTypeQName);
                Map<QName, Serializable> customProperties = new HashMap<QName, Serializable>();
                customProperties.put(authorisedByQname, "customPropertyString");
                customProperties.put(ContentModel.PROP_NAME, docName);
                nodeService.setProperties(fileInfo.getNodeRef(), customProperties);
                return fileInfo;
            }
        });
        CmisService service = factory.getService(context);
        try {
            List<RepositoryInfo> repositories = service.getRepositoryInfos(null);
            assertTrue(repositories.size() > 0);
            RepositoryInfo repo = repositories.get(0);
            repositoryId = repo.getId();
            objectData = service.getObjectByPath(repositoryId, "/" + folderName + "/" + docName, null, true, IncludeRelationships.NONE, null, false, true, null);
            // checkout
            objectId = new Holder<String>(objectData.getId());
            service.checkOut(repositoryId, objectId, null, new Holder<Boolean>(true));
        } finally {
            service.close();
        }
        try {
            service = factory.getService(context);
            PropertyStringImpl prop = new PropertyStringImpl();
            prop.setId("abc:" + authorisedByQname.toPrefixString());
            prop.setValue(null);
            Collection<PropertyData<?>> propsList = new ArrayList<PropertyData<?>>();
            propsList.add(prop);
            Properties properties = new PropertiesImpl(propsList);
            // checkIn on pwc
            service.checkIn(repositoryId, objectId, false, properties, null, null, null, null, null, null);
        } finally {
            service.close();
        }
        // check that value is null
        assertTrue(nodeService.getProperty(fileInfo.getNodeRef(), authorisedByQname) == null);
    } finally {
        AuthenticationUtil.popAuthentication();
    }
}
Also used : Serializable(java.io.Serializable) PropertyData(org.apache.chemistry.opencmis.commons.data.PropertyData) ObjectData(org.apache.chemistry.opencmis.commons.data.ObjectData) ArrayList(java.util.ArrayList) Properties(org.apache.chemistry.opencmis.commons.data.Properties) NodeRef(org.alfresco.service.cmr.repository.NodeRef) FileInfo(org.alfresco.service.cmr.model.FileInfo) PropertyStringImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyStringImpl) PropertiesImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertiesImpl) RepositoryInfo(org.apache.chemistry.opencmis.commons.data.RepositoryInfo) QName(org.alfresco.service.namespace.QName) CallContext(org.apache.chemistry.opencmis.commons.server.CallContext) CmisService(org.apache.chemistry.opencmis.commons.server.CmisService) Map(java.util.Map) MimetypeMap(org.alfresco.repo.content.MimetypeMap) HashMap(java.util.HashMap) VersionableAspectTest(org.alfresco.repo.version.VersionableAspectTest) Test(org.junit.Test)

Example 10 with CallContext

use of org.apache.chemistry.opencmis.commons.server.CallContext in project alfresco-repository by Alfresco.

the class AlfrescoCmisServiceImpl method beforeCall.

@Override
public void beforeCall() {
    AuthenticationUtil.pushAuthentication();
    if (authentication != null) {
        // Use the previously-obtained authentication
        AuthenticationUtil.setFullAuthentication(authentication);
    } else {
        CallContext context = getContext();
        if (context == null) {
            // Service not opened, yet
            return;
        }
        // Sticky sessions?
        if (connector.openHttpSession()) {
            // create a session -> set a cookie
            // if the CMIS client supports cookies that might help in clustered environments
            ((HttpServletRequest) context.get(CallContext.HTTP_SERVLET_REQUEST)).getSession();
        }
        // Authenticate
        if (authentication != null) {
            // We have already authenticated; just reuse the authentication
            AuthenticationUtil.setFullAuthentication(authentication);
        } else {
            // First check if we already are authenticated
            if (AuthenticationUtil.getFullyAuthenticatedUser() == null) {
                // We have to go to the repo and authenticate
                String user = context.getUsername();
                String password = context.getPassword();
                Authorization auth = new Authorization(user, password);
                if (auth.isTicket()) {
                    connector.getAuthenticationService().validate(auth.getTicket());
                } else {
                    connector.getAuthenticationService().authenticate(auth.getUserName(), auth.getPasswordCharArray());
                }
            }
            this.authentication = AuthenticationUtil.getFullAuthentication();
        }
    // // TODO: How is the proxy user working.
    // //       Until we know what it is meant to do, it's not available
    // String currentUser = connector.getAuthenticationService().getCurrentUserName();
    // String user = getContext().getUsername();
    // String password = getContext().getPassword();
    // if (currentUser != null && currentUser.equals(connector.getProxyUser()))
    // {
    // if (user != null && user.length() > 0)
    // {
    // AuthenticationUtil.setFullyAuthenticatedUser(user);
    // }
    // }
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) Authorization(org.alfresco.repo.security.authentication.Authorization) CallContext(org.apache.chemistry.opencmis.commons.server.CallContext)

Aggregations

CallContext (org.apache.chemistry.opencmis.commons.server.CallContext)11 CmisService (org.apache.chemistry.opencmis.commons.server.CmisService)5 VersionableAspectTest (org.alfresco.repo.version.VersionableAspectTest)4 NodeRef (org.alfresco.service.cmr.repository.NodeRef)4 Test (org.junit.Test)4 ArrayList (java.util.ArrayList)3 HttpServletRequest (javax.servlet.http.HttpServletRequest)3 FileInfo (org.alfresco.service.cmr.model.FileInfo)3 ObjectData (org.apache.chemistry.opencmis.commons.data.ObjectData)3 RepositoryInfo (org.apache.chemistry.opencmis.commons.data.RepositoryInfo)3 UnfileObject (org.apache.chemistry.opencmis.commons.enums.UnfileObject)3 Serializable (java.io.Serializable)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 MimetypeMap (org.alfresco.repo.content.MimetypeMap)2 RetryingTransactionHelper (org.alfresco.repo.transaction.RetryingTransactionHelper)2 QName (org.alfresco.service.namespace.QName)2 Properties (org.apache.chemistry.opencmis.commons.data.Properties)2 BigInteger (java.math.BigInteger)1 HashSet (java.util.HashSet)1