-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: using jcasbin in springsecurity
- Loading branch information
Showing
23 changed files
with
633 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Always validate the PR title AND all the commits | ||
titleAndCommits: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
name: build | ||
|
||
on: [push, pull_request] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
services: | ||
mysql: | ||
image: mysql | ||
env: | ||
MYSQL_ROOT_PASSWORD: casbin_test | ||
MYSQL_DATABASE: casbin | ||
MYSQL_USER: casbin_test | ||
MYSQL_PASSWORD: TEST_casbin | ||
ports: | ||
- 3306:3306 | ||
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 | ||
postgres: | ||
image: postgres | ||
env: | ||
POSTGRES_DB: casbin | ||
POSTGRES_USER: casbin_test | ||
POSTGRES_PASSWORD: TEST_casbin | ||
ports: | ||
- 5432:5432 | ||
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 | ||
sqlserver: | ||
image: mcr.microsoft.com/mssql/server:2019-latest | ||
env: | ||
SA_PASSWORD: 9G3iqmzQDw9zCXII | ||
ACCEPT_EULA: Y | ||
ports: | ||
- 1433:1433 | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
with: | ||
fetch-depth: '0' | ||
|
||
- name: Install mssql-tools | ||
run: | | ||
curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add - | ||
curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list | sudo tee /etc/apt/sources.list.d/msprod.list | ||
sudo apt-get update | ||
sudo apt-get install mssql-tools unixodbc-dev | ||
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile | ||
- name: Create database for sqlserver | ||
run: sqlcmd -S 127.0.0.1,1433 -U sa -P '9G3iqmzQDw9zCXII' -Q "CREATE DATABASE casbin" | ||
|
||
- name: Set up JDK 1.8 | ||
uses: actions/setup-java@v1 | ||
with: | ||
java-version: 1.8 | ||
server-id: ossrh | ||
server-username: OSSRH_JIRA_USERNAME | ||
server-password: OSSRH_JIRA_PASSWORD | ||
gpg-private-key: ${{ secrets.GPG_PRIVATE_KEY }} | ||
gpg-passphrase: GPG_PASSPHRASE | ||
|
||
- name: Build with Maven | ||
run: mvn clean test cobertura:cobertura | ||
|
||
- name: Codecov | ||
uses: codecov/codecov-action@v1 | ||
with: | ||
token: ${{ secrets.CODECOV_TOKEN }} | ||
|
||
- name: Set up Node.js | ||
uses: actions/setup-node@v2 | ||
with: | ||
node-version: 18 | ||
|
||
- name: Sematic Release | ||
run: | | ||
npm install -g @conveyal/maven-semantic-release semantic-release | ||
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 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
GPG_KEY_NAME: ${{ secrets.GPG_KEY_NAME }} | ||
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }} | ||
OSSRH_JIRA_USERNAME: ${{ secrets.OSSRH_JIRA_USERNAME }} | ||
OSSRH_JIRA_PASSWORD: ${{ secrets.OSSRH_JIRA_PASSWORD }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
name: build | ||
|
||
on: [push, pull_request] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
services: | ||
mysql: | ||
image: mysql | ||
env: | ||
MYSQL_ROOT_PASSWORD: casbin_test | ||
MYSQL_DATABASE: casbin | ||
MYSQL_USER: casbin_test | ||
MYSQL_PASSWORD: TEST_casbin | ||
ports: | ||
- 3306:3306 | ||
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 | ||
postgres: | ||
image: postgres | ||
env: | ||
POSTGRES_DB: casbin | ||
POSTGRES_USER: casbin_test | ||
POSTGRES_PASSWORD: TEST_casbin | ||
ports: | ||
- 5432:5432 | ||
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 | ||
sqlserver: | ||
image: mcr.microsoft.com/mssql/server:2019-latest | ||
env: | ||
SA_PASSWORD: 9G3iqmzQDw9zCXII | ||
ACCEPT_EULA: Y | ||
ports: | ||
- 1433:1433 | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
with: | ||
fetch-depth: '0' | ||
|
||
- name: Install mssql-tools | ||
run: | | ||
curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add - | ||
curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list | sudo tee /etc/apt/sources.list.d/msprod.list | ||
sudo apt-get update | ||
sudo apt-get install mssql-tools unixodbc-dev | ||
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile | ||
- name: Create database for sqlserver | ||
run: sqlcmd -S 127.0.0.1,1433 -U sa -P '9G3iqmzQDw9zCXII' -Q "CREATE DATABASE casbin" | ||
|
||
- name: Set up JDK 1.8 | ||
uses: actions/setup-java@v1 | ||
with: | ||
java-version: 1.8 | ||
server-id: ossrh | ||
server-username: OSSRH_JIRA_USERNAME | ||
server-password: OSSRH_JIRA_PASSWORD | ||
gpg-private-key: ${{ secrets.GPG_PRIVATE_KEY }} | ||
gpg-passphrase: GPG_PASSPHRASE | ||
|
||
- name: Build with Maven | ||
run: mvn clean test cobertura:cobertura | ||
|
||
- name: Codecov | ||
uses: codecov/codecov-action@v1 | ||
with: | ||
token: ${{ secrets.CODECOV_TOKEN }} | ||
|
||
- name: Set up Node.js | ||
uses: actions/setup-node@v2 | ||
with: | ||
node-version: 20.8.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,19 @@ | ||
# casbin-spring-security-starter | ||
# using casbin in SpringSecurity | ||
|
||
## inform | ||
To skip the tedious and complicated login process of Spring Security, | ||
we're using its built-in login mode, which allows us to focus on the model authentication module. | ||
|
||
## DataBase | ||
For the database, we're using mysql. | ||
Remember to create a casbin database if you don't have one, and configure it in the application.yml file. | ||
|
||
## Simple Example | ||
check file examples.rbac.policy.csv you can find out we are using rbac model | ||
I registered with the identity of Alice who can read data1 | ||
![img_1.png](img_1.png) | ||
|
||
Than test the result | ||
![img_2.png](img_2.png) | ||
|
||
![img_3.png](img_3.png) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
[request_definition] | ||
r = sub, obj, act | ||
|
||
[policy_definition] | ||
p = sub, obj, act | ||
|
||
[role_definition] | ||
g = _, _ | ||
|
||
[policy_effect] | ||
e = some(where (p.eft == allow)) | ||
|
||
[matchers] | ||
m = g(r.sub, p.sub) && r.obj == p.obj && r.act == p.act |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
p, alice, data1, read | ||
p, bob, data2, write | ||
p, data2_admin, data2, read | ||
p, data2_admin, data2, write | ||
g, alice, data2_admin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
[request_definition] | ||
r = sub, dom, obj, act | ||
|
||
[policy_definition] | ||
p = sub, dom, obj, act | ||
|
||
[role_definition] | ||
g = _, _, _ | ||
|
||
[policy_effect] | ||
e = some(where (p.eft == allow)) | ||
|
||
[matchers] | ||
m = g(r.sub, p.sub, r.dom) && r.dom == p.dom && r.obj == p.obj && r.act == p.act |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>groupId</groupId> | ||
<artifactId>casbin-spring-security-starter</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
|
||
<parent> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-parent</artifactId> | ||
<version>2.2.6.RELEASE</version> | ||
<relativePath /> | ||
</parent> | ||
<dependencies> | ||
<dependency> | ||
<groupId>mysql</groupId> | ||
<artifactId>mysql-connector-java</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.casbin</groupId> | ||
<artifactId>jdbc-adapter</artifactId> | ||
<version>2.5.0</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-web</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-security</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-test</artifactId> | ||
</dependency> | ||
|
||
</dependencies> | ||
|
||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Copyright 2024 The Casdoor Authors. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package org.casbin; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
@SpringBootApplication | ||
|
||
public class Application { | ||
public static void main(String[] args) { | ||
SpringApplication.run(Application.class, args); | ||
} | ||
} |
Oops, something went wrong.