From f70331a47555ddc4a6b96c590749cdaf2f79096e Mon Sep 17 00:00:00 2001 From: luca Date: Tue, 7 May 2024 10:22:12 +0800 Subject: [PATCH] feat[orm]: mongo authentication database can be configured --- .../main/java/com/zfoo/orm/config/HostConfig.java | 12 +++++++++++- .../main/java/com/zfoo/orm/manager/OrmManager.java | 5 ++++- orm/src/main/resources/orm-1.0.xsd | 1 + 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/orm/src/main/java/com/zfoo/orm/config/HostConfig.java b/orm/src/main/java/com/zfoo/orm/config/HostConfig.java index f24aa42eb..eca85be01 100644 --- a/orm/src/main/java/com/zfoo/orm/config/HostConfig.java +++ b/orm/src/main/java/com/zfoo/orm/config/HostConfig.java @@ -23,13 +23,15 @@ public class HostConfig { private String user; private String password; private Map address; + private String authSource; - public static HostConfig valueOf(String database, String user, String password, Map addressMap) { + public static HostConfig valueOf(String database, String user, String password, Map addressMap, String authSource) { HostConfig config = new HostConfig(); config.database = database; config.user = user; config.password = password; config.address = addressMap; + config.authSource = authSource; return config; } @@ -64,4 +66,12 @@ public Map getAddress() { public void setAddress(Map address) { this.address = address; } + + public String getAuthSource() { + return authSource; + } + + public void setAuthSource(String authSource) { + this.authSource = authSource; + } } diff --git a/orm/src/main/java/com/zfoo/orm/manager/OrmManager.java b/orm/src/main/java/com/zfoo/orm/manager/OrmManager.java index 6ce95ccc4..38f0088ee 100644 --- a/orm/src/main/java/com/zfoo/orm/manager/OrmManager.java +++ b/orm/src/main/java/com/zfoo/orm/manager/OrmManager.java @@ -118,7 +118,10 @@ public void initBefore() { // 设置数据库账号密码 if (StringUtils.isNotBlank(hostConfig.getUser()) && StringUtils.isNotBlank(hostConfig.getPassword())) { - mongoBuilder.credential(MongoCredential.createCredential(hostConfig.getUser(), "admin", hostConfig.getPassword().toCharArray())); + var authSource = "admin"; + if (hostConfig.getAuthSource() != null) + authSource = hostConfig.getAuthSource(); + mongoBuilder.credential(MongoCredential.createCredential(hostConfig.getUser(), authSource, hostConfig.getPassword().toCharArray())); } // 设置连接池的大小 diff --git a/orm/src/main/resources/orm-1.0.xsd b/orm/src/main/resources/orm-1.0.xsd index 00ad0f512..6b5fa7b93 100644 --- a/orm/src/main/resources/orm-1.0.xsd +++ b/orm/src/main/resources/orm-1.0.xsd @@ -32,6 +32,7 @@ +