call a web service after TAM authentication - (401)Unauthorized

call a web service after TAM authentication - (401)Unauthorized

We have a requirement to call a web service running on another websphere 6.1.
Our application runs on a different websphere 6.1 unix box. Between these two boxes, TAM authentication layer exists.
So my application being the client, I am trying to invoke a web service running on another machine.
All my client stubs are generated using Axis.

The web service that we are going to consume is https based web service.
Initially i had a problem in SSL handshake between websphere servers which I resolved successfully by adding the certificates in truststore.

Now to invoke the web service I am using a code as following:
Sample1InterfaceService service = new Sample1InterfaceServiceLocator();
Sample1Interface stub = service.getSample1();
(Sample1SoapBindingStub)stub)._setProperty(javax.xml.rpc.Stub.USERNAME_PROPERTY, domain + "\\" + username);
((Sample1SoapBindingStub)stub)._setProperty(javax.xml.rpc.Stub.PASSWORD_PROPERTY, password);
stub.getGreeting(someinput);

But i constantly get Axisfault error as (401)Unauthorized.
Basically TAM is blocking my requests as it is unable to authenticate (my user credentials are correct.. i have verified it many times. When i call the web service end point url on IE, it prompts for user id/password. On entering the credentials, it shows that web service is running. This also means TAM authenticated successfully and allowed me to pass through. So my credentials are correct).

I was going through this forum and many others and tried to apply various solutions that were proposed.
1) Send the web service endpoint URL as "

2) (Sample1SoapBindingStub)stub).setUsername(domain + "\\" + username);
(Sample1SoapBindingStub)stub).setPassword(password);

I tried the above options, by running a stand alone java program. But I am still getting the same error.
Any ideas what could be the problem?

My Axisfault error is as follows -
Exception in thread "main" AxisFault
faultCode: {http://xml.apache.org/axis/}HTTP
faultSubcode:
faultString: (401)Unauthorized
faultActor:
faultNode:
faultDetail:
{}:return code: 401

Hi - I also tried using JAX-WS.
Generated all JAX-WS stubs.

I am trying to perform the TAM authentication using the following code
Sample1Interface port = service.getSample1SOAP();
BindingProvider theBindingProvider = (BindingProvider)port ;
Map<String, Object> theRequestContext = theBindingProvider.getRequestContext();
theRequestContext.put("javax.xml.ws.security.auth.username", domain + "\\" + user");
theRequestContext.put("javax.xml.ws.security.auth.password", password);
port.getGreeting(someinput);

I am getting the following exception. Any clue?

Exception in thread "P=95493:O=0:CT" javax.xml.ws.WebServiceException: java.lang.StringIndexOutOfBoundsException
at org.apache.axis2.jaxws.ExceptionFactory.createWebServiceException(ExceptionFactory.java:175)
at org.apache.axis2.jaxws.ExceptionFactory.makeWebServiceException(ExceptionFactory.java:70)
at org.apache.axis2.jaxws.ExceptionFactory.makeWebServiceException(ExceptionFactory.java:128)
at org.apache.axis2.jaxws.core.controller.impl.AxisInvocationController.execute(AxisInvocationController.java:559)
at org.apache.axis2.jaxws.core.controller.impl.AxisInvocationController.doInvoke(AxisInvocationController.java:118)
at org.apache.axis2.jaxws.core.controller.impl.InvocationControllerImpl.invoke(InvocationControllerImpl.java:82)
at org.apache.axis2.jaxws.client.proxy.JAXWSProxyHandler.invokeSEIMethod(JAXWSProxyHandler.java:295)
at org.apache.axis2.jaxws.client.proxy.JAXWSProxyHandler.invoke(JAXWSProxyHandler.java:158)
at $Proxy25.getGreeting(Unknown Source)
...
Caused by: java.lang.StringIndexOutOfBoundsException
at java.lang.StringBuffer.substring(StringBuffer.java:779)
at com.ibm.ws.websvcs.transport.http.SOAPOverHTTPSender.receiveSOAPResponse(SOAPOverHTTPSender.java:991)
at com.ibm.ws.websvcs.transport.http.SOAPOverHTTPSender.send(SOAPOverHTTPSender.java:458)
at com.ibm.ws.websvcs.transport.http.HTTPTransportSender.invoke(HTTPTransportSender.java:320)
at org.apache.axis2.engine.AxisEngine.send(AxisEngine.java:446)
at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:401)
at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:228)
at org.apache.axis2.client.OperationClient.execute(OperationClient.java:163)
at org.apache.axis2.jaxws.core.controller.impl.AxisInvocationController.execute(AxisInvocationController.java:554)
... 6 more

Use import javax.xml.rpc.Stub;  
 
Not Sample1SoapBindingStub  
 
 
        javax.xml.rpc.Stub rpcStub = (javax.xml.rpc.Stub) stub;  
          rpcStub._setProperty(javax.xml.rpc.Stub.USERNAME_PROPERTY, "username");  
          rpcStub._setProperty(javax.xml.rpc.Stub.PASSWORD_PROPERTY, "password"); 
Please have a look at

http-://www.ibm.-com/developerworks/tivoli/library/t-ssl/

Taken from the link: "This article will assist integrators and developers programming Web Services using Apache AXIS
that want to add authentication and authorization using Tivoli Access Manager.
In this article, you will reuse an existing sample SOAP/HTTP web service provided by the IBM WebSphere SDK for Web Services,
and then you will configure Tivoli Access Manager WebSEAL to make authentication and authorization on your web service.
Finally you will see how to develop a sample client passing the right parameters to access your secure web service."

It used Https (SSL) + Basic Auth as your use case.

1. The funny part (or a concidence) is that the sample code you used in the original post 1st is identical to the code used in this sample.

view plaincopy to clipboardprint?
Note: Text content in the code blocks is automatically word-wrapped
Send the Basic authentication headers  
 
  // Sample* classes are client proxy classes generated by AXIS from the WSDL  
  Sample1InterfaceService service = new Sample1InterfaceServiceLocator();  
  Sample1Interface stub = service.getSample1();  
    
  // The username and password used here need to be registered in WebSEAL.  
// They are passed dynamically at the client runtime  
  ((Sample1SoapBindingStub)stub)._setProperty(javax.xml.rpc.Stub.USERNAME_PROPERTY, args[0]);  
  ((Sample1SoapBindingStub)stub)._setProperty(javax.xml.rpc.Stub.PASSWORD_PROPERTY, args[1]); 
Send the Basic authentication headers

  // Sample* classes are client proxy classes generated by AXIS from the WSDL
  Sample1InterfaceService service = new Sample1InterfaceServiceLocator();
  Sample1Interface stub = service.getSample1();
 
  // The username and password used here need to be registered in WebSEAL.
// They are passed dynamically at the client runtime
  ((Sample1SoapBindingStub)stub)._setProperty(javax.xml.rpc.Stub.USERNAME_PROPERTY, args[0]);
  ((Sample1SoapBindingStub)stub)._setProperty(javax.xml.rpc.Stub.PASSWORD_PROPERTY, args[1]);

// The username and password used here need to be registered in WebSEAL.

Copyright © 2007-2012 www.chuibin.com Chuibin Copyright