dolyw / shirojwt Goto Github PK
View Code? Open in Web Editor NEWAPI SpringBoot + Shiro + Java-Jwt + Redis(Jedis)
Home Page: https://gitee.com/dolyw/ShiroJwt
License: MIT License
API SpringBoot + Shiro + Java-Jwt + Redis(Jedis)
Home Page: https://gitee.com/dolyw/ShiroJwt
License: MIT License
遇到这么一个问题, shiro把SimpleAuthenticationInfo 换存进去后, 再要取出时, 无法转化为AuthorizationInfo;
shiro源码:
protected AuthorizationInfo getAuthorizationInfo(PrincipalCollection principals) {
if (principals == null) {
return null;
}
AuthorizationInfo info = null;
if (log.isTraceEnabled()) {
log.trace("Retrieving AuthorizationInfo for principals [" + principals + "]");
}
Cache<Object, AuthorizationInfo> cache = getAvailableAuthorizationCache();
if (cache != null) {
if (log.isTraceEnabled()) {
log.trace("Attempting to retrieve the AuthorizationInfo from cache.");
}
Object key = getAuthorizationCacheKey(principals);
** info = cache.get(key); ** // 这里就是报错的地方
if (log.isTraceEnabled()) {
if (info == null) {
log.trace("No AuthorizationInfo found in cache for principals [" + principals + "]");
} else {
log.trace("AuthorizationInfo found in cache for principals [" + principals + "]");
}
}
}
if (info == null) {
// Call template method if the info was not found in a cache
info = doGetAuthorizationInfo(principals);
// If the info is not null and the cache has been created, then cache the authorization info.
if (info != null && cache != null) {
if (log.isTraceEnabled()) {
log.trace("Caching authorization info for principals: [" + principals + "].");
}
Object key = getAuthorizationCacheKey(principals);
cache.put(key, info);
}
}
return info;
}
示例代码中并发请求判断在有效时间内之后,登陆依然用的是旧的token(this.getSubject(request,response).login(oldToken)),这样shiro不是会继续报出token失效的异常吗,依然会登陆不成功
如题
ExceptionAdvice这个全局异常捕获不起作用吧 这个捕获应该只对进入controller的请求出错抛出的异常才起作用 才能拦截到吧 对于JwtFilter里面抛出的异常都是处理不到的
不知道我理解的对不对,以后每次访问携带jwt,都要走Realm里的认证方法,里面每次都从数据库查询用户信息,这样效率行么?
定义了CustomCache类,但是当前缓存是在哪put了呢?
我参考了你的代码,把用户认证单独放在一个微服务里,那这样其他微服务是不是都要有token认证和鉴权?
你好,大佬。我这边跑大佬的代码出现了一个问题,JedisPool为空。
比如 spring-boot-starter-data-redis ?
你是通过捕获TokenExpiredException异常来判断是否需要刷新accessToken,但是没看到这个异常是在什么地方抛出来的
String token = (String)authenticationToken.getCredentials();
这里获取的token前会被加上Bearer
原本应该是:
eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJjdXJyZW50VGltZU1pbGx ……
现在
Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJjdXJyZW50VGltZU1pbGx ……
同时多个请求,第一个请求刷新了 Token
,后面的请求还是携带的刷新前的旧 Token
就无法通过,该怎么处理
考虑升级一下springboot么 版本有点老
比如我直接throw new AuthenticationException("token_expire"); 他会直接给前端“token_expire”,而不是我在全局异常捕获中定义的对AuthenticationException异常的封装?
为什么前台调用后台的接口,后台总是调用不到?
显示:The current Subject is not authenticated
前台应该怎么写?求指导,好像是跨域问题
sso的各个系统在不同的域下,不同域下cookie vue_admin_template_token没法共享,有没有好的解决办法?
该方法是还没有完成么,还是完成后没有去除 TODO 标记
token刷新的时候后台会打印一大堆东西,而且Shiro也会报异常类型警官的说。
这种写法好像只能一方登录,可以整合下多方登录与踢出吗?
我怎么觉得有问题
首先你写在config.properties里面的accessTokenExpireTime等没有读取到
其次是当token超时以后
执行executeLogin抛出了 AuthenticationException
这个异常你的程序里面没有处理
但是我看控制台抛出的是TokenExpiredException(这个好像是从verity那边跑出来的)
但是在JwtFilter里面的是AuthenticationException
所以没法刷新token
不知道是我自己问题还是你的问题,麻烦大佬看一下
在JwtFilter中为什么每次请求都需要调用shiro的subject.login ?
有没有办法一次性登陆后续的接口不用登陆? 因为token从实际意义来看,也只能是已登陆用户才能持有的凭证。
yml配置文件缩进问题以及数据库配置用户名应为username
SpringBoot本身提供了注解支持读取配置文件的说
在项目中没有找到数据库初始化文件
这个问题怎样解决的
同一个页面一般情况下都会同时请求多个后台接口,当accessToken失效的时候,同时有多个请求,后端会不会刷新出多个newtoken的问题?
您的代码中自定义的realm中,
在身份验证的方法, 为什么token是从getCredentials()中取呢? 不是应该从 getPrincipal()中取出吗?
源码中getCredentials()返回的应该是密码吧, 为什么要把token保存在密码中呢,
不是一般都是用用户ID去做Token的吗?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.