-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update quarkus-oidc-token-propagation to better work with JWT tokens …
…and update smalrye-jwt to 2.4.4
- Loading branch information
1 parent
eb98535
commit e0af988
Showing
38 changed files
with
1,043 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
...ken-propagation/runtime/src/main/java/io/quarkus/oidc/token/propagation/JsonWebToken.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package io.quarkus.oidc.token.propagation; | ||
|
||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
@Target({ ElementType.TYPE }) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Documented | ||
public @interface JsonWebToken { | ||
} |
36 changes: 36 additions & 0 deletions
36
...on/runtime/src/main/java/io/quarkus/oidc/token/propagation/JsonWebTokenRequestFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package io.quarkus.oidc.token.propagation; | ||
|
||
import java.io.IOException; | ||
|
||
import javax.enterprise.inject.Instance; | ||
import javax.inject.Inject; | ||
import javax.ws.rs.client.ClientRequestContext; | ||
|
||
import org.eclipse.microprofile.config.inject.ConfigProperty; | ||
|
||
import io.quarkus.oidc.token.propagation.runtime.AbstractTokenRequestFilter; | ||
import io.smallrye.jwt.build.Jwt; | ||
|
||
public class JsonWebTokenRequestFilter extends AbstractTokenRequestFilter { | ||
@Inject | ||
Instance<org.eclipse.microprofile.jwt.JsonWebToken> jwtAccessToken; | ||
|
||
@Inject | ||
@ConfigProperty(name = "quarkus.oidc-token-propagation.secure-json-web-token") | ||
boolean resignToken; | ||
|
||
@Override | ||
public void filter(ClientRequestContext requestContext) throws IOException { | ||
if (verifyTokenInstance(requestContext, jwtAccessToken)) { | ||
propagateToken(requestContext, getToken()); | ||
} | ||
} | ||
|
||
private String getToken() { | ||
if (resignToken) { | ||
return Jwt.claims(jwtAccessToken.get()).sign(); | ||
} else { | ||
return jwtAccessToken.get().getRawToken(); | ||
} | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
...e/src/main/java/io/quarkus/oidc/token/propagation/runtime/AbstractTokenRequestFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package io.quarkus.oidc.token.propagation.runtime; | ||
|
||
import java.io.IOException; | ||
|
||
import javax.annotation.Priority; | ||
import javax.enterprise.inject.Instance; | ||
import javax.inject.Singleton; | ||
import javax.ws.rs.Priorities; | ||
import javax.ws.rs.client.ClientRequestContext; | ||
import javax.ws.rs.client.ClientRequestFilter; | ||
import javax.ws.rs.core.HttpHeaders; | ||
import javax.ws.rs.core.Response; | ||
import javax.ws.rs.ext.Provider; | ||
|
||
import org.jboss.logging.Logger; | ||
|
||
@Provider | ||
@Singleton | ||
@Priority(Priorities.AUTHENTICATION) | ||
public abstract class AbstractTokenRequestFilter implements ClientRequestFilter { | ||
private static final Logger LOG = Logger.getLogger(AbstractTokenRequestFilter.class); | ||
private static final String BEARER_SCHEME_WITH_SPACE = "Bearer "; | ||
|
||
public void propagateToken(ClientRequestContext requestContext, String token) throws IOException { | ||
if (token != null) { | ||
requestContext.getHeaders().add(HttpHeaders.AUTHORIZATION, BEARER_SCHEME_WITH_SPACE + token); | ||
} else { | ||
LOG.debugf("Injected access token is null, aborting the request with HTTP 401 error"); | ||
abortRequest(requestContext); | ||
} | ||
} | ||
|
||
protected boolean verifyTokenInstance(ClientRequestContext requestContext, Instance<?> instance) throws IOException { | ||
if (!instance.isResolvable()) { | ||
LOG.debugf("Access token is not injected, aborting the request with HTTP 401 error"); | ||
abortRequest(requestContext); | ||
return false; | ||
} | ||
if (instance.isAmbiguous()) { | ||
LOG.debugf("More than one access token instance is available, aborting the request with HTTP 401 error"); | ||
abortRequest(requestContext); | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
protected void abortRequest(ClientRequestContext requestContext) { | ||
requestContext.abortWith(Response.status(401).build()); | ||
} | ||
} |
Oops, something went wrong.