ldap support
This commit is contained in:
parent
8bab21d795
commit
79ea34e70e
11 changed files with 287 additions and 15 deletions
|
@ -30,7 +30,7 @@ func LoginUserLdap(name, passwd string) (*User, error) {
|
|||
Email: mail}
|
||||
_, err := RegisterUser(&user)
|
||||
if err != nil {
|
||||
log.Debug("LDAP local user %s fond (%s) ", name, err)
|
||||
log.Debug("LDAP local user %s found (%s) ", name, err)
|
||||
}
|
||||
// simulate local user login
|
||||
localUser, err2 := GetUserByName(user.Name)
|
||||
|
|
|
@ -1,9 +1,12 @@
|
|||
package models
|
||||
|
||||
import
|
||||
import (
|
||||
"encoding/json"
|
||||
"time"
|
||||
|
||||
// Login types.
|
||||
"github.com/go-xorm/core"
|
||||
"github.com/go-xorm/core"
|
||||
"github.com/gogits/gogs/modules/auth/ldap"
|
||||
)
|
||||
|
||||
/*const (
|
||||
LT_PLAIN = iota + 1
|
||||
|
@ -14,20 +17,54 @@ import
|
|||
var _ core.Conversion = &LDAPConfig{}
|
||||
|
||||
type LDAPConfig struct {
|
||||
ldap.Ldapsource
|
||||
}
|
||||
|
||||
// implement
|
||||
func (cfg *LDAPConfig) FromDB(bs []byte) error {
|
||||
return nil
|
||||
return json.Unmarshal(bs, &cfg.Ldapsource)
|
||||
}
|
||||
|
||||
func (cfg *LDAPConfig) ToDB() ([]byte, error) {
|
||||
return nil, nil
|
||||
return json.Marshal(cfg.Ldapsource)
|
||||
}
|
||||
|
||||
type LoginSource struct {
|
||||
Id int64
|
||||
Type int
|
||||
Name string
|
||||
Cfg LDAPConfig
|
||||
Id int64
|
||||
Type int
|
||||
Name string
|
||||
IsActived bool
|
||||
Cfg core.Conversion `xorm:"TEXT"`
|
||||
Created time.Time `xorm:"created"`
|
||||
Updated time.Time `xorm:"updated"`
|
||||
}
|
||||
|
||||
func GetAuths() ([]*LoginSource, error) {
|
||||
var auths = make([]*LoginSource, 0)
|
||||
err := orm.Find(&auths)
|
||||
return auths, err
|
||||
}
|
||||
|
||||
func AddLDAPSource(name string, cfg *LDAPConfig) error {
|
||||
_, err := orm.Insert(&LoginSource{Type: LT_LDAP,
|
||||
Name: name,
|
||||
IsActived: true,
|
||||
Cfg: cfg,
|
||||
})
|
||||
return err
|
||||
}
|
||||
|
||||
func UpdateLDAPSource(id int64, name string, cfg *LDAPConfig) error {
|
||||
_, err := orm.AllCols().Id(id).Update(&LoginSource{
|
||||
Id: id,
|
||||
Type: LT_LDAP,
|
||||
Name: name,
|
||||
Cfg: cfg,
|
||||
})
|
||||
return err
|
||||
}
|
||||
|
||||
func DelLoginSource(id int64) error {
|
||||
_, err := orm.Id(id).Delete(&LoginSource{})
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ var (
|
|||
func init() {
|
||||
tables = append(tables, new(User), new(PublicKey), new(Repository), new(Watch),
|
||||
new(Action), new(Access), new(Issue), new(Comment), new(Oauth2), new(Follow),
|
||||
new(Mirror), new(Release))
|
||||
new(Mirror), new(Release), new(LoginSource))
|
||||
}
|
||||
|
||||
func LoadModelsConfig() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue