authz

package module
v0.0.0-...-db61753 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 29, 2017 License: MIT Imports: 2 Imported by: 0

README

Revel-authz Build Status Coverage Status GoDoc

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

Installation

go get github.com/casbin/revel-authz

Simple Example

package main

import (
	"net/http"
	"net/http/httptest"

    "github.com/casbin/casbin"
	"github.com/casbin/revel-authz"
	"github.com/revel/revel"
)

var testFilters = []revel.Filter{
	authz.AuthzFilter,
	func(c *revel.Controller, fc []revel.Filter) {
		c.RenderHTML("OK.")
	},
}

func main() {
	r, _ := http.NewRequest("GET", "/dataset1/resource1", nil)
    	r.SetBasicAuth("alice", "123")
    	w := httptest.NewRecorder()
    	c := revel.NewController(revel.NewRequest(r), revel.NewResponse(w))
    
    	testFilters[0](c, testFilters)
}

Documentation

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.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AuthzFilter

func AuthzFilter(c *revel.Controller, fc []revel.Filter)

AuthzFilter enables the authorization based on Casbin.

Usage:

  1. Add `authz.AuthzFilter` to the app's filters (it must come after the authentication).
  2. Init the Casbin enforcer.

func CheckPermission

func CheckPermission(e *casbin.Enforcer, r *revel.Request) bool

CheckPermission checks the user/method/path combination from the request. Returns true (permission granted) or false (permission forbidden)

func GetUserName

func GetUserName(r *revel.Request) string

GetUserName gets the user name from the request. Currently, only HTTP basic authentication is supported

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL