forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Don't run CDI interceptors on class-level exception mappers
The previous behavior was pretty weird and prevented us from using @ServerExceptionMapper in classes that were annotated with security annnotations The longer discussion is at: https://quarkusio.zulipchat.com/#narrow/stream/187038-dev/topic/Bean.20scope.20is.20changed.20when.20adding.20a.20.40ServerExceptionMapper.20.3F/near/427889997 Co-authored-by: Ladislav Thon <ladicek@gmail.com>
- Loading branch information
Showing
3 changed files
with
87 additions
and
0 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
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
45 changes: 45 additions & 0 deletions
45
...o/quarkus/resteasy/reactive/server/test/security/CustomClassLevelExceptionMapperTest.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,45 @@ | ||
package io.quarkus.resteasy.reactive.server.test.security; | ||
|
||
import static io.restassured.RestAssured.when; | ||
|
||
import jakarta.annotation.security.RolesAllowed; | ||
import jakarta.ws.rs.GET; | ||
import jakarta.ws.rs.Path; | ||
import jakarta.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 CustomClassLevelExceptionMapperTest { | ||
|
||
@RegisterExtension | ||
static QuarkusUnitTest runner = new QuarkusUnitTest() | ||
.withApplicationRoot((jar) -> jar | ||
.addClasses(HelloResource.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"; | ||
} | ||
|
||
@ServerExceptionMapper(UnauthorizedException.class) | ||
public Response forbidden() { | ||
return Response.status(999).build(); | ||
} | ||
} | ||
} |