forked from quarkus-qe/quarkus-test-suite
-
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.
Implement test for OIDC filtered client
Test for quarkusio/quarkus#36459 and quarkusio/quarkus#36501
- Loading branch information
Showing
6 changed files
with
110 additions
and
0 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
...curity/keycloak/oidcclient/extended/restclient/ping/filters/CustomTokenRequestFilter.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.ts.security.keycloak.oidcclient.extended.restclient.ping.filters; | ||
|
||
import io.quarkus.oidc.token.propagation.AccessTokenRequestFilter; | ||
|
||
public class CustomTokenRequestFilter extends AccessTokenRequestFilter { | ||
@Override | ||
protected String getClientName() { | ||
return "exchange-token"; | ||
} | ||
|
||
@Override | ||
protected boolean isExchangeToken() { | ||
return true; | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
.../ts/security/keycloak/oidcclient/extended/restclient/principal/FilteredTokenResource.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,22 @@ | ||
package io.quarkus.ts.security.keycloak.oidcclient.extended.restclient.principal; | ||
|
||
import jakarta.inject.Inject; | ||
import jakarta.ws.rs.GET; | ||
import jakarta.ws.rs.Path; | ||
|
||
import org.eclipse.microprofile.rest.client.inject.RestClient; | ||
|
||
import io.quarkus.ts.security.keycloak.oidcclient.extended.restclient.principal.clients.TokenPropagationFilteredClient; | ||
|
||
@Path("/token-propagation-filter") | ||
public class FilteredTokenResource { | ||
|
||
@Inject | ||
@RestClient | ||
TokenPropagationFilteredClient tokenPropagationFilterClient; | ||
|
||
@GET | ||
public String getUserName() { | ||
return tokenPropagationFilterClient.getUserName(); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
...rkus/ts/security/keycloak/oidcclient/extended/restclient/principal/PrincipalResource.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,22 @@ | ||
package io.quarkus.ts.security.keycloak.oidcclient.extended.restclient.principal; | ||
|
||
import java.security.Principal; | ||
|
||
import jakarta.inject.Inject; | ||
import jakarta.ws.rs.GET; | ||
import jakarta.ws.rs.Path; | ||
|
||
import io.quarkus.security.Authenticated; | ||
|
||
@Path("/principal") | ||
@Authenticated | ||
public class PrincipalResource { | ||
|
||
@Inject | ||
Principal principal; | ||
|
||
@GET | ||
public String principalName() { | ||
return principal.getName(); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...loak/oidcclient/extended/restclient/principal/clients/TokenPropagationFilteredClient.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,20 @@ | ||
package io.quarkus.ts.security.keycloak.oidcclient.extended.restclient.principal.clients; | ||
|
||
import jakarta.ws.rs.GET; | ||
import jakarta.ws.rs.Path; | ||
|
||
import org.eclipse.microprofile.rest.client.annotation.RegisterClientHeaders; | ||
import org.eclipse.microprofile.rest.client.annotation.RegisterProvider; | ||
import org.eclipse.microprofile.rest.client.inject.RegisterRestClient; | ||
|
||
import io.quarkus.ts.security.keycloak.oidcclient.extended.restclient.ping.filters.CustomTokenRequestFilter; | ||
|
||
@RegisterRestClient | ||
@RegisterClientHeaders | ||
@Path("/principal") | ||
@RegisterProvider(CustomTokenRequestFilter.class) | ||
public interface TokenPropagationFilteredClient { | ||
|
||
@GET | ||
String getUserName(); | ||
} |
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
22 changes: 22 additions & 0 deletions
22
...quarkus/ts/security/keycloak/oidcclient/extended/restclient/TokenPropagationFilterIT.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,22 @@ | ||
package io.quarkus.ts.security.keycloak.oidcclient.extended.restclient; | ||
|
||
import static io.restassured.RestAssured.given; | ||
import static org.hamcrest.CoreMatchers.containsString; | ||
|
||
import org.apache.http.HttpStatus; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import io.quarkus.test.scenarios.QuarkusScenario; | ||
|
||
@QuarkusScenario | ||
public class TokenPropagationFilterIT extends BaseOidcIT { | ||
|
||
@Test | ||
public void usernameTest() { | ||
given() | ||
.auth().oauth2(createToken()) | ||
.when().get("/token-propagation-filter") | ||
.then().statusCode(HttpStatus.SC_OK) | ||
.body(containsString(USER)); | ||
} | ||
} |