@@ -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); | |||||
} | } | ||||
} | } |
@@ -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); | ||||
} | } | ||||
@@ -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()); | ||||
} | } | ||||