|
|
|
@ -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
|
|
|
|
|
type LDAPAuthService struct {
|
|
|
|
|
// ldapAuthService just holds the remote host of the HTTP LDAP service to make requests to
|
|
|
|
|
type ldapAuthService struct {
|
|
|
|
|
Host string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func NewLDAPAuthService(host string) Service {
|
|
|
|
|
return &LDAPAuthService{host}
|
|
|
|
|
func newLDAPAuthService(host string) Service {
|
|
|
|
|
return &ldapAuthService{host}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 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(
|
|
|
|
|
"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
|
|
|
|
|
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)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
@ -89,7 +89,7 @@ func (a *LDAPAuthService) doPostRequest(url string, request interface{}, respons
|
|
|
|
|
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
|
|
|
|
|
if err := a.doGetRequest(fmt.Sprintf("/user/%s", username), &user); err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
@ -98,7 +98,7 @@ func (a *LDAPAuthService) GetUser(username string) (*model.User, error) {
|
|
|
|
|
return user.AsUser(), nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (a *LDAPAuthService) GetUsers() ([]*model.User, error) {
|
|
|
|
|
func (a *ldapAuthService) GetUsers() ([]*model.User, error) {
|
|
|
|
|
ldapUsers := []*ldapUser{}
|
|
|
|
|
if err := a.doGetRequest("/users", &ldapUsers); err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
@ -112,7 +112,7 @@ func (a *LDAPAuthService) GetUsers() ([]*model.User, error) {
|
|
|
|
|
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
|
|
|
|
|
if err := a.doGetRequest(fmt.Sprintf("/session/%s", token), &response); err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
@ -121,7 +121,7 @@ func (a *LDAPAuthService) GetSession(token string) (*model.Session, error) {
|
|
|
|
|
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{}{
|
|
|
|
|
"username": username,
|
|
|
|
|
"password": password,
|
|
|
|
|