我在 Tomcat 6 下部署了一个 Web 服务,它运行良好。 现在我想验证任何客户端,但通过 URL 将 wsdl 保持在公共(public)访问状态 http://localhost:8080/services/MyService?wsdl
我试过这样解决问题(webapp的web.xml),但是不行:
<security-constraint>
<web-resource-collection>
<web-resource-name>WSDL access - to anybody</web-resource-name>
<url-pattern>/services/MyService?wsdl</url-pattern>
</web-resource-collection>
<auth-constraint><role-name>*</role-name></auth-constraint>
</security-constraint>
<security-constraint>
<web-resource-collection>
<web-resource-name>Some authentification required</web-resource-name>
<url-pattern>/services/MyService</url-pattern>
</web-resource-collection>
<auth-constraint><role-name>somebody</role-name></auth-constraint>
</security-constraint>
目前我看到的唯一解决方案是创建额外的 servlet 并赋予一个访问 WSDL 的权限。 servlet 会将所需的 wsdl 传递给客户端,无论它是否经过身份验证。在这种情况下 WSDL URL 不会很明显,所以我不喜欢这个解决方案。还有其他建议吗?
最佳答案
我遇到了类似的问题,我已经找到了解决方案。 WebServices 方法通过 POST 调用,而 WSDL 通过 GET 获取。所以解决方案是只限制 POST 访问。
security-constraint>
<web-resource-collection>
<web-resource-name>Some authentification required</web-resource-name>
<url-pattern>/services/MyService</url-pattern>
<http-method>POST</http-method>
</web-resource-collection>
<auth-constraint><role-name>somebody</role-name></auth-constraint>
</security-constraint>
我将 WebSphere 7 与 JAXWS 结合使用,但 web.xml 配置对于所有容器和应用程序服务器都是相同的。
关于java - 如何限制对 wsdl 以外的所有内容的访问?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7315033/