CmisUnauthorizedException: Unauthorized - error using Apache Chemistry library interfacing to Sharepoint 2013

▼魔方 西西 提交于 2020-01-14 03:30:09

问题


I'm having concern connecting to Sharepoint 2013 via CMIS using Apache Chemistry library.

I am receiving Unauthorized error, but the credentials (U/P) I used are correct.

I used it to login to the Sharepoint Online so it should be working on my code.

Hope someone could help me solving this. Thanks!

See my code below I am using to create a session to Sharepoint:

public Session fillParams()    {//define some values for the connection string
    String rest_base = "http://<server>/sites/_api/web/";
    String repository_id = "c013ab76-4821-489f-9a1c-1d43bfce1c32";
    String atompub_url = rest_base + "/" + repository_id + "";
    String username ="notTobeShown";
    String password = "notTobeShown";
    SessionFactory factory = SessionFactoryImpl.newInstance();
    Map<String, String> parameter = new HashMap<String,String>();

    parameter.put(SessionParameter.ATOMPUB_URL, rest_base);
    parameter.put(SessionParameter.BINDING_TYPE, BindingType.ATOMPUB.value());
    parameter.put(SessionParameter.AUTH_HTTP_BASIC, "true");
    parameter.put(SessionParameter.USER, username);
    parameter.put(SessionParameter.PASSWORD, password);
    System.out.println("Pfft");
    List<Repository> repositories = factory.getRepositories(parameter);
    System.out.println("repositories: " + repositories.size());
    return repositories.get(0).createSession();
}

For the complete exception stacktrace, please see below:

Exception in thread "main" org.apache.chemistry.opencmis.commons.exceptions.CmisUnauthorizedException: Unauthorized at org.apache.chemistry.opencmis.client.bindings.spi.atompub.AbstractAtomPubService.convertStatusCode(AbstractAtomPubService.java:466) at org.apache.chemistry.opencmis.client.bindings.spi.atompub.AbstractAtomPubService.read(AbstractAtomPubService.java:619) at org.apache.chemistry.opencmis.client.bindings.spi.atompub.AbstractAtomPubService.getRepositoriesInternal(AbstractAtomPubService.java:782) at org.apache.chemistry.opencmis.client.bindings.spi.atompub.RepositoryServiceImpl.getRepositoryInfos(RepositoryServiceImpl.java:65) at org.apache.chemistry.opencmis.client.bindings.impl.RepositoryServiceImpl.getRepositoryInfos(RepositoryServiceImpl.java:88) at org.apache.chemistry.opencmis.client.runtime.SessionFactoryImpl.getRepositories(SessionFactoryImpl.java:133) at org.apache.chemistry.opencmis.client.runtime.SessionFactoryImpl.getRepositories(SessionFactoryImpl.java:111) at sample.CMISConnect.fillParams(CMISConnect.java:35) at sample.CMISConnect.main(CMISConnect.java:42)


回答1:


Click on the gear icon on the top right of your site page. Goto Site Settings ->Manage site features under 'Site Actions' . In this 'CMIS producer' must be active .




回答2:


Make sure that the 'Cmis Producer" setting is active on SharePoint site. If still the problem persists, you can try NTLM authentication. You can consider the below code :

String atompub_url = "http://<your site>/_vti_bin/cmis/rest/<repository id>?getRepositoryInfo";

//put everything into a HashMap
Map<String, String> parameter = new HashMap<String,String>();
parameter.put(SessionParameter.USER,<username>);
parameter.put(SessionParameter.PASSWORD, <password>);
parameter.put(SessionParameter.ATOMPUB_URL, atompub_url);
parameter.put(SessionParameter.BINDING_TYPE,BindingType.ATOMPUB.value());
parameter.put(SessionParameter.AUTHENTICATION_PROVIDER_CLASS, CmisBindingFactory.NTLM_AUTHENTICATION_PROVIDER);
parameter.put(SessionParameter.REPOSITORY_ID, <repository id>);

SessionFactory factory = SessionFactoryImpl.newInstance();
session = factory.createSession(parameter);


来源:https://stackoverflow.com/questions/24954600/cmisunauthorizedexception-unauthorized-error-using-apache-chemistry-library-i

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!