From 1d4d76cbb1fc3c88942867b7132e31fb412d0dac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=90=8C=E8=90=8C=E5=93=92Sakura=E9=85=B1?= Date: Tue, 19 Feb 2019 19:20:42 +0800 Subject: [PATCH] :art: Improving structure / format of the code. --- .../com/pig4cloud/pigx/auth/endpoint/PigxTokenEndpoint.java | 3 +-- .../component/PigxWebResponseExceptionTranslator.java | 6 +++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/pigx-auth/src/main/java/com/pig4cloud/pigx/auth/endpoint/PigxTokenEndpoint.java b/pigx-auth/src/main/java/com/pig4cloud/pigx/auth/endpoint/PigxTokenEndpoint.java index 96e57982d..01a720d45 100644 --- a/pigx-auth/src/main/java/com/pig4cloud/pigx/auth/endpoint/PigxTokenEndpoint.java +++ b/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() diff --git a/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/component/PigxWebResponseExceptionTranslator.java b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/component/PigxWebResponseExceptionTranslator.java index 8e54cf32e..92bd4d4de 100644 --- a/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/component/PigxWebResponseExceptionTranslator.java +++ b/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())); } // 客户端异常直接返回客户端,不然无法解析