Comments (3)
可能我提问中的 Stream 方式不太容易理解,我将其简化为如下 for 循环方式,两种方式应该是等效的,都能够说明问题
public List<String> getCurrentUserLoginPlatform() {
// 获取当前登录账号的ID
Object loginId = StpUtil.getLoginId();
// 获取该账号的所有设备的Token Value
List<String> tokenValues = StpUtil.getTokenValueListByLoginId(loginId);
ArrayList<String> deviceList = new ArrayList<>();
// 遍历所有Token Value
for (String tokenValue : tokenValues) {
// 通过Token Value获取Session信息
SaSession tokenSession = StpUtil.getTokenSessionByToken(tokenValue);
if (tokenSession != null) {
// 获取 session 的 dataMap
Map<String, Object> dataMap = tokenSession.getDataMap();
// 获取 dataMap 中保存的 device 字段(登录时写入)
String device = dataMap.getOrDefault("device", "未知设备").toString();
deviceList.add(device);
}
}
return deviceList;
}
from sa-token.
写的有点麻烦, 我大致写一个你先看看行不行, 稍后我再看看你的代码
Set<String> currentUserLoginDevices = StpUtil.getSession()
.getTokenSignList()
.stream().map(TokenSign::getDevice)
.collect(Collectors.toSet());
from sa-token.
写的有点麻烦, 我大致写一个你先看看行不行, 稍后我再看看你的代码 ...
谢谢,可以获取到了!原来是这样实现的😂
看来是我的打开方式不对,没注意到TokenSign::getDevice这个方法哈哈哈,再次感谢!
from sa-token.
Related Issues (20)
- 反向代理配置后调用接口抛出cn.dev33.satoken.exception.NotLoginException: 未能读取到有效 token
- SaCheckRole注解鉴权
- 注释鉴权可以模糊匹配内容进行鉴权 HOT 1
- 建议Oauth2 增加 base64(client_id:client_secret)自动解析功能 以看似提升了安全性~ HOT 1
- SaHolder怎么替换为 ThreadLocalHolder,分离本地存储
- login、
- StpLogic类中的方法checkLoginArgs中有一段是不是有 HOT 1
- 在路由校验的时候应该忽略掉 context path
- 日志输出国际化 HOT 1
- token session 过期时间bug HOT 2
- 能否实现网关处理认证,服务处理权限校验 HOT 2
- 我想禁用cookie,但是配置了跨域禁用cookie之后没有什么用 HOT 3
- 能否支持数据库替代redis HOT 2
- sa-token-dao-redis-jackson没有1.37.0版本吗 HOT 1
- StpLogic#replaced为什么不清除token-session?
- 请问1.36绕开鉴权的危害 HOT 2
- 访问一个不存在的接口时抛出NotLoginException但RestControllerAdvice无法捕获这个异常 HOT 2
- springboot 2.4.5 集成satoken报错Error creating bean with name 'cn.dev33.satoken.spring.SaBeanInject'
- 动态将token和和缓存数据存取到不同的redis实例
- 多账户认证下,集成jwt时tokenName被覆盖的问题
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sa-token.