Skip to content

jcasbin/play-authz

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

play-authz

codebeat badge Build Status codecov javadoc Maven Central Discord

Table of Contents
  1. About The Project
  2. Getting Started
  3. Usage

About The Project

This provides jcasbin support to Play Framework.

Policy can be defined either in a .conf file or through JDBC adapter.

Getting Started

Dependency

(versions used for the project -sbt)

  "org.casbin" % "jcasbin" % "1.24.0",
  "org.casbin" % "jdbc-adapter" % "2.3.3",
  "org.postgresql" % "postgresql" % "42.5.0"

Configuration

  1. Default:
casbin {
  model = conf/casbin/model.conf
  policy = conf/casbin/policy.csv
  storeType = jdbc
  
  ...
  
}
  1. To use model, policy files:
  • Make sure to add your model and policy files in casbin directory which is under the conf directory.
  • Set storeType = file

Note: If model file is not provided then default model will be used.

  1. To use JDBC Adapter for defining policy:
  • Add your rules in casbin_rule table (will be created by default if not present).

Config example:

db.default {
  driver = org.someDriver.Driver
  url = "jdbc:example:example:play"
  username = user
  password = password
  
  ...
  
}

Usage

You can use enforcer by doing dependency injection in your controller.

@Inject
public PostResourceHandler(... other params, CasbinEnforcer enforcer) {
    ...
    this.enforcer = enforcer;
}

Then everything else stays the same.

if(enforcer.enforce(role, resource, action)) {
    // some logic
}