Skip to content

Commit

Permalink
Merge pull request #99 from LucaLq/main
Browse files Browse the repository at this point in the history
feat[orm]: mongo authentication database can be configured
  • Loading branch information
jaysunxiao authored May 7, 2024
2 parents db0bd5e + f70331a commit 5019a89
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
12 changes: 11 additions & 1 deletion orm/src/main/java/com/zfoo/orm/config/HostConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -64,4 +66,12 @@ public Map<String, String> getAddress() {
public void setAddress(Map<String, String> address) {
this.address = address;
}

public String getAuthSource() {
return authSource;
}

public void setAuthSource(String authSource) {
this.authSource = authSource;
}
}
5 changes: 4 additions & 1 deletion orm/src/main/java/com/zfoo/orm/manager/OrmManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
}

// 设置连接池的大小
Expand Down
1 change: 1 addition & 0 deletions orm/src/main/resources/orm-1.0.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down

0 comments on commit 5019a89

Please sign in to comment.