Пример #1
0
func UserShow(w http.ResponseWriter, r *http.Request) {
	vars := mux.Vars(r)
	userId := vars["userId"]
	token := r.URL.Query().Get("auth")

	// parameters OK ?
	if parametersOk(userId, token) == false {
		encodeStandardResponse(w, http.StatusBadRequest, nil)
		return
	}

	// validate the token
	if authtoken.Validate(config.Configuration.AuthTokenEndpoint, token) == false {
		encodeStandardResponse(w, http.StatusForbidden, nil)
		return
	}

	// do the lookup
	user, err := ldap.LookupUser(config.Configuration.LdapUrl, config.Configuration.LdapBaseDn, userId)

	// lookup error?
	if err != nil {
		encodeStandardResponse(w, http.StatusInternalServerError, nil)
		return
	}

	// user not found (probably an error)?
	if user == nil {
		encodeStandardResponse(w, http.StatusNotFound, nil)
		return
	}

	// all good...
	encodeStandardResponse(w, http.StatusOK, user)
}
Пример #2
0
func HealthCheck(w http.ResponseWriter, r *http.Request) {

	healthy := true
	message := ""

	user, err := ldap.LookupUser(config.Configuration.LdapUrl, config.Configuration.LdapBaseDn, config.Configuration.HealthCheckUser)
	if err != nil {
		healthy = false
		message = err.Error()
	} else if user == nil {
		healthy = false
	}

	encodeHealthCheckResponse(w, http.StatusOK, healthy, message)
}