Skip to content

Commit e91f96f

Browse files
committed
feat: Security工具方法改为static
1 parent 6f52997 commit e91f96f

2 files changed

Lines changed: 5 additions & 6 deletions

File tree

framework/src/main/java/top/cadecode/uniboot/framework/security/TokenAuthHolder.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import org.springframework.security.core.context.SecurityContextHolder;
1111
import org.springframework.stereotype.Component;
1212
import top.cadecode.uniboot.system.bean.dto.SysUserDto;
13+
import top.cadecode.uniboot.system.bean.dto.SysUserDto.SysUserDetailsDto;
1314

1415
import javax.servlet.http.Cookie;
1516
import javax.servlet.http.HttpServletRequest;
@@ -145,7 +146,7 @@ public String getTokenFromRequest(HttpServletRequest request) {
145146
* @param authentication Security认证信息
146147
* @return token
147148
*/
148-
public boolean isAuthenticated(Authentication authentication) {
149+
public static boolean isAuthenticated(Authentication authentication) {
149150
if (ObjectUtil.isNull(authentication)) {
150151
authentication = SecurityContextHolder.getContext().getAuthentication();
151152
}
@@ -158,7 +159,7 @@ public boolean isAuthenticated(Authentication authentication) {
158159
* @param authentication Security认证信息
159160
* @return SysUserDetailsDto
160161
*/
161-
public SysUserDto.SysUserDetailsDto getUserDetails(Authentication authentication) {
162+
public static SysUserDetailsDto getUserDetails(Authentication authentication) {
162163
if (ObjectUtil.isNull(authentication)) {
163164
authentication = SecurityContextHolder.getContext().getAuthentication();
164165
}

framework/src/main/java/top/cadecode/uniboot/framework/security/voter/DataBaseRoleVoter.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,9 @@ public class DataBaseRoleVoter extends RoleVoter {
3131

3232
private final SysApiService sysApiService;
3333

34-
private final TokenAuthHolder tokenAuthHolder;
35-
3634
@Override
3735
public int vote(Authentication authentication, Object object, Collection<ConfigAttribute> attributes) {
38-
if (!tokenAuthHolder.isAuthenticated(authentication)) {
36+
if (!TokenAuthHolder.isAuthenticated(authentication)) {
3937
return ACCESS_ABSTAIN;
4038
}
4139
// 获取请求 url
@@ -44,7 +42,7 @@ public int vote(Authentication authentication, Object object, Collection<ConfigA
4442
// 获取 api role 的关系列表
4543
List<SysApiRolesVo> sysApiRolesVos = sysApiService.listSysApiVo();
4644
// 获取用户角色
47-
SysUserDto.SysUserDetailsDto sysUserDetailsDto = tokenAuthHolder.getUserDetails(authentication);
45+
SysUserDto.SysUserDetailsDto sysUserDetailsDto = TokenAuthHolder.getUserDetails(authentication);
4846
List<String> roles = sysUserDetailsDto.getRoles();
4947
// 获取与 url 相同的配置,不存在与 url 相同配置则使用 ant 风格匹配
5048
SysApiRolesVo sysApiRolesVo = sysApiRolesVos.stream()

0 commit comments

Comments
 (0)