-
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.
Add RestEasy Reactive and OidcSecurity test
- Loading branch information
1 parent
836376c
commit 6ddf2d2
Showing
4 changed files
with
145 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
52 changes: 52 additions & 0 deletions
52
...token-propagation-reactive/src/main/java/io/quarkus/it/keycloak/ProtectedJwtResource.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,52 @@ | ||
package io.quarkus.it.keycloak; | ||
|
||
import javax.annotation.security.RolesAllowed; | ||
import javax.inject.Inject; | ||
import javax.ws.rs.Consumes; | ||
import javax.ws.rs.GET; | ||
import javax.ws.rs.POST; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.core.Context; | ||
import javax.ws.rs.core.SecurityContext; | ||
|
||
import org.eclipse.microprofile.jwt.JsonWebToken; | ||
|
||
import io.quarkus.security.Authenticated; | ||
import io.quarkus.security.identity.SecurityIdentity; | ||
|
||
@Path("/web-app") | ||
@Authenticated | ||
public class ProtectedJwtResource { | ||
|
||
@Inject | ||
SecurityIdentity identity; | ||
|
||
@Inject | ||
JsonWebToken accessToken; | ||
|
||
@Context | ||
SecurityContext securityContext; | ||
|
||
@GET | ||
@Path("test-security") | ||
@RolesAllowed("viewer") | ||
public String testSecurity() { | ||
return securityContext.getUserPrincipal().getName(); | ||
} | ||
|
||
@POST | ||
@Path("test-security") | ||
@Consumes("application/json") | ||
@RolesAllowed("viewer") | ||
public String testSecurityJson(User user) { | ||
return user.getName() + ":" + securityContext.getUserPrincipal().getName(); | ||
} | ||
|
||
@GET | ||
@Path("test-security-jwt") | ||
@RolesAllowed("viewer") | ||
public String testSecurityJwt() { | ||
return accessToken.getName() + ":" + accessToken.getGroups().iterator().next() | ||
+ ":" + accessToken.getClaim("email"); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...tion-tests/oidc-token-propagation-reactive/src/main/java/io/quarkus/it/keycloak/User.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,15 @@ | ||
package io.quarkus.it.keycloak; | ||
|
||
public class User { | ||
|
||
private String name; | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
} |
56 changes: 56 additions & 0 deletions
56
...n-propagation-reactive/src/test/java/io/quarkus/it/keycloak/TestSecurityLazyAuthTest.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,56 @@ | ||
package io.quarkus.it.keycloak; | ||
|
||
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.quarkus.test.security.oidc.Claim; | ||
import io.quarkus.test.security.oidc.OidcSecurity; | ||
import io.restassured.RestAssured; | ||
import io.restassured.http.ContentType; | ||
|
||
@QuarkusTest | ||
@TestHTTPEndpoint(ProtectedJwtResource.class) | ||
public class TestSecurityLazyAuthTest { | ||
|
||
@Test | ||
@TestSecurity(user = "user1", roles = "viewer") | ||
public void testWithDummyUser() { | ||
RestAssured.when().get("test-security").then() | ||
.body(is("user1")); | ||
} | ||
|
||
@Test | ||
@TestSecurity(user = "user1", roles = "tester") | ||
public void testWithDummyUserForbidden() { | ||
RestAssured.when().get("test-security").then().statusCode(403); | ||
} | ||
|
||
@Test | ||
@TestSecurity(user = "user1", roles = "viewer") | ||
public void testPostWithDummyUser() { | ||
RestAssured.given().contentType(ContentType.JSON).when().body("{\"name\":\"user1\"}").post("test-security").then() | ||
.body(is("user1:user1")); | ||
} | ||
|
||
@Test | ||
@TestSecurity(user = "user1", roles = "tester") | ||
public void testPostWithDummyUserForbidden() { | ||
RestAssured.given().contentType(ContentType.JSON).when().body("{\"name\":\"user1\"}").post("test-security").then() | ||
.statusCode(403); | ||
} | ||
|
||
@Test | ||
@TestSecurity(user = "userJwt", roles = "viewer") | ||
@OidcSecurity(claims = { | ||
@Claim(key = "email", value = "[email protected]") | ||
}) | ||
public void testJwtGetWithDummyUser() { | ||
RestAssured.when().get("test-security-jwt").then() | ||
.body(is("userJwt:viewer:[email protected]")); | ||
} | ||
|
||
} |