浏览代码

modify:

1. 登录异常处理;
tags/24090601
WendyYang 2 个月前
父节点
当前提交
6be72d9838
共有 3 个文件被更改,包括 11 次插入8 次删除
  1. +3
    -8
      hz-pm-api/src/main/java/com/hz/pm/api/user/security/auth/code/AuthCodeLoginFilter.java
  2. +4
    -0
      hz-pm-api/src/main/java/com/hz/pm/api/user/security/auth/code/AuthCodeLoginUserDetailService.java
  3. +4
    -0
      hz-pm-api/src/main/java/com/hz/pm/api/user/util/LoginUserUtil.java

+ 3
- 8
hz-pm-api/src/main/java/com/hz/pm/api/user/security/auth/code/AuthCodeLoginFilter.java 查看文件

@@ -47,14 +47,9 @@ public class AuthCodeLoginFilter extends AbstractAuthenticationProcessingFilter
if (StrUtil.isBlank(userId)) {
throw new BadCredentialsException("授权码无效");
}
try {
AuthCodeToken authRequest = new AuthCodeToken(userId, userId);
authRequest.setDetails(new WebRequestDetails(request));
return this.getAuthenticationManager().authenticate(authRequest);
} catch (Exception e) {
logger.error(e.getMessage(), e);
throw new BadCredentialsException("授权失败");
}
AuthCodeToken authRequest = new AuthCodeToken(userId, userId);
authRequest.setDetails(new WebRequestDetails(request));
return this.getAuthenticationManager().authenticate(authRequest);
}

}

+ 4
- 0
hz-pm-api/src/main/java/com/hz/pm/api/user/security/auth/code/AuthCodeLoginUserDetailService.java 查看文件

@@ -1,6 +1,7 @@
package com.hz.pm.api.user.security.auth.code;


import cn.hutool.core.collection.CollUtil;
import com.hz.pm.api.common.helper.UserInfoHelper;
import com.hz.pm.api.user.convert.UserInfoConvertor;
import com.hz.pm.api.user.model.enumeration.UserAvailableEnum;
@@ -38,6 +39,9 @@ public class AuthCodeLoginUserDetailService implements UserDetailsService {
if (UserAvailableEnum.DISABLE.equals(ufi.getAvailable())) {
throw new CommonLoginException("账号已禁用");
}
if (CollUtil.isEmpty(ufi.getUserRoleList())) {
throw new CommonLoginException("账号未配置角色");
}
return UserInfoConvertor.convert(ufi);
}



+ 4
- 0
hz-pm-api/src/main/java/com/hz/pm/api/user/util/LoginUserUtil.java 查看文件

@@ -5,6 +5,7 @@ import com.hz.pm.api.sys.model.entity.Role;
import com.hz.pm.api.user.model.enumeration.RoleEnum;
import com.hz.pm.api.user.security.model.UserInfoDetails;

import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

@@ -26,6 +27,9 @@ public class LoginUserUtil extends AbstractLoginUserUtil {
public static List<Long> getRoleIdList() {
UserInfoDetails userInfoDetails = loginUserDetail();
List<Role> userRoleList = userInfoDetails.getUserRoleList();
if (userRoleList == null) {
return Collections.emptyList();
}
return userRoleList.stream().map(Role::getId).collect(Collectors.toList());
}



正在加载...
取消
保存