Kim Monnens created CXF-5890:
--------------------------------

             Summary: NTLM authentication does not work
                 Key: CXF-5890
                 URL: https://issues.apache.org/jira/browse/CXF-5890
             Project: CXF
          Issue Type: Bug
          Components: Core
    Affects Versions: 3.0.0
         Environment: Java: jdk1.7.0_13
Application server: Tomcat 6 / Weblogic 12.1.1
Operating system: Windows 7
            Reporter: Kim Monnens
            Priority: Blocker


>From a MicroSoft SharePoint WSDL I have generated java web service and client 
>using wsdl2java.

On SharePoint (HTTP protocol) NTLM is enabled and I need to provide a specific 
username and password.

I have tried several solutions that I could find, but none of them seem to work.

Here is most of the code that I have tested. The result of the method should 
return the status of the server.

{code}
public String getStatus() {
        try {
                Authenticator.setDefault(new Authenticator() { 
                        protected PasswordAuthentication 
getPasswordAuthentication() { 
                                return new PasswordAuthentication 
("DOMAIN\MY_USER", "MY_PASSWORD".toCharArray()); 
                        } 
                });
                
                QueryService queryService = new QueryService();
                QueryServiceSoap port = queryService.getQueryServiceSoap();
                BindingProvider bindingProvider = (BindingProvider) port;
                
bindingProvider.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, 
"DOMAIN\MY_USER");
                
bindingProvider.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, 
"MY_PASSWORD");
                
//bindingProvider.getRequestContext().put("use.async.http.conduit", 
Boolean.TRUE);
                Client client = ClientProxy.getClient(port);
                HTTPConduit conduit = (HTTPConduit) client.getConduit();
                conduit.getClient().setAllowChunking(false);
                //conduit.getClient().setAutoRedirect(true);
                conduit.getAuthorization().setAuthorizationType("NTLM");
                conduit.getAuthorization().setUserName("DOMAIN\MY_USER");
                conduit.getAuthorization().setPassword("MY_PASSWORD");
                
                /*AuthorizationPolicy authorization = new AuthorizationPolicy();
                authorization.setAuthorizationType("NTLM");
                authorization.setUserName("DOMAIN\MY_USER");
                authorization.setPassword("MY_PASSWORD");
                conduit.setAuthorization(authorization);*/
                
                /*HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
                httpClientPolicy.setConnectionTimeout(36000);
                httpClientPolicy.setAllowChunking(false);
                conduit.setClient(httpClientPolicy);*/
                return port.status();
        } catch (Exception e) {
                e.printStackTrace();
        }
        return "";
}
{code}

*Result on Tomcat 6:*
The service returns a result, but is does not use the provided username and 
password. It uses my account, the username name and password that I use to 
login on my PC.)

*Result on Weblogic 12.1.1:*
The service does not return a result, the following exception is thrown:

2014-07-18 08:58:10,503 WARN   org.apache.cxf.phase.PhaseInterceptorChain - 
Interceptor for 
{http://microsoft.com/webservices/OfficeServer/QueryService}QueryService#{http://microsoft.com/webservices/OfficeServer/QueryService}Status
 has thrown exception, unwinding now
org.apache.cxf.interceptor.Fault: Could not send Message.
        at 
org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor.handleMessage(MessageSenderInterceptor.java:64)
        at 
org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:307)
        at org.apache.cxf.endpoint.ClientImpl.doInvoke(ClientImpl.java:514)
        at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:423)
        at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:326)
        at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:279)
        at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:96)
        at 
org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:137)
        at sun.proxy.$Proxy128.status(Unknown Source)
...
Caused by: org.apache.cxf.transport.http.HTTPException: HTTP response '401: 
Unauthorized' when communicating with http://myurl/_vti_bin/search.asmx
        at 
org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponseInternal(HTTPConduit.java:1573)
        at 
org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponse(HTTPConduit.java:1525)
        at 
org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.close(HTTPConduit.java:1330)
        at 
org.apache.cxf.transport.AbstractConduit.close(AbstractConduit.java:56)
        at org.apache.cxf.transport.http.HTTPConduit.close(HTTPConduit.java:638)
        at 
org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor.handleMessage(MessageSenderInterceptor.java:62)
        at 
org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:307)
        at org.apache.cxf.endpoint.ClientImpl.doInvoke(ClientImpl.java:514)
        at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:423)
        at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:326)
        at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:279)
        at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:96)
        at 
org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:137)



--
This message was sent by Atlassian JIRA
(v6.2#6252)

Reply via email to