org.apache.chemistry.opencmis.commons.SessionParameter Java Examples

The following examples show how to use org.apache.chemistry.opencmis.commons.SessionParameter. 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: OpenCmisLocalTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
private Repository getRepository(String user, String password)
{
    // default factory implementation
    SessionFactory sessionFactory = SessionFactoryImpl.newInstance();
    Map<String, String> parameters = new HashMap<String, String>();

    // user credentials
    parameters.put(SessionParameter.USER, "admin");
    parameters.put(SessionParameter.PASSWORD, "admin");

    // connection settings
    parameters.put(SessionParameter.BINDING_TYPE, BindingType.LOCAL.value());
    parameters.put(SessionParameter.LOCAL_FACTORY, "org.alfresco.opencmis.OpenCmisLocalTest$TestCmisServiceFactory");

    // create session
    List<Repository> repositories = sessionFactory.getRepositories(parameters);
    return repositories.size() > 0 ? repositories.get(0) : null;
}
 
Example #2
Source File: CMISDataCreatorTest.java    From SearchServices with GNU Lesser General Public License v3.0 6 votes vote down vote up
private static Session getSession(String user, String pwd)
{
    String url = "http://localhost:8080/alfresco/api/-default-/public/cmis/versions/1.1/atom";
    
    SessionFactory factory = SessionFactoryImpl.newInstance();
    Map<String, String> parameter = new HashMap<String, String>();
    parameter.put(SessionParameter.USER, user);
    parameter.put(SessionParameter.PASSWORD, pwd);
    parameter.put(SessionParameter.ATOMPUB_URL, url);
    parameter.put(SessionParameter.BINDING_TYPE, BindingType.ATOMPUB.value());
    
    List<Repository> repositories = factory.getRepositories(parameter);
    Session session = repositories.get(0).createSession();
    
    return session;
}
 
Example #3
Source File: TestRemovePermissions.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 6 votes vote down vote up
protected Session getATOMPUB_10_Session()
{
    try
    {
        Map<String, String> parameters = new HashMap<String, String>();
        int port = getTestFixture().getJettyComponent().getPort();

        parameters.put(SessionParameter.USER, ADMIN_USER);
        parameters.put(SessionParameter.PASSWORD, ADMIN_PASSWORD);
        parameters.put(SessionParameter.ATOMPUB_URL, MessageFormat.format(ATOMPUB_URL_OC, DEFAULT_HOSTNAME, String.valueOf(port)));
        parameters.put(SessionParameter.BINDING_TYPE, BindingType.ATOMPUB.value());

        SessionFactory sessionFactory = SessionFactoryImpl.newInstance();

        parameters.put(SessionParameter.REPOSITORY_ID, sessionFactory.getRepositories(parameters).get(0).getId());
        return sessionFactory.createSession(parameters);
    }
    catch (Exception ex)
    {
        logger.error(ex);
    }
    return null;
}
 
Example #4
Source File: TestRemovePermissions.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 6 votes vote down vote up
protected Session getATOMPUB_11_Session()
{
    try
    {
        Map<String, String> parameters = new HashMap<String, String>();
        int port = getTestFixture().getJettyComponent().getPort();

        parameters.put(SessionParameter.USER, ADMIN_USER);
        parameters.put(SessionParameter.PASSWORD, ADMIN_PASSWORD);
        parameters.put(SessionParameter.ATOMPUB_URL, MessageFormat.format(ATOMPUB_URL_11, DEFAULT_HOSTNAME, String.valueOf(port)));
        parameters.put(SessionParameter.BINDING_TYPE, BindingType.ATOMPUB.value());

        SessionFactory sessionFactory = SessionFactoryImpl.newInstance();

        parameters.put(SessionParameter.REPOSITORY_ID, sessionFactory.getRepositories(parameters).get(0).getId());
        return sessionFactory.createSession(parameters);
    }
    catch (Exception ex)
    {
        logger.error(ex);

    }
    return null;
}
 
Example #5
Source File: TestRemovePermissions.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 6 votes vote down vote up
protected Session getBROWSER_11_Session()
{
    try
    {
        Map<String, String> parameter = new HashMap<String, String>();
        int port = getTestFixture().getJettyComponent().getPort();

        parameter.put(SessionParameter.BINDING_TYPE, BindingType.BROWSER.value());
        parameter.put(SessionParameter.BROWSER_URL, MessageFormat.format(BROWSE_URL_11, DEFAULT_HOSTNAME, String.valueOf(port)));
        parameter.put(SessionParameter.COOKIES, "true");

        parameter.put(SessionParameter.USER, ADMIN_USER);
        parameter.put(SessionParameter.PASSWORD, ADMIN_PASSWORD);

        SessionFactory sessionFactory = SessionFactoryImpl.newInstance();

        parameter.put(SessionParameter.REPOSITORY_ID, sessionFactory.getRepositories(parameter).get(0).getId());
        return sessionFactory.createSession(parameter);
    }
    catch (Exception ex)
    {
        logger.error(ex);

    }
    return null;
}
 
Example #6
Source File: PublicApiClient.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Create a CMIS session using Enterprise AtomPub binding.
 *
 * @param repositoryId String
 * @param username String
 * @param password String
 * @return CmisSession
 */
public CmisSession createCMISSession(String repositoryId, String username, String password)
{
    // default factory implementation
    SessionFactory factory = SessionFactoryImpl.newInstance();
    Map<String, String> parameters = new HashMap<String, String>();

    // user credentials
    parameters.put(SessionParameter.USER, username);
    parameters.put(SessionParameter.PASSWORD, password);

    // connection settings
    parameters.put(SessionParameter.ATOMPUB_URL, client.getCmisUrl(repositoryId, null));
    parameters.put(SessionParameter.BINDING_TYPE, BindingType.ATOMPUB.value());
    if(repositoryId != null)
    {
        parameters.put(SessionParameter.REPOSITORY_ID, repositoryId);
    }
    parameters.put(SessionParameter.OBJECT_FACTORY_CLASS, AlfrescoObjectFactoryImpl.class.getName());

    // create session
    Session session = factory.createSession(parameters);

    CmisSession cmisSession = new CmisSession(session);
    return cmisSession;
}
 
Example #7
Source File: OpenCMISClientContext.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 6 votes vote down vote up
public OpenCMISClientContext(BindingType bindingType, String url, String username, String password, Map<String, String> parameters, ApplicationContext ctx) throws IOException
{
   	cmisParameters = new HashMap<String, String>();
   	cmisParameters.putAll(parameters);
   	cmisParameters.put(SessionParameter.BINDING_TYPE, bindingType.value());
   	if(bindingType.equals(BindingType.ATOMPUB))
   	{
   		cmisParameters.put(SessionParameter.ATOMPUB_URL, url);
   	}
   	else if(bindingType.equals(BindingType.BROWSER))
   	{
   		cmisParameters.put(SessionParameter.BROWSER_URL, url);
   	}
   	cmisParameters.put(SessionParameter.USER, username);
   	cmisParameters.put(SessionParameter.PASSWORD, password);
   	
   	if (ctx != null)
   	{
   		Properties properties =  (Properties)ctx.getBean("global-properties");
       	cmisParameters.put(SessionParameter.CONNECT_TIMEOUT, properties.getProperty("opencmis.tck.connecttimeout"));
       	cmisParameters.put(SessionParameter.READ_TIMEOUT, properties.getProperty("opencmis.tck.readtimeout"));
   	}
   	createCMISParametersFile();
}
 
Example #8
Source File: SampleClient.java    From document-management-software with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Connect to logicaldoc repository
 * 
 * @return root folder object
 */
private static Folder connect(String username, String password) {
	SessionFactory sessionFactory = SessionFactoryImpl.newInstance();
	Map<String, String> parameter = new HashMap<String, String>();
	parameter.put(SessionParameter.USER, username);
	parameter.put(SessionParameter.PASSWORD, password);
	parameter.put(SessionParameter.ATOMPUB_URL, CONNECTION_URL);
	parameter.put(SessionParameter.BINDING_TYPE, BindingType.ATOMPUB.value());
	parameter.put(SessionParameter.REPOSITORY_ID, Long.toString(5L));

	session = sessionFactory.createSession(parameter);
	return session.getRootFolder();
}
 
Example #9
Source File: TestCMIS.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void testCanConnectCMISUsingDefaultTenantImpl(Binding binding, String cmisVersion)
{
    String url = httpClient.getPublicApiCmisUrl(TenantUtil.DEFAULT_TENANT, binding, cmisVersion, null);
    
    Map<String, String> parameters = new HashMap<String, String>();
    
    // user credentials
    parameters.put(SessionParameter.USER, "admin");
    parameters.put(SessionParameter.PASSWORD, "admin");
    
    parameters.put(SessionParameter.ATOMPUB_URL, url);
    parameters.put(SessionParameter.BROWSER_URL, url);
    parameters.put(SessionParameter.BINDING_TYPE, binding.getOpenCmisBinding().value());
    
    SessionFactory factory = SessionFactoryImpl.newInstance();
    // perform request : http://host:port/alfresco/api/-default-/public/cmis/versions/${cmisVersion}/${binding}
    List<Repository> repositories = factory.getRepositories(parameters);
    
    assertTrue(repositories.size() > 0);
    
    parameters.put(SessionParameter.REPOSITORY_ID, TenantUtil.DEFAULT_TENANT);
    Session session = factory.createSession(parameters);
    // perform request : http://host:port/alfresco/api/-default-/public/cmis/versions/${cmisVersion}/${binding}/type?id=cmis:document
    ObjectType objectType = session.getTypeDefinition("cmis:document");
    
    assertNotNull(objectType);
}
 
Example #10
Source File: PublicApiClient.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Get CMIS repositories (Enterprise AtomPub CMIS binding)
 *
 * @return List<Repository>
 */
public List<Repository> getCMISRepositories()
{
    List<Repository> repositories = null;

    RequestContext rc = getRequestContext();
    if(rc == null)
    {
        throw new RuntimeException("Must set a request context");
    }

    UserData userData = findUser(rc.getRunAsUser());
    if(userData != null)
    {
        // default factory implementation
        SessionFactory factory = SessionFactoryImpl.newInstance();
        Map<String, String> parameters = new HashMap<String, String>();

        // user credentials
        parameters.put(SessionParameter.USER, rc.getRunAsUser());
        parameters.put(SessionParameter.PASSWORD, userData.getPassword());

        // connection settings
        parameters.put(SessionParameter.ATOMPUB_URL, client.getCmisUrl(null, null));
        parameters.put(SessionParameter.BINDING_TYPE, BindingType.ATOMPUB.value());

        repositories = factory.getRepositories(parameters);
    }

    return repositories;
}
 
Example #11
Source File: PublicApiClient.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 5 votes vote down vote up
public List<String> getNetworkIds(String version)
{
    RequestContext rc = getRequestContext();

    UserData userData = findUser(rc.getRunAsUser());
    if(userData == null)
    {
        throw new RuntimeException("Must provide a valid username");
    }

    SessionFactory factory = SessionFactoryImpl.newInstance();

    Map<String, String> parameters = new HashMap<String, String>();

    // connection settings
    parameters.put(SessionParameter.ATOMPUB_URL, client.getPublicApiCmisUrl(null, Binding.atom, version, null));
    parameters.put(SessionParameter.BINDING_TYPE, BindingType.ATOMPUB.value());

    // user credentials
    parameters.put(SessionParameter.USER, rc.getRunAsUser());
    parameters.put(SessionParameter.PASSWORD, userData.getPassword());
    List<Repository> repositories = factory.getRepositories(parameters);

    List<String> repositoryIds = new ArrayList<String>(repositories.size());
    for(Repository repository : repositories)
    {
        repositoryIds.add(repository.getId());
    }

    return repositoryIds;
}
 
Example #12
Source File: CmisIntegrationTest.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
private Session createSession() {
    SessionFactory sessionFactory = SessionFactoryImpl.newInstance();
    Map<String, String> parameter = new HashMap<String, String>();
    parameter.put(SessionParameter.ATOMPUB_URL, "http://127.0.0.1:8080/chemistry-opencmis-server-inmemory/atom11/atom11");
    parameter.put(SessionParameter.BINDING_TYPE, BindingType.ATOMPUB.value());
    Repository repository = sessionFactory.getRepositories(parameter).get(0);
    return repository.createSession();
}
 
Example #13
Source File: TestRemovePermissions.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 4 votes vote down vote up
protected Session getWEBSERVICE_10_Session()
{
    try
    {
        SessionFactory sessionFactory = SessionFactoryImpl.newInstance();
        int port = 8080;

        Map<String, String> parameters = new HashMap<String, String>();

        parameters.put(SessionParameter.USER, ADMIN_USER);
        parameters.put(SessionParameter.PASSWORD, ADMIN_PASSWORD);
        parameters.put(SessionParameter.BINDING_TYPE, BindingType.WEBSERVICES.value());

        parameters.put(SessionParameter.WEBSERVICES_ACL_SERVICE,
                MessageFormat.format(ACLSERVICE_OC_URL, DEFAULT_HOSTNAME, String.valueOf(port)));
        parameters.put(SessionParameter.WEBSERVICES_DISCOVERY_SERVICE,
                MessageFormat.format(DISCOVERYSERVICE_OC_URL, DEFAULT_HOSTNAME, String.valueOf(port)));
        parameters.put(SessionParameter.WEBSERVICES_MULTIFILING_SERVICE,
                MessageFormat.format(MULTIFILINGSERVICE_OC_URL, DEFAULT_HOSTNAME, String.valueOf(port)));
        parameters.put(SessionParameter.WEBSERVICES_NAVIGATION_SERVICE,
                MessageFormat.format(NAVIGATIONSERVICE_OC_URL, DEFAULT_HOSTNAME, String.valueOf(port)));
        parameters.put(SessionParameter.WEBSERVICES_OBJECT_SERVICE,
                MessageFormat.format(OBJECTSERVICE_OC_URL, DEFAULT_HOSTNAME, String.valueOf(port)));
        parameters.put(SessionParameter.WEBSERVICES_POLICY_SERVICE,
                MessageFormat.format(POLICYSERVICE_OC_URL, DEFAULT_HOSTNAME, String.valueOf(port)));
        parameters.put(SessionParameter.WEBSERVICES_RELATIONSHIP_SERVICE,
                MessageFormat.format(RELATIONSHIPSERVICE_OC_URL, DEFAULT_HOSTNAME, String.valueOf(port)));
        parameters.put(SessionParameter.WEBSERVICES_REPOSITORY_SERVICE,
                MessageFormat.format(REPOSITORYSERVICE_OC_URL, DEFAULT_HOSTNAME, String.valueOf(port)));
        parameters.put(SessionParameter.WEBSERVICES_VERSIONING_SERVICE,
                MessageFormat.format(REPOSITORYSERVICE_OC_URL, DEFAULT_HOSTNAME, String.valueOf(port)));
        parameters.put(SessionParameter.REPOSITORY_ID, sessionFactory.getRepositories(parameters).get(0).getId());

        return sessionFactory.createSession(parameters);
    }
    catch (Exception ex)
    {
        logger.error(ex);
    }
    return null;
}
 
Example #14
Source File: PublicApiClient.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 4 votes vote down vote up
public CmisSession createPublicApiCMISSession(Binding binding, String version, String objectFactoryName)
{
    CmisSession cmisSession = null;

    RequestContext rc = getRequestContext();
    if(rc == null)
    {
        throw new RuntimeException("Must set a request context");
    }

    String networkId = rc.getNetworkId();
    String username = rc.getRunAsUser();
    UserData userData = findUser(rc.getRunAsUser());
    if(userData != null)
    {
        String password = userData.getPassword();

        // default factory implementation
        SessionFactory factory = SessionFactoryImpl.newInstance();
        Map<String, String> parameters = new HashMap<String, String>();

        // user credentials
        parameters.put(SessionParameter.USER, username);
        parameters.put(SessionParameter.PASSWORD, password);

        // connection settings
        if(binding == Binding.atom)
        {
            parameters.put(SessionParameter.ATOMPUB_URL, client.getPublicApiCmisUrl(networkId, binding, version, null));
            parameters.put(SessionParameter.BINDING_TYPE, binding.getOpenCmisBinding().value());
        }
        else if(binding == Binding.browser)
        {
            parameters.put(SessionParameter.BROWSER_URL, client.getPublicApiCmisUrl(networkId, binding, version, null));
            parameters.put(SessionParameter.BINDING_TYPE, binding.getOpenCmisBinding().value());
        }
        if(networkId != null)
        {
            parameters.put(SessionParameter.REPOSITORY_ID, networkId);
        }
        if(objectFactoryName != null)
        {
            parameters.put(SessionParameter.OBJECT_FACTORY_CLASS, objectFactoryName);
        }

        // create session
        Session session = factory.createSession(parameters);

        cmisSession = new CmisSession(session);
    }

    return cmisSession;
}
 
Example #15
Source File: CmisHttpInvoker.java    From iaf with Apache License 2.0 4 votes vote down vote up
private CmisHttpSender getInstance(BindingSession session) throws SenderException, ConfigurationException {
	if(sender == null) {
		log.debug("creating new CmisHttpInvoker");
		sender = new CmisHttpSender();

		sender.setUrlParam("url");

		//Auth
		if(session.get(SessionParameter.USER) != null)
			sender.setUserName((String) session.get(SessionParameter.USER));
		if(session.get(SessionParameter.PASSWORD) != null)
			sender.setPassword((String) session.get(SessionParameter.PASSWORD));

		//Proxy
		if(session.get("proxyHost") != null) {
			sender.setProxyHost((String) session.get("proxyHost"));
			if(session.get("proxyPort") != null)
				sender.setProxyPort(Integer.parseInt((String) session.get("proxyPort")));
			if(session.get("proxyUserName") != null)
				sender.setProxyUserName((String) session.get("proxyUserName"));
			if(session.get("proxyPassword") != null)
				sender.setProxyPassword((String) session.get("proxyPassword"));
		}

		//SSL
		if(session.get("certificateUrl") != null)
			sender.setCertificate((String) session.get("certificateUrl"));
		if(session.get("certificatePassword") != null)
			sender.setCertificatePassword((String) session.get("certificatePassword"));
		if(session.get("keystoreType") != null)
			sender.setKeystoreType((String) session.get("keystoreType"));
		if(session.get("keyManagerAlgorithm") != null)
			sender.setKeyManagerAlgorithm((String) session.get("keyManagerAlgorithm"));
		if(session.get("truststoreUrl") != null)
			sender.setTruststore((String) session.get("truststoreUrl"));
		if(session.get("truststorePassword") != null)
			sender.setTruststorePassword((String) session.get("truststorePassword"));
		if(session.get("truststoreType") != null)
			sender.setTruststoreType((String) session.get("truststoreType"));
		if(session.get("trustManagerAlgorithm") != null)
			sender.setTrustManagerAlgorithm((String) session.get("trustManagerAlgorithm"));

		//SSL+
		if(session.get("isAllowSelfSignedCertificates") != null) {
			boolean isAllowSelfSignedCertificates = Boolean.parseBoolean((String) session.get("isAllowSelfSignedCertificates"));
			sender.setAllowSelfSignedCertificates(isAllowSelfSignedCertificates);
		}
		if(session.get("isVerifyHostname") != null) {
			boolean isVerifyHostname = Boolean.parseBoolean((String) session.get("isVerifyHostname"));
			sender.setVerifyHostname(isVerifyHostname);
		}
		if(session.get("isIgnoreCertificateExpiredException") != null) {
			boolean isIgnoreCertificateExpiredException = Boolean.parseBoolean((String) session.get("isIgnoreCertificateExpiredException"));
			sender.setIgnoreCertificateExpiredException(isIgnoreCertificateExpiredException);
		}

		//Add parameters
		Parameter parameter = new Parameter();
		parameter.setName("writer");
		parameter.setSessionKey("writer");
		sender.addParameter(parameter);
		Parameter urlParam = new Parameter();
		urlParam.setName("url");
		urlParam.setSessionKey("url");
		sender.addParameter(urlParam);

		// timeouts
		int connectTimeout = session.get(SessionParameter.CONNECT_TIMEOUT, -1);
		int readTimeout = session.get(SessionParameter.READ_TIMEOUT, -1);
		int timeout = Math.max(connectTimeout, readTimeout);
		if (timeout >= 0) {
			sender.setTimeout(timeout);
		}

		int maxConnections = session.get("maxConnections", 0);
		if(maxConnections > 0) {
			sender.setMaxConnections(maxConnections);
		}

		sender.setMethodType("custom");
		sender.configure();
		sender.open();
	}
	return sender;
}