<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
</dependency>
<?xml version="1.0" encoding="UTF-8"?>
<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.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/s ... spring-security.xsd">
<!--配置页面拦截规则:配置放行的资源-->
<http pattern="/login.html" security="none"/>
<http pattern="/login_error.html" security="none"/>
<!-- use-expressions=”false” 不需要使用表达式方式来写权限-->
<http use-expressions="false">
<!--配置拥有ROLE_USER角色可以任意访问,pattern="/**"表示可以访问任意资源-->
<intercept-url pattern="/**" access="ROLE_USER"/>
<!--配置表单登录信息-->
<!--login-page:指定登录的页面,default-target-url:默认进入的页面,authentication-failure-url:登录失败的跳转的页面-->
<form-login login-page="/login.html" default-target-url="/index.html" authentication-failure-url="/login_error.html"/>
<!--禁言跨站请求伪造校验-->
<csrf disabled="true"/>
</http>
<!--认证管理器-->
<authentication-manager>
<authentication-provider>
<user-service>
<!--拥有角色的用户和密码-->
<user name="admin" password="123456" authorities="ROLE_USER"/>
</user-service>
</authentication-provider>
</authentication-manager>
</beans:beans>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>spring security</title>
</head>
<body>
<form action="/login" method="post">
用户名:<input name="username" type="text"><br>
密码:<input name="password" type="password"><br>
<button type="submit">登录</button>
</form>
</body>
</html>
| 欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) | 黑马程序员IT技术论坛 X3.2 |