Spring Security的HTTP基本验证示例

2014-11-24 03:00:26 · 作者: · 浏览: 0

[导读]当配置了http的基本验证时,浏览器访问时就会显示一个登陆框,本人就是展示怎么用Spring Security配置http的最基本的验证。 最新的Spring Security 实现的一个Hello World例子将会被再次使用...

当配置了http的基本验证时,浏览器访问时就会显示一个登陆框,本人就是展示怎么用Spring Security配置http的最基本的验证。

1 2 3 4 <http> <intercept-url pattern=/welcome* access=ROLE_USER /> <http-basic /> http>

最新的Spring Security 实现的一个Hello World例子将会被再次使用,只不过这次验证的是http.

1.Spring Secutiry

为了验证基本的http,只需要将“form-login”改成“http-basic”标签即可.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 <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> <intercept-url pattern=/welcome* access=ROLE_USER /> <http-basic /> http> <authentication-manager> <authentication-provider> <user-service> <user name=mkyong password=123456 authorities=ROLE_USER /> user-service> authentication-provider> authentication-manager> beans:beans>

好了,就上面那些。

2.示例

当访问加密的链接时,浏览器将会自动跳出登陆验证框。

\

原创文章,转载请注明出处:http://www.it161.com/article/javaDetail articleid=140109230722

更多原创内容,请访问:http://www.it161.com/