示例#1
0
// Destroys a session
func (ac AuthController) del(request *restful.Request,
	response *restful.Response) {
	am := new(AuthManager)
	//Get the session id
	sessId, err := am.GetSessionId(request.Request)
	if err != nil {
		auth.ClearAuth(response.ResponseWriter)
		Unauthenticated(request, response)
		return
	}
	//Read the session
	sess, err := am.ReadSession(sessId)
	if err != nil {
		// Most likely, we have an expired session.
		// Just clear the session cookie and move on
		auth.ClearAuth(response.ResponseWriter)
		response.WriteEntity(BooleanResponse{Success: true})
		return
	}
	if err = am.Destroy(sess); err != nil {
		WriteError(err, response)
	} else {
		//Clear the session cookie
		auth.ClearAuth(response.ResponseWriter)
		response.WriteEntity(BooleanResponse{Success: true})
	}
}
示例#2
0
//Writes unauthenticated error to response
func Unauthenticated(request *restful.Request, response *restful.Response) {
	LogError(request, response, errors.New("Unauthenticated"))
	response.AddHeader("Content-Type", "text/plain")
	response.WriteErrorString(401, "Unauthenticated")
	//Clear any Auth cookies that might be hanging around
	auth.ClearAuth(response.ResponseWriter)
}
示例#3
0
// Returns the list of all enabled plugins
// Non-enabled plugins are not included
func getPluginList(w http.ResponseWriter, r *http.Request) {
	_, err := AuthUser(r)
	if err != nil {
		auth.ClearAuth(w)
		http.Error(w, err.Error(), http.StatusUnauthorized)
	}
	LogRequest(r)
	pluginList := fserv.GetEnabledPlugins()
	jsonList, err := json.Marshal(pluginList)
	if err != nil {
		LogError(err)
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
	w.Header().Set("Content-Type", "application/json")
	w.Write(jsonList)
}