Browse Source

modify:

1. 登录异常处理;
tags/24090601
WendyYang 2 months ago
parent
commit
6be72d9838
3 changed files with 11 additions and 8 deletions
  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 View File

@@ -47,14 +47,9 @@ public class AuthCodeLoginFilter extends AbstractAuthenticationProcessingFilter
if (StrUtil.isBlank(userId)) { if (StrUtil.isBlank(userId)) {
throw new BadCredentialsException("授权码无效"); 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 View File

@@ -1,6 +1,7 @@
package com.hz.pm.api.user.security.auth.code; 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.common.helper.UserInfoHelper;
import com.hz.pm.api.user.convert.UserInfoConvertor; import com.hz.pm.api.user.convert.UserInfoConvertor;
import com.hz.pm.api.user.model.enumeration.UserAvailableEnum; import com.hz.pm.api.user.model.enumeration.UserAvailableEnum;
@@ -38,6 +39,9 @@ public class AuthCodeLoginUserDetailService implements UserDetailsService {
if (UserAvailableEnum.DISABLE.equals(ufi.getAvailable())) { if (UserAvailableEnum.DISABLE.equals(ufi.getAvailable())) {
throw new CommonLoginException("账号已禁用"); throw new CommonLoginException("账号已禁用");
} }
if (CollUtil.isEmpty(ufi.getUserRoleList())) {
throw new CommonLoginException("账号未配置角色");
}
return UserInfoConvertor.convert(ufi); return UserInfoConvertor.convert(ufi);
} }




+ 4
- 0
hz-pm-api/src/main/java/com/hz/pm/api/user/util/LoginUserUtil.java View File

@@ -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.model.enumeration.RoleEnum;
import com.hz.pm.api.user.security.model.UserInfoDetails; import com.hz.pm.api.user.security.model.UserInfoDetails;


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


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




Loading…
Cancel
Save