mirror of
https://github.com/tiennm99/zfoo.git
synced 2026-05-29 16:25:38 +00:00
feat[orm]: mongo authentication database can be configured
This commit is contained in:
@@ -23,13 +23,15 @@ public class HostConfig {
|
||||
private String user;
|
||||
private String password;
|
||||
private Map<String, String> address;
|
||||
private String authSource;
|
||||
|
||||
public static HostConfig valueOf(String database, String user, String password, Map<String, String> addressMap) {
|
||||
public static HostConfig valueOf(String database, String user, String password, Map<String, String> 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 class HostConfig {
|
||||
public void setAddress(Map<String, String> address) {
|
||||
this.address = address;
|
||||
}
|
||||
|
||||
public String getAuthSource() {
|
||||
return authSource;
|
||||
}
|
||||
|
||||
public void setAuthSource(String authSource) {
|
||||
this.authSource = authSource;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -118,7 +118,10 @@ public class OrmManager implements IOrmManager {
|
||||
|
||||
// 设置数据库账号密码
|
||||
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()));
|
||||
}
|
||||
|
||||
// 设置连接池的大小
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
<xsd:element name="address" maxOccurs="unbounded" type="addressAttributeType"/>
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="database" type="xsd:string" use="required"/>
|
||||
<xsd:attribute name="authSource" type="xsd:string"/>
|
||||
<xsd:attribute name="user" type="xsd:string" use="required"/>
|
||||
<xsd:attribute name="password" type="xsd:string" use="required"/>
|
||||
</xsd:complexType>
|
||||
|
||||
Reference in New Issue
Block a user