feat(sj_1.0.0): 采用全局拦截普通用户权限为空的情况

This commit is contained in:
opensnail 2024-06-07 09:04:47 +08:00
parent c1071d82f4
commit 5e32dc2cd7

View File

@ -91,7 +91,7 @@ public class AuthenticationInterceptor implements HandlerInterceptor {
Long count = namespaceMapper.selectCount( Long count = namespaceMapper.selectCount(
new LambdaQueryWrapper<Namespace>().eq(Namespace::getUniqueId, namespaceId)); new LambdaQueryWrapper<Namespace>().eq(Namespace::getUniqueId, namespaceId));
Assert.isTrue(count > 0, () -> new SnailJobServerException("[{}] 命名空间不存在", namespaceId)); Assert.isTrue(count > 0, () -> new SnailJobAuthenticationException("[{}] 命名空间不存在", namespaceId));
UserSessionVO userSessionVO = new UserSessionVO(); UserSessionVO userSessionVO = new UserSessionVO();
userSessionVO.setId(systemUser.getId()); userSessionVO.setId(systemUser.getId());
userSessionVO.setUsername(systemUser.getUsername()); userSessionVO.setUsername(systemUser.getUsername());
@ -106,7 +106,9 @@ public class AuthenticationInterceptor implements HandlerInterceptor {
.eq(SystemUserPermission::getSystemUserId, systemUser.getId()) .eq(SystemUserPermission::getSystemUserId, systemUser.getId())
.eq(SystemUserPermission::getNamespaceId, namespaceId) .eq(SystemUserPermission::getNamespaceId, namespaceId)
); );
userSessionVO.setGroupNames(StreamUtils.toList(systemUserPermissions, SystemUserPermission::getGroupName)); List<String> groupNames = StreamUtils.toList(systemUserPermissions, SystemUserPermission::getGroupName);
Assert.notEmpty(groupNames, () -> new SnailJobAuthenticationException("用户组权限为空"));
userSessionVO.setGroupNames(groupNames);
} }
httpServletRequest.setAttribute("currentUser", userSessionVO); httpServletRequest.setAttribute("currentUser", userSessionVO);