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 ...
随机推荐
- var t = a&&b;的问题
var a = "avalue";var b = "bvalue";var t = a&&b;console.info(t); // bvalu ...
- RabbitMQ PHP操作类,守护进程及相关测试数据
封装类如下: <?php /* * amqp协议操作类,可以访问rabbitMQ * 需先安装php_amqp扩展 */ class RabbitMQCommand{ public $confi ...
- WPF中增加Month Calendar月历控件
XAML代码:(这里使用了codeproject.com网站上的一个Dll,你可以在这里下载它:http://www.codeproject.com/cs/miscctrl/MonthCalendar ...
- 意犹未尽而来的第一篇Android 逆向
游戏:咕噜王国大冒险 平台:android 目标: 1. 去除乱七八糟提示(本篇目标) 2. 去除google弹窗 3. 破解“all stages” 破文开始: 1. 使用APKIDE反编译:搜索字 ...
- bzoj 1845: [Cqoi2005] 三角形面积并 扫描线
1845: [Cqoi2005] 三角形面积并 Time Limit: 3 Sec Memory Limit: 64 MBSubmit: 848 Solved: 206[Submit][Statu ...
- Hard Life
poj3155:http://poj.org/problem?id=3155 题意:最大密度子图的模板题. 题解:直接看代码. /* 题意简述一个公司有n个人,给出了一些有冲突的人的对数(u,v),所 ...
- 了解php的session_start的工作原理
一.php使用session_start开启SESSION 二.浏览器访问该php脚本时,将产生两个可能: 1.(客户端的提交的cookie没有找到PHPSESSID的键) 或 (在服务器端没有找到P ...
- 带圆角的EditText
转载请注明出处:http://blog.csdn.net/krislight/article 1.定义一个Drawable <?xml version="1.0" encod ...
- Drainage Ditches(Dinic最大流)
http://poj.org/problem?id=1273 用Dinic求最大流的模板题,注意会有重边. 邻接矩阵建图 #include<stdio.h> #include<str ...
- (转载)Linux中cp直接覆盖不提示的方法
(转载)http://soft.chinabyte.com/os/220/11760720.shtml 新做了服务器,cp覆盖时,无论加什么参数-f之类的还是提示是否覆盖,这在大量cp覆盖操作的时候是 ...