一直以为给定的下面配置是短路方式的,即defaultJdbcRealm可以成功认证,backDoorJdbcRealm就不会被调用。
其实不然,org.apache.shiro.authc.pam.FirstSuccessfulStrategy并不是这个意思,所有的realm依然都会被调用。
只不过是第一个认证成功的AuthenticationInfo作为最后的结果返回。
<bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager">
<!-- 其他配置 -->
<property name="authenticator" ref="authenticator" />
<property name="realms">
<list>
<ref bean="defaultJdbcRealm" />
<ref bean="backDoorJdbcRealm" />
</list>
</property>
</bean>
<bean id="defaultJdbcRealm" class="..." />
<bean id="backDoorJdbcRealm" class="..." />
<bean id="authenticator" class="org.apache.shiro.authc.pam.ModularRealmAuthenticator">
<property name="authenticationStrategy">
<bean class="org.apache.shiro.authc.pam.FirstSuccessfulStrategy" />
</property>
</bean>
为了实现目的,必须对org.apache.shiro.authc.pam.ModularRealmAuthenticator改造。
package xxx.yyy.security;
import java.util.Collection;
import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.pam.AuthenticationStrategy;
import org.apache.shiro.realm.Realm;
import org.apache.shiro.util.CollectionUtils;
public class ModularRealmAuthenticator extends org.apache.shiro.authc.pam.ModularRealmAuthenticator {
@Override
protected AuthenticationInfo doMultiRealmAuthentication(Collection<Realm> realms, AuthenticationToken token) {
AuthenticationStrategy strategy = getAuthenticationStrategy();
AuthenticationInfo aggregate = strategy.beforeAllAttempts(realms, token);
for (Realm realm : realms) {
aggregate = strategy.beforeAttempt(realm, token, aggregate);
if (realm.supports(token)) {
AuthenticationInfo info = null;
Throwable t = null;
try {
info = realm.getAuthenticationInfo(token);
} catch (Throwable throwable) {
t = throwable;
}
aggregate = strategy.afterAttempt(realm, token, info, aggregate, t);
// dirty dirty hack
if (aggregate != null && !CollectionUtils.isEmpty(aggregate.getPrincipals())) {
return aggregate;
}
// end dirty dirty hack
} else {
}
}
aggregate = strategy.afterAllAttempts(token, aggregate);
return aggregate;
}
}
<bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager">
<!-- 其他配置 -->
<property name="authenticator" ref="authenticator" />
<property name="realms">
<list>
<ref bean="defaultJdbcRealm" />
<ref bean="backDoorJdbcRealm" />
</list>
</property>
</bean>
<bean id="defaultJdbcRealm" class="..." />
<bean id="backDoorJdbcRealm" class="..." />
<bean id="authenticator" class="xxx.yyy.security.ModularRealmAuthenticator">
<property name="authenticationStrategy">
<bean class="org.apache.shiro.authc.pam.FirstSuccessfulStrategy" />
</property>
</bean>
分享到:
相关推荐
Apache Shiro是一个功能强大、灵活的开放式安全框架,干净利落地处理身份验证、授权、企业会话管理和加密。 Shiro可以帮助我们完成:认证、授权、加密、会话管理...【apache-shiro-1-2-x-reference,"waylau"翻译自官网】
shiro官方文档(中文) apache-shiro-1-2-x-reference apache-shiro-1-2-x-reference
Apache-Shiro-使用手册 Apache Shiro 是一个框架,可用于身份验证和授权。本文提供了几个示例用来展示如何在 Java™ 应用程序中使用 Shiro 并给出了如何在一个 Grails web 应用程序中使用它的概述。
apache-shiro-1.2.x-reference-中文文档
Apache-Shiro反序列化1
apache-shiro中文开发技术手册,很实用
thymeleaf-extras-shiro, 用于 Apache Shiro标记的Thymeleaf方言 thymeleaf-extras-shiro Shiro的Thymeleaf 方言, 。下载 Maven<dependency> <groupId>com.github.th
如果要使用shiro的话,可以引入 thymeleaf-extras-shiro.jar这个拓展包来曲线实现shiro的前端验证
SpringMVC-Mybatis-Shiro-redis-master..............
老版本存在Shiro命令执行漏洞,使用漏洞工具测试,可以发送命令至服务器获得执行。需要升级最新的shiro文件。
基于SpringMVC Mybatis Shiro Redis 的权限管理系统,该系统已经部署到线上,线上访问地址:http://shiro.itboy.net,登录账号:admin 密码:sojson,,详细教程参考sojson.com/shiro
# sso-shiro-cas spring下使用shiro+cas配置单点登录,多个系统之间的访问,每次只需要登录一次 ## 系统模块说明 1. cas: 单点登录模块,这里直接拿的是cas的项目改了点样式而已 2. doc: 文档目录,里面有数据库...
apache-shiro-webapp-tutorial 介绍了如何使用Apache Shiro保护Web应用程序。
Apache Shiro 是一个强大而灵活的开源安全框架,它干净利落地处理身份认证,授权,企业会话管理和加密。 Apache Shiro 的首要目标是易于使用和理解。安全有时候是很复杂的,甚至是痛苦的,但它没有必要这样。框架...
基于SpringMVC、Mybatis、Redis、Freemarker的Shiro管理Demo源码的升级版 相关详细配置说明请参看 --> http://www.sojson.com/shiro
张开涛《跟我学Shiro》PDF原件版本,学习交流使用,带目录,清晰。
apace shiro安全框架api,喜欢的童鞋下载吧
- the cas-shiro-demo-app module is a demo web application which uses the CAS Shiro support library with protected area requiring CAS authentication : http://shiro.apache.org/cas.html - the cas-shiro-...
apache-shiro-reference《Apache Shiro 参考手册》 Chinese translation of and the other article collection. The laset version of Apache Shiro is 1.5.x. You can also see the demos of the reference at ....
thymeleaf-extras-shiro-master通过Maven打包成的。里面另外包含resource.jar