could not be authenticated by any configured realms. 。Please ensure that at least one realm问题
问题描述:
shiro配置多realm时出现的问题。
org.apache.shiro.authc.AuthenticationException: Authentication token of type [class com.finn.springboot002.common.config.shiro.JwtToken] could not be authenticated by any configured realms. Please ensure that at least one realm can authenticate these tokens.
我的理解是,该token没有配置的realm来认证。请你最少得整一个。百度许久得到解决办法!如下:
解决方案:
token错误或失效也会引起该错误。确保token正确但还会引起错误的话,下面是一种解决方案。
配置自定义证书匹配器
package com.finn.springboot002.common.config.shiro;import com.auth0.jwt.JWTVerifier;
import com.auth0.jwt.JWT;
import com.auth0.jwt.algorithms.Algorithm;
import com.auth0.jwt.exceptions.JWTVerificationException;
import com.finn.springboot002.common.utils.JwtUtils;
import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.credential.CredentialsMatcher;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;/*** 自定义证书匹配器*/
public class JwtCredentialsMatcher implements CredentialsMatcher {private Logger logger = LoggerFactory.getLogger(this.getClass());@Overridepublic boolean doCredentialsMatch(AuthenticationToken authToken, AuthenticationInfo info) {String token = authToken.getPrincipal().toString();try {Algorithm algorithm = Algorithm.HMAC256(JwtUtils.SECRET);JWTVerifier verifier = JWT.require(algorithm).withClaim("username", JwtUtils.getUsername(token)).build();verifier.verify(token);return true;} catch (JWTVerificationException e) {logger.error(e.getMessage());return false;}}
}
在shiroconfig配置类中的JwtRealm bean增加如下配置
/*** JwtRealm 配置自定义匹配器*/@Beanpublic JwtRealm jwtRealm() {JwtRealm jwtRealm = new JwtRealm();CredentialsMatcher credentialsMatcher = new JwtCredentialsMatcher();jwtRealm.setCredentialsMatcher(credentialsMatcher);return jwtRealm;}
OK,问题解决!
感谢大佬:https://blog.csdn.net/pengjunlee/article/details/95600843
could not be authenticated by any configured realms. 。Please ensure that at least one realm问题相关推荐
- shiro 多realm报错could not be authenticated by any configured realms. Please ensure that at least o
使用中的项目采用shiro,虽然使用下来感觉虽然轻量化,但是很多东西还是要自己摸索,最近正好碰到一个问题就是采用多种方式登录,有一个方式成功就成功登录,相比一些功能比如说踢人什么的,这个多种方式登录时 ...
- shiro学习一 (开涛的跟我学系列 ) 身份验证
原文来自于http://jinnianshilongnian.iteye.com/blog/2018398 1.简介 Apache Shiro是Java的一个安全框架.可以帮助我们完成:认证.授权.加 ...
- 【开发技术】2万字分析shiro、spring security两大安全框架,spring session,OAuth2 入门级教程
SpringBoot 内容管理 Shiro 创建demo 用户[用户包括token ,角色,权限] :fist_oncoming: Shiro配置 配置5个基本对象 + 3额外对象 路径匹配有先后 : ...
- 手机短信登录、邮箱登录、QQ 登录都想要,咋办?
文章目录 1. ModularRealmAuthenticator 1.1 Realm 去哪了? 1.2 ModularRealmAuthenticator 怎么玩 2. Authentication ...
- shiro-No realms have been configured
文章目录 描述 解决办法 源码重点解析 1. 初始化 2. 赋值 总结 描述 Configuration error: No realms have been configured! One or m ...
- Shiro实现多Realm认证、SecurityManager配置realms
认证策略实际上是AuthenticationStrategy这个接口,它有三个实现: • AuthenticationStrategy 接口的默认实现: • FirstSuccessfulStrate ...
- shiro之AuthenticationStrategy
2019独角兽企业重金招聘Python工程师标准>>> AuthenticationStrategy When two or more realms are configured f ...
- Apache Tomcat Configuration Reference
http://www.jaxmao.org/tomcat-docs/config/index.html 概 述 print-friendly version Overview 这个手册包括可能被包括在 ...
- Apache Shiro 全面源码解析汇总
什么是shiro? Apache Shiro官网上对Shiro的解释如下: Apache Shiro (pronounced "shee-roh", the Japanese wo ...
最新文章
- 安装ATi显卡驱动后增加的鼠标右键菜单的清理
- jquery插件课程2 放大镜、多文件上传和在线编辑器插件如何使用
- jdbc,mybatis,hibernate各自优缺点及区别
- 工作44:阅读代码1 dictionary
- 敏捷开发用户故事系列之三:用户建模
- 解决serv-u中文乱码的问题
- CATIA VBA二次开发介绍
- 威纶通触摸屏可以解密吗_老电工选型威纶通触摸屏时的3大技巧!知道了能帮你省事不少...
- mysql的update条件语句_MySQL UPDATE语句介绍
- 昂达vi40精英版刷Linux,昂达Vi40精英版V1.0固件专业网友实测
- pandas从时间序列中判断是一周的第几天或星期几
- C语言必会100题(2)。用*号输出字母C的图案/输出特殊图案/输出9*9口诀/输出国际象棋棋盘/打印楼梯,同时在楼梯上方打印两个笑脸
- pat 训练题 7-5 基友团 (25分) 暴力判团和最大团
- 大数据可视化工程师岗位要求包括哪些?
- PDF怎么转换成Word文档呢?不妨试试这两种方法!
- DNA-蛋白翻译过程的Python实现
- 蘑菇街 java 面试_【蘑菇街java工程师面试】蘑菇街Java后台开发二面挫败-看准网...
- 关于线程同步的几种方法
- 嵌入式-ARM-学习总结(7):按键与中断
- Android 8.0(Android O) AccountManager 行为变更
热门文章
- mcp23017接线图_MCP23017,MCP23017 pdf中文资料,MCP23017引脚图,MCP23017电路-Datasheet-电子工程世界...
- Android WiFi直连 双向通信
- 【STM32CubeMx你不知道的那些事】第三章:STM32CubeMx串口配置(中断接收)
- c语言 conio h,c语言中conio.h是什么?
- Spring Boot Actuator监控页面报错解决
- 企业隐患排查文本挖掘比赛(二):算法篇(从词向量到BERT)
- 大数据可以揭示基因密码吗?
- 企业在ERP系统下的全面预算管理系统的实现
- matlab计算夏普比率,用凯利公式计算最优配置
- Nginx 负载均衡 初步配置验证 笔记