-
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.
Support path-based auth with @testsecurity annotation
- Loading branch information
1 parent
b77999a
commit fcdebde
Showing
10 changed files
with
281 additions
and
9 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
39 changes: 39 additions & 0 deletions
39
...ion-tests/oidc-tenancy/src/main/java/io/quarkus/it/keycloak/MultipleAuthMechResource.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,39 @@ | ||
package io.quarkus.it.keycloak; | ||
|
||
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.oidc.BearerTokenAuthentication; | ||
import io.quarkus.vertx.http.runtime.security.annotation.BasicAuthentication; | ||
|
||
@Path("multiple-auth-mech") | ||
public class MultipleAuthMechResource { | ||
|
||
@GET | ||
@Path("bearer/policy") | ||
public String bearerPolicy(@Context SecurityContext sec) { | ||
return sec.getUserPrincipal().getName(); | ||
} | ||
|
||
@GET | ||
@Path("basic/policy") | ||
public String basicPolicy(@Context SecurityContext sec) { | ||
return sec.getUserPrincipal().getName(); | ||
} | ||
|
||
@BearerTokenAuthentication | ||
@GET | ||
@Path("bearer/annotation") | ||
public String bearerAnnotation(@Context SecurityContext sec) { | ||
return sec.getUserPrincipal().getName(); | ||
} | ||
|
||
@BasicAuthentication | ||
@GET | ||
@Path("basic/annotation") | ||
public String basicAnnotation(@Context SecurityContext sec) { | ||
return sec.getUserPrincipal().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
105 changes: 105 additions & 0 deletions
105
.../oidc-tenancy/src/test/java/io/quarkus/it/keycloak/TestSecurityCombiningAuthMechTest.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,105 @@ | ||
package io.quarkus.it.keycloak; | ||
|
||
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; | ||
import io.restassured.http.ContentType; | ||
|
||
@TestHTTPEndpoint(MultipleAuthMechResource.class) | ||
@QuarkusTest | ||
public class TestSecurityCombiningAuthMechTest { | ||
|
||
@TestSecurity(user = "testUser", authMechanism = "basic") | ||
@Test | ||
public void testBasicAuthentication() { | ||
RestAssured | ||
.given() | ||
.contentType(ContentType.TEXT) | ||
.get("basic/policy") | ||
.then() | ||
.statusCode(200); | ||
RestAssured | ||
.given() | ||
.contentType(ContentType.TEXT) | ||
.redirects().follow(false) | ||
.get("bearer/policy") | ||
.then() | ||
.statusCode(401); | ||
RestAssured | ||
.given() | ||
.contentType(ContentType.TEXT) | ||
.get("basic/annotation") | ||
.then() | ||
.statusCode(200); | ||
RestAssured | ||
.given() | ||
.contentType(ContentType.TEXT) | ||
.redirects().follow(false) | ||
.get("bearer/annotation") | ||
.then() | ||
.statusCode(401); | ||
} | ||
|
||
@TestSecurity(user = "testUser", authMechanism = "Bearer") | ||
@Test | ||
public void testBearerBasedAuthentication() { | ||
RestAssured | ||
.given() | ||
.contentType(ContentType.TEXT) | ||
.get("basic/policy") | ||
.then() | ||
.statusCode(401); | ||
RestAssured | ||
.given() | ||
.contentType(ContentType.TEXT) | ||
.get("bearer/policy") | ||
.then() | ||
.statusCode(200); | ||
RestAssured | ||
.given() | ||
.contentType(ContentType.TEXT) | ||
.get("basic/annotation") | ||
.then() | ||
.statusCode(401); | ||
RestAssured | ||
.given() | ||
.contentType(ContentType.TEXT) | ||
.get("bearer/annotation") | ||
.then() | ||
.statusCode(200); | ||
} | ||
|
||
@TestSecurity(user = "testUser", authMechanism = "custom") | ||
@Test | ||
public void testCustomAuthentication() { | ||
RestAssured | ||
.given() | ||
.contentType(ContentType.TEXT) | ||
.get("basic/policy") | ||
.then() | ||
.statusCode(401); | ||
RestAssured | ||
.given() | ||
.contentType(ContentType.TEXT) | ||
.redirects().follow(false) | ||
.get("bearer/policy") | ||
.then() | ||
.statusCode(401); | ||
RestAssured | ||
.given() | ||
.contentType(ContentType.TEXT) | ||
.get("basic/annotation") | ||
.then() | ||
.statusCode(401); | ||
RestAssured | ||
.given() | ||
.contentType(ContentType.TEXT) | ||
.redirects().follow(false) | ||
.get("bearer/annotation") | ||
.then() | ||
.statusCode(401); | ||
} | ||
} |
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