Esempio n. 1
0
//Filter function, figures out the current user from the auth header
func AuthUser(request *restful.Request, resp *restful.Response,
	chain *restful.FilterChain) {
	authenticator := auth.NewAuthenticator(config.Auth.Authenticator)
	cAuth, err := authenticator.GetAuth(request.Request)
	if err != nil && config.Auth.AllowGuest {
		cAuth = &couchdb.BasicAuth{
			Username: "******",
			Password: "******",
		}
	} else if err != nil {
		Unauthenticated(request, resp)
		return
	}
	userInfo, err := GetUserFromAuth(cAuth)
	if err != nil {
		Unauthenticated(request, resp)
		return
	}
	cui := &CurrentUserInfo{
		Auth: cAuth,
		User: userInfo,
	}
	request.SetAttribute("currentUser", cui)
	chain.ProcessFilter(request, resp)
}
Esempio n. 2
0
// Authenticate a user
// Returns CurrentUserInfo if authenticated, error if not
func AuthUser(r *http.Request) (*entities.CurrentUserInfo, error) {
	authenticator := auth.NewAuthenticator(config.Auth.Authenticator)
	cAuth, err := authenticator.GetAuth(r)
	if err != nil && config.Auth.AllowGuest {
		cAuth = &couchdb.BasicAuth{
			Username: "******",
			Password: "******",
		}
	} else if err != nil {
		return nil, err
	}
	userInfo, err := services.GetUserFromAuth(cAuth)
	if err != nil {
		return nil, err
	}
	cui := &entities.CurrentUserInfo{
		Auth: cAuth,
		User: userInfo,
	}
	return cui, nil
}
Esempio n. 3
0
//Set Updated auth cookies
func SetAuth(response *restful.Response, cAuth couchdb.Auth) {
	authenticator := auth.NewAuthenticator(config.Auth.Authenticator)
	authenticator.SetAuth(response.ResponseWriter, cAuth)
}