From cbaa427c3daaf9d119094a7c9c846be3920d9c54 Mon Sep 17 00:00:00 2001 From: smallbun <2689170096@qq.com> Date: Wed, 25 Dec 2024 08:23:14 +0800 Subject: [PATCH] =?UTF-8?q?:zap:=20=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DingTalkAuthenticationConfigurer.java | 10 +++++----- ...a => DingtalkOAuth2AuthenticationFilter.java} | 16 +++++++++------- ...OAuth2AuthorizationRequestRedirectFilter.java | 2 +- 3 files changed, 15 insertions(+), 13 deletions(-) rename eiam-authentication/eiam-authentication-dingtalk/src/main/java/cn/topiam/employee/authentication/dingtalk/filter/{DingtalkOauthAuthenticationFilter.java => DingtalkOAuth2AuthenticationFilter.java} (93%) diff --git a/eiam-authentication/eiam-authentication-dingtalk/src/main/java/cn/topiam/employee/authentication/dingtalk/configurer/DingTalkAuthenticationConfigurer.java b/eiam-authentication/eiam-authentication-dingtalk/src/main/java/cn/topiam/employee/authentication/dingtalk/configurer/DingTalkAuthenticationConfigurer.java index a966e899..43e791f6 100644 --- a/eiam-authentication/eiam-authentication-dingtalk/src/main/java/cn/topiam/employee/authentication/dingtalk/configurer/DingTalkAuthenticationConfigurer.java +++ b/eiam-authentication/eiam-authentication-dingtalk/src/main/java/cn/topiam/employee/authentication/dingtalk/configurer/DingTalkAuthenticationConfigurer.java @@ -29,8 +29,8 @@ import org.springframework.util.Assert; import cn.topiam.employee.authentication.common.IdentityProviderAuthenticationService; import cn.topiam.employee.authentication.common.client.RegisteredIdentityProviderClientRepository; +import cn.topiam.employee.authentication.dingtalk.filter.DingtalkOAuth2AuthenticationFilter; import cn.topiam.employee.authentication.dingtalk.filter.DingtalkOAuth2AuthorizationRequestRedirectFilter; -import cn.topiam.employee.authentication.dingtalk.filter.DingtalkOauthAuthenticationFilter; import lombok.NonNull; import lombok.Setter; @@ -44,10 +44,10 @@ import static cn.topiam.employee.support.security.util.HttpSecurityFilterOrderRe */ @SuppressWarnings("AlibabaClassNamingShouldBeCamel") public final class DingTalkAuthenticationConfigurer extends - AbstractAuthenticationFilterConfigurer { + AbstractAuthenticationFilterConfigurer { @Setter @NonNull - private String loginProcessingUrl = DingtalkOauthAuthenticationFilter.DEFAULT_FILTER_PROCESSES_URI; + private String loginProcessingUrl = DingtalkOAuth2AuthenticationFilter.DEFAULT_FILTER_PROCESSES_URI; private final RegisteredIdentityProviderClientRepository registeredIdentityProviderClientRepository; private final IdentityProviderAuthenticationService identityProviderAuthenticationService; @@ -76,7 +76,7 @@ public final class DingTalkAuthenticationConfigurer extends @Override public void init(HttpSecurity http) throws Exception { //钉钉登录认证 - this.setAuthenticationFilter(new DingtalkOauthAuthenticationFilter( + this.setAuthenticationFilter(new DingtalkOAuth2AuthenticationFilter( registeredIdentityProviderClientRepository, identityProviderAuthenticationService)); putFilterBefore(http, this.getAuthenticationFilter(), OAuth2LoginAuthenticationFilter.class); @@ -95,7 +95,7 @@ public final class DingTalkAuthenticationConfigurer extends public RequestMatcher getRequestMatcher() { return new OrRequestMatcher( DingtalkOAuth2AuthorizationRequestRedirectFilter.getRequestMatcher(), - DingtalkOauthAuthenticationFilter.getRequestMatcher()); + DingtalkOAuth2AuthenticationFilter.getRequestMatcher()); } public static DingTalkAuthenticationConfigurer dingTalkOAuth2(RegisteredIdentityProviderClientRepository registeredIdentityProviderClientRepository, diff --git a/eiam-authentication/eiam-authentication-dingtalk/src/main/java/cn/topiam/employee/authentication/dingtalk/filter/DingtalkOauthAuthenticationFilter.java b/eiam-authentication/eiam-authentication-dingtalk/src/main/java/cn/topiam/employee/authentication/dingtalk/filter/DingtalkOAuth2AuthenticationFilter.java similarity index 93% rename from eiam-authentication/eiam-authentication-dingtalk/src/main/java/cn/topiam/employee/authentication/dingtalk/filter/DingtalkOauthAuthenticationFilter.java rename to eiam-authentication/eiam-authentication-dingtalk/src/main/java/cn/topiam/employee/authentication/dingtalk/filter/DingtalkOAuth2AuthenticationFilter.java index af43360f..cae5a04a 100644 --- a/eiam-authentication/eiam-authentication-dingtalk/src/main/java/cn/topiam/employee/authentication/dingtalk/filter/DingtalkOauthAuthenticationFilter.java +++ b/eiam-authentication/eiam-authentication-dingtalk/src/main/java/cn/topiam/employee/authentication/dingtalk/filter/DingtalkOAuth2AuthenticationFilter.java @@ -23,6 +23,7 @@ import java.util.Objects; import java.util.UUID; import java.util.concurrent.TimeUnit; +import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.http.HttpMethod; import org.springframework.security.core.Authentication; @@ -73,8 +74,8 @@ import static cn.topiam.employee.authentication.dingtalk.constant.DingTalkAuthen * Created by support@topiam.cn on 2021/12/8 21:11 */ @SuppressWarnings("DuplicatedCode") -public class DingtalkOauthAuthenticationFilter extends - AbstractIdentityProviderAuthenticationProcessingFilter { +public class DingtalkOAuth2AuthenticationFilter extends + AbstractIdentityProviderAuthenticationProcessingFilter { public final static String DEFAULT_FILTER_PROCESSES_URI = DINGTALK_OAUTH .getLoginPathPrefix() + "/" + "{" + PROVIDER_CODE + "}"; /** @@ -89,8 +90,8 @@ public class DingtalkOauthAuthenticationFilter extends * @param registeredIdentityProviderClientRepository the {@link RegisteredIdentityProviderClientRepository} * @param identityProviderAuthenticationService {@link IdentityProviderAuthenticationService} */ - public DingtalkOauthAuthenticationFilter(RegisteredIdentityProviderClientRepository registeredIdentityProviderClientRepository, - IdentityProviderAuthenticationService identityProviderAuthenticationService) { + public DingtalkOAuth2AuthenticationFilter(RegisteredIdentityProviderClientRepository registeredIdentityProviderClientRepository, + IdentityProviderAuthenticationService identityProviderAuthenticationService) { super(REQUEST_MATCHER, identityProviderAuthenticationService, registeredIdentityProviderClientRepository); } @@ -178,8 +179,9 @@ public class DingtalkOauthAuthenticationFilter extends * @return {@link String} */ public String getToken(String authCode, DingTalkIdentityProviderOAuth2Config config) { + String cacheKey = OAuth2ParameterNames.ACCESS_TOKEN + DigestUtils.md5Hex(config.toString()); if (!Objects.isNull(cache)) { - return cache.getIfPresent(OAuth2ParameterNames.ACCESS_TOKEN); + return cache.getIfPresent(cacheKey); } Config clientConfig = new Config(); clientConfig.setProtocol("https"); @@ -198,8 +200,8 @@ public class DingtalkOauthAuthenticationFilter extends //放入缓存 cache = Caffeine.newBuilder().expireAfterWrite(body.getExpireIn(), TimeUnit.SECONDS) .build(); - cache.put(OAuth2ParameterNames.ACCESS_TOKEN, body.getAccessToken()); - return cache.getIfPresent(OAuth2ParameterNames.ACCESS_TOKEN); + cache.put(cacheKey, body.getAccessToken()); + return cache.getIfPresent(cacheKey); } catch (Exception exception) { throw new RuntimeException(exception.getMessage()); } diff --git a/eiam-authentication/eiam-authentication-dingtalk/src/main/java/cn/topiam/employee/authentication/dingtalk/filter/DingtalkOAuth2AuthorizationRequestRedirectFilter.java b/eiam-authentication/eiam-authentication-dingtalk/src/main/java/cn/topiam/employee/authentication/dingtalk/filter/DingtalkOAuth2AuthorizationRequestRedirectFilter.java index 65c28240..b1000061 100644 --- a/eiam-authentication/eiam-authentication-dingtalk/src/main/java/cn/topiam/employee/authentication/dingtalk/filter/DingtalkOAuth2AuthorizationRequestRedirectFilter.java +++ b/eiam-authentication/eiam-authentication-dingtalk/src/main/java/cn/topiam/employee/authentication/dingtalk/filter/DingtalkOAuth2AuthorizationRequestRedirectFilter.java @@ -55,7 +55,7 @@ import static cn.topiam.employee.authentication.common.IdentityProviderType.DING import static cn.topiam.employee.authentication.common.constant.AuthenticationConstants.PROVIDER_CODE; import static cn.topiam.employee.authentication.dingtalk.constant.DingTalkAuthenticationConstants.CORP_ID; import static cn.topiam.employee.authentication.dingtalk.constant.DingTalkAuthenticationConstants.URL_AUTHORIZE; -import static cn.topiam.employee.authentication.dingtalk.filter.DingtalkOauthAuthenticationFilter.getLoginUrl; +import static cn.topiam.employee.authentication.dingtalk.filter.DingtalkOAuth2AuthenticationFilter.getLoginUrl; /** * 微信扫码登录请求重定向过滤器