Skip to content

Commit

Permalink
Log in smallrye-jwt when no bearer access token is available
Browse files Browse the repository at this point in the history
  • Loading branch information
sberyozkin committed Nov 14, 2024
1 parent 6775bf1 commit 542da9d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
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

0 comments on commit 542da9d

Please sign in to comment.