|
@ -4,7 +4,7 @@ package com.storeroom.utils; |
|
|
import cn.hutool.json.JSONArray; |
|
|
import cn.hutool.json.JSONArray; |
|
|
import cn.hutool.json.JSONObject; |
|
|
import cn.hutool.json.JSONObject; |
|
|
import cn.hutool.json.JSONUtil; |
|
|
import cn.hutool.json.JSONUtil; |
|
|
import com.storeroom.exception.JsonException; |
|
|
|
|
|
|
|
|
import com.storeroom.exception.BaseException; |
|
|
import com.storeroom.exception.constant.ResponseStatus; |
|
|
import com.storeroom.exception.constant.ResponseStatus; |
|
|
import com.storeroom.utils.enums.DataScopeEnum; |
|
|
import com.storeroom.utils.enums.DataScopeEnum; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
@ -36,13 +36,13 @@ public class SecurityUtils { |
|
|
public static String getCurrentUsername() { |
|
|
public static String getCurrentUsername() { |
|
|
final Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); |
|
|
final Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); |
|
|
if (authentication == null) { |
|
|
if (authentication == null) { |
|
|
throw new JsonException(ResponseStatus.TOKEN_UNAUTHORIZED.getCode(), ResponseStatus.TOKEN_UNAUTHORIZED.getMessage()); |
|
|
|
|
|
|
|
|
throw new BaseException(ResponseStatus.TOKEN_UNAUTHORIZED.getMessage()); |
|
|
} |
|
|
} |
|
|
if (authentication.getPrincipal() instanceof UserDetails) { |
|
|
if (authentication.getPrincipal() instanceof UserDetails) { |
|
|
UserDetails userDetails = (UserDetails) authentication.getPrincipal(); |
|
|
UserDetails userDetails = (UserDetails) authentication.getPrincipal(); |
|
|
return userDetails.getUsername(); |
|
|
return userDetails.getUsername(); |
|
|
} |
|
|
} |
|
|
throw new JsonException(ResponseStatus.TOKEN_IS_NULL.getCode(), ResponseStatus.TOKEN_IS_NULL.getMessage()); |
|
|
|
|
|
|
|
|
throw new BaseException(ResponseStatus.TOKEN_IS_NULL.getMessage()); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|