项目作者: casbin

项目描述 :
negroni-authz is an authorization middleware for Negroni
高级语言: Go
项目地址: git://github.com/casbin/negroni-authz.git
创建时间: 2017-06-17T02:02:22Z
项目社区:https://github.com/casbin/negroni-authz

开源协议:MIT License

下载


Negroni-authz Build Status Coverage Status GoDoc

Negroni-authz is an authorization middleware for Negroni, it’s based on https://github.com/casbin/casbin.

Installation

  1. go get github.com/casbin/negroni-authz

Simple Example

  1. package main
  2. import (
  3. "fmt"
  4. "net/http"
  5. "github.com/casbin/casbin"
  6. "github.com/casbin/negroni-authz"
  7. "github.com/urfave/negroni"
  8. )
  9. func main() {
  10. mux := http.NewServeMux()
  11. mux.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) {
  12. fmt.Fprintf(w, "Welcome to the home page!")
  13. })
  14. n := negroni.Classic()
  15. // load the casbin model and policy from files, database is also supported.
  16. e := casbin.NewEnforcer("authz_model.conf", "authz_policy.csv")
  17. n.Use(authz.Authorizer(e))
  18. http.ListenAndServe(":3000", n)
  19. }

How to control the access

The authorization determines a request based on {subject, object, action}, which means what subject can perform what action on what object. In this plugin, the meanings are:

  1. subject: the logged-on user name
  2. object: the URL path for the web resource like “dataset1/item1”
  3. action: HTTP method like GET, POST, PUT, DELETE, or the high-level actions you defined like “read-file”, “write-blog”

For how to write authorization policy and other details, please refer to the Casbin’s documentation.

Getting Help

License

This project is under MIT License. See the LICENSE file for the full license text.