我已在我的计算机中创建了一个 Web 服务。它的网址是
http://localhost:8080/aaa/test?wsdl
我想启用它的一项功能。一旦用户在浏览器中输入网址,它就会要求提供凭据。可以在网络服务中完成吗?
如果是的话,有人可以指导如何实现它吗?
谢谢。
最佳答案
如果您已经在使用 Spring,您可以轻松申请 basic authentication使用 Spring Security 到特定的 URL 模式。在您的 applicationContext.xml
中,只需添加:
<beans:beans xmlns="http://www.springframework.org/schema/security"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-3.0.3.xsd">
<!-- HTTP basic authentication in Spring Security -->
<http>
<intercept-url pattern="/*wsdl?" access="ROLE_USER" />
<http-basic />
</http>
<authentication-manager>
<authentication-provider>
<user-service>
<user name="someUser" password="somePassword" authorities="ROLE_USER" />
</user-service>
</authentication-provider>
</authentication-manager>
</beans:beans>
示例取自 Mkyong's Spring Security HTTP Basic Authentication Example .
如果您想在数据库中查找用户,则需要使用不同的身份验证提供程序。 Spring Security reference如果您想查询standard Spring Security user data tables,请提及data-source-ref
。如果您已经有了自己的结构,您可能有兴趣使用 user-service-ref
来代替,您可以在其中自己查找用户。
<authentication-manager>
<authentication-provider user-service-ref='myUserDetailsService'/>
</authentication-manager>
<beans:bean id="myUserDetailsService"
class="mypackage.MyUserDetailsService">
<beans:property name="dataSource" ref="dataSource"/>
</beans:bean>
代码 mypackage.MyUserDetailsService
扩展 JdbcDaoImpl并实现UserDetailsService
.
关于java - 启用安全检查以访问 wsdl url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14396771/