fix critical userPassword bug,
improve ldap user/group data handling
This commit is contained in:
80
app/utils.go
80
app/utils.go
@@ -4,6 +4,9 @@ import (
|
||||
"encoding/json"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/go-ldap/ldap/v3"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
@@ -38,11 +41,86 @@ type Login struct { // login body struct
|
||||
Password string `form:"password" binding:"required"`
|
||||
}
|
||||
|
||||
type User struct { // add or modify user body struct
|
||||
type LDAPUserAttributes struct {
|
||||
CN string
|
||||
SN string
|
||||
Mail string
|
||||
UID string
|
||||
MemberOf []string
|
||||
}
|
||||
|
||||
type LDAPUser struct {
|
||||
DN string
|
||||
Attributes LDAPUserAttributes
|
||||
}
|
||||
|
||||
func LDAPEntryToLDAPUser(entry *ldap.Entry) LDAPUser {
|
||||
return LDAPUser{
|
||||
DN: entry.DN,
|
||||
Attributes: LDAPUserAttributes{
|
||||
CN: entry.GetAttributeValue("cn"),
|
||||
SN: entry.GetAttributeValue("sn"),
|
||||
Mail: entry.GetAttributeValue("mail"),
|
||||
UID: entry.GetAttributeValue("uid"),
|
||||
MemberOf: entry.GetAttributeValues("memberOf"),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func LDAPUserToGin(user LDAPUser) gin.H {
|
||||
return gin.H{
|
||||
"dn": user.DN,
|
||||
"attributes": gin.H{
|
||||
"cn": user.Attributes.CN,
|
||||
"sn": user.Attributes.SN,
|
||||
"mail": user.Attributes.Mail,
|
||||
"uid": user.Attributes.UID,
|
||||
"memberOf": user.Attributes.MemberOf,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
type LDAPGroupAttributes struct {
|
||||
CN string
|
||||
Member []string
|
||||
}
|
||||
|
||||
type LDAPGroup struct {
|
||||
DN string
|
||||
Attributes LDAPGroupAttributes
|
||||
}
|
||||
|
||||
func LDAPEntryToLDAPGroup(entry *ldap.Entry) LDAPGroup {
|
||||
return LDAPGroup{
|
||||
DN: entry.DN,
|
||||
Attributes: LDAPGroupAttributes{
|
||||
CN: entry.GetAttributeValue("cn"),
|
||||
Member: entry.GetAttributeValues("member"),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func LDAPGroupToGin(group LDAPGroup) gin.H {
|
||||
return gin.H{
|
||||
"dn": group.DN,
|
||||
"attributes": gin.H{
|
||||
"cn": group.Attributes.CN,
|
||||
"member": group.Attributes.Member,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
type UserOptional struct { // add or modify user body struct
|
||||
CN string `form:"cn"`
|
||||
SN string `form:"sn"`
|
||||
UserPassword string `form:"userpassword"`
|
||||
}
|
||||
|
||||
type UserRequired struct { // add or modify user body struct
|
||||
CN string `form:"cn" binding:"required"`
|
||||
SN string `form:"sn" binding:"required"`
|
||||
UserPassword string `form:"userpassword" binding:"required"`
|
||||
}
|
||||
|
||||
type Group struct { // add or modify group body struct
|
||||
}
|
||||
|
Reference in New Issue
Block a user