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..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 @@ -89,19 +94,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. diff --git a/pom.xml b/pom.xml index 5ca89cb..316a967 100644 --- a/pom.xml +++ b/pom.xml @@ -4,12 +4,12 @@ org.springframework.boot spring-boot-starter-parent - 3.0.0 + 3.3.3 io.github.wimdeblauwe error-handling-spring-boot-starter - 4.3.0 + 4.4.0 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 @@ -295,6 +295,12 @@ org.apache.maven.plugins maven-gpg-plugin ${maven-gpg-plugin.version} + + + --pinentry-mode + loopback + + sign-artifacts 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); 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")) 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")); }