Shiro集成多个Realm,认证都不通过返回y configured realms. Please ensure that at least one realm can authenticate these tokens.
异常内容:Authentication token of type [class org.apache.shiro.authc.UsernamePasswordToken] could not be authenticated by any configured realms. Please ensure that at least one realm can authenticate these tokens.
意思是没有Realm进行处理,但实际上是当配置了多个realm时,就会 org.apache.shiro.authc.pam.ModularRealmAuthenticator#doMultiRealmAuthentication 通过这个方法进行执行,如果所有的对应的realm都返回认证异常或者null的话,就会出现以上错误
解决办法
第一种 集成ModularRealmAuthenticator重写doMultiRealmAuthentication方法
第二种,重写Authenticator的认证策略,由于ModularRealmAuthenticator默认是配置的这个 AtLeastOneSuccessfulStrategy策略,那么重写以下方法,当异常是认证异常时,则进行抛出认证异常
public class MyAtLeastOneSuccessfulStrategy extends AtLeastOneSuccessfulStrategy {
@Override
public AuthenticationInfo afterAttempt(Realm realm, AuthenticationToken token, AuthenticationInfo singleRealmInfo, AuthenticationInfo aggregateInfo, Throwable t) throws AuthenticationException {
if(t instanceof AuthenticationException){
throw (AuthenticationException)t;
}
return super.afterAttempt(realm, token, singleRealmInfo, aggregateInfo, t);
}
public static void main(String[] args) {
Provider[] providers = Security.getProviders();
System.out.println(providers);
}
}

根据所需抛出的异常时机,重写以上方法即可,方法作用直接看doc就能明白
那么最关键的怎么配置呢?

这2个shiro的配置类,至少我这边没有使用上,如果你的代码使用了,继承此类重写对应的方法返回的实例即可。
而我是这么解决的。

Shiro集成多个Realm,认证都不通过返回y configured realms. Please ensure that at least one realm can authenticate these tokens.的更多相关文章
- Shiro集成web环境[Springboot]-认证与授权
Shiro集成web环境[Springboot]--认证与授权 在登录页面提交登陆数据后,发起请求也被ShiroFilter拦截,状态码为302 <form action="${pag ...
- ae:org.apache.shiro.authc.AuthenticationException: Authentication token of type [class org.apache.shiro.authc.UsernamePasswordToken] could not be authenticated by any configured realms. Please ensure
看问题是说要保证有一个realm正确,但是之前运行就一直成功,后来就不行了.有可能是:以为自己输入了正确的用户名和密码,结果是因为用户名前面添加了空格导致了这个错误发生. 实质问题是:你输入的用户名和 ...
- SpringBoot 整合 Shiro 密码登录与邮件验证码登录(多 Realm 认证)
导入依赖(pom.xml) <!--整合Shiro安全框架--> <dependency> <groupId>org.apache.shiro</group ...
- Shiro笔记(四)Shiro的realm认证
认证流程: 1.获取当前Subject.调用SecurityUtils.getSubject(); 2.测试当前用户是否已经被认证,即是否已经登录,调用Subject的isAurhenticated( ...
- spring-boot-2.0.3应用篇 - shiro集成
前言 上一篇:spring-boot-2.0.3源码篇 - 国际化,讲了如何实现国际化,实际上我工作用的模版引擎是freemaker,而不是thymeleaf,不过原理都是相通的. 接着上一篇,这一篇 ...
- shiro集成encache
针对多频次或者几乎不变的大数量的数据,我们可以通过缓存来实现,具体的比如说权限认证,这个,每次操作都需要权限认证,所以,这里添加encache注解.具体的认证过程是: 1,用户第一次访问用户权限信息, ...
- 【从0到1,搭建Spring Boot+RESTful API+Shiro+Mybatis+SQLServer权限系统】05、Shiro集成
1.POM文件中加入Shiro和fastJSON依赖 <dependency> <groupId>org.apache.shiro</groupId> <ar ...
- 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 ...
- Shiro+easyUI+SpringMVC实现登录认证
最近在做一个小项目,其中认证这块使用shiro+SpringMVC+easyUI,因为easyUI在提交数据的时候使用的是ajax的异步提交,所以shiro在处理数据的时候需要重写FormAuth ...
随机推荐
- java POI 导出到word文档 (附工具类)
1,导入poi相关依赖 <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi-o ...
- [题解]UVA658 It's not a Bug, it's a Feature!
链接:http://vjudge.net/problem/viewProblem.action?id=22169 描述:有n个漏洞,m个修复漏洞的方法,每种方法耗时不一样,求修复漏洞的最短时间.每种方 ...
- Unicode 详细介绍
总结起来为啥需要Unicodey就是为了适应全球化的发展,便于不同语言之间的兼容交互,而ASCII不再能胜任此任务了 UTF-8 与UTF-16的区别 UTF-8的优缺点 程序员那么到底该如何选择呢? ...
- mysql-8.0.12 安装使用教程
Microsoft Windows [版本 10.0.15063] (c) 2017 Microsoft Corporation.保留所有权利. C:\WINDOWS\system32>D: D ...
- Spring Cloud Gateway 远程代码执行漏洞(CVE-2022-22947)
参考: https://y4er.com/post/cve-2022-22947-springcloud-gateway-spel-rce-echo-responsehttps://cloud.spr ...
- WPF子窗体
效果: 1. 点击WPF主窗体上的一个按钮,弹出子窗体, 2. 窗体最小化后,在菜单栏中点击子窗体,会连带显示它所从属的主窗体. 1. 在WPF项目中,已有主窗体MainWindow,再新建子窗体Ch ...
- 矩池云上使用nohup和&让任务后台运行
1.nohup 用途:不挂断地运行命令. 语法:nohup Command [ Arg - ] [ & ] 无论是否将 nohup 命令的输出重定向到终端,输出都将附加到当前目录的 nohup ...
- awk讲义-1-快速入门
awk讲义-1-快速入门 一.目标问题: 1.统计各个省份中城市的数量(一维数组) 2.统计城市中区县数量,要求输出格式:省份 城市 区县数量(二维数组) 3.求两个文件的交集 4.省市和市区两个文件 ...
- 字节一面:go的协程相比线程,轻量在哪?
1. 用户态和内核态 Linux整个体系分为用户态和内核态(或者叫用户空间和内核空间), 那内核态究竟是什么呢? 本质上我们所说的内核态, 它是一种特殊的软件程序,特殊在哪? 统筹计算机的硬件资源,例 ...
- ASP.NET Core 6框架揭秘实例演示[24]:中间件的多种定义方式
ASP.NET Core的请求处理管道由一个服务器和一组中间件组成,位于 "龙头" 的服务器负责请求的监听.接收.分发和最终的响应,针对请求的处理由后续的中间件来完成.中间件最终体 ...