Skip to content

Commit

Permalink
Implement test for OIDC filtered client
Browse files Browse the repository at this point in the history
  • Loading branch information
mocenas committed Nov 9, 2023
1 parent 69d46ff commit 5aa6b86
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 0 deletions.
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;
}
}
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();
}
}
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();
}
}
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();
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ quarkus.oidc-client.test-user.grant.type=password
quarkus.oidc-client.test-user.grant-options.password.username=test-user
quarkus.oidc-client.test-user.grant-options.password.password=test-user


## Exchange token client
quarkus.oidc-client.exchange-token.auth-server-url=${quarkus.oidc.auth-server-url}
quarkus.oidc-client.exchange-token.client-id=test-application-client
quarkus.oidc-client.exchange-token.credentials.secret=test-application-client-secret
quarkus.oidc-client.exchange-token.grant.type=exchange

# RestClient
io.quarkus.ts.security.keycloak.oidcclient.extended.restclient.ping.clients.PongClient/mp-rest/url=http://localhost:${quarkus.http.port}
io.quarkus.ts.security.keycloak.oidcclient.extended.restclient.ping.clients.PongClient/mp-rest/scope=jakarta.inject.Singleton
Expand All @@ -38,5 +45,7 @@ io.quarkus.ts.security.keycloak.oidcclient.extended.restclient.ping.clients.Auto

io.quarkus.ts.security.keycloak.oidcclient.extended.restclient.ping.clients.TokenPropagationPongClient/mp-rest/url=http://localhost:${quarkus.http.port}

io.quarkus.ts.security.keycloak.oidcclient.extended.restclient.principal.clients.TokenPropagationFilteredClient/mp-rest/url=http://localhost:${quarkus.http.port}

#OpenAPI
quarkus.smallrye-openapi.store-schema-directory=target/generated/jakarta-rest/
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));
}
}

0 comments on commit 5aa6b86

Please sign in to comment.