spring security 3中的10个典型用法小结
spring security 3比较庞大,但功能很强,下面小结下spring security 3中值得
1)多个authentication-provide可以同时使用
- <authentication-manager alias='authenticationManager'>
- <authentication-provider>
- <user-service>
- <user authorities='ROLE_GUEST' name='guest' password=''/>
- </user-service>
- </authentication-provider>
- <authentication-provider>
- <jdbc-user-service data-source-ref='dataSource'/>
- </authentication-provider>
- </authentication-manager>
2 传统的<security:http>
- <security:http>
- <security:intercept-url pattern='/admin/**' access='hasRole('ROLE_ADMIN')'/>
- <security:intercept-url pattern='/account/**' access='hasRole('ROLE_USER')' />
- <security:intercept-url pattern='/**' access='hasRole('ROLE_ANONYMOUS')' />
- <!-- other elements removed for clarity -->
- </security:http>
3 可以使用一大堆密码加密器:
aseDigestPasswordEncoder
BasePasswordEncoder
LdapShaPasswordEncoder
Md4PasswordEncoder,
Md5PasswordEncoder
MessageDigestPasswordEncoder
MessageDigestPasswordEncoder
PlaintextPasswordEncoder
ShaPasswordEncoder
4 SPRING security的标签
- <sec:authorize access='hasRole('supervisor')'>
- This content will only be visible to users who have
- the 'supervisor' authority in their list of <tt>GrantedAuthority</tt>s.
- </sec:authorize>
这是根据角色判断是否显示
还可以根据URL判断是否显示
- <sec:authorize url='/admin'>
- This content will only be visible to users who are authorized to send requests to the '/admin' URL.
- </sec:authorize>
5 方法级的鉴别
@PreAuthorize @PostAuthorize @Secure
要启用上面三者,要
<global-method-security pre-post-annotations='enabled' />
这三个是在方法调用前,先鉴别是否有权限使用,比如
- public interface IUserService
- {
- @PreAuthorize("hasRole('ROLE_USER')")
- 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,步骤
- <form action='j_spring-openid-security-check' method='post'>
- <label for='openid_idenifier'>Login</label>:
- <input id='openid_identifier' name='openid_identifier' type='text'/>
- <input type='submit' value='Login' />
- </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个典型用法小结的更多相关文章
- Spring Security 5中的默认密码编码器
1.概述 在Spring Security 4中,可以使用内存中身份验证以纯文本格式存储密码. 对版本5中的密码管理过程进行了重大改进,为密码编码和解码引入了更安全的默认机制.这意味着如果您的Spri ...
- Spring Security 5中 PasswordEncoder的使用
在最新的 Spring Security 5发布版本中, 出于安全性的考虑调整了PasswordEncoder的实现与使用策略. 1.以前常用的实现 StandardPasswordEncoder, ...
- Spring Security框架中踢人下线技术探索
1.背景 在某次项目的开发中,使用到了Spring Security权限框架进行后端权限开发的权限校验,底层集成Spring Session组件,非常方便的集成Redis进行分布式Session的会话 ...
- Spring mvc中@RequestMapping 6个基本用法小结
Spring mvc中@RequestMapping 6个基本用法小结 小结下spring mvc中的@RequestMapping的用法. 1)最基本的,方法级别上应用,例如: @RequestMa ...
- 转:Spring mvc中@RequestMapping 6个基本用法小结
Spring mvc中@RequestMapping 6个基本用法小结 发表于3年前(2013-02-17 19:58) 阅读(11698) | 评论(1) 13人收藏此文章, 我要收藏 赞3 4 ...
- 关于 Spring Security OAuth2 中 CORS 跨域问题
CORS 是一个 W3C 标准,全称是”跨域资源共享”(Cross-origin resource sharing).它允许浏览器向跨源服务器,发出XMLHttpRequest请求,从而克服了 AJA ...
- 关于 Spring Security OAuth2 中 Feign 调用 Token 问题
微服务体系中,避免不了服务之间链式调用,一般使用 Feign ,由于使用 Spring Security OAuth2 全局做了安全认证,简单的一种实现方式就是在服务提供方获得 Token 再次通过 ...
- JAVA中字符串函数subString的用法小结
本篇文章主要是对JAVA中字符串函数subString的用法进行了详细的介绍,需要的朋友可以过来参考下,希望对大家有所帮助 String str; str=str.substring(int begi ...
- js正则表达式中的问号几种用法小结
这篇文章主要介绍了js正则表达式中的问号几种用法,比如+?,*?,{2,3}?可以停止匹配的贪婪模式,感兴趣的朋友可以参考下 在表示重复的字符后面加问号,比如+?,*?,{2,3}?可以停止匹配的贪婪 ...
随机推荐
- 二十七、oracle 例外
一.例外分类oracle将例外分为预定义例外.非预定义例外和自定义例外三种.1).预定义例外用于处理常见的oracle错误.2).非预定义例外用于处理预定义例外不能处理的例外.3).自定义例外用于处理 ...
- HDU:3368-Reversi(暴力枚举)
Reversi Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Su ...
- 基础dp
队友的建议,让我去学一学kuangbin的基础dp,在这里小小的整理总结一下吧. 首先我感觉自己还远远不够称为一个dp选手,一是这些题目还远不够,二是定义状态的经验不足.不过这些题目让我在一定程度上加 ...
- logstash 输出到elasticsearch 自动建立index
由于es 单index 所能承受的数据量有限,之前情况是到400w数据300G左右的时候,整个数据的插入会变得特别慢(索引重建)甚至会导致集群之间的通信断开,于是我们采用每天一个index的方法来缓解 ...
- ECMAScript6标准新增加的内容
首选呐,你得了解一下javascript和ECMAScript的关系: 编程语言JavaScript是ECMAScript的实现和扩展,由ECMA(一个类似W3C的标准组织)参与进行标准化.ECMAS ...
- 关于Webapp的注意事项
meta标签 <meta name="viewport" content="width=device-width, initial-scale=1.0, user- ...
- 《JS权威指南学习总结--7.10 数组类型》
内容要点: 一.数组类型 判断它是否为数组通常非常有用.在ES5中,可以使用Array.isArray()函数来做这件事情: Array.isArray([]); //=>true Array. ...
- jquery 画板折叠
<!doctype html><html lang="en"><head> <meta charset="utf-8" ...
- hdu 5664 Lady CA and the graph(树的点分治+容斥)
题意: 给你一个有n个点的树,给定根,叫你找第k大的特殊链 .特殊的链的定义:u,v之间的路径,经过题给的根节点. 题解:(来自BC官方题解) 对于求第k大的问题,我们可以通过在外层套一个二分,将其转 ...
- a标签href跳转---传值---禁止单引号
禁止加单引号1 href传参的值 (&t_type='航班') 错误 <a href="check_apply?applyid=<?=$applyid?>&am ...