Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log in smallrye-jwt and oauth2 extensions when no bearer access token is available #44505

Merged
merged 1 commit into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

import jakarta.enterprise.context.ApplicationScoped;

import org.jboss.logging.Logger;

import io.netty.handler.codec.http.HttpHeaderNames;
import io.netty.handler.codec.http.HttpResponseStatus;
import io.quarkus.security.credential.TokenCredential;
Expand All @@ -23,7 +25,7 @@
*/
@ApplicationScoped
public class OAuth2AuthMechanism implements HttpAuthenticationMechanism {

private static final Logger LOG = Logger.getLogger(OAuth2AuthMechanism.class);
private static final String BEARER_PREFIX = "Bearer ";

protected static final ChallengeData CHALLENGE_DATA = new ChallengeData(
Expand All @@ -46,7 +48,9 @@ public Uni<SecurityIdentity> authenticate(RoutingContext context,
String authHeader = context.request().headers().get("Authorization");

if (authHeader == null || !authHeader.startsWith(BEARER_PREFIX)) {
// No suitable bearer token has been found in this request,
// No suitable bearer token has been found in this request
LOG.debug("Bearer access token is not available");

return Uni.createFrom().nullItem();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;

import org.jboss.logging.Logger;

import io.netty.handler.codec.http.HttpHeaderNames;
import io.netty.handler.codec.http.HttpResponseStatus;
import io.netty.handler.codec.http.cookie.ServerCookieDecoder;
Expand All @@ -34,6 +36,7 @@
*/
@ApplicationScoped
public class JWTAuthMechanism implements HttpAuthenticationMechanism {
private static final Logger LOG = Logger.getLogger(JWTAuthMechanism.class);
private static final String ERROR_MSG = "SmallRye JWT requires a safe (isolated) Vert.x sub-context for propagation "
+ "of the '" + TokenCredential.class.getName() + "', but the current context hasn't been flagged as such.";
protected static final String COOKIE_HEADER = "Cookie";
Expand Down Expand Up @@ -86,6 +89,8 @@ public void run() {
return identityProviderManager
.authenticate(HttpSecurityUtils.setRoutingContextAttribute(
new TokenAuthenticationRequest(new JsonWebTokenCredential(jwtToken)), context));
} else {
LOG.debug("Bearer access token is not available");
}
return Uni.createFrom().optional(Optional.empty());
}
Expand Down