Skip to content

Commit

Permalink
temporary fix for Class does not exist in ClassLoader error
Browse files Browse the repository at this point in the history
  • Loading branch information
rmanibus committed Sep 14, 2024
1 parent 56acf4b commit 334c66f
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,16 @@ FeatureBuildItem feature() {
@BuildStep
void additionalBean(
Capabilities capabilities,
BuildProducer<AdditionalBeanBuildItem> additionalBeanBuildItem) {
BuildProducer<AdditionalBeanBuildItem> producer) {

if (capabilities.isPresent(Capability.REST_CLIENT_REACTIVE)) {
additionalBeanBuildItem.produce(
producer.produce(
AdditionalBeanBuildItem.builder().addBeanClass(ReactiveOidcClientRequestFilterDelegate.class)
.setDefaultScope(DotName.createSimple(Dependent.class))
.setUnremovable()
.build());
} else {
additionalBeanBuildItem.produce(
producer.produce(
AdditionalBeanBuildItem.builder().addBeanClass(ClassicOidcClientRequestFilterDelegate.class)
.setDefaultScope(DotName.createSimple(Dependent.class))
.setUnremovable()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,28 @@
package io.quarkiverse.openapi.generator;

import java.io.IOException;

import jakarta.annotation.Priority;
import jakarta.enterprise.inject.spi.InjectionPoint;
import jakarta.ws.rs.Priorities;
import jakarta.ws.rs.client.ClientRequestContext;
import jakarta.ws.rs.client.ClientRequestFilter;

import org.jboss.logging.Logger;

import io.quarkiverse.openapi.generator.providers.OAuth2AuthenticationProvider;
import io.quarkus.oidc.client.filter.runtime.AbstractOidcClientRequestFilter;
import io.quarkus.oidc.client.runtime.AbstractTokensProducer;
import io.quarkus.oidc.client.runtime.DisabledOidcClientException;

@Priority(Priorities.AUTHENTICATION)
@OidcClient
public class ClassicOidcClientRequestFilterDelegate extends AbstractOidcClientRequestFilter
implements OAuth2AuthenticationProvider.OidcClientRequestFilterDelegate {
public class ClassicOidcClientRequestFilterDelegate extends AbstractTokensProducer
implements ClientRequestFilter, OAuth2AuthenticationProvider.OidcClientRequestFilterDelegate {

private static final Logger LOG = Logger
.getLogger(io.quarkus.oidc.client.filter.runtime.AbstractOidcClientRequestFilter.class);
private static final String BEARER_SCHEME_WITH_SPACE = "Bearer ";

ClassicOidcClientRequestFilterDelegate(InjectionPoint injectionPoint) {
OidcClient annotation = (OidcClient) injectionPoint.getQualifiers().stream()
Expand All @@ -27,4 +39,20 @@ protected java.util.Optional<String> clientId() {
return java.util.Optional.of(clientId);
}

public void filter(ClientRequestContext requestContext) throws IOException {

Check notice

Code scanning / CodeQL

Missing Override annotation Note

This method overrides
OidcClientRequestFilterDelegate.filter
; it is advisable to add an Override annotation.
This method overrides
ClientRequestFilter.filter
; it is advisable to add an Override annotation.
try {
String accessToken = this.getAccessToken();
requestContext.getHeaders().add("Authorization", "Bearer " + accessToken);
} catch (DisabledOidcClientException var3) {
LOG.debug("Client is disabled, acquiring and propagating the token is not necessary");
} catch (Exception var4) {
Exception ex = var4;
LOG.debugf("Access token is not available, cause: %s, aborting the request", ex.getMessage());
throw ex instanceof RuntimeException ? (RuntimeException) ex : new RuntimeException(ex);
}
}

private String getAccessToken() {
return this.awaitTokens().getAccessToken();
}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,31 @@
package io.quarkiverse.openapi.generator;

import java.util.function.Consumer;

import jakarta.annotation.Priority;
import jakarta.enterprise.inject.spi.InjectionPoint;
import jakarta.ws.rs.Priorities;
import jakarta.ws.rs.client.ClientRequestContext;
import jakarta.ws.rs.core.HttpHeaders;

import org.jboss.logging.Logger;
import org.jboss.resteasy.reactive.client.spi.ResteasyReactiveClientRequestContext;
import org.jboss.resteasy.reactive.client.spi.ResteasyReactiveClientRequestFilter;

import io.quarkiverse.openapi.generator.providers.OAuth2AuthenticationProvider;
import io.quarkus.oidc.client.reactive.filter.runtime.AbstractOidcClientRequestReactiveFilter;
import io.quarkus.oidc.client.Tokens;
import io.quarkus.oidc.client.runtime.AbstractTokensProducer;
import io.quarkus.oidc.client.runtime.DisabledOidcClientException;
import io.quarkus.oidc.common.runtime.OidcConstants;

@Priority(Priorities.AUTHENTICATION)
@OidcClient
public class ReactiveOidcClientRequestFilterDelegate extends AbstractOidcClientRequestReactiveFilter
implements OAuth2AuthenticationProvider.OidcClientRequestFilterDelegate {
public class ReactiveOidcClientRequestFilterDelegate extends AbstractTokensProducer
implements ResteasyReactiveClientRequestFilter, OAuth2AuthenticationProvider.OidcClientRequestFilterDelegate {

private static final Logger LOG = Logger
.getLogger(ReactiveOidcClientRequestFilterDelegate.class);
private static final String BEARER_SCHEME_WITH_SPACE = OidcConstants.BEARER_SCHEME + " ";

ReactiveOidcClientRequestFilterDelegate(InjectionPoint injectionPoint) {
OidcClient annotation = (OidcClient) injectionPoint.getQualifiers().stream()
Expand All @@ -29,8 +41,39 @@ protected java.util.Optional<String> clientId() {
return java.util.Optional.of(clientId);
}

protected void initTokens() {

Check notice

Code scanning / CodeQL

Missing Override annotation Note

This method overrides
AbstractTokensProducer.initTokens
; it is advisable to add an Override annotation.
if (earlyTokenAcquisition) {
LOG.debug("Token acquisition will be delayed until this filter is executed to avoid blocking an IO thread");
}
}

@Override
public void filter(ClientRequestContext requestContext) throws java.io.IOException {

Check notice

Code scanning / CodeQL

Confusing overloading of methods Note

Method ReactiveOidcClientRequestFilterDelegate.filter(..) could be confused with overloaded method
filter
, since dispatch depends on static types.
super.filter((ResteasyReactiveClientRequestContext) requestContext);
filter((ResteasyReactiveClientRequestContext) requestContext);
}

@Override
public void filter(ResteasyReactiveClientRequestContext requestContext) {
requestContext.suspend();

super.getTokens().subscribe().with(new Consumer<>() {
@Override
public void accept(Tokens tokens) {
requestContext.getHeaders().putSingle(HttpHeaders.AUTHORIZATION,
BEARER_SCHEME_WITH_SPACE + tokens.getAccessToken());
requestContext.resume();
}
}, new Consumer<>() {
@Override
public void accept(Throwable t) {
if (t instanceof DisabledOidcClientException) {
LOG.debug("Client is disabled, acquiring and propagating the token is not necessary");
requestContext.resume();
} else {
LOG.debugf("Access token is not available, cause: %s, aborting the request", t.getMessage());
requestContext.resume((t instanceof RuntimeException) ? t : new RuntimeException(t));
}
}
});
}
}

0 comments on commit 334c66f

Please sign in to comment.