【发布时间】:2014-10-15 02:03:34
【问题描述】:
我正在尝试使用Apache CXF 中提到的 NTLM 身份验证对 SOAP Web 服务进行身份验证,堆栈如下 -
- jcifs-1.3.17.jar
- cxf-2.7.11
- NTLM + SSL
- JDK 5(我可能无法更改)
每次我尝试连接时,它都会拒绝 401 未经授权的访问,因为它使用了我未经授权的底层 NT 凭据,而不是我在代码中配置的有效凭据。 (我不得不修改 jCIFS,因为它不支持 SSL + NTLM 以返回 NtlmHttpURLConnection 的 HTTPs 版本)。使用 HTTP 异步机制时的类似结果。
String domainController = "xxx.xxx.xxx";
UniAddress dc = UniAddress.getByName(domainController, true);
jcifs.Config.setProperty("http.auth.ntlm.domain", "xxx.xxx.xxx");
jcifs.Config.setProperty("jcifs.smb.client.domain", "domain");
jcifs.Config.setProperty("jcifs.netbios.wins", dc.getHostAddress());
jcifs.Config.setProperty("jcifs.smb.client.soTimeout", "300000"); // 5 minutes
jcifs.Config.setProperty("jcifs.netbios.cachePolicy", "1200"); // 20 minutes
jcifs.Config.setProperty("jcifs.smb.client.username", USER);
jcifs.Config.setProperty("jcifs.smb.client.password", PWD);
//Register the jcifs URL handler to enable NTLM
jcifs.Config.registerSmbURLHandler();
HelloWorld src = new HelloWorld();
ClientProxyFactoryBean factory = new ClientProxyFactoryBean(new JaxWsClientFactoryBean());
factory.setServiceClass( IHelloWorld.class );
factory.setAddress(SERVICE_URL);
factory.setUsername(USER);
factory.setPassword(PWD);
IHelloWorld service = (IHelloWorld ) factory.create();
Client client = ClientProxy.getClient(service);
HTTPConduit http = (HTTPConduit) client.getConduit();
System.out.println(http.getClass().getName());
//org.apache.cxf.transport.http.URLConnectionHTTPConduit
HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
httpClientPolicy.setConnectionTimeout(36000);
httpClientPolicy.setAllowChunking(false);
http.setClient(httpClientPolicy);
http.getAuthorization().setAuthorizationType("NTLM");
http.getAuthorization().setUserName(USER);
http.getAuthorization().setPassword(PWD);
http.getClient().setAllowChunking( false );
http.getClient().setAutoRedirect( true );
TLSClientParameters tcp = new TLSClientParameters();
tcp.setTrustManagers( new TrustManager[]{ new TrustAllX509TrustManager() } );
http.setTlsClientParameters( tcp );
System.out.println("Invoking service...");
String msg= "echo";
try {
String res = service.readMessage(msg);
System.out.println("readMessage.result=" + res);
} catch (Exception e) {
e.printStackTrace();
}
运行此代码后,我得到以下异常跟踪
: domain\ 是未经授权的用户 sun.reflect.NativeConstructorAccessorImpl.newInstance0(本机方法) 在 sun.reflect.NativeConstructorAccessorImpl.newInstance(未知 来源)在 sun.reflect.DelegatingConstructorAccessorImpl.newInstance(未知 来源)在 java.lang.reflect.Constructor.newInstance(未知来源) 在 org.apache.cxf.interceptor.ClientFaultConverter.processFaultDetail(ClientFaultConverter.java:175) 在 org.apache.cxf.interceptor.ClientFaultConverter.handleMessage(ClientFaultConverter.java:78) 在 org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:272) 在 org.apache.cxf.interceptor.AbstractFaultChainInitiatorObserver.onMessage(AbstractFaultChainInitiatorObserver.java:113) 在 org.apache.cxf.binding.soap.interceptor.CheckFaultInterceptor.handleMessage(CheckFaultInterceptor.java:69) 在 org.apache.cxf.binding.soap.interceptor.CheckFaultInterceptor.handleMessage(CheckFaultInterceptor.java:34) 在 org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:272) 在 org.apache.cxf.endpoint.ClientImpl.onMessage(ClientImpl.java:845) 在 org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponseInternal(HTTPConduit.java:1624) 在 org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponse(HTTPConduit.java:1513) 在 org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.close(HTTPConduit.java:1318) 在 org.apache.cxf.transport.AbstractConduit.close(AbstractConduit.java:56) 在 org.apache.cxf.transport.http.HTTPConduit.close(HTTPConduit.java:632) 在 org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor.handleMessage(MessageSenderInterceptor.java:62) 在 org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:272) 在 org.apache.cxf.endpoint.ClientImpl.doInvoke(ClientImpl.java:570) 在 org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:479) 在 org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:382) 在 org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:335) 在 org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:96) 在 org.apache.cxf.frontend.ClientProxy.invoke(ClientProxy.java:81) 在 com.sun.proxy.$Proxy44.readMessage(Unknown Source)
【问题讨论】:
标签: ssl cxf soap-client ntlm jcifs