Skip to content

Commit 46b5fd1

Browse files
authored
feat: add the code (#2)
* Init the adapter for MyBatis-Plus * feat: add CI and semantic-release
1 parent b9543d0 commit 46b5fd1

File tree

10 files changed

+1021
-1
lines changed

10 files changed

+1021
-1
lines changed

.github/workflows/ci.yml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: CI
2+
3+
on: [ push, pull_request ]
4+
5+
jobs:
6+
test-and-coverage:
7+
runs-on: ubuntu-latest
8+
services:
9+
mysql:
10+
image: mysql:5.7
11+
ports:
12+
- 3306:3306
13+
env:
14+
MYSQL_USER: casbin_test
15+
MYSQL_PASSWORD: TEST_casbin
16+
MYSQL_ROOT_PASSWORD: TEST_casbin
17+
MYSQL_DATABASE: casbin
18+
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
19+
20+
steps:
21+
- uses: actions/checkout@v3
22+
- name: Set up JDK 1.8
23+
uses: actions/setup-java@v3
24+
with:
25+
java-version: '8'
26+
distribution: 'zulu'
27+
cache: 'maven'
28+
server-id: ossrh
29+
server-username: OSSRH_JIRA_USERNAME
30+
server-password: OSSRH_JIRA_PASSWORD
31+
gpg-private-key: ${{ secrets.GPG_PRIVATE_KEY }}
32+
gpg-passphrase: GPG_PASSPHRASE
33+
34+
- name: Build with Maven
35+
run: mvn clean test jacoco:report
36+
37+
- name: Upload To Codecov
38+
uses: codecov/codecov-action@v1
39+
with:
40+
token: ${{ secrets.CODECOV_TOKEN }}
41+
42+
- name: Set up Node.js
43+
uses: actions/setup-node@v2
44+
with:
45+
node-version: 20
46+
47+
- name: Semantic Release
48+
run: |
49+
npm install -g @conveyal/maven-semantic-release semantic-release
50+
semantic-release --prepare @conveyal/maven-semantic-release --publish @semantic-release/github,@conveyal/maven-semantic-release --verify-conditions @semantic-release/github,@conveyal/maven-semantic-release --verify-release @conveyal/maven-semantic-release
51+
env:
52+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
53+
GPG_KEY_NAME: ${{ secrets.GPG_KEY_NAME }}
54+
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
55+
OSSRH_JIRA_USERNAME: ${{ secrets.OSSRH_JIRA_USERNAME }}
56+
OSSRH_JIRA_PASSWORD: ${{ secrets.OSSRH_JIRA_PASSWORD }}

README.md

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,38 @@
1-
# mybatisplus-adapter
1+
# mybatisplus-adapter
2+
3+
Mybatis-Plus Adapter is the Mybatis-Plus adapter for jCasbin, which provides interfaces for loading policies from Mybatis-Plus and saving policies to it.
4+
5+
## Example
6+
7+
package com.company.example;
8+
9+
import org.casbin.jcasbin.main.Enforcer;
10+
import org.casbin.jcasbin.util.Util;
11+
import org.casbin.adapter.MybatisPlusAdapter;
12+
13+
public class Example {
14+
public void test() {
15+
Enforcer e = new Enforcer("examples/rbac_model.conf", "examples/rbac_policy.csv");
16+
17+
String driver = "com.mysql.cj.jdbc.Driver";
18+
String url = "jdbc:mysql://localhost:3306/casbin";
19+
String username = "YourUsername";
20+
String password = "YourPassword";
21+
22+
MybatisAdapter a = new MybatisAdapter(driver, url, username, password, true);
23+
24+
// Save policy to DB
25+
a.savePolicy(e.getModel());
26+
27+
// Load policy from DB
28+
a.loadPolicy(e.getModel());
29+
}
30+
}
31+
32+
## Getting Help
33+
34+
- [jCasbin](https://github.com/casbin/jcasbin)
35+
36+
## License
37+
38+
This project is under Apache 2.0 License. See the [LICENSE](LICENSE) file for the full license text.

examples/rbac_model.conf

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[request_definition]
2+
r = sub, obj, act
3+
4+
[policy_definition]
5+
p = sub, obj, act
6+
7+
[role_definition]
8+
g = _, _
9+
10+
[policy_effect]
11+
e = some(where (p.eft == allow))
12+
13+
[matchers]
14+
m = g(r.sub, p.sub) && r.obj == p.obj && r.act == p.act

examples/rbac_policy.csv

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
p, alice, data1, read
2+
p, bob, data2, write
3+
p, data2_admin, data2, read
4+
p, data2_admin, data2, write
5+
g, alice, data2_admin

maven-settings.xml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<settings>
2+
<servers>
3+
<server>
4+
<id>ossrh</id>
5+
<username>${OSSRH_JIRA_USERNAME}</username>
6+
<password>${OSSRH_JIRA_PASSWORD}</password>
7+
</server>
8+
</servers>
9+
<profiles>
10+
<profile>
11+
<id>ossrh</id>
12+
<activation>
13+
<activeByDefault>true</activeByDefault>
14+
</activation>
15+
<properties>
16+
<gpg.executable>gpg</gpg.executable>
17+
<gpg.keyname>${GPG_KEY_NAME}</gpg.keyname>
18+
<gpg.passphrase>${GPG_PASSPHRASE}</gpg.passphrase>
19+
</properties>
20+
</profile>
21+
</profiles>
22+
</settings>

pom.xml

Lines changed: 190 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>org.casbin</groupId>
8+
<artifactId>mybatisplus-adapter</artifactId>
9+
<version>1.0.0</version>
10+
11+
<name>Mybatis-Plus Adapter for JCasbin</name>
12+
<description>Load policy from Mybatis-Plus or save policy to it</description>
13+
<url>https://github.com/jcasbin/mybatisplus-adapter</url>
14+
<inceptionYear>2020</inceptionYear>
15+
16+
<issueManagement>
17+
<system>Github</system>
18+
<url>https://github.com/jcasbin/mybatisplus-adapter/issues</url>
19+
</issueManagement>
20+
21+
<parent>
22+
<groupId>org.sonatype.oss</groupId>
23+
<artifactId>oss-parent</artifactId>
24+
<version>7</version>
25+
</parent>
26+
27+
<licenses>
28+
<license>
29+
<name>The Apache Software License, Version 2.0</name>
30+
<url>https://www.apache.org/licenses/LICENSE-2.0.txt</url>
31+
<distribution>repo</distribution>
32+
</license>
33+
</licenses>
34+
35+
<scm>
36+
<url>https://github.com/jcasbin/mybatisplus-adapter</url>
37+
<connection>git@github.com:jcasbin/mybatisplus-adapter.git</connection>
38+
<developerConnection>https://github.com/hsluoyz</developerConnection>
39+
</scm>
40+
41+
<developers>
42+
<developer>
43+
<name>Yang Luo</name>
44+
<email>hsluoyz@qq.com</email>
45+
<url>https://github.com/hsluoyz</url>
46+
</developer>
47+
</developers>
48+
49+
<properties>
50+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
51+
</properties>
52+
53+
<profiles>
54+
<profile>
55+
<id>default</id>
56+
<activation>
57+
<activeByDefault>true</activeByDefault>
58+
</activation>
59+
<build>
60+
<plugins>
61+
<plugin>
62+
<!-- Automatically close and deploy from OSSRH -->
63+
<groupId>org.sonatype.central</groupId>
64+
<artifactId>central-publishing-maven-plugin</artifactId>
65+
<version>0.5.0</version>
66+
<extensions>true</extensions>
67+
<configuration>
68+
<publishingServerId>ossrh</publishingServerId>
69+
<tokenAuth>true</tokenAuth>
70+
<!-- Release versions will be synced to Maven Central automatically. -->
71+
<autoPublish>true</autoPublish>
72+
</configuration>
73+
</plugin>
74+
<plugin>
75+
<groupId>org.apache.maven.plugins</groupId>
76+
<artifactId>maven-source-plugin</artifactId>
77+
<version>3.2.1</version>
78+
<executions>
79+
<execution>
80+
<phase>package</phase>
81+
<goals>
82+
<goal>jar-no-fork</goal>
83+
</goals>
84+
</execution>
85+
</executions>
86+
</plugin>
87+
<plugin>
88+
<groupId>org.apache.maven.plugins</groupId>
89+
<artifactId>maven-javadoc-plugin</artifactId>
90+
<version>3.2.0</version>
91+
<executions>
92+
<execution>
93+
<phase>package</phase>
94+
<goals>
95+
<goal>jar</goal>
96+
</goals>
97+
</execution>
98+
</executions>
99+
</plugin>
100+
<plugin>
101+
<groupId>org.apache.maven.plugins</groupId>
102+
<artifactId>maven-gpg-plugin</artifactId>
103+
<version>1.5</version>
104+
<executions>
105+
<execution>
106+
<id>sign-artifacts</id>
107+
<phase>verify</phase>
108+
<goals>
109+
<goal>sign</goal>
110+
</goals>
111+
</execution>
112+
</executions>
113+
<configuration>
114+
<!-- Prevent gpg from using pinentry programs -->
115+
<gpgArguments>
116+
<arg>--pinentry-mode</arg>
117+
<arg>loopback</arg>
118+
</gpgArguments>
119+
</configuration>
120+
</plugin>
121+
<plugin>
122+
<groupId>org.jacoco</groupId>
123+
<artifactId>jacoco-maven-plugin</artifactId>
124+
<version>0.7.6.201602180812</version>
125+
<executions>
126+
<execution>
127+
<id>prepare-agent</id>
128+
<goals>
129+
<goal>prepare-agent</goal>
130+
</goals>
131+
</execution>
132+
</executions>
133+
</plugin>
134+
<plugin>
135+
<groupId>org.apache.maven.plugins</groupId>
136+
<artifactId>maven-compiler-plugin</artifactId>
137+
<configuration>
138+
<source>8</source>
139+
<target>8</target>
140+
</configuration>
141+
</plugin>
142+
</plugins>
143+
</build>
144+
<distributionManagement>
145+
<snapshotRepository>
146+
<id>ossrh</id>
147+
<url>https://central.sonatype.com</url>
148+
</snapshotRepository>
149+
</distributionManagement>
150+
</profile>
151+
</profiles>
152+
153+
<dependencies>
154+
<dependency>
155+
<groupId>junit</groupId>
156+
<artifactId>junit</artifactId>
157+
<version>4.13.1</version>
158+
<scope>test</scope>
159+
</dependency>
160+
<dependency>
161+
<groupId>org.casbin</groupId>
162+
<artifactId>jcasbin</artifactId>
163+
<version>1.31.2</version>
164+
</dependency>
165+
<dependency>
166+
<groupId>mysql</groupId>
167+
<artifactId>mysql-connector-java</artifactId>
168+
<version>8.0.16</version>
169+
<scope>test</scope>
170+
</dependency>
171+
<!-- MyBatis-Plus 依赖 -->
172+
<dependency>
173+
<groupId>com.baomidou</groupId>
174+
<artifactId>mybatis-plus</artifactId>
175+
<version>3.5.7</version>
176+
</dependency>
177+
<dependency>
178+
<groupId>com.microsoft.sqlserver</groupId>
179+
<artifactId>mssql-jdbc</artifactId>
180+
<version>8.2.2.jre8</version>
181+
<scope>test</scope>
182+
</dependency>
183+
<dependency>
184+
<groupId>commons-collections</groupId>
185+
<artifactId>commons-collections</artifactId>
186+
<version>3.2.2</version>
187+
</dependency>
188+
</dependencies>
189+
190+
</project>

0 commit comments

Comments
 (0)