Apache Shiro 集成-Cas
http://blog.csdn.net/peterwanghao/article/details/8825008
Shiro集成CAS是在1.2版本里新增的功能。
Shiro-cas模块将应用作为CAS客户端与CAS SSO服务器一起保护web应用。
CAS协议的一个基本理解:
1. 如果你想访问一个被CAS客户端保护的应用,而你还没有进行认证。你讲被重定向到CAS服务端的登录页面。在应用中你需要配置CAS的登录url地址。
|
http://application.examples.com/protected/index.jsp → HTTP 302 → https://server.cas.com/login?service=http://application.examples.com/shiro-cas |
2. 当你填上登录名和密码在CAS服务端进行认证后,你就被重定向到一个带有服务端票据的应用URL。服务端票据是一次性使用的令牌,可在CAS服务端标识用户的唯一性(或用户属性)。
|
https://server.cas.com/login?service=http://application.examples.com/shiro-cas → HTTP 302 → http://application.examples.com/shiro-cas?ticket=ST-4545454542121-cas |
3. 应用去CAS服务端询问票据的有效性,CAS服务端响应经过认证的用户唯一标识。CAS客户端将页面转发到受保护的页面。
|
http://application.examples.com/shiro-cas?ticket=ST-4545454542121-cas → HTTP 302 → http://application.examples.com/protected/index.jsp |
如何配置shiro与CAS服务器工作?
在你的应用中添加shiro-cas Maven依赖
|
<dependency> <groupId>org.apache.shiro</groupId> <artifactId>shiro-cas</artifactId> <version>version</version> </dependency> |
在你的应用中添加服务端url,这个url被用来接收CAS服务端票据。
在Shiro配置中定义CasFilter:
|
[main] casFilter = org.apache.shiro.cas.CasFilter casFilter.failureUrl = /error.jsp |
定义过滤器对应的url:
|
[urls] /shiro-cas = casFilter |
这样一来,当用户经过CAS服务端的有效票据认证后被重定向到应用的服务地址(/shiro-cas),这个过滤器接收服务端票据并创建一个可以被CasRealm使用的CasToken。
CasRealm使用被CasFilter创建的CasToken来验证用户的合法性。在你的shiro配置中添加CasRealm:
|
[main] casRealm = org.apache.shiro.cas.CasRealm casRealm.defaultRoles = ROLE_USER #casRealm.defaultPermissions #casRealm.roleAttributeNames #casRealm.permissionAttributeNames #casRealm.validationProtocol = SAML casRealm.casServerUrlPrefix = https://server.cas.com/ casRealm.casService = http://application.examples.com/shiro-cas |
casServerUrlPrefix是CAS服务端地址。
casService是应用服务地址,用来接收CAS服务端票据。
validationProcol值为SAML or CAS,默认是CAS。它依赖于CAS服务器的版本,SAML协议只能使用在CAS server version >= 3.1。
defaultRoles是认证通过后默认角色。
defaultPermissions是认证通过后默认权限。
roleAttributeNames是认证通过的用户的角色属性名称,用逗号分隔。
permissionAttributeNames是认证通过的用户的权限属性名称,用逗号分隔。
CAS服务端可以支持 ‘remember me’ 功能,这个信息通过SAML验证或CAS定制验证发布。你需要在Shiro配置中定义CasSubjectFactory:
|
[main] casSubjectFactory = org.apache.shiro.cas.CasSubjectFactory securityManager.subjectFactory = $casSubjectFactory |
最后,为你的应用增加安全控制。定义需要保护的url地址和需要进行认证的CAS服务端地址:
|
[main] roles.loginUrl = https://server.cas.com/login?service=http://application.examples.com/shiro-cas [urls] /protected/** = roles[ROLE_USER] /** = anon |
一个完整的配置例子:
|
[main] casFilter = org.apache.shiro.cas.CasFilter casFilter.failureUrl = /error.jsp casRealm = org.apache.shiro.cas.CasRealm casRealm.defaultRoles = ROLE_USER casRealm.casServerUrlPrefix = https://server.cas.com/ casRealm.casService = http://application.examples.com/shiro-cas casSubjectFactory = org.apache.shiro.cas.CasSubjectFactory securityManager.subjectFactory = $casSubjectFactory roles.loginUrl = https://server.cas.com/login?service=http://application.examples.com/shiro-cas [urls] /shiro-cas = casFilter /protected/** = roles[ROLE_USER] /** = anon |
Apache Shiro 集成-Cas的更多相关文章
- cas+tomcat+shiro实现单点登录-4-Apache Shiro 集成Cas作为cas client端实现
目录 1.tomcat添加https安全协议 2.下载cas server端部署到tomcat上 3.CAS服务器深入配置(连接MYSQL) 4.Apache Shiro 集成Cas作为cas cli ...
- Apache Shiro 集成Spring(二)
1.依赖: <dependency> <groupId>org.apache.shiro</groupId> <artifactId>shiro-cor ...
- 十一、Spring Boot 集成Shiro和CAS
1.Shiro 是什么?怎么用? 2.Cas 是什么?怎么用? 3.最好有spring基础 首先看一下下面这张图: 第一个流程是单纯使用Shiro的流程. 第二个流程是单纯使用Cas的流程. 第三个图 ...
- Spring Boot 集成Shiro和CAS
Spring Boot 集成Shiro和CAS 标签: springshirocas 2016-01-17 23:03 35765人阅读 评论(22) 收藏 举报 分类: Spring(42) 版 ...
- 基于spring框架的apache shiro简单集成
关于项目的安全保护,我一直想找一个简单配置就能达到目的的方法,自从接触了shiro,这个目标总算达成了,以下结合我使用shiro的经验,谈谈比较轻便地集成该功能. 首先我们先了解一下shiro是什么. ...
- 【Shiro】Apache Shiro架构之集成web
Shiro系列文章: [Shiro]Apache Shiro架构之身份认证(Authentication) [Shiro]Apache Shiro架构之权限认证(Authorization) [Shi ...
- Apache Shiro:【2】与SpringBoot集成完成登录验证
Apache Shiro:[2]与SpringBoot集成完成登录验证 官方Shiro文档:http://shiro.apache.org/documentation.html Shiro自定义Rea ...
- Apache Shiro:【1】Shiro基础及Web集成
Apache Shiro:[1]Shiro基础及Web集成 Apache Shiro是什么 Apache Shiro是一个强大且易于使用的Java安全框架,提供了认证.授权.加密.会话管理,与spri ...
- SpringBoot中Shiro使用Pac4j集成CAS认证
SpringBoot中Shiro使用Pac4j集成CAS认证 Pac4j 简介 Pac4j与Shiro,Spring Security一样都是权限框架,并且提供了OAuth - SAML - CAS ...
随机推荐
- cocos2d-x笔记2: 编译到安卓的步骤与注意事项
博客地址: www.cnblogs.com/wolfred7464/ 不得不说,真心复杂,本篇博客总结的基本是最简最直接的步骤了,不用Cygwin和Ant的,当然用也可以... 以下用 %PROJEC ...
- silverlight5开发的翻牌游戏
扑克牌用了一个自定义控件,代码如下 public class CardButton : Button { public int state;//是否翻转0是未翻转,1是已翻转 private stat ...
- RESTheart安装与设置
作者:Maurizio Turatti, 最后在Feb 25, 2016时被 Andrea Di Cesare更新 安装与设置 1. 快速开始 Docker Vagrant Bare metal 2. ...
- NODE.JS玩玩
按一个网页的来,最好最后能到EXPRESS.JS. http://www.nodebeginner.org/index-zh-cn.html 这样就能对比DJANGO,看看两者的WEB框架,加深认识. ...
- asp.net 登陆后在ashx处理程序中获取不到Session
登录后存储Session,另一个页面Ajax请求 ashx页面,发现无法获取到Session,Session is NULL 使用“IReadOnlySessionState”这个接口就可以
- 【HDU 2255】奔小康赚大钱 (最佳二分匹配KM算法)
奔小康赚大钱 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Subm ...
- 单片机 C 语言模块化编程
好的开始是成功的一半 通过上一章的学习,我想你已经掌握了如何在程序中释放CPU了.希望能够继续坚持下去.一个良好的开始是成功的一半.我们今天所做的一切都是为了在单片机编程上做的更好. 在谈论今天的主题 ...
- STL unordered_set
http://www.cplusplus.com/reference/unordered_set/unordered_set/ template < class Key, // unordere ...
- Yii处理流程
Yii的应用程序处理流程 用户访问URL http://www.example.com/blog/index.php?r=site/contact 1.入口脚本被网站服务器执行以处理此请求. 2.一个 ...
- TeeChart中Axis的CalcIncrement属性
private void Init() { tChart = new TChart(); panel1.Controls.Add(tChart); tChart.Aspect.View3D = fal ...