|
@@ -7,6 +7,7 @@ import (
|
|
|
"regexp"
|
|
|
"strconv"
|
|
|
|
|
|
+ "github.com/go-ldap/ldap"
|
|
|
auth "imuslab.com/arozos/mod/auth"
|
|
|
"imuslab.com/arozos/mod/auth/ldap/ldapreader"
|
|
|
"imuslab.com/arozos/mod/auth/oauth2/syncdb"
|
|
@@ -217,6 +218,39 @@ func (ldap *ldapHandler) getAllUser(limit int) []UserAccount {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+func (ldap *ldapHandler) convertGroup(ldapUser *ldap.Entry) []UserAccount {
|
|
|
+ var accounts []UserAccount
|
|
|
+ //check the group belongs
|
|
|
+ var Group []string
|
|
|
+ var EquivGroup []string
|
|
|
+ regexSyntax := regexp.MustCompile("cn=([^,]+),")
|
|
|
+ for _, v := range ldapUser.GetAttributeValues("memberOf") {
|
|
|
+ groups := regexSyntax.FindStringSubmatch(v)
|
|
|
+ if len(groups) > 0 {
|
|
|
+ //check if the LDAP group is already exists in ArOZOS system
|
|
|
+ if ldap.permissionHandler.GroupExists(groups[1]) {
|
|
|
+ EquivGroup = append(EquivGroup, groups[1])
|
|
|
+ }
|
|
|
+ //LDAP list
|
|
|
+ Group = append(Group, groups[1])
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if len(EquivGroup) < 1 {
|
|
|
+ EquivGroup = append(EquivGroup, ldap.reg.DefaultUserGroup)
|
|
|
+ }
|
|
|
+ account := UserAccount{
|
|
|
+ Username: ldapUser.GetAttributeValue("cn"),
|
|
|
+ Group: Group,
|
|
|
+ EquivGroup: EquivGroup,
|
|
|
+ }
|
|
|
+ accounts = append(accounts, account)
|
|
|
+ if len(accounts) > 0 {
|
|
|
+ return accounts[1:]
|
|
|
+ } else {
|
|
|
+ return []UserAccount{}
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
func (ldap *ldapHandler) TestConnection(w http.ResponseWriter, r *http.Request) {
|
|
|
//marshall it and return
|
|
|
accountJSON, err := json.Marshal(ldap.getAllUser(10))
|
|
@@ -425,6 +459,11 @@ func (ldap *ldapHandler) HandleSetPassword(w http.ResponseWriter, r *http.Reques
|
|
|
//check if the input key matches the database's username
|
|
|
isValid := ldap.syncdb.Read(authkey) == username
|
|
|
if isValid {
|
|
|
-
|
|
|
+ if !ldap.ag.UserExists(username) {
|
|
|
+ ldap.ag.CreateUserAccount(username, password, ldapUser.EquivGroup)
|
|
|
+ } else {
|
|
|
+ common.SendErrorResponse(w, "User existed!!")
|
|
|
+ return
|
|
|
+ }
|
|
|
}
|
|
|
}
|