initial support for LDAP authentication/MSAD
This commit is contained in:
parent
dbdaf934e1
commit
efc05ea1de
7 changed files with 216 additions and 8 deletions
38
models/ldap.go
Normal file
38
models/ldap.go
Normal file
|
@ -0,0 +1,38 @@
|
|||
// Copyright github.com/juju2013. All rights reserved.
|
||||
// Use of this source code is governed by a MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package models
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/gogits/gogs/modules/auth/ldap"
|
||||
"github.com/gogits/gogs/modules/log"
|
||||
)
|
||||
|
||||
// Query if name/passwd can login against the LDAP direcotry pool
|
||||
// Create a local user if success
|
||||
// Return the same LoginUserPlain semantic
|
||||
func LoginUserLdap(name, passwd string) (*User, error) {
|
||||
mail, logged := ldap.LoginUser(name, passwd)
|
||||
if !logged {
|
||||
// user not in LDAP, do nothing
|
||||
return nil, ErrUserNotExist
|
||||
}
|
||||
// fake a local user creation
|
||||
user := User{
|
||||
LowerName: strings.ToLower(name),
|
||||
Name: strings.ToLower(name),
|
||||
LoginType: 389,
|
||||
IsActive: true,
|
||||
Passwd: passwd,
|
||||
Email: mail}
|
||||
_, err := RegisterUser(&user)
|
||||
if err != nil {
|
||||
log.Debug("LDAP local user %s fond (%s) ", name, err)
|
||||
}
|
||||
// simulate local user login
|
||||
localUser, err2 := GetUserByName(user.Name)
|
||||
return localUser, err2
|
||||
}
|
|
@ -125,6 +125,7 @@ func GetUserSalt() string {
|
|||
|
||||
// RegisterUser creates record of a new user.
|
||||
func RegisterUser(user *User) (*User, error) {
|
||||
|
||||
if !IsLegalName(user.Name) {
|
||||
return nil, ErrUserNameIllegal
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue