From 798250c08d055c1079c3a94511c3609904a34d90 Mon Sep 17 00:00:00 2001 From: Wim Deblauwe Date: Tue, 30 Apr 2024 08:48:30 +0200 Subject: [PATCH 01/10] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 5ca89cb..0f86ea7 100644 --- a/pom.xml +++ b/pom.xml @@ -9,7 +9,7 @@ io.github.wimdeblauwe error-handling-spring-boot-starter - 4.3.0 + 4.4.0-SNAPSHOT Error Handling Spring Boot Starter Spring Boot starter that configures error handling @@ -50,7 +50,7 @@ scm:git:git@github.com:wimdeblauwe/error-handling-spring-boot-starter.git git@github.com:wimdeblauwe/error-handling-spring-boot-starter.git - 4.3.0 + HEAD github From ae76a464f40edf4ce1c6eba305ec274a911c7291 Mon Sep 17 00:00:00 2001 From: Wim Deblauwe Date: Tue, 30 Apr 2024 08:55:05 +0200 Subject: [PATCH 02/10] Update readme to add version 4.3.0 in compatibility matrix --- README.adoc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.adoc b/README.adoc index ff4dd5c..c112780 100644 --- a/README.adoc +++ b/README.adoc @@ -33,6 +33,11 @@ NOTE: Documentation is very important to us, so if you find something missing fr |=== |error-handling-spring-boot-starter |Spring Boot|Minimum Java version|Docs +|https://github.com/wimdeblauwe/error-handling-spring-boot-starter/releases/tag/4.3.0[4.3.0] +|3.x +|17 +|https://wimdeblauwe.github.io/error-handling-spring-boot-starter/4.3.0/[Documentation 4.3.0] + |https://github.com/wimdeblauwe/error-handling-spring-boot-starter/releases/tag/4.2.0[4.2.0] |3.x |17 From 6bae263c2e1146aab721e660d035e00bc318bd8f Mon Sep 17 00:00:00 2001 From: Wim Deblauwe Date: Thu, 12 Sep 2024 08:21:16 +0200 Subject: [PATCH 03/10] build: Update to Spring Boot 3.3.3 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 0f86ea7..de8378c 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ org.springframework.boot spring-boot-starter-parent - 3.0.0 + 3.3.3 io.github.wimdeblauwe From 992abd990a1d056dd6fed1bd58afafeafd4af2d1 Mon Sep 17 00:00:00 2001 From: Wim Deblauwe Date: Thu, 12 Sep 2024 08:21:50 +0200 Subject: [PATCH 04/10] feat: Map AuthorizationDeniedException to 403 Forbidden by default Fixes #97 --- .../handler/SpringSecurityApiExceptionHandler.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/io/github/wimdeblauwe/errorhandlingspringbootstarter/handler/SpringSecurityApiExceptionHandler.java b/src/main/java/io/github/wimdeblauwe/errorhandlingspringbootstarter/handler/SpringSecurityApiExceptionHandler.java index f3f85ce..c2d6532 100644 --- a/src/main/java/io/github/wimdeblauwe/errorhandlingspringbootstarter/handler/SpringSecurityApiExceptionHandler.java +++ b/src/main/java/io/github/wimdeblauwe/errorhandlingspringbootstarter/handler/SpringSecurityApiExceptionHandler.java @@ -8,6 +8,7 @@ import org.springframework.http.HttpStatus; import org.springframework.security.access.AccessDeniedException; import org.springframework.security.authentication.*; +import org.springframework.security.authorization.AuthorizationDeniedException; import org.springframework.security.core.userdetails.UsernameNotFoundException; import java.util.HashMap; @@ -22,6 +23,7 @@ public class SpringSecurityApiExceptionHandler extends AbstractApiExceptionHandl static { EXCEPTION_TO_STATUS_MAPPING = new HashMap<>(); EXCEPTION_TO_STATUS_MAPPING.put(AccessDeniedException.class, FORBIDDEN); + EXCEPTION_TO_STATUS_MAPPING.put(AuthorizationDeniedException.class, FORBIDDEN); EXCEPTION_TO_STATUS_MAPPING.put(AccountExpiredException.class, BAD_REQUEST); EXCEPTION_TO_STATUS_MAPPING.put(AuthenticationCredentialsNotFoundException.class, UNAUTHORIZED); EXCEPTION_TO_STATUS_MAPPING.put(AuthenticationServiceException.class, INTERNAL_SERVER_ERROR); From 3e8684faef580df1e21e4b320dd0da39596a95fd Mon Sep 17 00:00:00 2001 From: Wim Deblauwe Date: Thu, 12 Sep 2024 08:29:08 +0200 Subject: [PATCH 05/10] fix: Adjust for Spring Boot using MethodArgumentNotValidException instead of BindException --- .../handler/BindApiExceptionHandlerTest.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/test/java/io/github/wimdeblauwe/errorhandlingspringbootstarter/handler/BindApiExceptionHandlerTest.java b/src/test/java/io/github/wimdeblauwe/errorhandlingspringbootstarter/handler/BindApiExceptionHandlerTest.java index 2226af6..cc6377b 100644 --- a/src/test/java/io/github/wimdeblauwe/errorhandlingspringbootstarter/handler/BindApiExceptionHandlerTest.java +++ b/src/test/java/io/github/wimdeblauwe/errorhandlingspringbootstarter/handler/BindApiExceptionHandlerTest.java @@ -129,11 +129,11 @@ void testObjectValidationWithMessageOverride(@Autowired ErrorHandlingProperties @Test @WithMockUser void testTopLevelCodeOverride(@Autowired ErrorHandlingProperties properties) throws Exception { - properties.getCodes().put("org.springframework.validation.BindException", "BIND_FAILED"); + properties.getCodes().put("org.springframework.web.bind.MethodArgumentNotValidException", "METHOD_ARG_NOT_VALID"); mockMvc.perform(MockMvcRequestBuilders.get("/test/field-validation") .queryParam("param1", "foo")) .andExpect(status().isBadRequest()) - .andExpect(jsonPath("code").value("BIND_FAILED")) + .andExpect(jsonPath("code").value("METHOD_ARG_NOT_VALID")) .andExpect(jsonPath("fieldErrors", hasSize(1))) .andExpect(jsonPath("fieldErrors[0].code").value("REQUIRED_NOT_NULL")) .andExpect(jsonPath("fieldErrors[0].message").value("must not be null")) @@ -146,12 +146,12 @@ void testTopLevelCodeOverride(@Autowired ErrorHandlingProperties properties) thr @Test @WithMockUser void testDisableAddingPath(@Autowired ErrorHandlingProperties properties) throws Exception { - properties.getCodes().put("org.springframework.validation.BindException", "BIND_FAILED"); + properties.getCodes().put("org.springframework.web.bind.MethodArgumentNotValidException", "METHOD_ARG_NOT_VALID"); properties.setAddPathToError(false); mockMvc.perform(MockMvcRequestBuilders.get("/test/field-validation") .queryParam("param1", "foo")) .andExpect(status().isBadRequest()) - .andExpect(jsonPath("code").value("BIND_FAILED")) + .andExpect(jsonPath("code").value("METHOD_ARG_NOT_VALID")) .andExpect(jsonPath("fieldErrors", hasSize(1))) .andExpect(jsonPath("fieldErrors[0].code").value("REQUIRED_NOT_NULL")) .andExpect(jsonPath("fieldErrors[0].message").value("must not be null")) From 205c3886a1a7a01cc76e3929fbc3a5f027783212 Mon Sep 17 00:00:00 2001 From: Wim Deblauwe Date: Thu, 12 Sep 2024 08:30:28 +0200 Subject: [PATCH 06/10] fix: Adjust for Spring Boot using AuthorizationDenied instead of AccessDenied --- .../handler/SpringSecurityApiExceptionHandlerTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/io/github/wimdeblauwe/errorhandlingspringbootstarter/handler/SpringSecurityApiExceptionHandlerTest.java b/src/test/java/io/github/wimdeblauwe/errorhandlingspringbootstarter/handler/SpringSecurityApiExceptionHandlerTest.java index 28644e4..62f9db3 100644 --- a/src/test/java/io/github/wimdeblauwe/errorhandlingspringbootstarter/handler/SpringSecurityApiExceptionHandlerTest.java +++ b/src/test/java/io/github/wimdeblauwe/errorhandlingspringbootstarter/handler/SpringSecurityApiExceptionHandlerTest.java @@ -53,7 +53,7 @@ void testForbiddenViaSecuredAnnotation() throws Exception { mockMvc.perform(get("/test/spring-security/admin")) .andExpect(status().isForbidden()) .andExpect(header().string("Content-Type", "application/json")) - .andExpect(jsonPath("code").value("ACCESS_DENIED")) + .andExpect(jsonPath("code").value("AUTHORIZATION_DENIED")) .andExpect(jsonPath("message").value("Access Denied")); } From 28fd15bcd396b24297349169ee64de135f0f2b51 Mon Sep 17 00:00:00 2001 From: Wim Deblauwe Date: Thu, 12 Sep 2024 08:40:43 +0200 Subject: [PATCH 07/10] Allow releasing via GitHub Actions --- .github/workflows/build.yml | 12 +++--------- .github/workflows/release.yml | 36 +++++++++++++++++++++++++++++++++++ README.adoc | 28 ++++++++++++--------------- 3 files changed, 51 insertions(+), 25 deletions(-) create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 992693d..dda08a0 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -19,17 +19,11 @@ jobs: - uses: actions/checkout@v2 - name: Setup java ${{ matrix.java }} - uses: actions/setup-java@v1 + uses: actions/setup-java@v4 with: java-version: ${{ matrix.java }} - - - name: Cache local Maven repository - uses: actions/cache@v2 - with: - path: ~/.m2/repository - key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} - restore-keys: | - ${{ runner.os }}-maven- + distribution: 'temurin' + cache: maven - name: Build with Maven run: ./mvnw -B -ntp clean verify diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..f6779f7 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,36 @@ +name: Release + +on: + release: + types: [ published ] + +jobs: + release: + name: Release on Sonatype OSS + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - name: Set up Apache Maven Central + uses: actions/setup-java@v4 + with: # running setup-java again overwrites the settings.xml + distribution: 'temurin' + java-version: 17 + cache: 'maven' + server-id: ossrh + server-username: OSSRH_USERNAME + server-password: OSSRH_PASSWORD + gpg-private-key: ${{ secrets.GPG_PRIVATE_KEY }} + gpg-passphrase: MAVEN_GPG_PASSPHRASE + + - name: Publish to Apache Maven Central + run: | + mvn -Prelease \ + --no-transfer-progress \ + --batch-mode \ + deploy + env: + OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }} + OSSRH_PASSWORD: ${{ secrets.OSSRH_PASSWORD }} + MAVEN_GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }} diff --git a/README.adoc b/README.adoc index c112780..ff24642 100644 --- a/README.adoc +++ b/README.adoc @@ -89,19 +89,15 @@ Blogs and articles about this library: == Release -Release is done via the Maven Release Plugin: - -`mvn release:prepare` - -and - -`mvn release:perform` - -Merge the tag to `master` so the documentation is updated. - -Finally, push the local commits and the tag to remote. - -[NOTE] -==== -Before releasing, run `export GPG_TTY=$(tty)` -==== +To release a new version of the project, follow these steps: + +1. Update `pom.xml` with the new version (Use `mvn versions:set -DgenerateBackupPoms=false -DnewVersion=`) +2. Commit the changes locally. +3. Tag the commit with the version (e.g. `1.0.0`) and push the tag. +4. Create a new release in GitHub via https://github.com/wimdeblauwe/error-handling-spring-boot-starter/releases/new +- Select the newly pushed tag +- Update the release notes. +This should automatically start the [release action](https://github.com/wimdeblauwe/error-handling-spring-boot-starter/actions). +5. Merge the tag to `master` so the documentation is updated. +6. Update `pom.xml` again with the next `SNAPSHOT` version. +7. Close the milestone in the GitHub issue tracker. From 21186e23fad575d02893efc02038d580b7511a6f Mon Sep 17 00:00:00 2001 From: Wim Deblauwe Date: Thu, 12 Sep 2024 08:42:32 +0200 Subject: [PATCH 08/10] Update readme to add version 4.4.0 in compatibility matrix --- README.adoc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.adoc b/README.adoc index ff24642..119ba62 100644 --- a/README.adoc +++ b/README.adoc @@ -33,6 +33,11 @@ NOTE: Documentation is very important to us, so if you find something missing fr |=== |error-handling-spring-boot-starter |Spring Boot|Minimum Java version|Docs +|https://github.com/wimdeblauwe/error-handling-spring-boot-starter/releases/tag/4.4.0[4.4.0] +|3.3.x +|17 +|https://wimdeblauwe.github.io/error-handling-spring-boot-starter/4.4.0/[Documentation 4.4.0] + |https://github.com/wimdeblauwe/error-handling-spring-boot-starter/releases/tag/4.3.0[4.3.0] |3.x |17 From 2de218344b047264a7e9b8258c2439e98cae1acf Mon Sep 17 00:00:00 2001 From: Wim Deblauwe Date: Thu, 12 Sep 2024 08:43:14 +0200 Subject: [PATCH 09/10] Release 4.4.0 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index de8378c..d2e701b 100644 --- a/pom.xml +++ b/pom.xml @@ -9,7 +9,7 @@ io.github.wimdeblauwe error-handling-spring-boot-starter - 4.4.0-SNAPSHOT + 4.4.0 Error Handling Spring Boot Starter Spring Boot starter that configures error handling From a8ec58ec0933194eaf0dea16314c9f6bb6c1e6ae Mon Sep 17 00:00:00 2001 From: Wim Deblauwe Date: Thu, 12 Sep 2024 08:47:20 +0200 Subject: [PATCH 10/10] Update maven-gpg-plugin for release via GitHub actions --- pom.xml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pom.xml b/pom.xml index d2e701b..316a967 100644 --- a/pom.xml +++ b/pom.xml @@ -295,6 +295,12 @@ org.apache.maven.plugins maven-gpg-plugin ${maven-gpg-plugin.version} + + + --pinentry-mode + loopback + + sign-artifacts