From ec9499f2a9c0b31fc12e7be6e7c47779a1a19b87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=86=B7=E5=86=B7?= Date: Wed, 24 Oct 2018 14:57:52 +0800 Subject: [PATCH] =?UTF-8?q?:bug:=20=E4=BF=AE=E5=A4=8D=E7=A4=BE=E4=BA=A4?= =?UTF-8?q?=E7=99=BB=E5=BD=95=E3=80=81=E9=AA=8C=E8=AF=81=E7=A0=81=E7=99=BB?= =?UTF-8?q?=E5=BD=95=20=E6=88=90=E5=8A=9F=E3=80=81=E5=A4=B1=E8=B4=A5?= =?UTF-8?q?=E4=BA=8B=E4=BB=B6=E4=B8=8D=E9=80=9A=E7=9F=A5=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/PigxClientDetailsService.java | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/service/PigxClientDetailsService.java diff --git a/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/service/PigxClientDetailsService.java b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/service/PigxClientDetailsService.java new file mode 100644 index 000000000..6a6007b38 --- /dev/null +++ b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/service/PigxClientDetailsService.java @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + */ + +package com.pig4cloud.pigx.common.security.service; + +import com.pig4cloud.pigx.common.core.constant.SecurityConstants; +import org.springframework.cache.annotation.Cacheable; +import org.springframework.security.oauth2.common.exceptions.InvalidClientException; +import org.springframework.security.oauth2.provider.ClientDetails; +import org.springframework.security.oauth2.provider.client.JdbcClientDetailsService; + +import javax.sql.DataSource; + +/** + * @author lengleng + * @date 2018/10/22 + *

+ * see JdbcClientDetailsService + */ +public class PigxClientDetailsService extends JdbcClientDetailsService { + + public PigxClientDetailsService(DataSource dataSource) { + super(dataSource); + } + + /** + * 重写原生方法支持redis缓存 + * + * @param clientId + * @return + * @throws InvalidClientException + */ + @Override + @Cacheable(value = SecurityConstants.CLIENT_DETAILS_KEY, key = "#clientId", unless = "#result == null") + public ClientDetails loadClientByClientId(String clientId) throws InvalidClientException { + return super.loadClientByClientId(clientId); + } +}