SpringSecurity开发步骤
Spring Security是一个能够为基于Spring的企业应用系统提供声明式的安全访问控制解决方案的安全框架。它提供了一组可以在Spring应用上下文中配置的Bean,充分利用了Spring IoC,DI(控制反转Inversion of Control ,DI:Dependency Injection 依赖注入)和AOP(面向切面编程)功能,为应用系统提供声明式的安全访问控制功能,减少了为企业系统安全控制编写大量重复代码的工作
1.开发思路
1. 拦截用户请求 登录页的路径为("../login" method="post")
2. 当前登陆的用户是谁?
3. 配置访问某一个资源需要什么角色?
4. 当前登陆用户具有什么角色?
5. 认证/登陆 授权
2.开发步骤
1.第一步: 引入依赖(spring + spring security)
< dependency>
< groupId> org.springframework.security</ groupId>
< artifactId> spring-security-web</ artifactId>
</ dependency>
< dependency>
< groupId> org.springframework.security</ groupId>
< artifactId> spring-security-config</ artifactId>
</ dependency>
2.配置web.xml文件(spring配置文件 + DelegatingFilterProxy-委托代理过滤器)
<?xmlversion="1.0"encoding="UTF-8"?>
<web-appxmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
< context-param>
< param-name> contextConfigLocation</ param-name>
< param-value> classpath:spring-security.xml</ param-value>
</ context-param>
< listener>
< listener-class>
org.springframework.web.context.ContextLoaderListener
</ listener-class>
</ listener>
< filter>
< filter-name> springSecurityFilterChain</ filter-name>
< filter-class> org.springframework.web.filter.DelegatingFilterProxy</ filter-class>
</ filter>
< filter-mapping>
< filter-name> springSecurityFilterChain</ filter-name>
< url-pattern> /*</ url-pattern>
</ filter-mapping>
</ web-app>
3.配置spring配置文件