forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request quarkusio#22562 from geoand/rr-custom-security-map…
…pers Allow user defined exception mappers to override built-in security exception mapping
- Loading branch information
Showing
4 changed files
with
57 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
...est/java/io/quarkus/resteasy/reactive/server/test/security/CustomExceptionMapperTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package io.quarkus.resteasy.reactive.server.test.security; | ||
|
||
import static io.restassured.RestAssured.when; | ||
|
||
import javax.annotation.security.RolesAllowed; | ||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.core.Response; | ||
|
||
import org.jboss.resteasy.reactive.server.ServerExceptionMapper; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.security.UnauthorizedException; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class CustomExceptionMapperTest { | ||
|
||
@RegisterExtension | ||
static QuarkusUnitTest runner = new QuarkusUnitTest() | ||
.withApplicationRoot((jar) -> jar | ||
.addClasses(HelloResource.class, CustomExceptionMappers.class)); | ||
|
||
@Test | ||
public void shouldDenyUnannotated() { | ||
when().get("hello") | ||
.then() | ||
.statusCode(999); | ||
} | ||
|
||
@Path("hello") | ||
@RolesAllowed("test") | ||
public static final class HelloResource { | ||
|
||
@GET | ||
public String hello() { | ||
return "hello world"; | ||
} | ||
} | ||
|
||
public static final class CustomExceptionMappers { | ||
|
||
@ServerExceptionMapper(UnauthorizedException.class) | ||
public Response forbidden() { | ||
return Response.status(999).build(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters