Spring Security教程
2016-01-20 21:59
375 查看
原文地址:/article/1335421.html
http://blog.csdn.net/jaune161/article/details/18736687
spring-security官网网址:http://docs.spring.io/spring-security/site/docs/3.2.0.RELEASE/reference/htmlsingle/#ns-config
目前Spring官方只提供Meven的下载方式。但在http://maven.springframework.org中有SpringSecurity及其他所有Spring产品的下载方式。
http://maven.springframework.org/release/org/springframework/中有Spring相关的所有下载,但好像直到3.2版的,最新的版本在这个里面找不到
http://maven.springframework.org/release/org/springframework/security/spring-security/3.2.0.RELEASE/这个是SpringSecurity3.2的下载地址
Meven下载地址:
[html] view plain copy
<dependencies>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
<version>3.2.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
<version>3.2.0.RELEASE</version>
</dependency>
</dependencies>
本教程是基于SpringMVC3.2+Hibernate4+JPA2.0+SpringSecurity3.2的环境。SpringMVC3.2+Hibernate4+JPA2.0环境的搭建在这里就不多说了,主要讲下SpringSecurity的环境搭建
web.xml配置
[html] view plain copy
<!-- 加载Spring的配置文件 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:applicationContext.xml,
classpath:applicationContext-security.xml
</param-value>
</context-param>
<!-- SpringSecurity 核心过滤器配置 -->
<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>
applicationContext-security.xml命名空间配置,官方提供了两种配置方案
第一种、命名空间用beans开头,但是在配置中一直需要用<security:*>来配置。
[html] view plain copy
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:security="http://www.springframework.org/schema/security"
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.xsd">
...
</beans>
第二种、命名空间用security开头,在配置中不需要security前缀,但是bean的配置需要用<beans:bean>配置。
[html] view plain copy
<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.xsd">
...
</beans:beans>
到此为止SpringSecurity的环境配置已基本完成
命名空间的配置可在spring的官方文档,第4章 Security Namespace Configuration 中找到,一下附上链接地址
http://docs.spring.io/spring-security/site/docs/3.2.0.RELEASE/reference/htmlsingle/#ns-config
http://blog.csdn.net/jaune161/article/details/18736687
spring-security官网网址:http://docs.spring.io/spring-security/site/docs/3.2.0.RELEASE/reference/htmlsingle/#ns-config
目前Spring官方只提供Meven的下载方式。但在http://maven.springframework.org中有SpringSecurity及其他所有Spring产品的下载方式。
http://maven.springframework.org/release/org/springframework/中有Spring相关的所有下载,但好像直到3.2版的,最新的版本在这个里面找不到
http://maven.springframework.org/release/org/springframework/security/spring-security/3.2.0.RELEASE/这个是SpringSecurity3.2的下载地址
Meven下载地址:
[html] view plain copy
<dependencies>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
<version>3.2.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
<version>3.2.0.RELEASE</version>
</dependency>
</dependencies>
本教程是基于SpringMVC3.2+Hibernate4+JPA2.0+SpringSecurity3.2的环境。SpringMVC3.2+Hibernate4+JPA2.0环境的搭建在这里就不多说了,主要讲下SpringSecurity的环境搭建
web.xml配置
[html] view plain copy
<!-- 加载Spring的配置文件 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:applicationContext.xml,
classpath:applicationContext-security.xml
</param-value>
</context-param>
<!-- SpringSecurity 核心过滤器配置 -->
<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>
applicationContext-security.xml命名空间配置,官方提供了两种配置方案
第一种、命名空间用beans开头,但是在配置中一直需要用<security:*>来配置。
[html] view plain copy
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:security="http://www.springframework.org/schema/security"
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.xsd">
...
</beans>
第二种、命名空间用security开头,在配置中不需要security前缀,但是bean的配置需要用<beans:bean>配置。
[html] view plain copy
<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.xsd">
...
</beans:beans>
到此为止SpringSecurity的环境配置已基本完成
命名空间的配置可在spring的官方文档,第4章 Security Namespace Configuration 中找到,一下附上链接地址
http://docs.spring.io/spring-security/site/docs/3.2.0.RELEASE/reference/htmlsingle/#ns-config
相关文章推荐
- Spring Boot 使用总结(二) Spring Boot注解
- Spring注解之事务管理
- SpringMvc (七) 对象转json字符串/视图解析器
- javaweb 中的路径问题汇总
- moon Java I/O系统 编程思想第18张
- moon 枚举类型 (enum) java编程思想第19章
- moon 注解(annotation)/元数据 Java编程思想第20章
- Java调用js
- 【慕课笔记】第四章 流程控制语句 第11节 JAVA循环语句之多重循环
- 自己写的java实现的多路搜索树 B-Tree
- 解决 Mac OS X 下 IntelliJ IDEA、jEdit 等 Java 程序中文标点输入无效的方法
- Java数组分隔成子数组
- Java数组分隔成子数组
- Java数组分隔成子数组
- javaweb学习(一)——servlet总结
- JVM学习04-class字节码的结构
- 【慕课笔记】第四章 流程控制语句 第9节 JAVA循环跳转语句之break
- rpm -qa | grep jdk
- Eclipse开发JAVA中如何Debug
- javax.el.PropertyNotFoundException: Property 'name' not found on type java.lang.String