3.0代码提交 · selectgithub/opscloud@3c0cf4b · GitHub
Skip to content

Commit 3c0cf4b

Browse files
author
白衣
committed
3.0代码提交
1 parent 58b26c6 commit 3c0cf4b

579 files changed

Lines changed: 34225 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 1 addition & 0 deletions

opscloud-account/pom.xml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<parent>
6+
<artifactId>opscloud</artifactId>
7+
<groupId>com.baiyi</groupId>
8+
<version>0.0.1-SNAPSHOT</version>
9+
</parent>
10+
<modelVersion>4.0.0</modelVersion>
11+
12+
<artifactId>opscloud-account</artifactId>
13+
14+
<dependencies>
15+
<dependency>
16+
<groupId>com.baiyi</groupId>
17+
<artifactId>opscloud-ldap</artifactId>
18+
</dependency>
19+
<dependency>
20+
<groupId>com.baiyi</groupId>
21+
<artifactId>opscloud-zabbix</artifactId>
22+
</dependency>
23+
<dependency>
24+
<groupId>com.baiyi</groupId>
25+
<artifactId>opscloud-jumpserver</artifactId>
26+
</dependency>
27+
<dependency>
28+
<groupId>com.baiyi</groupId>
29+
<artifactId>opscloud-service</artifactId>
30+
</dependency>
31+
<dependency>
32+
<groupId>com.baiyi</groupId>
33+
<artifactId>opscloud-domain</artifactId>
34+
</dependency>
35+
<dependency>
36+
<groupId>com.baiyi</groupId>
37+
<artifactId>opscloud-common</artifactId>
38+
</dependency>
39+
</dependencies>
40+
</project>
Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
package com.baiyi.opscloud.account;
2+
3+
import com.baiyi.opscloud.account.factory.AccountFactory;
4+
import com.baiyi.opscloud.common.util.UUIDUtils;
5+
import com.baiyi.opscloud.domain.generator.opscloud.OcUser;
6+
import com.baiyi.opscloud.domain.param.auth.LogParam;
7+
import com.baiyi.opscloud.domain.vo.auth.LogVO;
8+
import com.baiyi.opscloud.facade.OcAuthFacade;
9+
import com.baiyi.opscloud.ldap.credential.PersonCredential;
10+
import com.baiyi.opscloud.ldap.handler.LdapHandler;
11+
import com.baiyi.opscloud.service.user.OcUserService;
12+
import org.springframework.stereotype.Component;
13+
14+
import javax.annotation.Resource;
15+
import java.util.Map;
16+
17+
/**
18+
* @Author baiyi
19+
* @Date 2020/1/8 8:06 下午
20+
* @Version 1.0
21+
*/
22+
@Component("AccountCenter")
23+
public class AccountCenter {
24+
25+
@Resource
26+
private LdapHandler ldapHandler;
27+
28+
@Resource
29+
private OcAuthFacade ocAuthFacade;
30+
31+
@Resource
32+
private OcUserService ocUserService;
33+
34+
public static final String LDAP_ACCOUNT_KEY = "LdapAccount";
35+
36+
public LogVO.LoginVO loginCheck(LogParam.LoginParam loginParam) {
37+
com.baiyi.opscloud.ldap.credential.PersonCredential credential = PersonCredential.builder()
38+
.username(loginParam.getUsername())
39+
.password(loginParam.getPassword())
40+
.build();
41+
// 验证通过
42+
if (ldapHandler.loginCheck(credential)) {
43+
String token = UUIDUtils.getUUID();
44+
ocAuthFacade.setUserToken(loginParam.getUsername(), token);
45+
OcUser ocUser = ocUserService.queryOcUserByUsername(loginParam.getUsername());
46+
LogVO.LoginVO loginVO = new LogVO.LoginVO();
47+
loginVO.setName(ocUser.getDisplayName());
48+
loginVO.setUuid(ocUser.getUuid());
49+
loginVO.setToken(token);
50+
ocAuthFacade.setOcUserPassword(ocUser, loginParam.getPassword());
51+
return loginVO;
52+
} else {
53+
return null;
54+
}
55+
}
56+
57+
public Boolean create(String key, OcUser user) {
58+
IAccount account = AccountFactory.getAccountByKey(key);
59+
return account.create(user);
60+
}
61+
62+
public Boolean create(OcUser user) {
63+
Boolean result = create(LDAP_ACCOUNT_KEY, user);
64+
if (result) {
65+
Map<String, IAccount> accountContainer = AccountFactory.getAccountContainer();
66+
for (String key : accountContainer.keySet()) {
67+
if (key.equals(LDAP_ACCOUNT_KEY)) continue;
68+
IAccount account = accountContainer.get(key);
69+
if (!account.create(user))
70+
return Boolean.FALSE;
71+
}
72+
}
73+
return Boolean.TRUE;
74+
}
75+
76+
/**
77+
* 授权
78+
*
79+
* @param user
80+
* @param resource
81+
* @return
82+
*/
83+
public Boolean grant(OcUser user, String resource) {
84+
Map<String, IAccount> accountContainer = AccountFactory.getAccountContainer();
85+
for (String key : accountContainer.keySet()) {
86+
if (key.equals(LDAP_ACCOUNT_KEY)) continue;
87+
IAccount account = accountContainer.get(key);
88+
if (!account.grant(user, resource))
89+
return Boolean.FALSE;
90+
}
91+
return Boolean.TRUE;
92+
}
93+
94+
/**
95+
* 撤销授权
96+
*
97+
* @param user
98+
* @param resource
99+
* @return
100+
*/
101+
public Boolean revoke(OcUser user, String resource) {
102+
Map<String, IAccount> accountContainer = AccountFactory.getAccountContainer();
103+
for (String key : accountContainer.keySet()) {
104+
if (key.equals(LDAP_ACCOUNT_KEY)) continue;
105+
IAccount account = accountContainer.get(key);
106+
if (!account.revoke(user, resource))
107+
return Boolean.FALSE;
108+
}
109+
return Boolean.TRUE;
110+
}
111+
112+
113+
public Boolean update(String key, OcUser user) {
114+
IAccount account = AccountFactory.getAccountByKey(key);
115+
return account.update(user);
116+
}
117+
118+
/**
119+
* 更新用户信息
120+
*
121+
* @param user
122+
* @return
123+
*/
124+
public Boolean update(OcUser user) {
125+
Boolean result = update(LDAP_ACCOUNT_KEY, user);
126+
if (result) {
127+
Map<String, IAccount> accountContainer = AccountFactory.getAccountContainer();
128+
for (String key : accountContainer.keySet()) {
129+
if (key.equals(LDAP_ACCOUNT_KEY)) continue;
130+
IAccount account = accountContainer.get(key);
131+
if (!account.update(user))
132+
return Boolean.FALSE;
133+
}
134+
}
135+
return Boolean.TRUE;
136+
}
137+
138+
public Boolean pushSSHKey(OcUser user) {
139+
Map<String, IAccount> accountContainer = AccountFactory.getAccountContainer();
140+
for (String key : accountContainer.keySet()) {
141+
if (key.equals(LDAP_ACCOUNT_KEY)) continue;
142+
IAccount account = accountContainer.get(key);
143+
if (!account.pushSSHKey(user))
144+
return Boolean.FALSE;
145+
}
146+
return Boolean.TRUE;
147+
}
148+
149+
public Boolean sync(String key) {
150+
IAccount account = AccountFactory.getAccountByKey(key);
151+
return account.sync();
152+
}
153+
154+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
package com.baiyi.opscloud.account;
2+
3+
import com.baiyi.opscloud.domain.generator.opscloud.OcUser;
4+
5+
/**
6+
* @Author baiyi
7+
* @Date 2020/1/10 4:38 下午
8+
* @Version 1.0
9+
*/
10+
public interface IAccount {
11+
12+
/**
13+
* 同步账户
14+
*
15+
* @return
16+
*/
17+
Boolean sync();
18+
19+
/**
20+
* 创建账户
21+
*
22+
* @param user
23+
* @return
24+
*/
25+
Boolean create(OcUser user);
26+
27+
void async();
28+
29+
/**
30+
* 是否激活
31+
*
32+
* @param user
33+
* @param active
34+
* @return
35+
*/
36+
Boolean active(OcUser user, boolean active);
37+
38+
Boolean delete(OcUser user);
39+
40+
Boolean update(OcUser user);
41+
42+
String getKey();
43+
44+
/**
45+
* 授权
46+
*
47+
* @param user
48+
* @param resource
49+
* @return
50+
*/
51+
Boolean grant(OcUser user, String resource);
52+
53+
/**
54+
* 撤销授权
55+
*
56+
* @param user
57+
* @param resource
58+
* @return
59+
*/
60+
Boolean revoke(OcUser user, String resource);
61+
62+
/**
63+
* 推送用户公钥 PubKey
64+
*
65+
* @param user
66+
* @return
67+
*/
68+
Boolean pushSSHKey(OcUser user);
69+
70+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.baiyi.opscloud.account.base;
2+
3+
4+
5+
public enum AccountType {
6+
LDAP(0),
7+
ZABBIX(1),
8+
JUMPSEVER(2),
9+
RAM(3),
10+
IAM(4),
11+
GITLAB(5);
12+
13+
private int type;
14+
15+
AccountType(int type) {
16+
this.type = type;
17+
}
18+
19+
public int getType() {
20+
return this.type;
21+
}
22+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package com.baiyi.opscloud.account.builder;
2+
3+
import lombok.Builder;
4+
import lombok.Data;
5+
6+
import java.util.Date;
7+
8+
/**
9+
* @Author baiyi
10+
* @Date 2020/1/10 11:26 上午
11+
* @Version 1.0
12+
*/
13+
@Data
14+
@Builder
15+
public class OcAccountBO {
16+
17+
private Integer id;
18+
private String accountUid;
19+
private String accountId;
20+
private Integer accountType;
21+
private Integer userId;
22+
private String username;
23+
private String password;
24+
private String name;
25+
private String displayName;
26+
private String email;
27+
private Boolean isActive;
28+
private Integer lastLogin;
29+
private String wechat;
30+
private String phone;
31+
private Date createTime;
32+
private Date updateTime;
33+
private String comment;
34+
35+
}
Lines changed: 31 additions & 0 deletions

0 commit comments

Comments
 (0)