Parcourir la source

:art: Improving structure / format of the code.

萌萌哒Sakura酱 il y a 6 ans
Parent
commit
1d4d76cbb1

+ 1 - 2
pigx-auth/src/main/java/com/pig4cloud/pigx/auth/endpoint/PigxTokenEndpoint.java

@@ -58,7 +58,6 @@ import java.util.Map;
 @RequestMapping("/token")
 public class PigxTokenEndpoint {
 	private static final String PIGX_OAUTH_ACCESS = SecurityConstants.PIGX_PREFIX + SecurityConstants.OAUTH_PREFIX + "auth_to_access:";
-	private static final String PIGX__ACCESS = SecurityConstants.PIGX_PREFIX + SecurityConstants.OAUTH_PREFIX + "access:";
 	private final TokenStore tokenStore;
 	private final RedisTemplate redisTemplate;
 	private final CacheManager cacheManager;
@@ -87,7 +86,7 @@ public class PigxTokenEndpoint {
 					.msg("退出失败,token 为空").build();
 		}
 
-		String tokenValue = authHeader.replace("Bearer", "").trim();
+		String tokenValue = authHeader.replace(OAuth2AccessToken.BEARER_TYPE, StrUtil.EMPTY).trim();
 		OAuth2AccessToken accessToken = tokenStore.readAccessToken(tokenValue);
 		if (accessToken == null || StrUtil.isBlank(accessToken.getValue())) {
 			return R.builder()

+ 3 - 3
pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/component/PigxWebResponseExceptionTranslator.java

@@ -89,10 +89,10 @@ public class PigxWebResponseExceptionTranslator implements WebResponseExceptionT
 
 		int status = e.getHttpErrorCode();
 		HttpHeaders headers = new HttpHeaders();
-		headers.set("Cache-Control", "no-store");
-		headers.set("Pragma", "no-cache");
+		headers.set(HttpHeaders.CACHE_CONTROL, "no-store");
+		headers.set(HttpHeaders.PRAGMA, "no-cache");
 		if (status == HttpStatus.UNAUTHORIZED.value() || (e instanceof InsufficientScopeException)) {
-			headers.set("WWW-Authenticate", String.format("%s %s", OAuth2AccessToken.BEARER_TYPE, e.getSummary()));
+			headers.set(HttpHeaders.WWW_AUTHENTICATE, String.format("%s %s", OAuth2AccessToken.BEARER_TYPE, e.getSummary()));
 		}
 
 		// 客户端异常直接返回客户端,不然无法解析