From 02fa2dcd73fce4c09a8be1f20af013e1af01a1e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=86=B7=E5=86=B7?= Date: Mon, 21 Jan 2019 17:12:43 +0800 Subject: [PATCH] =?UTF-8?q?:sparkles:=20=E6=B7=BB=E5=8A=A0=E6=96=B0?= =?UTF-8?q?=E7=89=B9=E6=80=A7=EF=BC=8C=E6=94=AF=E6=8C=81=E5=AE=A2=E6=88=B7?= =?UTF-8?q?=E7=AB=AF=E6=A8=A1=E5=BC=8F=E4=BB=A4=E7=89=8C=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pigx/auth/config/AuthorizationServerConfig.java | 10 ++++++++++ .../pigx/common/core/constant/SecurityConstants.java | 5 +++++ 2 files changed, 15 insertions(+) diff --git a/pigx-auth/src/main/java/com/pig4cloud/pigx/auth/config/AuthorizationServerConfig.java b/pigx-auth/src/main/java/com/pig4cloud/pigx/auth/config/AuthorizationServerConfig.java index 7f650a3a6..2e899ad53 100644 --- a/pigx-auth/src/main/java/com/pig4cloud/pigx/auth/config/AuthorizationServerConfig.java +++ b/pigx-auth/src/main/java/com/pig4cloud/pigx/auth/config/AuthorizationServerConfig.java @@ -104,9 +104,19 @@ public class AuthorizationServerConfig extends AuthorizationServerConfigurerAdap return tokenStore; } + /** + * token增强,客户端模式不增强。 + * + * @return TokenEnhancer + */ @Bean public TokenEnhancer tokenEnhancer() { return (accessToken, authentication) -> { + if (SecurityConstants.CLIENT_CREDENTIALS + .equals(authentication.getOAuth2Request().getGrantType())) { + return accessToken; + } + final Map additionalInfo = new HashMap<>(8); PigxUser pigxUser = (PigxUser) authentication.getUserAuthentication().getPrincipal(); additionalInfo.put("user_id", pigxUser.getId()); diff --git a/pigx-common/pigx-common-core/src/main/java/com/pig4cloud/pigx/common/core/constant/SecurityConstants.java b/pigx-common/pigx-common-core/src/main/java/com/pig4cloud/pigx/common/core/constant/SecurityConstants.java index 22935a874..b1ad0b556 100644 --- a/pigx-common/pigx-common-core/src/main/java/com/pig4cloud/pigx/common/core/constant/SecurityConstants.java +++ b/pigx-common/pigx-common-core/src/main/java/com/pig4cloud/pigx/common/core/constant/SecurityConstants.java @@ -120,4 +120,9 @@ public interface SecurityConstants { */ String RESOURCE_SERVER_CONFIGURER = "resourceServerConfigurerAdapter"; + /** + * 客户端模式 + */ + String CLIENT_CREDENTIALS = "client_credentials"; + }