gpt4 book ai didi

java - 验证 JAX-WS Web 服务中的凭据

转载 作者:太空宇宙 更新时间:2023-11-04 15:23:20 27 4
gpt4 key购买 nike

我想在 Java Web 服务操作中验证用户和密码值。凭证必须位于数据库中,但为了避免多次调用该层,我有一个缓存。我一直在考虑使用过滤器 ( http://viralpatel.net/blogs/tutorial-java-servlet-filter-example-using-eclipse-apache-tomcat/ ) 并将此过滤器映射到充当端点的 servlet,但这样来 self 的端点的所有操作都必须使用此过滤器。如果一项操作不需要验证怎么办?

我在 http://docs.oracle.com/cd/E19226-01/820-7627/bnccv/index.html 的示例中发现了这一点web.xml 中使用以下内容:

<auth-constraint>
<role-name>SomeName</role-name>
</auth-constraint>

我可以使用角色进行身份验证,但必须在应用程序服务器中添加用户,而我不希望这样做。

最好的选择是什么?

谢谢

最佳答案

一种选择是使用 HTTP header ,您可以在其中发送用户名和密码等参数。使用 webservicecontext,您可以访问 HTTP_REQUEST_HEADERS。

@Resource
WebServiceContext wsctx;

@Override
public String callOperation() {

MessageContext mctx = wsctx.getMessageContext();

//get detail from request headers
Map http_headers = (Map) mctx.get(MessageContext.HTTP_REQUEST_HEADERS);
List userList = (List) http_headers.get("Username");
List passList = (List) http_headers.get("Password");


String username = "";
String password = "";
// do whatever you want with user and password

希望这对其他人有帮助。

关于java - 验证 JAX-WS Web 服务中的凭据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20144312/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com