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的更多相关文章

  1. 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 ...

  2. Apache Shiro 集成Spring(二)

    1.依赖: <dependency> <groupId>org.apache.shiro</groupId> <artifactId>shiro-cor ...

  3. 十一、Spring Boot 集成Shiro和CAS

    1.Shiro 是什么?怎么用? 2.Cas 是什么?怎么用? 3.最好有spring基础 首先看一下下面这张图: 第一个流程是单纯使用Shiro的流程. 第二个流程是单纯使用Cas的流程. 第三个图 ...

  4. Spring Boot 集成Shiro和CAS

    Spring Boot 集成Shiro和CAS 标签: springshirocas 2016-01-17 23:03 35765人阅读 评论(22) 收藏 举报  分类: Spring(42)  版 ...

  5. 基于spring框架的apache shiro简单集成

    关于项目的安全保护,我一直想找一个简单配置就能达到目的的方法,自从接触了shiro,这个目标总算达成了,以下结合我使用shiro的经验,谈谈比较轻便地集成该功能. 首先我们先了解一下shiro是什么. ...

  6. 【Shiro】Apache Shiro架构之集成web

    Shiro系列文章: [Shiro]Apache Shiro架构之身份认证(Authentication) [Shiro]Apache Shiro架构之权限认证(Authorization) [Shi ...

  7. Apache Shiro:【2】与SpringBoot集成完成登录验证

    Apache Shiro:[2]与SpringBoot集成完成登录验证 官方Shiro文档:http://shiro.apache.org/documentation.html Shiro自定义Rea ...

  8. Apache Shiro:【1】Shiro基础及Web集成

    Apache Shiro:[1]Shiro基础及Web集成 Apache Shiro是什么 Apache Shiro是一个强大且易于使用的Java安全框架,提供了认证.授权.加密.会话管理,与spri ...

  9. SpringBoot中Shiro使用Pac4j集成CAS认证

    SpringBoot中Shiro使用Pac4j集成CAS认证 Pac4j 简介 Pac4j与Shiro,Spring Security一样都是权限框架,并且提供了OAuth - SAML - CAS ...

随机推荐

  1. QQ宠物吹泡泡游戏小助手 VC++6.0代码分析

    最近玩QQ宠物,他总是心情低落,让我很不爽,让他玩耍吧,还得自己点鼠标,所以想偷个懒,试试能不能编个程序让电脑帮我做这个事情. 要干这件事就得先找一个游戏开刀,刚开始我找的是弹力球游戏,不就是点鼠标么 ...

  2. microsoft office visio基本使用方法

    以下是画流程图.程序内存分配等等框图用到的点滴使用方法,记录在这里以备偶尔只需. 1.画大括号“{}” 在Visio操作界面下,依次点击“文件(File)”—“形状(Shapes)”--“其他Visi ...

  3. Linq 筛选出一条数据

    InBoxInfo boxInfo = boxList.Find(p => p.GoodsID == goods.GoodsID.ToString().Trim() && p.S ...

  4. 【UVA 11354】 Bond (最小瓶颈生成树、树上倍增)

    [题意] n个点m条边的图 q次询问 找到一条从s到t的一条边 使所有边的最大危险系数最小 InputThere will be at most 5 cases in the input file.T ...

  5. 忽然想到,为什么以前iOS的工资高

    听说做iOS的在上海工资也可以  前几年还行,现在也不太行了除非你水平很高 现在移动应用已经100多万了,基本饱和了以前是新的商业模式要抢时间,会的人也少

  6. android使用tabhost实现导航

    参考 http://blog.csdn.net/xixinyan/article/details/6771341 http://blog.sina.com.cn/s/blog_6b04c8eb0101 ...

  7. oracle热点表online rename

    对于在线的繁忙业务表的任何操作都可能带来意想不到的风险.一张业务表,对partition key进行升位,其步骤是: rename原表 新建临时表 交换分区到临时表 升位临时表的字段的长度 交换临时表 ...

  8. ECSHOP首页调用指定分类下的商品

    转:http://bbs.ecshop.com/thread-1123207-1-1.html 调用某个分类下的商品,方法有很多种的,不过都需要先在后台设置模板那里设置显示和显示条数, 然后在需要调用 ...

  9. (转载)顺序栈c++实现

    (转载)http://myswirl.blog.163.com/blog/static/51318642200882310239324/ SqStack.h********************** ...

  10. 国外成熟的程序交易系统的思路 z

    波涛(1998)在<系统交易方法>中提出,一个设计良好的交易系统,必须对投资决策的各个相关环节做出相应明确的规定,同时还必须符合使用者的心理特征.投资对象的统计特征以及投资资金的风险特征. ...