我一直在尝试使用 GlassFish 作为 Web 服务器和 SOAP UI 来实现基于数字证书的身份验证和授权,以测试我的应用程序的功能,但作为身份验证过程的一部分,我需要保存所有消息信息的日志,包括在来自使用 Web 服务的客户端的 glassfish 的 cacerts 文件中找到的别名和消息的内容。
是否真的可以从应用层做到这一点?我尝试在服务器端使用消息和逻辑处理程序,但我看不到与数字证书相关的任何内容,我唯一的线索是 SOAP UI 从客户端获取服务器证书。
最佳答案
经过一些研究和一些失败后,我最终将证书详细信息添加到 Web 描述符上的项目并从中捕获用户名,然后找到该用户名的别名,最后在 TrustStore 中搜索别名以获取公钥。
首先我们需要在 web.xml 文件中添加身份验证的详细信息:
<!-- Security constraint for resource only accessible to role -->
<security-constraint>
<display-name>WebServiceSecurity</display-name>
<web-resource-collection>
<web-resource-name>Authorized users only</web-resource-name>
<url-pattern>/ExampleWSService</url-pattern>
<http-method>POST</http-method>
</web-resource-collection>
<auth-constraint>
<role-name>user</role-name>
</auth-constraint>
</security-constraint>
<!-- BASIC authorization -->
<login-config>
<auth-method>CLIENT-CERT</auth-method>
</login-config>
<!-- Definition of role -->
<security-role>
<role-name>user</role-name>
</security-role>
在 sun-web.xml 中,我们添加了角色映射和来自客户端的详细信息,这可以使用公钥检索。
<sun-web-app>
<security-role-mapping>
<role-name>user</role-name>
<!-- <group-name>wsusers</group-name> -->
<principal-name>CN=Name, OU=Department, O=Organization, L=City, ST=State, C=nl</principal-name>
</security-role-mapping>
<security-role-mapping>
<role-name>user</role-name>
<group-name>wsusers</group-name>
</security-role-mapping>
</sun-web-app>
基于本教程:http://javaeenotes.blogspot.com/2010/10/securing-jax-ws-web-services.html
关于java - 是否可以从 SOAP Web 服务保存客户端证书?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31863633/