Browse Source

1、shiro、swagger配置

2、登录配置
master
Aug 17 hours ago
parent
commit
af874b4477
5 changed files with 46 additions and 1 deletions
  1. +6
    -0
      jeecg-boot-base/jeecg-boot-base-api/jeecg-system-cloud-api/src/main/java/org/jeecg/common/system/api/fallback/SysBaseAPIFallback.java
  2. +7
    -0
      jeecg-boot-base/jeecg-boot-base-core/src/main/java/org/jeecg/common/api/CommonAPI.java
  3. +1
    -1
      jeecg-boot-base/jeecg-boot-base-core/src/main/java/org/jeecg/config/Swagger2Config.java
  4. +2
    -0
      jeecg-boot-base/jeecg-boot-base-core/src/main/java/org/jeecg/config/shiro/ShiroConfig.java
  5. +30
    -0
      jeecg-boot-base/jeecg-boot-base-core/src/main/java/org/jeecg/config/shiro/ShiroRealm.java

+ 6
- 0
jeecg-boot-base/jeecg-boot-base-api/jeecg-system-cloud-api/src/main/java/org/jeecg/common/system/api/fallback/SysBaseAPIFallback.java View File

@ -234,6 +234,12 @@ public class SysBaseAPIFallback implements ISysBaseAPI {
log.error("服务节点不通,导致获取登录用户信息失败: " + cause.getMessage(), cause); log.error("服务节点不通,导致获取登录用户信息失败: " + cause.getMessage(), cause);
return null; return null;
} }
@Override
public HanHaiMember getUserByNameHanHaiXcxOpenId(String username) {
log.error("服务节点不通,导致获取登录用户信息失败: " + cause.getMessage(), cause);
return null;
}
// //
// @Override // @Override
// public DbMumber getUserByName3(String username,Integer isOrgan) { // public DbMumber getUserByName3(String username,Integer isOrgan) {


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

@ -63,6 +63,13 @@ public interface CommonAPI {
* */ * */
public HanHaiMember getUserByNameHanHaiAccount(String username); public HanHaiMember getUserByNameHanHaiAccount(String username);
/**
* 小程序验证 - 小程序openid验证
* @param username
* @return
* */
public HanHaiMember getUserByNameHanHaiXcxOpenId(String username);
/** /**


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

@ -68,7 +68,7 @@ public class Swagger2Config implements WebMvcConfigurer {
.apiInfo(apiInfo()) .apiInfo(apiInfo())
.select() .select()
//此包路径下的类才生成接口文档 //此包路径下的类才生成接口文档
.apis(RequestHandlerSelectors.basePackage("org.jeecg.modules.api"))
.apis(RequestHandlerSelectors.basePackage("org.jeecg.modules.api.studytourController"))
//加了ApiOperation注解的类才生成接口文档 //加了ApiOperation注解的类才生成接口文档
.apis(RequestHandlerSelectors.withClassAnnotation(RestController.class)) .apis(RequestHandlerSelectors.withClassAnnotation(RestController.class))
.apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class)) .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))


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

@ -72,6 +72,8 @@ public class ShiroConfig {
} }
} }
filterChainDefinitionMap.put("/studytour/**", "anon"); //小程序验证放开
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"); //图片上传验证放开
filterChainDefinitionMap.put("/sys/cas/client/validateLogin", "anon"); //cas验证登录 filterChainDefinitionMap.put("/sys/cas/client/validateLogin", "anon"); //cas验证登录


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

@ -190,6 +190,36 @@ public class ShiroRealm extends AuthorizingRealm {
return user; return user;
} }
/**
* 校验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;
}
/** /**


Loading…
Cancel
Save