-
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.
Merge pull request #26529 from michalvavrik/feature/fix-nonblocking-s…
…ync-when-proactive-disabled Resolve Sec. Identity in Reactive routes when Proactive Auth disabled
- Loading branch information
Showing
6 changed files
with
186 additions
and
7 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
100 changes: 100 additions & 0 deletions
100
...ions/reactive-routes/deployment/src/test/java/io/quarkus/vertx/web/LazyAuthRouteTest.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,100 @@ | ||
package io.quarkus.vertx.web; | ||
|
||
import static io.restassured.RestAssured.given; | ||
import static org.hamcrest.Matchers.is; | ||
|
||
import javax.annotation.security.DenyAll; | ||
import javax.annotation.security.RolesAllowed; | ||
import javax.inject.Inject; | ||
|
||
import org.jboss.shrinkwrap.api.asset.StringAsset; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.security.Authenticated; | ||
import io.quarkus.security.runtime.SecurityIdentityAssociation; | ||
import io.quarkus.security.test.utils.TestIdentityController; | ||
import io.quarkus.security.test.utils.TestIdentityProvider; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
import io.vertx.ext.web.RoutingContext; | ||
|
||
public class LazyAuthRouteTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.withApplicationRoot((jar) -> jar | ||
.addAsResource(new StringAsset("quarkus.http.auth.proactive=false\n"), "application.properties") | ||
.addClasses(TestIdentityProvider.class, TestIdentityController.class, HelloWorldBean.class)); | ||
|
||
@BeforeAll | ||
public static void setupUsers() { | ||
TestIdentityController.resetRoles() | ||
.add("admin", "admin", "admin") | ||
.add("user", "user", "user"); | ||
} | ||
|
||
@Test | ||
public void testAuthZInPlace() { | ||
given().auth().basic("user", "user").when().get("/hello-ra").then().statusCode(403); | ||
} | ||
|
||
@Test | ||
public void testRolesAllowedVoidMethod() { | ||
given().auth().basic("admin", "admin").when().get("/hello-ra").then().statusCode(200).body(is("Hello admin")); | ||
} | ||
|
||
@Test | ||
public void testRolesAllowedDirectResponse() { | ||
given().auth().basic("admin", "admin").when().get("/hello-ra-direct").then().statusCode(200).body(is("Hello admin")); | ||
} | ||
|
||
@Test | ||
public void testAuthenticated() { | ||
given().auth().basic("user", "user").when().get("/hello-auth").then().statusCode(200); | ||
} | ||
|
||
@Test | ||
public void testDenyAll() { | ||
given().auth().basic("user", "user").when().get("/hello-deny").then().statusCode(403); | ||
} | ||
|
||
public static final class HelloWorldBean { | ||
|
||
@Inject | ||
SecurityIdentityAssociation securityIdentityAssociation; | ||
|
||
@Authenticated | ||
@Route(path = "/hello-auth", methods = Route.HttpMethod.GET) | ||
public void greetingsAuth(RoutingContext rc) { | ||
respond(rc); | ||
} | ||
|
||
@RolesAllowed("admin") | ||
@Route(path = "/hello-ra", methods = Route.HttpMethod.GET) | ||
public void greetingsRA(RoutingContext rc) { | ||
respond(rc); | ||
} | ||
|
||
@RolesAllowed("admin") | ||
@Route(path = "/hello-ra-direct", methods = Route.HttpMethod.GET) | ||
public String greetingsRADirect() { | ||
return hello(); | ||
} | ||
|
||
@DenyAll | ||
@Route(path = "/hello-deny", methods = Route.HttpMethod.GET) | ||
public String greetingsDeny() { | ||
return hello(); | ||
} | ||
|
||
private void respond(RoutingContext rc) { | ||
rc.response().end(hello()); | ||
} | ||
|
||
private String hello() { | ||
return "Hello " + securityIdentityAssociation.getIdentity().getPrincipal().getName(); | ||
} | ||
} | ||
|
||
} |
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