refactor: 刷新角色权限代码位置调整
This commit is contained in:
@@ -20,7 +20,7 @@ public class SecurityUtils {
|
||||
/**
|
||||
* 获取当前登录人信息
|
||||
*
|
||||
* @return
|
||||
* @return SysUserDetails
|
||||
*/
|
||||
public static SysUserDetails getUser() {
|
||||
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
||||
@@ -36,7 +36,7 @@ public class SecurityUtils {
|
||||
/**
|
||||
* 获取用户ID
|
||||
*
|
||||
* @return
|
||||
* @return Long
|
||||
*/
|
||||
public static Long getUserId() {
|
||||
Long userId = Convert.toLong(getUser().getUserId());
|
||||
@@ -65,7 +65,7 @@ public class SecurityUtils {
|
||||
/**
|
||||
* 获取用户角色集合
|
||||
*
|
||||
* @return
|
||||
* @return 角色集合
|
||||
*/
|
||||
public static Set<String> getRoles() {
|
||||
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
||||
@@ -80,25 +80,6 @@ public class SecurityUtils {
|
||||
return Collections.EMPTY_SET;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户权限集合
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static Set<String> getPerms() {
|
||||
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
||||
if (authentication != null) {
|
||||
Collection<? extends GrantedAuthority> authorities = authentication.getAuthorities();
|
||||
if (CollectionUtil.isNotEmpty(authorities)) {
|
||||
return authorities.stream()
|
||||
.map(GrantedAuthority::getAuthority)
|
||||
.filter(authority -> !authority.startsWith("ROLE_"))
|
||||
.collect(Collectors.toSet());
|
||||
}
|
||||
}
|
||||
return Collections.EMPTY_SET;
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否超级管理员
|
||||
* <p>
|
||||
@@ -111,23 +92,4 @@ public class SecurityUtils {
|
||||
return roles.contains(SystemConstants.ROOT_ROLE_CODE);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 是否拥有权限判断
|
||||
* <p>
|
||||
* 适用业务判断(接口权限判断适用Spring Security 自带注解 PreAuthorize 判断即可 )
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static boolean hasPerm(String perm) {
|
||||
|
||||
if (isRoot()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Set<String> perms = getPerms();
|
||||
|
||||
return perms.stream().anyMatch(item -> PatternMatchUtils.simpleMatch(perm, item));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user