Ver Fonte

:bug: 修复社交登录、验证码登录 成功、失败事件不通知问题

冷冷 há 6 anos atrás
pai
commit
ec9499f2a9

+ 52 - 0
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
+ * <p>
+ * 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);
+	}
+}