Shiro Casbin Plugin for JCasbin

Apache Shiro's RBAC Plug-in based on jCasbin

License

License

GroupId

GroupId

org.casbin
ArtifactId

ArtifactId

shiro-casbin
Last Version

Last Version

0.0.1
Release Date

Release Date

Type

Type

jar
Description

Description

Shiro Casbin Plugin for JCasbin
Apache Shiro's RBAC Plug-in based on jCasbin
Project URL

Project URL

https://github.com/jcasbin/shiro-casbin
Source Code Management

Source Code Management

https://github.com/jcasbin/jcasbin-shiro-plugin

Download shiro-casbin

How to add to project

<!-- https://jarcasting.com/artifacts/org.casbin/shiro-casbin/ -->
<dependency>
    <groupId>org.casbin</groupId>
    <artifactId>shiro-casbin</artifactId>
    <version>0.0.1</version>
</dependency>
// https://jarcasting.com/artifacts/org.casbin/shiro-casbin/
implementation 'org.casbin:shiro-casbin:0.0.1'
// https://jarcasting.com/artifacts/org.casbin/shiro-casbin/
implementation ("org.casbin:shiro-casbin:0.0.1")
'org.casbin:shiro-casbin:jar:0.0.1'
<dependency org="org.casbin" name="shiro-casbin" rev="0.0.1">
  <artifact name="shiro-casbin" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.casbin', module='shiro-casbin', version='0.0.1')
)
libraryDependencies += "org.casbin" % "shiro-casbin" % "0.0.1"
[org.casbin/shiro-casbin "0.0.1"]

Dependencies

compile (11)

Group / Artifact Type Version
org.apache.shiro : shiro-spring jar 1.4.0
org.casbin : jcasbin jar 1.6.2
org.springframework : spring-context jar 5.2.9.RELEASE
org.casbin : jdbc-adapter jar 2.0.1
javax.servlet : javax.servlet-api jar 4.0.1
mysql : mysql-connector-java jar 8.0.16
org.slf4j : slf4j-api jar 1.7.25
org.springframework : spring-beans jar 5.2.9.RELEASE
org.springframework.boot : spring-boot jar 2.3.4.RELEASE
org.springframework.boot : spring-boot-autoconfigure jar 2.3.4.RELEASE
org.springframework : spring-core jar 5.2.9.RELEASE

test (3)

Group / Artifact Type Version
junit : junit jar 4.13.1
org.springframework.boot : spring-boot-starter-test jar 2.3.4.RELEASE
org.springframework.boot : spring-boot-starter-web jar 2.3.4.RELEASE

Project Modules

There are no modules declared in this project.

shiro-casbin

codebeat badge Build Status Coverage Status Javadocs Maven Central Gitter

Apache Shiro's RBAC & ABAC Authorization Plug-in based on jCasbin

How it works?

1.Add configuration

You need to specify the path of the model file in the configuration file.

shiro-jcasbin:
  // madel path
  modelPath: src/test/resources/model/rbac_model.conf

Of course, you also need to configure the data source information in the spring configuration file. For example:

shiro-jcasbin:
  // madel path
  modelPath: src/test/resources/model/rbac_model.conf

spring:
  datasource:
    driver-class-name: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://localhost:3306/casbin?serverTimezone=GMT%2B8
    username: casbin_test
    password: TEST_casbin

2.Enable annotation interception

You need to enable annotation interception in Shiro's configuration file.As for annotation startup classes, please use the ShiroAdvisor, like this:

@Configuration
public class ShiroConfig {
    // Other configs is omitted.
    @Bean
    public AuthorizationAttributeSourceAdvisor authorizationAttributeSourceAdvisor(SecurityManager securityManager) {
        AuthorizationAttributeSourceAdvisor advisor = new ShiroAdvisor();
        advisor.setSecurityManager(securityManager);
        return advisor;
    }
}

3.Use the EnforcerAuth annotation.

Now you can use the EnforcerAuth annotation to the controller method, like this:

@RestController
public class EnforcerAuthController {
    // Other methods is omitted.
    @EnforcerAuth
    @GetMapping("/data")
    public String function1() {
        return "success";
    }
}

It will verify whether the current login user has the requested address permission. If the current login user has the permission, this controller method will work properly. If not, it will throw the exception which can prompt you that the current login user does not have the permission.If no user is currently logged in, it will throw the exception which can prompt you that you should login in.

org.casbin

jCasbin

jCasbin authorization library and the official middlewares

Versions

Version
0.0.1