diff --git a/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/util/AuthUtils.java b/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/util/AuthUtils.java index 386bcbbc..db7c3642 100644 --- a/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/util/AuthUtils.java +++ b/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/util/AuthUtils.java @@ -111,16 +111,18 @@ public class AuthUtils { * 获取登陆的帐户类型 */ public static String getAccountType(Authentication authentication) { - Object details = authentication.getDetails(); String accountType = null; - if (details != null) { - if (details instanceof CustomWebAuthenticationDetails) { - CustomWebAuthenticationDetails detailsObj = (CustomWebAuthenticationDetails) details; - accountType = detailsObj.getAccountType(); - } else { - Map detailsMap = (Map) details; - if (detailsMap != null) { - accountType = detailsMap.get(SecurityConstants.ACCOUNT_TYPE_PARAM_NAME); + if (authentication != null) { + Object details = authentication.getDetails(); + if (details != null) { + if (details instanceof CustomWebAuthenticationDetails) { + CustomWebAuthenticationDetails detailsObj = (CustomWebAuthenticationDetails) details; + accountType = detailsObj.getAccountType(); + } else { + Map detailsMap = (Map) details; + if (detailsMap != null) { + accountType = detailsMap.get(SecurityConstants.ACCOUNT_TYPE_PARAM_NAME); + } } } } diff --git a/zlt-uaa/src/main/java/com/central/oauth/config/AuthorizationServerConfig.java b/zlt-uaa/src/main/java/com/central/oauth/config/AuthorizationServerConfig.java index 85dd7950..e7d68db9 100644 --- a/zlt-uaa/src/main/java/com/central/oauth/config/AuthorizationServerConfig.java +++ b/zlt-uaa/src/main/java/com/central/oauth/config/AuthorizationServerConfig.java @@ -1,5 +1,6 @@ package com.central.oauth.config; +import cn.hutool.core.util.StrUtil; import com.central.common.constant.SecurityConstants; import com.central.common.model.SysUser; import com.central.oauth.model.Client; @@ -120,7 +121,9 @@ public class AuthorizationServerConfig extends AuthorizationServerConfigurerAdap Set responseTypes = authentication.getOAuth2Request().getResponseTypes(); Map additionalInfo = new HashMap<>(3); String accountType = AuthUtils.getAccountType(authentication.getUserAuthentication()); - additionalInfo.put(SecurityConstants.ACCOUNT_TYPE_PARAM_NAME, accountType); + if (StrUtil.isNotEmpty(accountType)) { + additionalInfo.put(SecurityConstants.ACCOUNT_TYPE_PARAM_NAME, accountType); + } if (responseTypes.contains(SecurityConstants.ID_TOKEN) || "authJwt".equals(tokenStoreProperties.getType())) {