https://github.com/casdoor/casdoor-spring-boot-starter
Spring Boot 2.x & 3.x Starter for Casdoor, see example at: https://github.com/casdoor/casdoor-spring-boot-example
https://github.com/casdoor/casdoor-spring-boot-starter
casdoor java oauth oidc saml sdk spring-boot spring-boot-2 spring-boot-3 springboot sso
Last synced: 6 months ago
JSON representation
Spring Boot 2.x & 3.x Starter for Casdoor, see example at: https://github.com/casdoor/casdoor-spring-boot-example
- Host: GitHub
- URL: https://github.com/casdoor/casdoor-spring-boot-starter
- Owner: casdoor
- License: apache-2.0
- Created: 2021-07-19T10:43:58.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2024-10-18T12:23:38.000Z (12 months ago)
- Last Synced: 2025-03-29T01:13:06.701Z (6 months ago)
- Topics: casdoor, java, oauth, oidc, saml, sdk, spring-boot, spring-boot-2, spring-boot-3, springboot, sso
- Language: Java
- Homepage: https://mvnrepository.com/artifact/org.casbin/casdoor-spring-boot-starter
- Size: 54.7 KB
- Stars: 18
- Watchers: 2
- Forks: 20
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# Casdoor SpringBoot Starter
[](https://github.com/casdoor/casdoor-spring-boot-starter/actions/workflows/maven-ci.yml)
[](http://www.apache.org/licenses/LICENSE-2.0.txt)
[](code_of_conduct.md)
[](https://spring.io/projects/spring-boot)
[](https://www.javadoc.io/doc/org.casbin/casdoor-spring-boot-starter)
[](https://mvnrepository.com/artifact/org.casbin/casdoor-spring-boot-starter/latest)
[](https://github.com/casdoor/casdoor-spring-boot-starter/releases/latest)
[](https://discord.gg/5rPsrAzK7S)Casdoor SpringBoot Starter is designed to help you easily integrate [Casdoor](https://github.com/casbin/casdoor) into
your Spring Boot project.## What you need
The Casdoor should be deployed.
You can refer to the Casdoor official documentation for the [Server Installation](/docs/basic/server-installation).
After a successful deployment, you need to ensure:
- The Casdoor server is successfully running on **http://localhost:8000**.
- Open your favorite browser and visit **http://localhost:7001**, you will see the login page of Casdoor.
- Input `admin` and `123` to test login functionality is working fine.## Quickstart
### Include the dependency
Add ```casdoor-spring-boot-starter``` to the Spring Boot project.
For Apache Maven:
```Maven
org.casbin
casdoor-spring-boot-starter
1.x.y```
For Gradle:
```gradle
// https://mvnrepository.com/artifact/org.casbin/casdoor-spring-boot-starter
implementation group: 'org.casbin', name: 'casdoor-spring-boot-starter', version: '1.x.y'
```### Configure your properties
Initialization requires 6 parameters, which are all string type.
| Name (in order) | Must | Description |
|------------------|------|-----------------------------------------------------|
| endpoint | Yes | Casdoor Server Url, such as `http://localhost:8000` |
| clientId | Yes | Application.client_id |
| clientSecret | Yes | Application.client_secret |
| certificate | Yes | The public key for the Casdoor application's cert |
| organizationName | Yes | Application.organization |
| applicationName | No | Application.name |You can use Java properties or YAML files to init as below.
For properties:
```properties
casdoor.endpoint = http://localhost:8000
casdoor.clientId =
casdoor.clientSecret =
casdoor.certificate =
casdoor.organizationName = built-in
casdoor.applicationName = app-built-in
```For yaml:
```yaml
casdoor:
endpoint: http://localhost:8000
client-id:
client-secret:
certificate:
organization-name: built-in
application-name: app-built-in
```### Get the Service and use
Now provide 5 services: `CasdoorAuthService`, `CasdoorUserService`, `CasdoorEmailService`, `CasdoorSmsService` and `CasdoorResourceService`.
You can create them as below in SpringBoot project.
```java
@Resource
private CasdoorAuthService casdoorAuthService;
```Examples of APIs are shown below.
- CasdoorAuthService
- `String token = casdoorAuthService.getOAuthToken(code, "app-built-in");`
- `CasdoorUser casdoorUser = casdoorAuthService.parseJwtToken(token);`
- CasdoorUserService
- `CasdoorUser casdoorUser = casdoorUserService.getUser("admin");`
- `CasdoorUser casdoorUser = casdoorUserService.getUserByEmail("admin@example.com");`
- `CasdoorUser[] casdoorUsers = casdoorUserService.getUsers();`
- `CasdoorUser[] casdoorUsers = casdoorUserService.getSortedUsers("created_time", 5);`
- `int count = casdoorUserService.getUserCount("0");`
- `CasdoorResponse response = casdoorUserService.addUser(user);`
- `CasdoorResponse response = casdoorUserService.updateUser(user);`
- `CasdoorResponse response = casdoorUserService.deleteUser(user);`
- CasdoorEmailService
- `CasdoorResponse response = casdoorEmailService.sendEmail(title, content, sender, receiver);`
- CasdoorSmsService
- `CasdoorResponse response = casdoorSmsService.sendSms(randomCode(), receiver);`
- CasdoorResourceService
- `CasdoorResponse response = casdoorResourceService.uploadResource(user, tag, parent, fullFilePath, file);`
- `CasdoorResponse response = casdoorResourceService.deleteResource(file.getName());`## What's more
You can explore the following projects/docs to learn more about the integration of Java with Casdoor.
- [casdoor-java-sdk](https://github.com/casdoor/casdoor-java-sdk)
- [casdoor-spring-boot-example](https://github.com/casdoor/casdoor-spring-boot-example)
- [casdoor-spring-boot-security-example](https://casdoor.org/docs/category/spring-security)
- [casdoor-spring-boot-shiro-example](https://github.com/casdoor/casdoor-spring-boot-shiro-example)