当用户名和密码位于数据库中时,JAX-WS 和 BASIC 身份验证
我是 JAX-WS 的新手,有件事我不明白。
有大量关于如何设置 JAX-WS 安全性的教程,但在几乎所有情况下 BindingProvider.USERNAME_PROPERTY 和 BindingProvider.PASSWORD_PROPERTY 都存储在一些 .xml 文件中(取决于我认为的容器) - 它们是“硬编码的”那是。这就是我不明白的。如何通过将 BindingProvider.USERNAME_PROPERTY 和 BindingProvider.PASSWORD_PROPERTY 与数据库中的用户名和密码进行比较来验证 Web 服务客户端?我尝试在客户端设置 BindingProvider.USERNAME_PROPERTY 和 BindingProvider.PASSWORD_PROPERTY 如下:
ShopingCartService scs = new ShopingCartService(wsdlURL, name);
ShopingCart sc = scs.getShopingCartPort();
Map<String, Object> requestContext = ((BindingProvider)sc).getRequestContext();
requestContext.put(BindingProvider.USERNAME_PROPERTY, userName);
requestContext.put(BindingProvider.PASSWORD_PROPERTY, password);
sc.someFunctionCall();
然后,在服务器端检索如下:
@Resource
WebServiceContext wsContext;
@WebMethod
public void someFunctionCall() {
MessageContext mc = wsContext.getMessageContext();
mc.get(BindingProvider.USERNAME_PROPERTY);
mc.get(BindingProvider.PASSWORD_PROPERTY);
}
但我总是得到 null,我没有在 xml 中设置任何内容,Web 服务工作得很好,除了我无法获取这些变量:(
我在 java 1.6、tomcat 6 和 JAX- 上运行WS
非常感谢使用数据库中的密码对用户进行身份验证的任何帮助, 谢谢。
I'm new to JAX-WS and there's a thing which I don't understand.
There's a ton of tutorials available on how to set up JAX-WS security, but in pretty much all cases BindingProvider.USERNAME_PROPERTY and BindingProvider.PASSWORD_PROPERTY are stored in some .xml file(depending on the container I believe) - they are "hardcoded" that is. And that's what I don't get. How can I authenticate a web service client by comparing BindingProvider.USERNAME_PROPERTY and BindingProvider.PASSWORD_PROPERTY with a user name and password that's in a database? I tried setting BindingProvider.USERNAME_PROPERTY and BindingProvider.PASSWORD_PROPERTY on the client side like this:
ShopingCartService scs = new ShopingCartService(wsdlURL, name);
ShopingCart sc = scs.getShopingCartPort();
Map<String, Object> requestContext = ((BindingProvider)sc).getRequestContext();
requestContext.put(BindingProvider.USERNAME_PROPERTY, userName);
requestContext.put(BindingProvider.PASSWORD_PROPERTY, password);
sc.someFunctionCall();
And then, on the server side retrieving like this:
@Resource
WebServiceContext wsContext;
@WebMethod
public void someFunctionCall() {
MessageContext mc = wsContext.getMessageContext();
mc.get(BindingProvider.USERNAME_PROPERTY);
mc.get(BindingProvider.PASSWORD_PROPERTY);
}
But I always get null, I didn't set up anything in xml, web service works just fine, except I can't get those variables :(
I'm running both on java 1.6, tomcat 6 and JAX-WS.
Any help with authenticating users with passwords from a database is greatly appreciated,
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
我认为您正在寻找应用程序级别的 JAX-WS 身份验证,而不是服务器级别的 HTTP 基本身份验证。请参阅以下完整示例:
使用 JAX-WS 进行应用程序身份验证
在Web服务客户端站点上,只需将您的“用户名”和“密码”放入请求标头中即可。
在Web服务服务器站点上,通过WebServiceContext获取请求标头参数。
I think you are looking for JAX-WS authentication in application level, not HTTP basic in server level. See following complete example :
Application Authentication with JAX-WS
On the web service client site, just put your “username” and “password” into request header.
On the web service server site, get the request header parameters via WebServiceContext.
BindingProvider.USERNAME_PROPERTY 和 BindingProvider.PASSWORD_PROPERTY 与 HTTP 基本身份验证机制匹配,该机制在 HTTP 级别启用身份验证过程,而不是在应用程序或 servlet 级别。
基本上,只有 HTTP 服务器知道用户名和密码(并最终根据 HTTP/应用程序服务器规范(例如 Apache/PHP)来应用程序)。
使用 Tomcat/Java,在 web.xml 中添加登录配置 BASIC 和适当的安全约束/安全角色(稍后将与真实用户的用户/组关联的角色)。
然后,将 HTTP 服务器(或应用程序服务器)级别的领域与适当的用户存储库连接起来。对于 tomcat,您可以查看可能适合您需求的 JAASRealm、JDBCRealm 或 DataSourceRealm。
http://tomcat.apache.org/tomcat-6.0-doc/realm -howto.html
BindingProvider.USERNAME_PROPERTY and BindingProvider.PASSWORD_PROPERTY are matching HTTP Basic Authentication mechanism that enable authentication process at the HTTP level and not at the application nor servlet level.
Basically, only the HTTP server will know the username and the password (and eventually application according to HTTP/application server specification, such with Apache/PHP).
With Tomcat/Java, add a login config BASIC in your web.xml and appropriate security-constraint/security-roles (roles that will be later associated to users/groups of real users).
Then, connect the realm at the HTTP server (or application server) level with the appropriate user repository. For tomcat you may look at JAASRealm, JDBCRealm or DataSourceRealm that may suit your needs.
http://tomcat.apache.org/tomcat-6.0-doc/realm-howto.html
我遇到了同样的问题,并在这里找到了解决方案:
http://www.mastertheboss.com/web-interfaces/336-jax-ws-basic-authentication.html?start=1
祝你好运
I had the same problem, and found the solution here :
http://www.mastertheboss.com/web-interfaces/336-jax-ws-basic-authentication.html?start=1
good luck
有关同时使用应用程序级别身份验证和 HTTP 基本身份验证的示例,请参阅我的一篇之前的帖子。
For an example using both, authentication on application level and HTTP Basic Authentication see one of my previous posts.
我遇到了类似的情况,我需要向我的 WS 提供:用户名、密码和 WSS 密码类型。
我最初使用“Http Basic Auth”(如@ahoge),我尝试使用@Philipp-Dev 的参考。也。我没有得到成功的解决方案。
在谷歌进行了一番深入搜索后,我发现了这篇文章:
https://stackoverflow.com/a/3117841/1223901
这是我的问题解决方案,
我希望这对其他人有帮助,就像对我有帮助一样。
平均值,
爱维
I was face-off a similar situation, I need to provide to my WS: Username, Password and WSS Password Type.
I was initially using the "Http Basic Auth" (as @ahoge), I tried to use the @Philipp-Dev 's ref. too. I didn't get a success solution.
After a little deep search at google, I found this post:
https://stackoverflow.com/a/3117841/1223901
And there was my problem solution
I hope this can help to anyone else, like helps to me.
Rgds,
iVieL
在客户端 SOAP 处理程序中,您需要设置 javax.xml.ws.security.auth.username 和 javax.xml.ws.security.auth.password 属性,如下所示:
In your client SOAP handler you need to set javax.xml.ws.security.auth.username and javax.xml.ws.security.auth.password property as follow:
如果您将客户端的用户名和密码以这种方式放入请求中:
并调用您的Web服务
然后您可以在服务器端读取像这样的基本身份验证字符串(您必须添加一些检查并执行一些异常处理):
If you put the username and password at clientside into the request this way:
and call your webservice
Then you can read the Basic Authentication string like this at the server side (you have to add some checks and do some exceptionhandling):