feat(X-Pack): 第三方平台认证配置迁移到系统设置

This commit is contained in:
fit2cloud-chenyw 2024-05-22 17:12:24 +08:00
parent 50c958033d
commit 6a49642433
9 changed files with 148 additions and 10 deletions

View File

@ -48,7 +48,7 @@ dataease:
version: '@project.version@'
origin-list: http://192.168.2.70:9080
apisix-api:
domain: http://192.168.0.121:9180
domain: http://192.168.2.70:9180
key: edd1c9f034335f136f87ad84b625c8f1
# springdoc-openapi项目配置

View File

@ -11,5 +11,14 @@ CREATE TABLE `core_sys_startup_job`
) COMMENT ='项目启动任务';
BEGIN;
INSERT INTO `core_sys_startup_job` VALUES ('chartFilterMerge', 'chartFilterMerge', 'ready');
INSERT INTO `core_sys_startup_job`
VALUES ('chartFilterMerge', 'chartFilterMerge', 'ready');
COMMIT;
ALTER TABLE `xpack_setting_authentication`
ADD COLUMN `plugin_json` longtext NULL COMMENT '插件配置' AFTER `relational_ids`;
ALTER TABLE `xpack_setting_authentication`
ADD COLUMN `synced` tinyint(1) NOT NULL DEFAULT 0 COMMENT '已同步' AFTER `plugin_json`;
ALTER TABLE `xpack_setting_authentication`
ADD COLUMN `valid` tinyint(1) NOT NULL DEFAULT 0 COMMENT '有效' AFTER `synced`;

View File

@ -1532,6 +1532,7 @@ export default {
day_limit: '天不能小于1大于31'
},
commons: {
test_connect: '测试连接',
consanguinity: '血缘关系',
collapse_navigation: '收起导航',
operate_cancelled: '已取消操作',

@ -1 +1 @@
Subproject commit d92e14e286e9fed723b501323766bf8f2858ca42
Subproject commit eac4bdc0d387c44088dbc7585a09f61b8e45ea12

View File

@ -2,11 +2,14 @@ package io.dataease.api.xpack.settings;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import io.dataease.api.xpack.settings.request.XpackAuthenticationEditor;
import io.dataease.api.xpack.settings.vo.XpackCasVO;
import io.dataease.api.xpack.settings.vo.XpackOidcVO;
import io.dataease.api.xpack.settings.vo.XpackAuthenticationStatusVO;
import io.dataease.api.xpack.settings.vo.XpackAuthenticationVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
@ -16,17 +19,37 @@ import java.util.List;
@ApiSupport(order = 899)
public interface XpackAuthenticationApi {
@Operation(summary = "同步")
@GetMapping("/sync")
void sync();
@Operation(summary = "查询列表")
@GetMapping("/grid")
List<XpackAuthenticationVO> grid();
@Operation(summary = "切换状态")
@PostMapping("/update")
void update(@RequestBody XpackAuthenticationEditor editor);
@PostMapping("/switchEnable")
void switchEnable(@RequestBody XpackAuthenticationEditor editor);
@PostMapping("/save/oidc")
String saveOidc(@RequestBody XpackOidcVO editor);
@PostMapping("/save/cas")
String saveCas(@RequestBody XpackCasVO editor);
@GetMapping("/info/oidc")
XpackOidcVO oidcInfo();
@GetMapping("/info/cas")
XpackCasVO casInfo();
@PostMapping("/validate/oidc")
String validateOidc(@RequestBody XpackOidcVO editor);
@PostMapping("/validate/cas")
String validateCas(@RequestBody XpackCasVO editor);
@PostMapping("/validateId/{id}")
String validate(@PathVariable("id") Long id);
@Operation(summary = "查询状态")
@GetMapping("/status")

View File

@ -19,6 +19,8 @@ public class XpackAuthenticationVO implements Serializable {
private Long id;
@Schema(description = "名称")
private String name;
@Schema(description = "状态")
@Schema(description = "开启")
private boolean enable;
@Schema(description = "有效")
private boolean valid;
}

View File

@ -0,0 +1,14 @@
package io.dataease.api.xpack.settings.vo;
import lombok.Data;
import java.io.Serial;
import java.io.Serializable;
@Data
public class XpackCasVO implements Serializable {
@Serial
private static final long serialVersionUID = 3748231475265743038L;
private String idpUri;
}

View File

@ -0,0 +1,26 @@
package io.dataease.api.xpack.settings.vo;
import lombok.Data;
import java.io.Serial;
import java.io.Serializable;
@Data
public class XpackOidcVO implements Serializable {
@Serial
private static final long serialVersionUID = 3386314375628396307L;
private String discovery;
private String clientId;
private String clientSecret;
private String realm;
private String scope;
private boolean usePkce;
private String redirectUri;
}

View File

@ -6,9 +6,9 @@ import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.entity.mime.MultipartEntityBuilder;
import org.apache.http.client.entity.EntityBuilder;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpDelete;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPatch;
import org.apache.http.client.methods.HttpPost;
@ -20,6 +20,7 @@ import org.apache.http.conn.socket.PlainConnectionSocketFactory;
import org.apache.http.conn.ssl.NoopHostnameVerifier;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.mime.MultipartEntityBuilder;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.client.HttpClients;
@ -77,6 +78,37 @@ public class HttpClientUtil {
}
}
public static boolean validateUrl(String url, HttpClientConfig config) {
CloseableHttpClient httpClient = null;
try {
httpClient = buildHttpClient(url);
HttpGet httpGet = new HttpGet(url);
if (config == null) {
config = new HttpClientConfig();
}
httpGet.setConfig(config.buildRequestConfig());
Map<String, String> header = config.getHeader();
for (String key : header.keySet()) {
httpGet.addHeader(key, header.get(key));
}
HttpResponse response = httpClient.execute(httpGet);
int statusCode = response.getStatusLine().getStatusCode();
return statusCode <= 400;
} catch (Exception e) {
logger.error("HttpClient查询失败", e);
throw new DEException(SYSTEM_INNER_ERROR.code(), "HttpClient查询失败: " + e.getMessage());
} finally {
try {
if (httpClient != null) {
httpClient.close();
}
} catch (Exception e) {
logger.error("HttpClient关闭连接失败", e);
}
}
}
/**
* Get http请求
*
@ -342,4 +374,35 @@ public class HttpClientUtil {
config.addHeader(entry.getKey(), entry.getValue().toString());
}
}
public static String delete(String url, HttpClientConfig config) {
CloseableHttpClient httpClient = null;
try {
httpClient = buildHttpClient(url);
HttpDelete httpDelete = new HttpDelete(url);
if (config == null) {
config = new HttpClientConfig();
}
httpDelete.setConfig(config.buildRequestConfig());
Map<String, String> header = config.getHeader();
for (String key : header.keySet()) {
httpDelete.addHeader(key, header.get(key));
}
HttpResponse response = httpClient.execute(httpDelete);
return getResponseStr(response, config);
} catch (Exception e) {
logger.error("HttpClient查询失败", e);
throw new DEException(SYSTEM_INNER_ERROR.code(), "HttpClient查询失败: " + e.getMessage());
} finally {
try {
if (httpClient != null) {
httpClient.close();
}
} catch (Exception e) {
logger.error("HttpClient关闭连接失败", e);
}
}
}
}