Hi Srinivas,

The best example is the StandardAuthenticationProvider [1]. Either copy and modify it or extend it. If you want to enhance the UsernameToken, you have to override the getSOAPHeaders() method, not the getHTTPHeaders() method.


Florian


[1] https://svn.apache.org/repos/asf/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/StandardAuthenticationProvider.java



Hello Florian,
Do we have any example for the custom authentication?, I tried to
create custom authentication and use that but I am getting error that
its missing credentials

public static final String CUSTOM_AUTHENTICATION_PROVIDER =
"com.eohhs.cmis.example.MyAuthenticationProvider";


parameter.put(SessionParameter.AUTHENTICATION_PROVIDER_CLASS,CUSTOM_AUTHENTICATION_PROVIDER);
parameter.put("com.eohhs.cmis.example.user", "testuser"); //
MyAuthenticationProvider can get and evaluate this
parameter.put("com.eohhs.cmis.example.password", "testpassword");
parameter.put(SessionParameter.BINDING_TYPE,
BindingType.WEBSERVICES.value());

thanks
Srinivas

MYAUTHENTICATIONPROVIDER - CLASS

package com.eohhs.cmis.example;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import

org.apache.chemistry.opencmis.client.bindings.spi.AbstractAuthenticationProvider;

public class MyAuthenticationProvider extends
AbstractAuthenticationProvider {

 public String user, password;
 @Override
 public Map getHTTPHeaders(String url) {
 Map result = new HashMap();
 // get user and password
               user = getUser();
               password = getPassword();
 String appId="testappid";

                List lUser = new ArrayList();
 List lPwd = new ArrayList();
 List lappID = new ArrayList();
               lUser.add(user);
 lPwd.add(password);
 lappID.add(appId);

result.put(org.apache.chemistry.opencmis.commons.SessionParameter.USER,
lUser);
result.put(org.apache.chemistry.opencmis.commons.SessionParameter.PASSWORD,
lPwd);
 result.put("mass.gov.eohhs.edm.edmAppID", lappID);
                return result;
 //return super.getHTTPHeaders(url);
 }
}

On Thu, Nov 1, 2012 at 4:11 PM, Florian Müller  wrote:
 Hi Srinivas,

It looks like your server is using Basic Authentication (or something
similar). The status code 401 is not returned by the Web Services
server, but by some other component that looks at the HTTP headers. Is
this intentional? Do you have any reverse proxy in front of your
service or some SSO setup in place?

 It may also use UsernameTokens but it doesn't seem to reach that
check.
 OpenCMIS does also send Basic Authentication credentials, but it
assumes that the UsernameTokens credentials and the Basic
Authentication credentials are the same. If that's not the case, you
have to code that into your own authentication provider.

 Florian

 Hello Florian,
 Thanks for the info, I still have some issue, I cant get the cmis
client to
 send the username and password at all, I get authorization failed,
below is
 the snippet of the code. please let me know if you see anything
incorrect,
 the user and password work fine if I use it in SoapUI, I checked the
soap
xml at the CMIS Webservice and it does not have username and password
tag
 coming in at all
 thanks
 Srinivas

 SessionFactory f = SessionFactoryImpl.newInstance();
 Map  parameter = new HashMap();
   String wsdl = "http://IP:8100/cmis/services/RepositoryService?wsdl
[2]";
   parameter.put(SessionParameter.USER, "username");
 parameter.put(SessionParameter.PASSWORD, "password");
   parameter.put(SessionParameter.BINDING_TYPE,
 BindingType.WEBSERVICES.value());
 parameter.put(SessionParameter.WEBSERVICES_ACL_SERVICE, wsdl);
   parameter.put(SessionParameter.WEBSERVICES_DISCOVERY_SERVICE,
wsdl);
 parameter.put(SessionParameter.WEBSERVICES_MULTIFILING_SERVICE,
wsdl);
   parameter.put(SessionParameter.WEBSERVICES_NAVIGATION_SERVICE,
wsdl);
 parameter.put(SessionParameter.WEBSERVICES_OBJECT_SERVICE, wsdl);
   parameter.put(SessionParameter.WEBSERVICES_POLICY_SERVICE, wsdl);
 parameter.put(SessionParameter.WEBSERVICES_RELATIONSHIP_SERVICE,
wsdl);
   parameter.put(SessionParameter.WEBSERVICES_REPOSITORY_SERVICE,
wsdl);
parameter.put(SessionParameter.WEBSERVICES_VERSIONING_SERVICE, wsdl);
   parameter.put(SessionParameter.REPOSITORY_ID, "repo_dev");
 Session s = f.createSession(parameter);
   System.out.println("CMISTest.main()"+s.getRepositoryInfo());
 System.out.println("done!");

 Error:
 Exception in thread "main"
org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException:
 Error: The server sent HTTP status code 401: Unauthorized
 at


org.apache.chemistry.opencmis.client.bindings.spi.webservices.RepositoryServiceImpl.getRepositoryInfos(RepositoryServiceImpl.java:76)
   at


org.apache.chemistry.opencmis.client.bindings.impl.RepositoryServiceImpl.getRepositoryInfos(RepositoryServiceImpl.java:85)
 at


org.apache.chemistry.opencmis.client.runtime.SessionFactoryImpl.getRepositories(SessionFactoryImpl.java:111)
   at


org.apache.chemistry.opencmis.client.runtime.SessionFactoryImpl.getRepositories(SessionFactoryImpl.java:98)
 at com.eohhs.cmis.example.CMISTest.main(CMISTest.java:66)
Caused by: com.sun.xml.ws.client.ClientTransportException: The server
sent
 HTTP status code 401: Unauthorized
 at


com.sun.xml.ws.transport.http.client.HttpTransportPipe.checkStatusCode(HttpTransportPipe.java:203)
   at


com.sun.xml.ws.transport.http.client.HttpTransportPipe.process(HttpTransportPipe.java:179)
 at


com.sun.xml.ws.transport.http.client.HttpTransportPipe.processRequest(HttpTransportPipe.java:94)
   at


com.sun.xml.ws.transport.DeferredTransportPipe.processRequest(DeferredTransportPipe.java:116)
 at com.sun.xml.ws.api.pipe.Fiber.__doRun(Fiber.java:598)
   at com.sun.xml.ws.api.pipe.Fiber._doRun(Fiber.java:557)
 at com.sun.xml.ws.api.pipe.Fiber.doRun(Fiber.java:542)
   at com.sun.xml.ws.api.pipe.Fiber.runSync(Fiber.java:439)
 at com.sun.xml.ws.client.Stub.process(Stub.java:222)
   at com.sun.xml.ws.client.sei.SEIStub.doProcess(SEIStub.java:135)
 at


com.sun.xml.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:109)
   at


com.sun.xml.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:89)
 at com.sun.xml.ws.client.sei.SEIStub.invoke(SEIStub.java:118)
   at $Proxy40.getRepositories(Unknown Source)
 at


org.apache.chemistry.opencmis.client.bindings.spi.webservices.RepositoryServiceImpl.getRepositoryInfos(Repository

 On Wed, Oct 31, 2012 at 12:40 PM, Florian Müller  wrote:

 Hi Srinivas,

 You need your own authentication provider for that.

 Have a look at this class:
 org.apache.chemistry.opencmis.**client.bindings.spi.**

 StandardAuthenticationProvider

 The getSOAPHeaders() method generates the SOAP header. It should be
easy
 to add an additional tag there.

 You activate your custom authentication provider like this:

 parameter.put(**SessionParameter.**AUTHENTICATION_PROVIDER_CLASS,
 "com.example.custom.**authentication.provider");

 You can also add your custom session parameters (->  AppID) and
access them
 in the authentication provider.

 - Florian

   Hello I am new to this forum, If I have posted to the wrong
address,

 please
 direct me to the correct forum, I am writing a client using apache
 chemistry and I am having hard time in sending a custom element in
the
 username token
  
   myuser
                   mypassword
                   testappid

 How do I send in the AppID in the UsernameToken element, below only
has
 USER and PASSWORD. the AppID is of a different namespace

 parameter.put(**SessionParameter.USER, "myuser");
 parameter.put(**SessionParameter.PASSWORD, "mypassword");

 your input is greatly appreciated.
 thanks
 --
 Srinivas

Reply via email to