🐛 fix: 新分配用户无法直接登录
This commit is contained in:
parent
d1a2f5a59a
commit
deb521abcd
|
@ -18,6 +18,7 @@ import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
|
|||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
|
||||
|
@ -71,8 +72,9 @@ public class CustomAuthorizationManagerServiceImpl implements AuthorizationManag
|
|||
|
||||
// 判断是否与请求路径匹配
|
||||
return powerList.stream().map(Power::getRequestUrl)
|
||||
.filter(Objects::nonNull)
|
||||
.anyMatch(requestUrl -> {
|
||||
if (requestUrl.contains("/*") || requestUrl.contains("/**")) {
|
||||
if ((requestUrl.contains("/*") || requestUrl.contains("/**"))) {
|
||||
return new AntPathRequestMatcher(requestUrl).matches(request);
|
||||
} else {
|
||||
return requestURI.matches(requestUrl);
|
||||
|
|
|
@ -6,7 +6,6 @@ import cn.bunny.dao.entity.system.AdminUser;
|
|||
import cn.bunny.dao.pojo.result.ResultCodeEnum;
|
||||
import cn.bunny.dao.vo.system.user.LoginVo;
|
||||
import cn.bunny.services.factory.UserFactory;
|
||||
import cn.bunny.services.mapper.RoleMapper;
|
||||
import cn.bunny.services.mapper.UserMapper;
|
||||
import cn.bunny.services.security.custom.CustomUser;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
|
@ -26,9 +25,6 @@ public class CustomUserDetailsServiceImpl implements cn.bunny.services.security.
|
|||
@Autowired
|
||||
private UserFactory userFactory;
|
||||
|
||||
@Autowired
|
||||
private RoleMapper roleMapper;
|
||||
|
||||
/**
|
||||
* 根据用户名获取用户对象(获取不到直接抛异常)
|
||||
*
|
||||
|
|
|
@ -69,6 +69,9 @@ public class RouterServiceImpl extends ServiceImpl<RouterMapper, Router> impleme
|
|||
List<Role> roleList = roleMapper.selectListByUserId(userId);
|
||||
List<String> roleCodeList = roleList.stream().map(Role::getRoleCode).toList();
|
||||
|
||||
// 如果没有分配角色直接返回空数组
|
||||
if (roleCodeList.isEmpty()) return new ArrayList<>();
|
||||
|
||||
// 根据角色列表查询权限信息
|
||||
List<Power> powerList = powerMapper.selectListByUserId(userId);
|
||||
List<String> powerCodeList = powerList.stream().map(Power::getPowerCode).toList();
|
||||
|
|
|
@ -9,6 +9,7 @@ import cn.bunny.services.service.UserRoleService;
|
|||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
|
@ -29,6 +30,10 @@ public class UserRoleServiceImpl extends ServiceImpl<UserRoleMapper, UserRole> i
|
|||
@Autowired
|
||||
private UserRoleMapper userRoleMapper;
|
||||
|
||||
@Autowired
|
||||
private RedisTemplate<String, Object> redisTemplate;
|
||||
|
||||
|
||||
/**
|
||||
* * 根据用户id获取角色列表
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue