spring security 3比较庞大,但功能很强,下面小结下spring security 3中值得

注意的10个典型用法

1)多个authentication-provide可以同时使用

  1. <authentication-manager alias='authenticationManager'>
  2. <authentication-provider>
  3. <user-service>
  4. <user authorities='ROLE_GUEST' name='guest' password=''/>
  5. </user-service>
  6. </authentication-provider>
  7. <authentication-provider>
  8. <jdbc-user-service data-source-ref='dataSource'/>
  9. </authentication-provider>
  10. </authentication-manager>

2 传统的<security:http>

  1. <security:http>
  2. <security:intercept-url pattern='/admin/**' access='hasRole('ROLE_ADMIN')'/>
  3. <security:intercept-url pattern='/account/**' access='hasRole('ROLE_USER')' />
  4. <security:intercept-url pattern='/**' access='hasRole('ROLE_ANONYMOUS')' />
  5. <!-- other elements removed for clarity -->
  6. </security:http>

3 可以使用一大堆密码加密器: 
   aseDigestPasswordEncoder 
BasePasswordEncoder 
LdapShaPasswordEncoder 
Md4PasswordEncoder, 
Md5PasswordEncoder 
MessageDigestPasswordEncoder 
MessageDigestPasswordEncoder 
PlaintextPasswordEncoder 
ShaPasswordEncoder

4 SPRING security的标签

  1. <sec:authorize access='hasRole('supervisor')'>
  2. This content will only be visible to users who have
  3. the 'supervisor' authority in their list of <tt>GrantedAuthority</tt>s.
  4. </sec:authorize>

这是根据角色判断是否显示 
  
还可以根据URL判断是否显示

  1. <sec:authorize url='/admin'>
  2. This content will only be visible to users who are authorized to send requests to the '/admin' URL.
  3. </sec:authorize>

5 方法级的鉴别 
   @PreAuthorize  @PostAuthorize  @Secure

要启用上面三者,要 
<global-method-security pre-post-annotations='enabled' />

这三个是在方法调用前,先鉴别是否有权限使用,比如

  1. public interface IUserService
  2. @PreAuthorize("hasRole('ROLE_USER')")
  3. public void changePassword(String username, password);

感觉这个其实不是很常用 
6 同5,可以使用JSR-250 注解去做 
   <global-method-security jsr250-annotations=”enabled”/>

@RolesAllowed({“ROLE_USER”,”ROLE_ADMIN”}) 
@PermitAll 
@DenyAll

这样使用: 
    @RolesAllowed({"ROLE_ADMIN","ROLE_USER"}) 
public void deleteUser(String username); 
   这个东西反正没用到,具体见手册

7 配置open-id,步骤

  1. <form action='j_spring-openid-security-check' method='post'>
  2. <label for='openid_idenifier'>Login</label>:
  3. <input id='openid_identifier' name='openid_identifier' type='text'/>
  4. <input type='submit' value='Login' />
  5. </form>

<http auto-config='true'> 
<openid-login/>

</http> 
   当然要加上:spring-security-openid.jar

8 spring secruity能使用ldap 
  <ldap-server ldif='classpath:my-ldif-file.ldif' id='localserver' />

当然要加上:spring-security-openid.jar

9 使用远程 ldap-server 
   <ldap-server url='ldap://myServer/dc=captaindebug,dc=com:389' id='ldapExternal' 
  manager-dn='uid=admin,ou=users,ou=systems' manager-password='s3cret'/>

8和9还没用过,估计配置起来还有更多东西

10 使用https 
   <http auto-config='true' use-expressions='true'> 
    <intercept-url pattern='/login' requires-channel='https'/> 
    
</https>

这个比较简单,用requires-channel='https'

spring security 3中的10个典型用法小结的更多相关文章

  1. Spring Security 5中的默认密码编码器

    1.概述 在Spring Security 4中,可以使用内存中身份验证以纯文本格式存储密码. 对版本5中的密码管理过程进行了重大改进,为密码编码和解码引入了更安全的默认机制.这意味着如果您的Spri ...

  2. Spring Security 5中 PasswordEncoder的使用

    在最新的 Spring Security 5发布版本中, 出于安全性的考虑调整了PasswordEncoder的实现与使用策略. 1.以前常用的实现 StandardPasswordEncoder, ...

  3. Spring Security框架中踢人下线技术探索

    1.背景 在某次项目的开发中,使用到了Spring Security权限框架进行后端权限开发的权限校验,底层集成Spring Session组件,非常方便的集成Redis进行分布式Session的会话 ...

  4. Spring mvc中@RequestMapping 6个基本用法小结

    Spring mvc中@RequestMapping 6个基本用法小结 小结下spring mvc中的@RequestMapping的用法. 1)最基本的,方法级别上应用,例如: @RequestMa ...

  5. 转:Spring mvc中@RequestMapping 6个基本用法小结

    Spring mvc中@RequestMapping 6个基本用法小结 发表于3年前(2013-02-17 19:58)   阅读(11698) | 评论(1) 13人收藏此文章, 我要收藏 赞3 4 ...

  6. 关于 Spring Security OAuth2 中 CORS 跨域问题

    CORS 是一个 W3C 标准,全称是”跨域资源共享”(Cross-origin resource sharing).它允许浏览器向跨源服务器,发出XMLHttpRequest请求,从而克服了 AJA ...

  7. 关于 Spring Security OAuth2 中 Feign 调用 Token 问题

    微服务体系中,避免不了服务之间链式调用,一般使用 Feign ,由于使用 Spring Security OAuth2 全局做了安全认证,简单的一种实现方式就是在服务提供方获得 Token 再次通过 ...

  8. JAVA中字符串函数subString的用法小结

    本篇文章主要是对JAVA中字符串函数subString的用法进行了详细的介绍,需要的朋友可以过来参考下,希望对大家有所帮助 String str; str=str.substring(int begi ...

  9. js正则表达式中的问号几种用法小结

    这篇文章主要介绍了js正则表达式中的问号几种用法,比如+?,*?,{2,3}?可以停止匹配的贪婪模式,感兴趣的朋友可以参考下 在表示重复的字符后面加问号,比如+?,*?,{2,3}?可以停止匹配的贪婪 ...

随机推荐

  1. prototype原型解析

    每个对象都有原型, prototype能够实现实例共享,节约使您有能力向对象添加属性和方法. 如 <script type="text/javascript"> fun ...

  2. Linux中kettle自动化部署脚本

    自己写的一个自动化在Linux中部署kettle的脚本,包括一些遇到的问题在脚本中都有涉及. kettle是官网最新版本pdi-ce-6.1.0.1-196.zip 目前最新版本下载地址:https: ...

  3. HDU 2037 今年暑假不AC(贪心)

    今年暑假不AC Problem Description “今年暑假不AC?”“是的.”“那你干什么呢?”“看世界杯呀,笨蛋!”“@#$%^&*%...” 确实如此,世界杯来了,球迷的节日也来了 ...

  4. php 积少成多!

  5. apicloud ios 打包流程

    1创建APP ID 等 2创建pruduction创建证书,用 这个证书导出P12格式的.. 3profile 证书,选 APP STORE  AD-HOC ok... http://docs.api ...

  6. java抽象类的特点

    抽象类 抽象类的特点: 1.抽象类的方法可以是抽象的,也可以是不抽象的. 2.抽象类的方法可以全是抽象的,也可以全是不抽象的. 3.有抽象方法的类必须是抽象类,或者是接口(但是接口的方法定义必须是pu ...

  7. redis高级实用特性(1)

    1.安全性 2.主从复制 3.事务处理 4.持久化机制 5.发布订阅消息 6.虚拟内存的使用 安全性:设置客户端连接后进行任何其他指定前需要使用的密码 警告:因为redis速度相当快,所以在一台比较好 ...

  8. Ecstore1.2启用mongodb添加索引

    配置config(连接mongo) mongo define('KVSTORE_STORAGE', 'base_kvstore_mongodb'); define('MONGODB_SERVER_CO ...

  9. python&MongoDB

    1 #!/usr/bin/python 2 #-*- coding:utf-8 3 import pymongo 4 connection=pymongo.MongoClient() 5 tdb=co ...

  10. (1)Two Sum--求数组中相加为指定值的两个数

    Given an array of integers, find two numbers such that they add up to a specific target number. The ...