我怎样才能让 jcifs 与 apache axis 很好地配合
我需要将 Apache Axis 1.4 连接到使用 NTLM 身份验证来限制对其操作的访问的 Web 服务。 我期望使用 Samba Jcifs 来处理 NTLM 握手。
我发现
http://hc.apache.org/httpcomponents-client/ntlm.html< /a>
这为我提供了如何将 HttpClient 4.0 与 jcifs 连接起来的精彩指导。
问题是,Axis 希望使用 Http Client 3.0,而这两个 api 看起来非常不同。
我可以看到有两种可能性:
- 为 Axis 编写一个对象,让它插入 HttpClient 4。
- 弄清楚如何将 HttpClient 3.0 与 Samba Jcifs 连接起来。
第 1 点:看起来不平凡,但有可能 第二,我在网上找不到任何描述如何做到这一点的令人鼓舞的消息。
我的问题是:有人成功将 samba jcifs 与 HttpClient 3.0 连接吗? 是否有人已经创建了与 HttpClient 4 一起使用的 Axis HttpSender 对象?
还有其他我没有考虑过的更好的选择吗?
I need to connect Apache Axis 1.4 to a Webservice that uses NTLM authentication to restrict access to its operations.
I'm expecting to use Samba Jcifs to handle the NTLM handshake.
I found
http://hc.apache.org/httpcomponents-client/ntlm.html
which gives me fantastic directions for how to wire up HttpClient 4.0 with jcifs.
Trouble is, Axis wants to use Http Client 3.0 and the two apis look very different.
There are 2 possibilities that I can see
- Write an object for Axis that lets it plug into HttpClient 4.
- Figure out how to wire HttpClient 3.0 up with Samba Jcifs.
Number 1. looks non-trivial, but possible
Number 2. I cannot find any encouraging messages on the web describing how to do this.
My question is: has anyone successfully connected samba jcifs with HttpClient 3.0 ?
Has anyone already created an Axis HttpSender object that works with HttpClient 4 ?
Is there some better alternative that I have not considered?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
终于有办法解决这个问题了。
问题
Apache Axis 使用 Apache
HTTPClient
,它提供了自己的 NTLM 实现。然而这个实现是不完整的; 仅支持原始LM认证。
我需要连接的系统坚持使用更新的 NTLM 身份验证。
因此,在使用带有 NTLM 的 Apache HTTP 客户端时,我的 Web 服务无法进行身份验证。
这实际上会进入无限循环,因为
HTTPClient
将永远不会停止尝试身份验证并失败。解决方案
jcifs 完全支持所有 3 个版本的 NTLM 握手。
我已将 org.apache.commons.httpclient.auth.NTLM 复制并粘贴到我自己的类中(它被声明为“final”以击败继承),
然后我将该方法覆盖
为构造
jcifs.ntlmssp.Type3Message
的实例并使用此对象返回已正确生成 NTML 身份验证的
Type3Message
。然后我需要创建自己的 org.apache.commons.httpclient.auth.AuthScheme 实例
利用这个新的 NTLM 实现。 称呼
org.apache.commons.httpclient.auth.AuthPolicy.registerAuthScheme(AuthPolicy.NTLM, MyNewAuthScheme.class)
启动我的 WS 端点存根。
它有效!
Finally have a solution to this.
The problem
Apache Axis uses Apache
HTTPClient
which provides its own NTLM implementation.However this implementation is incomplete; it only supports the primitive LM authentication.
The system I need to connect to insists upon the more recent NTLM authentication.
Therefore my Webservice was failing to authenticate when using the Apache HTTP Client with NTLM.
This actually then enters an infinite loop as the
HTTPClient
will never stop trying and failing to authenticate.The solution
jcifs fully supports all 3 versions of the NTLM handshake.
I have copy-and-pasted
org.apache.commons.httpclient.auth.NTLM
into my own class (it is declared as 'final' in order to defeat inheritance)I have then overwritten the method
to construct an instance of
jcifs.ntlmssp.Type3Message
and use this object to return a
Type3Message
that has the NTML authentication correctly generated.I then needed to create my own instance of
org.apache.commons.httpclient.auth.AuthScheme
to make use of this new NTLM implementation. call
org.apache.commons.httpclient.auth.AuthPolicy.registerAuthScheme(AuthPolicy.NTLM, MyNewAuthScheme.class)
start up my WS endpoint stub.
And it works !!!
为了回应谢尔盖的评论......
我的解决方案中有两个课程。 像这样的授权方案
和一个注册授权方案的类,就像这样
在运行时我调用
我构建我的端点存根,它就可以工作。
作为一个有益的副作用,如果身份验证失败,这将简单地抛出异常 - 默认 Apache Commons 类将继续尝试无限连接 - 在 NTLM 的情况下,这很容易导致您的帐户被 Windows 锁定。
In response to Sergey's comment...
I have two clases in my solution. An Authorisation Scheme like this
And a class to register the authorisation scheme, like this
At runtime I call
I construct my endpoint stub, and it just works.
As a beneficial side-effect this will simply chuck an exception if if fails to authenticate - the Default Apache Commons class will keep trying to connect infinitely - which in the case of NTLM can easily lead to your account being locked out from windows.
非常感谢本,干得好。
对于我的解决方案,根据您的课程,我需要 2 项改进。
1) class JcifsNtlmScheme
jcifs中的接口发生了变化(我使用1.3.14版本)。
NTLM 标志是必需的,我不太确定,但 0x82 对我有用。
2) class NtlmJcifsCredentials
这对于第一次连接来说效果很好。 这似乎是一个全球性的环境。 它可能不是真正的线程安全。
我需要连接基础上的凭据。 所以我删除了这个类,并在创建 webservice 存根后直接插入内置的 Authenticator:
Thank yo very much Ben, good work.
For my solution I need 2 improvements, based on your classes.
1) class JcifsNtlmScheme
The interface has changed in jcifs (I use version 1.3.14).
The NTLM flag is required, I'm not really sure but 0x82 works for me.
2) class NtlmJcifsCredentials
This works fine for the first connection. It seems to be a global setting. It's probably not really thread-safe.
I need the credentials on connections base. So I dropped this class and inserted the built-in Authenticator directly after creation of the webservice stub:
我已经让它工作了,但我还没有在 HTTP 中实现代理服务器支持。
http://www.magsoft.nl/share/Axis2%20patch.zip
我使用的所有 jar 都位于项目 lib 目录中。
有一些类路径要求。 首先,Axis2 HTTPClient4 patch.jar 必须位于轴 jar 之上。 此外,commons-httpclient-3.1.jar 仍需要位于类路径中,但在 httpclient-4 jar 之后。
以下是我实现客户端的方法:
但是要使其工作,您将需要以下树类:
NTLMSchemeFactory.java
JCIFSScheme.java
JCIFSEngine.java
I've got it working, but I did NOT yet implement proxy server support in the HTTP.
http://www.magsoft.nl/share/Axis2%20patch.zip
All the jars I use are in the project lib directory.
There are some class path requirements. First the Axis2 HTTPClient4 patch.jar has to be above the axis jars. Furthermore, commons-httpclient-3.1.jar needs to be still in the classpath, but after the httpclient-4 jars.
Here is how I implemented the client:
But for this to work you will need the following tree classes:
NTLMSchemeFactory.java
JCIFSScheme.java
JCIFSEngine.java
这个 Axis2Patch.zip 是一个真正的救星。
这就是我所做的:
使用内置 NTLMv2 的 httpclient4.1 beta1 编译 Axis2Patch。
将其导入我的项目并导入 httpclient4.1beta1 。
我像这样更改了导入:
并且无需进行太多代码更改即可完美运行。
谢谢!
This Axis2Patch.zip has been a real lifesaver.
This is what I did:
Compiled Axis2Patch with httpclient4.1 beta1 which has NTLMv2 build in.
Imported that into my project and imported httpclient4.1beta1 also.
I changed my imports like this:
and without too much code change it works perfectly.
Thanks!