Spring Security 4 新增特性

1.概述

a) 特性

如下是Spring Security 4.0的新特性php

<intercept-url pattern="/**" access="hasRole('ROLE_USER')"/>

如今,咱们能够选择省略掉ROLE_前缀。具体而言,不管ROLE_是否存在,表达式hasRole已经定义了一个做为role的值。咱们能够像下面这样配置(效果和以前同样):html

<intercept-url pattern="/**" access="hasRole('USER')"/>

相似的,也能够像下面同样配置:html5

@PreAuthorize("hasRole('ROLE_USER')")
@PreAuthorize("hasRole('USER')")

b) 从3.x过渡到4.x

做为一个新版本,Spring Security团队作了主要的更新:git

如下是更新的完整详情,或者在JIRA中查看变更:github

2.XML配置的变化(Java注解的更新也差很少)

a)例子迁移

能够在github上查看web

b)更新到Spring 4.1.x

Spring Security 4须要Spring 4。而Spring Security 3.2.x 能够在Spring 3.2.x and Spring 4上运做。spring

详细介绍参见安全

c)过期

如下列出了一些官方再也不建议使用的配置,详情能够参考这里websocket

d)更新Spring Security

Maven:mvc

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-bom</artifactId>
            <version>4.0.0.RELEASE</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

不要忘记更新依赖

<dependency>
    <groupId>org.springframework.security</groupId>
    <artifactId>spring-security-core</artifactId>
    <version>4.0.0.RELEASE</version>
</dependency>

e)默认命名空间的改变

详情参考这里

f)默认Filter URLs的改变

详情能够参考这里:http://docs.spring.io/spring-security/site/migrate/current/3-to-4/html5/migrate-3-to-4-xml.html#m3to4-filter-urls

g)配置头的改变

详情能够参考这里:http://docs.spring.io/spring-security/site/migrate/current/3-to-4/html5/migrate-3-to-4-xml.html#m3to4-header

h)自动的ROLE_前缀

详情能够参考这里:http://docs.spring.io/spring-security/site/migrate/current/3-to-4/html5/migrate-3-to-4-xml.html#m3to4-role-prefixing

相关文章
相关标签/搜索