-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
RestEasy Reactive: Keep target when handling failed authorization check
So that exception mappers can access the target-specific `ResourceInfo` properties, the handling of the exceptions during the authorization checks must keep the target when switching to the abort chain. (cherry picked from commit 67ba7f4)
- Loading branch information
1 parent
3f61ae9
commit 158dda7
Showing
3 changed files
with
60 additions
and
10 deletions.
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
57
...sy/reactive/server/test/customexceptions/SecurityExceptionMapperWithResourceInfoTest.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,57 @@ | ||
package io.quarkus.resteasy.reactive.server.test.customexceptions; | ||
|
||
import static org.hamcrest.Matchers.is; | ||
|
||
import java.util.function.Supplier; | ||
|
||
import javax.annotation.security.DenyAll; | ||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.Produces; | ||
import javax.ws.rs.container.ResourceInfo; | ||
import javax.ws.rs.core.Response; | ||
|
||
import org.jboss.resteasy.reactive.server.ServerExceptionMapper; | ||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.test.QuarkusUnitTest; | ||
import io.restassured.RestAssured; | ||
|
||
public class SecurityExceptionMapperWithResourceInfoTest { | ||
|
||
@RegisterExtension | ||
static QuarkusUnitTest test = new QuarkusUnitTest() | ||
.setArchiveProducer(new Supplier<>() { | ||
@Override | ||
public JavaArchive get() { | ||
return ShrinkWrap.create(JavaArchive.class) | ||
.addClasses(Resource.class); | ||
} | ||
}); | ||
|
||
@Test | ||
void test() { | ||
RestAssured.get("/test/denied") | ||
.then().statusCode(403).body(is(Resource.class.getName())); | ||
} | ||
|
||
@Path("test") | ||
public static class Resource { | ||
@GET | ||
@Path("denied") | ||
@Produces("text/plain") | ||
@DenyAll | ||
public String denied() { | ||
return "denied"; | ||
} | ||
|
||
@ServerExceptionMapper(SecurityException.class) | ||
Response handle(SecurityException t, ResourceInfo resourceInfo) { | ||
return Response.status(403).entity(resourceInfo.getResourceClass().getName()).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