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#40408 from manovotn/issue40307
Quarkus REST - reuse CDI request context if it exists
- Loading branch information
Showing
6 changed files
with
81 additions
and
4 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
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
29 changes: 29 additions & 0 deletions
29
...tion-tests/openapi/src/main/java/io/quarkus/it/openapi/security/TestSecurityResource.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,29 @@ | ||
package io.quarkus.it.openapi.security; | ||
|
||
import jakarta.annotation.security.RolesAllowed; | ||
import jakarta.ws.rs.GET; | ||
import jakarta.ws.rs.Path; | ||
import jakarta.ws.rs.core.Context; | ||
import jakarta.ws.rs.core.SecurityContext; | ||
|
||
import io.quarkus.vertx.web.RouteFilter; | ||
import io.vertx.ext.web.RoutingContext; | ||
|
||
@Path("/security") | ||
public class TestSecurityResource { | ||
|
||
@RolesAllowed("admin") | ||
@GET | ||
@Path("reactive-routes") | ||
public String reactiveRoutes(@Context SecurityContext securityContext) { | ||
return securityContext.getUserPrincipal().getName(); | ||
} | ||
|
||
@RouteFilter(401) | ||
public void doNothing(RoutingContext routingContext) { | ||
// here so that the Reactive Routes extension activates CDI request context | ||
routingContext.response().putHeader("reactive-routes-filter", "true"); | ||
routingContext.next(); | ||
} | ||
|
||
} |
26 changes: 26 additions & 0 deletions
26
.../openapi/src/test/java/io/quarkus/it/openapi/security/TestSecurityReactiveRoutesTest.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,26 @@ | ||
package io.quarkus.it.openapi.security; | ||
|
||
import static org.hamcrest.Matchers.is; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import io.quarkus.test.common.http.TestHTTPEndpoint; | ||
import io.quarkus.test.junit.QuarkusTest; | ||
import io.quarkus.test.security.TestSecurity; | ||
import io.restassured.RestAssured; | ||
|
||
@QuarkusTest | ||
@TestHTTPEndpoint(TestSecurityResource.class) | ||
public class TestSecurityReactiveRoutesTest { | ||
|
||
@TestSecurity(user = "Martin", roles = "admin") | ||
@Test | ||
public void testSecurityWithReactiveRoutesAndQuarkusRest() { | ||
RestAssured.get("reactive-routes") | ||
.then() | ||
.statusCode(200) | ||
.header("reactive-routes-filter", is("true")) | ||
.body(is("Martin")); | ||
} | ||
|
||
} |