I am calling a web service written in .net located remotely running under IIS Server.
I created its respective stub using apache axis 1.4
with eclipse IDE and created a respective web service client. This is just a test client in actual it will be my web application going to call this web service.
We have kept its two different endpoint for keeping security credential enable/disable.
- "ip:port/pigeon/pigeon.svc;" // authentication disabled
-
"ip:port/pwa/pigeon.svc; // authentiction enabled
So now when I am using endpoint no (1) I am able to call web service and gets things done, but since I want to apply security credential mandatory so when I use endpoint no (2) I am getting below exception
(401)Unauthorized
(401)Unauthorized AxisFault
faultCode: {http://xml.apache.org/axis/}HTTP
faultSubcode:
faultString: (401)Unauthorized
faultActor:
faultNode:
faultDetail: {}:return code: 401
I want to pass credential which are in this format :
1) domain\username
2) password
I tried adding suggestion of other post over here which says set the respective before call method in stub but I am getting the same above mentioned exception.
(mystub)._setProperty(javax.xml.rpc.Stub.USERNAME_PROPERTY, domain +
"\" + username);
(mystub)._setProperty(javax.xml.rpc.Stub.PASSWORD_PROPERTY, password);
Hhowever with some search now I am able to do NTML authentication with java stand alone program invoking my remote .net web service by doing this :
public static void main(String[] args) throws Exception {
String urlStr = “http://example.com/root/action.dll?p1=value1″;
String domain = “”; // May also be referred as realm
String userName = “CHANGE_ME”;
String password = “CHANGE_ME”;
String responseText = getAuthenticatedResponse(urlStr, domain, userName, password);
System.out.println(”response: ” + responseText);
}
private static String getAuthenticatedResponse(final String urlStr, final String domain, final String userName, final String password) throws IOException {
StringBuilder response = new StringBuilder();
Authenticator.setDefault(new Authenticator() {
@Override
public PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(domain + “\\” + userName, password.toCharArray());
}
});
URL urlRequest = new URL(urlStr);
HttpURLConnection conn = (HttpURLConnection) urlRequest.openConnection();
conn.setDoOutput(true);
conn.setDoInput(true);
conn.setRequestMethod(”GET”);
InputStream stream = conn.getInputStream();
BufferedReader in = new BufferedReader(new InputStreamReader(stream));
String str = “”;
while ((str = in.readLine()) != null) {
response.append(str);
}
in.close();
return response.toString();
}
But I am not able to do so with my axis client as stub are generated with wsdl provided by .net web service in my web service client. I tried changing @stub level before invoke() call by modifying according to above demo but it throws same unauthorized exception.
This is just fyi/all that remote IIS server using NTLM authentication technique.
Help expected on windows authentication using java in order to pass security credential to IIS.
[Note : my axis client(java) passes domain\user with password ,this is configured with IIS server on the otherside properly]
Best Answer
The problem is that Axis 1.4 does not implement correctly the NTLM V2 protocol.
I experienced the problem with Sharepoint 2010 web services. I had a client working perfectly with Sharepoint 2007 running on Windows 2003 server. Then, I tested this client with Sharepoint 2010 web services running on Windows 2008 R2 server and they stop working. The error was:
Searching in google, the problem was that Windows 2003 is using NTLM V1 protocol as default, while Windows 2008 R2 was using NTLM V2 as default.
I found the solution and the problem explained perfectly in the following url:
http://devsac.blogspot.com.es/2010/10/supoprt-for-ntlmv2-with-apache.html
The solution is creating the following class to resolve the HttpClient 3.x:
}
Then it was Register the new JCIFS_NTLMScheme class as the replacement for NTLMScheme by using the following command:
Thanks to Sachin's Tech Place