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

25

stars

35

commits

Java

primary language

Oct 18, 2024

updated

mvnrepository.com/artifact/org.casbin/casdoor-spring-boot-starter
casdoor
java
oauth
oidc
saml
sdk
spring-boot
springboot
spring-boot-2
spring-boot-3
sso
Browse cluster: Identity & Access Management Platforms

README

Casdoor SpringBoot Starter

build License Contributor Covenant SpringBootVersion Javadocs Maven Central Release Discord

Casdoor SpringBoot Starter is designed to help you easily integrate 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.

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:

<!-- https://mvnrepository.com/artifact/org.casbin/casdoor-spring-boot-starter -->
<dependency>
    <groupId>org.casbin</groupId>
    <artifactId>casdoor-spring-boot-starter</artifactId>
    <version>1.x.y</version>
</dependency>

For 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)MustDescription
endpointYesCasdoor Server Url, such as http://localhost:8000
clientIdYesApplication.client_id
clientSecretYesApplication.client_secret
certificateYesThe public key for the Casdoor application's cert
organizationNameYesApplication.organization
applicationNameNoApplication.name

You can use Java properties or YAML files to init as below.

For properties:

casdoor.endpoint = http://localhost:8000
casdoor.clientId = <client-id>
casdoor.clientSecret = <client-secret>
casdoor.certificate = <jwt-public-key>
casdoor.organizationName = built-in
casdoor.applicationName = app-built-in

For yaml:

casdoor:
  endpoint: http://localhost:8000
  client-id: <client-id>
  client-secret: <client-secret>
  certificate: <jwt-public-key>
  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.

@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.

Contributors

hsluoyz

13 commits

seriouszyx

5 commits

tangyang9464

3 commits

Selflocking

2 commits

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

25

stars

35

commits

Java

primary language

Oct 18, 2024

updated

mvnrepository.com/artifact/org.casbin/casdoor-spring-boot-starter
casdoor
java
oauth
oidc
saml
sdk
spring-boot
springboot
spring-boot-2
spring-boot-3
sso
Browse cluster: Identity & Access Management Platforms

README

Casdoor SpringBoot Starter

build License Contributor Covenant SpringBootVersion Javadocs Maven Central Release Discord

Casdoor SpringBoot Starter is designed to help you easily integrate 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.

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:

<!-- https://mvnrepository.com/artifact/org.casbin/casdoor-spring-boot-starter -->
<dependency>
    <groupId>org.casbin</groupId>
    <artifactId>casdoor-spring-boot-starter</artifactId>
    <version>1.x.y</version>
</dependency>

For 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)MustDescription
endpointYesCasdoor Server Url, such as http://localhost:8000
clientIdYesApplication.client_id
clientSecretYesApplication.client_secret
certificateYesThe public key for the Casdoor application's cert
organizationNameYesApplication.organization
applicationNameNoApplication.name

You can use Java properties or YAML files to init as below.

For properties:

casdoor.endpoint = http://localhost:8000
casdoor.clientId = <client-id>
casdoor.clientSecret = <client-secret>
casdoor.certificate = <jwt-public-key>
casdoor.organizationName = built-in
casdoor.applicationName = app-built-in

For yaml:

casdoor:
  endpoint: http://localhost:8000
  client-id: <client-id>
  client-secret: <client-secret>
  certificate: <jwt-public-key>
  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.

@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.

Contributors

hsluoyz

13 commits

seriouszyx

5 commits

tangyang9464

3 commits

Selflocking

2 commits

Languages

Java

100.0%