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 ...
随机推荐
- asp.net管道模型
查了很多资料,终于大概弄懂管道模型(注意并非指定是asp.net范畴)是个什么概念了,其实就是从Unix移植过来的一种概念,也可以说是一种模式吧(只允许一头读,一头写,并且读完了就会自动消失). as ...
- 数据结构练习 02-线性结构2. Reversing Linked List (25)
Given a constant K and a singly linked list L, you are supposed to reverse the links of every K elem ...
- 安装app到Simulator
1.安装brew 打开命令行,执行以下命令: ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install ...
- 反编译Android APK及防止APK程序被反编译
怎么逆向工程对Android Apk 进行反编译 google Android开发是开源的,开发过程中有些时候会遇到一些功能,自己不知道该怎么做,然而别的软件里面已经有了,这个时候可以采用反编译的方式 ...
- Why longest path problem doesn't have optimal substructure?
We all know that the shortest path problem has optimal substructure. The reasoning is like below: Su ...
- applicationDefaultJvmArgs:
server.context-path=/HelloMultiServlet server.port=8080 applicationDefaultJvmArgs: [ "-agentlib ...
- 通过新的 Azure 媒体服务资源管理器工具管理媒体工作流
Xavier Pouyat Azure 媒体服务高级项目经理 几个月前,一家广播公司找到了我,希望我向他们提供一种图形界面工具,好让他们使用 Azure媒体服务来上传.管理资产并对资产进行编 ...
- 【转】Mac 下钥匙串不能授权访问怎么解决--不错
原文网址:https://www.v2ex.com/t/240495 如题,之前都好好的,后来有次 xcode 打包 app 时弹出提示框要授权,我点击允许和始终允许都没反映,点拒绝就可以,刚才安装 ...
- 12篇学通C#网络编程
转自:http://www.cnblogs.com/huangxincheng/archive/2012/01/03/2310779.html 在C#的网络编程中,进程和线程是必备的基础知识,同时也是 ...
- ASP.NET中验证控件的使用
转自:http://www.cnblogs.com/yangmingming/archive/2010/03/09/1682006.html 前言: 前几日,无奈用JS判断控件的有效性,发现的确是一件 ...