Skip to content

Commit

Permalink
WebFlux submodule (#4)
Browse files Browse the repository at this point in the history
* prep for webflux module

* Setup webflux

* WebFlux update logout url to port 3001

* separate job for webflux

* update README

* github actions separate mvc and webflux subprojects

* Refactor mvc vs webflux packages

* Make public for unit test

* Update WebFlux Theme Templates
  • Loading branch information
patkub authored Nov 6, 2024
1 parent 1fc04bc commit 11925d9
Show file tree
Hide file tree
Showing 55 changed files with 1,242 additions and 98 deletions.
49 changes: 41 additions & 8 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Build
on: [push]

jobs:
build:
mvc-login:
runs-on: ubuntu-latest
steps:
- name: Checkout sources
Expand All @@ -15,15 +15,15 @@ jobs:
java-version: 21
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4
- name: Build with Gradle
run: ./gradlew build
- name: Unit Test with Gradle
run: ./gradlew test
- name: Build MVC Login with Gradle
run: ./gradlew :mvc-login:build
- name: Unit Test MVC Login with Gradle
run: ./gradlew :mvc-login:test
- name: Generate JaCoCo badge
id: jacoco
uses: cicirello/jacoco-badge-generator@v2
with:
jacoco-csv-file: build/reports/jacoco/test/jacocoTestReport.csv
jacoco-csv-file: mvc-login/build/reports/jacoco/test/jacocoTestReport.csv
badges-directory: badges
generate-branches-badge: true
generate-summary: true
Expand All @@ -34,5 +34,38 @@ jobs:
- name: Upload JaCoCo coverage report as a workflow artifact
uses: actions/upload-artifact@v4
with:
name: jacoco-report
path: build/reports/jacoco/test/
name: jacoco-report-mvc-login
path: mvc-login/build/reports/jacoco/test/
webflux-login:
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v4
- name: Setup Java
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: 21
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4
- name: Build WebFlux Login with Gradle
run: ./gradlew :webflux-login:build
- name: Unit Test WebFlux Login with Gradle
run: ./gradlew :webflux-login:test
- name: Generate JaCoCo badge
id: jacoco
uses: cicirello/jacoco-badge-generator@v2
with:
jacoco-csv-file: webflux-login/build/reports/jacoco/test/jacocoTestReport.csv
badges-directory: badges
generate-branches-badge: true
generate-summary: true
- name: Log coverage percentages to workflow output
run: |
echo "coverage = ${{ steps.jacoco.outputs.coverage }}"
echo "branches = ${{ steps.jacoco.outputs.branches }}"
- name: Upload JaCoCo coverage report as a workflow artifact
uses: actions/upload-artifact@v4
with:
name: jacoco-report-webflux-login
path: webflux-login/build/reports/jacoco/test/
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,4 @@ bin/

### Custom ###
# Spring Boot config with secrets
src/main/resources/application.yml
**/src/main/resources/application.yml
2 changes: 2 additions & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 18 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Description

This is a fork of Okta's [Spring Boot Login - MVC](https://github.com/auth0-samples/auth0-spring-boot-login-samples/tree/master/mvc-login), without Okta Spring Boot Starter.
This is a fork of Okta's [Spring Boot Login Samples](https://github.com/auth0-samples/auth0-spring-boot-login-samples), without Okta Spring Boot Starter.

## Requirements

Expand All @@ -12,67 +12,66 @@ This is a fork of Okta's [Spring Boot Login - MVC](https://github.com/auth0-samp

### Auth0 Dashboard
1. On the [Auth0 Dashboard](https://manage.auth0.com/#/clients) create a new Application of type **Regular Web Application**.
1. On the **Settings** tab of your application, add the URL `http://localhost:3000/login/oauth2/code/okta` to the **Allowed Callback URLs** field.
1. On the **Settings** tab of your application, add the URL `http://localhost:3000/` to the **Allowed Logout URLs** field.
1. On the **Settings** tab of your application, add the following URLs to the **Allowed Callback URLs** field.
- `http://localhost:3000/login/oauth2/code/okta, http://localhost:3001/login/oauth2/code/okta`
1. On the **Settings** tab of your application, add the following URLs to the **Allowed Logout URLs** field.
- `http://localhost:3000, http://localhost:3001`
1. Save the changes to your application settings. Don't close this page; you'll need some of the settings when configuring the application below.

### Application configuration

Copy `src/main/resources/application.yml.example` to `src/main/resources/application.yml`:
Create application.yml by copying example config:

```bash
cp src/main/resources/application.yml.example src/main/resources/application.yml
cp mvc-login/src/main/resources/application.yml.example mvc-login/src/main/resources/application.yml
cp webflux-login/src/main/resources/application.yml.example webflux-login/src/main/resources/application.yml
```

Set the application values in the `src/main/resources/application.yml` file to the values of your Auth0 application.
Set the application values in the `src/main/resources/application.yml` file to the values of your Auth0 application for both mvc-login and webflux-login subprojects.

```yaml
issuer-uri: https://{YOUR-DOMAIN}/
client-id: {YOUR-CLIENT-ID}
client-secret: {YOUR-CLIENT-SECRET}
```
## Running the sample
## Running the MVC sample
Open a terminal, go to the project root directory and run the following command:
Linux or MacOS:
```bash
./gradlew bootRun
./gradlew :mvc-login:bootRun
```

Windows:

```bash
gradlew.bat bootRun
gradlew.bat :mvc-login:bootRun
```

The application will be accessible at http://localhost:3000.

### Running the sample with podman
## Running the WebFlux sample

In order to run the example with [Podman](https://podman.io/docs/installation) you need to have `podman` installed.

You also need to set the client values as explained [previously](#application-configuration).

Execute the command to run Podman for your environment:
Open a terminal, go to the project root directory and run the following command:

Linux or MacOS:

```bash
sh exec.sh
./gradlew :webflux-login:bootRun
```

Windows:

```bash
.\exec.ps1
gradlew.bat :webflux-login:bootRun
```

The application will be accessible at http://localhost:3000.
The application will be accessible at http://localhost:3001.

## Upgrading the sample
## Upgrading the samples

Use [OpenRewrite](https://docs.openrewrite.org/) to upgrade to latest Java and SpringBoot.

Expand Down
51 changes: 0 additions & 51 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,67 +1,16 @@
plugins {
id 'java'
id 'jacoco'

// https://plugins.gradle.org/plugin/org.springframework.boot
id 'org.springframework.boot' version '3.3.5'
// https://plugins.gradle.org/plugin/io.spring.dependency-management
id 'io.spring.dependency-management' version '1.1.6'

// Use OpenRewrite to upgrade Java / SpringBoot version: https://docs.openrewrite.org/
// https://plugins.gradle.org/plugin/org.openrewrite.rewrite
id 'org.openrewrite.rewrite' version '6.26.0'
}

ext {
springBootVersion = '3.3.5'
}

group = 'org.example'
version = '1.0-SNAPSHOT'

java {
sourceCompatibility = '21'
}

repositories {
mavenCentral()
}

dependencies {
//
// SpringBoot
//
// https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-web
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: "${springBootVersion}"
// https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-oauth2-client
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-oauth2-client', version: "${springBootVersion}"
// https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-test
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-test', version: "${springBootVersion}"

//
// Thymeleaf
//
// https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-thymeleaf
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-thymeleaf', version: "${springBootVersion}"
// https://mvnrepository.com/artifact/org.thymeleaf.extras/thymeleaf-extras-springsecurity6
implementation group: 'org.thymeleaf.extras', name: 'thymeleaf-extras-springsecurity6', version: '3.1.2.RELEASE'
// https://mvnrepository.com/artifact/nz.net.ultraq.thymeleaf/thymeleaf-layout-dialect
implementation group: 'nz.net.ultraq.thymeleaf', name: 'thymeleaf-layout-dialect', version: '3.3.0'
}

test {
useJUnitPlatform()
// report is always generated after tests run
finalizedBy jacocoTestReport
}
jacocoTestReport {
reports {
xml.required = true
csv.required = true
html.required = true
}
}

//
// Use OpenRewrite to upgrade Java / SpringBoot version: https://docs.openrewrite.org/
//
Expand Down
2 changes: 0 additions & 2 deletions exec.ps1

This file was deleted.

3 changes: 0 additions & 3 deletions exec.sh

This file was deleted.

File renamed without changes.
73 changes: 73 additions & 0 deletions mvc-login/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# sample-oauth2-spring-boot - MVC

## Description

This is a fork of Okta's [Spring Boot Login - MVC](https://github.com/auth0-samples/auth0-spring-boot-login-samples/tree/master/mvc-login), without Okta Spring Boot Starter.

## Requirements

- Java 21

## Configuration

### Auth0 Dashboard
1. On the [Auth0 Dashboard](https://manage.auth0.com/#/clients) create a new Application of type **Regular Web Application**.
1. On the **Settings** tab of your application, add the URL `http://localhost:3000/login/oauth2/code/okta` to the **Allowed Callback URLs** field.
1. On the **Settings** tab of your application, add the URL `http://localhost:3000/` to the **Allowed Logout URLs** field.
1. Save the changes to your application settings. Don't close this page; you'll need some of the settings when configuring the application below.

### Application configuration

Create application.yml by copying example config:

```bash
cp src/main/resources/application.yml.example src/main/resources/application.yml
```

Set the application values in the `src/main/resources/application.yml` file to the values of your Auth0 application.

```yaml
issuer-uri: https://{YOUR-DOMAIN}/
client-id: {YOUR-CLIENT-ID}
client-secret: {YOUR-CLIENT-SECRET}
```
## Running the Spring MVC Sample
Open a terminal, go to the project root directory and run the following command:
Linux or MacOS:
```bash
./gradlew bootRun
```

Windows:

```bash
gradlew.bat bootRun
```

The application will be accessible at http://localhost:3000.

### Running the sample with podman

In order to run the example with [Podman](https://podman.io/docs/installation) you need to have `podman` installed.

You also need to set the client values as explained [previously](#application-configuration).

Execute the command to run Podman for your environment:

Linux or MacOS:

```bash
sh exec.sh
```

Windows:

```bash
.\exec.ps1
```

The application will be accessible at http://localhost:3000.
59 changes: 59 additions & 0 deletions mvc-login/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
plugins {
id 'java'
id 'jacoco'

// https://plugins.gradle.org/plugin/org.springframework.boot
id 'org.springframework.boot' version '3.3.5'
// https://plugins.gradle.org/plugin/io.spring.dependency-management
id 'io.spring.dependency-management' version '1.1.6'
}

ext {
springBootVersion = '3.3.5'
}

group = 'org.example'
version = '1.0-SNAPSHOT'

java {
sourceCompatibility = '21'
}

repositories {
mavenCentral()
}

dependencies {
//
// SpringBoot
//
// https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-web
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: "${springBootVersion}"
// https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-oauth2-client
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-oauth2-client', version: "${springBootVersion}"
// https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-test
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-test', version: "${springBootVersion}"

//
// Thymeleaf
//
// https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-thymeleaf
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-thymeleaf', version: "${springBootVersion}"
// https://mvnrepository.com/artifact/org.thymeleaf.extras/thymeleaf-extras-springsecurity6
implementation group: 'org.thymeleaf.extras', name: 'thymeleaf-extras-springsecurity6', version: '3.1.2.RELEASE'
// https://mvnrepository.com/artifact/nz.net.ultraq.thymeleaf/thymeleaf-layout-dialect
implementation group: 'nz.net.ultraq.thymeleaf', name: 'thymeleaf-layout-dialect', version: '3.3.0'
}

test {
useJUnitPlatform()
// report is always generated after tests run
finalizedBy jacocoTestReport
}
jacocoTestReport {
reports {
xml.required = true
csv.required = true
html.required = true
}
}
2 changes: 2 additions & 0 deletions mvc-login/exec.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
podman build -t sample-oauth2-spring-boot-mvc .
podman run -p 3000:3000 -it sample-oauth2-spring-boot-mvc
Loading

0 comments on commit 11925d9

Please sign in to comment.