Browse Source

1、添加权限验证

master
Augcl 4 months ago
parent
commit
be0b7f8b12
4 changed files with 60 additions and 1 deletions
  1. +9
    -0
      jeecg-boot-base/jeecg-boot-base-core/src/main/java/org/jeecg/common/api/CommonAPI.java
  2. +1
    -1
      jeecg-boot-base/jeecg-boot-base-core/src/main/java/org/jeecg/config/shiro/ShiroConfig.java
  3. +33
    -0
      jeecg-boot-base/jeecg-boot-base-core/src/main/java/org/jeecg/config/shiro/ShiroRealm.java
  4. +17
    -0
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/service/impl/SysBaseApiImpl.java

+ 9
- 0
jeecg-boot-base/jeecg-boot-base-core/src/main/java/org/jeecg/common/api/CommonAPI.java View File

@ -65,6 +65,15 @@ public interface CommonAPI {
/**
* 小程序验证 - 小程序openid验证
* @param username
* @return
* */
public HanHaiMember getUserByNameHanHaiXcxOpenId(String username);
/** /**
* 6字典表的 翻译 * 6字典表的 翻译
* @param table * @param table


+ 1
- 1
jeecg-boot-base/jeecg-boot-base-core/src/main/java/org/jeecg/config/shiro/ShiroConfig.java View File

@ -73,7 +73,7 @@ public class ShiroConfig {
} }
//特易招 //特易招
filterChainDefinitionMap.put("/api/*", "anon"); //api相关接口全部放开
filterChainDefinitionMap.put("/api/**", "anon"); //api相关接口全部放开
filterChainDefinitionMap.put("/sys/oss/file/upload", "anon"); //图片上传验证放开 filterChainDefinitionMap.put("/sys/oss/file/upload", "anon"); //图片上传验证放开
filterChainDefinitionMap.put("/sys/common/upload", "anon"); //图片上传验证放开 filterChainDefinitionMap.put("/sys/common/upload", "anon"); //图片上传验证放开


+ 33
- 0
jeecg-boot-base/jeecg-boot-base-core/src/main/java/org/jeecg/config/shiro/ShiroRealm.java View File

@ -192,6 +192,39 @@ public class ShiroRealm extends AuthorizingRealm {
/**
* 校验token的有效性
*
* @param token
*/
public HanHaiMember checkUserTokenIsEffectHanHaiOpenId(String token) throws AuthenticationException {
Result result = new Result();
// 解密获得username用于和数据库进行对比
String openid = JwtUtil.getUsername(token);
if (openid == null) {
throw new AuthenticationException("token非法无效!");
}
// 查询用户信息
log.debug("———校验token是否有效————checkUserTokenIsEffect——————— "+ token);
HanHaiMember user = commonApi.getUserByNameHanHaiXcxOpenId(openid);
if (user == null || user.getAppletOpenid() == null) {
throw new AuthenticationException("用户不存在!");
}
// // 判断用户状态
// if (user.getDeleteFlag().equals("Y")) {
// throw new AuthenticationException("账号已被注销,请联系管理员!");
// }
// 校验token是否超时失效 & 或者账号密码是否错误
if (!jwtTokenRefresh(token, openid, openid)) {
throw new JeecgBoot401Exception(CommonConstant.TOKEN_IS_INVALID_MSG);
}
return user;
}
/** /**
* JWTToken刷新生命周期 实现 用户在线操作不掉线功能 * JWTToken刷新生命周期 实现 用户在线操作不掉线功能
* 1登录成功后将用户的JWT生成的Token作为kv存储到cache缓存里面(这时候kv值一样)缓存有效期设置为Jwt有效时间的2倍 * 1登录成功后将用户的JWT生成的Token作为kv存储到cache缓存里面(这时候kv值一样)缓存有效期设置为Jwt有效时间的2倍


+ 17
- 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/service/impl/SysBaseApiImpl.java View File

@ -144,6 +144,23 @@ public class SysBaseApiImpl implements ISysBaseAPI {
return user; return user;
} }
/**
* 公共验证--根据账号查询验证用户信息-客户端
* @param username
* @return
* */
@Override
public HanHaiMember getUserByNameHanHaiXcxOpenId(String username){
if(oConvertUtils.isEmpty(username)) {
return null;
}
HanHaiMember user = hanHaiMemberService.lambdaQuery().eq(HanHaiMember::getAppletOpenid,username).one();
if(user==null) {
return null;
}
return user;
}
@Override @Override
public String translateDictFromTable(String table, String text, String code, String key) { public String translateDictFromTable(String table, String text, String code, String key) {


Loading…
Cancel
Save