Skip to content
Session based role manager for Casbin
Branch: master
Clone or download
Latest commit 813bf0d Feb 10, 2018
Type Name Latest commit message Commit time
Failed to load latest commit information.
examples Add TestEnforcer(). Feb 9, 2018
.gitignore Ignore IDEA files. Feb 9, 2018
.travis.yml Add Travis CI and coverage. Feb 9, 2018
LICENSE Initial commit Feb 9, 2018 Fix typo in README. Feb 10, 2018
role_manager.go Return errors. Feb 10, 2018
role_manager_test.go Return errors. Feb 10, 2018

Session Role Manager Build Status Coverage Status Godoc

Session Role Manager is the Session-based role manager for Casbin. With this library, Casbin can load session-based role hierarchy (user-role mapping) from Casbin policy or save role hierarchy to it. The session is only active in the specified time range.


go get

Simple Example

package main

import (

func main() {
	// NewEnforcer(modelPath, policyPath) automatically uses the default
	// role manager when loading policy. So if we want to use a custom
	// role manager, and this role manager relies on Casbin policy,
	// we should manually set the role manager before loading policy.
	e := casbin.NewEnforcer("examples/rbac_model_with_sessions.conf")

	// Manually set an adapter.
	a := fileadapter.NewAdapter("examples/rbac_policy_with_sessions.csv")

	// Use our role manager.
	rm := sessionrolemanager.NewRoleManager(10)

	// If our role manager relies on Casbin policy (like reading "g"
	// policy rules), then we have to set the role manager before loading
	// policy.
	// Otherwise, we can set the role manager at any time, because role
	// manager has nothing to do with the adapter.
	// Check the permission.
	// the 4th arg is the querying time in UNIX time format.
	e.Enforce("alice", "data1", "read", "1508503308708987131")

Getting Help


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

You can’t perform that action at this time.