Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

微服务框架下的定时任务和字典项查询无权限 #2662

Closed
zhubinsheng opened this issue Jun 17, 2021 · 10 comments
Closed

微服务框架下的定时任务和字典项查询无权限 #2662

zhubinsheng opened this issue Jun 17, 2021 · 10 comments

Comments

@zhubinsheng
Copy link

zhubinsheng commented Jun 17, 2021

版本号:

最新

问题描述:

在module_dome模块下一个公开的接口 如何调用系统的查询字典项功能?

截图&代码:

[500] during [GET] to [http://jeecg-system/sys/api/translateDictFromTable?table=region&text=region_name&code=region_name&key=shqx] [ISysBaseAPI#translateDictFromTable(String,String,String,String)]: [{"timestamp":"2021-06-17 10:31:53","status":500,"error":"Internal Server Error","exception":"org.apache.shiro.authc.AuthenticationException","trace":"org.apache.shiro.authc.AuthenticationException: To... (7075 bytes)]

友情提示: 未按格式要求发帖,会直接删掉。

@zhubinsheng
Copy link
Author

` /**
* 校验token的有效性
*
* @param token
*/
public LoginUser checkUserTokenIsEffect(String token) throws AuthenticationException {
// 解密获得username,用于和数据库进行对比
String username = JwtUtil.getUsername(token);
if (username == null) {
throw new AuthenticationException("token非法无效!");
}

    // 查询用户信息
    log.debug("———校验token是否有效————checkUserTokenIsEffect——————— "+ token);
    LoginUser loginUser = commonAPI.getUserByName(username);
    if (loginUser == null) {
        throw new AuthenticationException("用户不存在!");
    }`

服务间调用的时候 没有token该如何处理这种情况?

@zhubinsheng
Copy link
Author

感谢平台,感谢作者,感谢开源。

@zhangdaiscott
Copy link
Member

定时任务没有登录状态,肯定获取不到token,为什么不直接调用service或者dao层

@zhubinsheng
Copy link
Author

定时任务没有登录状态,肯定获取不到token,为什么不直接调用service或者dao层

感谢回复,因为这个service归另外一个服务所有

@zhubinsheng
Copy link
Author

定时任务没有登录状态,肯定获取不到token,为什么不直接调用service或者dao层

查询字典项功能是system模块中的,其他模块想调用的话不就得走Feign 服务调用机制,但是我没有token怎么查询呢?

@zhangdaiscott
Copy link
Member

实在需求,你可以自己实现模拟登录,获取token

@zhubinsheng
Copy link
Author

实在需求,你可以自己实现模拟登录,获取token

我之前是这么写的,但是我觉得太low了,所以想请教一下有没有奇思淫巧可以解决的?

@zhangdaiscott
Copy link
Member

微服务之间调用免Token方案
http://doc.jeecg.com/2725212

@rocye
Copy link

rocye commented Jun 15, 2024

微服务之间调用免Token方案 http://doc.jeecg.com/2725212
按照此文档试过很多遍了,仍然报401,用的版本是3.4.3last

@rocye
Copy link

rocye commented Jun 15, 2024

@zhangdaiscott 按文档一步步操作的,不知道是什么原因在FeignConfig里面就是获不到在微服务的业务层里面用UserTokenContext设置的token

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants