Skip to content

Commit

Permalink
Fix a disabled OidcClient REST client issue
Browse files Browse the repository at this point in the history
  • Loading branch information
sberyozkin committed May 29, 2024
1 parent 7fb79c0 commit 02a1660
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -248,17 +248,17 @@ private static class DisabledOidcClient implements OidcClient {

@Override
public Uni<Tokens> getTokens(Map<String, String> additionalGrantParameters) {
throw new DisabledOidcClientException(message);
return Uni.createFrom().failure(new DisabledOidcClientException(message));
}

@Override
public Uni<Tokens> refreshTokens(String refreshToken, Map<String, String> additionalGrantParameters) {
throw new DisabledOidcClientException(message);
return Uni.createFrom().failure(new DisabledOidcClientException(message));
}

@Override
public Uni<Boolean> revokeAccessToken(String accessToken, Map<String, String> additionalParameters) {
throw new DisabledOidcClientException(message);
return Uni.createFrom().failure(new DisabledOidcClientException(message));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.WebApplicationException;

import org.eclipse.microprofile.rest.client.inject.RestClient;

Expand All @@ -25,6 +26,10 @@ public class FrontendResource {
@RestClient
ProtectedResourceServiceNamedFilter protectedResourceServiceNamedFilter;

@Inject
@RestClient
ProtectedResourceServiceDisabledClient protectedResourceServiceDisabledClient;

@Inject
@RestClient
MisconfiguredClientFilter misconfiguredClientFilter;
Expand All @@ -50,6 +55,14 @@ public Uni<String> userNameNamedFilter() {
return protectedResourceServiceNamedFilter.getUserName();
}

@GET
@Path("userNameDisabledClient")
@Produces("text/plain")
public Uni<String> userNameDisabledClient() {
return protectedResourceServiceDisabledClient.getUserName()
.onFailure(WebApplicationException.class).recoverWithItem(t -> t.getMessage());
}

@GET
@Path("userNameMisconfiguredClientFilter")
@Produces("text/plain")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package io.quarkus.it.keycloak;

import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;

import org.eclipse.microprofile.rest.client.inject.RegisterRestClient;

import io.quarkus.oidc.client.filter.OidcClientFilter;
import io.smallrye.mutiny.Uni;

@RegisterRestClient
@OidcClientFilter("disabled-client")
@Path("/")
public interface ProtectedResourceServiceDisabledClient {

@GET
@Produces("text/plain")
@Path("userNameReactive")
Uni<String> getUserName();
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ quarkus.oidc-client.grant.type=password
quarkus.oidc-client.grant-options.password.username=alice
quarkus.oidc-client.grant-options.password.password=alice

quarkus.oidc-client.disabled-client.auth-server-url=${quarkus.oidc.auth-server-url}
quarkus.oidc-client.disabled-client.client-id=${quarkus.oidc.client-id}
quarkus.oidc-client.disabled-client.client-enabled=false
quarkus.oidc-client.disabled-client.credentials.secret=${quarkus.oidc.credentials.secret}
quarkus.oidc-client.disabled-client.grant.type=password
quarkus.oidc-client.disabled-client.grant-options.password.username=alice
quarkus.oidc-client.disabled-client.grant-options.password.password=alice

quarkus.oidc-client.named-client.auth-server-url=${quarkus.oidc.auth-server-url}
quarkus.oidc-client.named-client.client-id=${quarkus.oidc.client-id}
quarkus.oidc-client.named-client.credentials.secret=${quarkus.oidc.credentials.secret}
Expand All @@ -27,6 +35,7 @@ quarkus.oidc-client.misconfigured-client.grant-options.password.password=bob
io.quarkus.it.keycloak.ProtectedResourceServiceCustomFilter/mp-rest/url=http://localhost:8081/protected
io.quarkus.it.keycloak.ProtectedResourceServiceReactiveFilter/mp-rest/url=http://localhost:8081/protected
io.quarkus.it.keycloak.ProtectedResourceServiceNamedFilter/mp-rest/url=http://localhost:8081/protected
io.quarkus.it.keycloak.ProtectedResourceServiceDisabledClient/mp-rest/url=http://localhost:8081/protected
io.quarkus.it.keycloak.MisconfiguredClientFilter/mp-rest/url=http://localhost:8081/protected

quarkus.log.category."io.quarkus.oidc.client.runtime.OidcClientImpl".min-level=TRACE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@ public void testGetUserNameNamedFilter() {
.body(equalTo("jdoe"));
}

@Test
public void testGetUserNameDisabledClient() {
RestAssured.given().header("Accept", "text/plain")
.when().get("/frontend/userNameDisabledClient")
.then()
.statusCode(200)
.body(containsString("Unauthorized, status code 401"));
}

@Test
public void testGetUserNameMisconfiguredClientFilter() {
RestAssured.given().header("Accept", "text/plain")
Expand Down

0 comments on commit 02a1660

Please sign in to comment.