|
|
@ -33,17 +33,17 @@ func (u ldapUser) AsUser() *model.User {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// LDAPAuthService just holds the remote host of the HTTP LDAP service to make requests to
|
|
|
|
// ldapAuthService just holds the remote host of the HTTP LDAP service to make requests to
|
|
|
|
type LDAPAuthService struct {
|
|
|
|
type ldapAuthService struct {
|
|
|
|
Host string
|
|
|
|
Host string
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func NewLDAPAuthService(host string) Service {
|
|
|
|
func newLDAPAuthService(host string) Service {
|
|
|
|
return &LDAPAuthService{host}
|
|
|
|
return &ldapAuthService{host}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// doGetRequest is a utility to make HTTP GET requests
|
|
|
|
// doGetRequest is a utility to make HTTP GET requests
|
|
|
|
func (a *LDAPAuthService) doGetRequest(url string, response interface{}) error {
|
|
|
|
func (a *ldapAuthService) doGetRequest(url string, response interface{}) error {
|
|
|
|
req, err := http.NewRequest(
|
|
|
|
req, err := http.NewRequest(
|
|
|
|
"GET", path.Join(a.Host, "poisson-ldap", url), bytes.NewBuffer([]byte("")),
|
|
|
|
"GET", path.Join(a.Host, "poisson-ldap", url), bytes.NewBuffer([]byte("")),
|
|
|
|
)
|
|
|
|
)
|
|
|
@ -68,7 +68,7 @@ func (a *LDAPAuthService) doGetRequest(url string, response interface{}) error {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// doPostRequest is a utility to make HTTP POST requests
|
|
|
|
// doPostRequest is a utility to make HTTP POST requests
|
|
|
|
func (a *LDAPAuthService) doPostRequest(url string, request interface{}, response interface{}) error {
|
|
|
|
func (a *ldapAuthService) doPostRequest(url string, request interface{}, response interface{}) error {
|
|
|
|
jsonStr, err := json.Marshal(request)
|
|
|
|
jsonStr, err := json.Marshal(request)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
return err
|
|
|
@ -89,7 +89,7 @@ func (a *LDAPAuthService) doPostRequest(url string, request interface{}, respons
|
|
|
|
return json.NewDecoder(res.Body).Decode(response)
|
|
|
|
return json.NewDecoder(res.Body).Decode(response)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (a *LDAPAuthService) GetUser(username string) (*model.User, error) {
|
|
|
|
func (a *ldapAuthService) GetUser(username string) (*model.User, error) {
|
|
|
|
var user ldapUser
|
|
|
|
var user ldapUser
|
|
|
|
if err := a.doGetRequest(fmt.Sprintf("/user/%s", username), &user); err != nil {
|
|
|
|
if err := a.doGetRequest(fmt.Sprintf("/user/%s", username), &user); err != nil {
|
|
|
|
return nil, err
|
|
|
|
return nil, err
|
|
|
@ -98,7 +98,7 @@ func (a *LDAPAuthService) GetUser(username string) (*model.User, error) {
|
|
|
|
return user.AsUser(), nil
|
|
|
|
return user.AsUser(), nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (a *LDAPAuthService) GetUsers() ([]*model.User, error) {
|
|
|
|
func (a *ldapAuthService) GetUsers() ([]*model.User, error) {
|
|
|
|
ldapUsers := []*ldapUser{}
|
|
|
|
ldapUsers := []*ldapUser{}
|
|
|
|
if err := a.doGetRequest("/users", &ldapUsers); err != nil {
|
|
|
|
if err := a.doGetRequest("/users", &ldapUsers); err != nil {
|
|
|
|
return nil, err
|
|
|
|
return nil, err
|
|
|
@ -112,7 +112,7 @@ func (a *LDAPAuthService) GetUsers() ([]*model.User, error) {
|
|
|
|
return users, nil
|
|
|
|
return users, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (a *LDAPAuthService) GetSession(token string) (*model.Session, error) {
|
|
|
|
func (a *ldapAuthService) GetSession(token string) (*model.Session, error) {
|
|
|
|
var response model.Session
|
|
|
|
var response model.Session
|
|
|
|
if err := a.doGetRequest(fmt.Sprintf("/session/%s", token), &response); err != nil {
|
|
|
|
if err := a.doGetRequest(fmt.Sprintf("/session/%s", token), &response); err != nil {
|
|
|
|
return nil, err
|
|
|
|
return nil, err
|
|
|
@ -121,7 +121,7 @@ func (a *LDAPAuthService) GetSession(token string) (*model.Session, error) {
|
|
|
|
return &response, nil
|
|
|
|
return &response, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (a *LDAPAuthService) Login(username, password string) (*model.Session, error) {
|
|
|
|
func (a *ldapAuthService) Login(username, password string) (*model.Session, error) {
|
|
|
|
reqBody := map[string]interface{}{
|
|
|
|
reqBody := map[string]interface{}{
|
|
|
|
"username": username,
|
|
|
|
"username": username,
|
|
|
|
"password": password,
|
|
|
|
"password": password,
|
|
|
|