-
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.
Make OidcRequestContextProperties modifiable
- Loading branch information
1 parent
e65d667
commit b666094
Showing
5 changed files
with
85 additions
and
34 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
49 changes: 49 additions & 0 deletions
49
...-tests/oidc-wiremock/src/main/java/io/quarkus/it/keycloak/TokenRequestResponseFilter.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,49 @@ | ||
package io.quarkus.it.keycloak; | ||
|
||
import java.time.Instant; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
|
||
import jakarta.enterprise.context.ApplicationScoped; | ||
|
||
import org.jboss.logging.Logger; | ||
|
||
import io.quarkus.arc.Unremovable; | ||
import io.quarkus.oidc.common.OidcEndpoint; | ||
import io.quarkus.oidc.common.OidcEndpoint.Type; | ||
import io.quarkus.oidc.common.OidcRequestFilter; | ||
import io.quarkus.oidc.common.OidcResponseFilter; | ||
import io.quarkus.oidc.common.runtime.OidcConstants; | ||
import io.quarkus.oidc.runtime.OidcUtils; | ||
|
||
@ApplicationScoped | ||
@Unremovable | ||
@OidcEndpoint(value = Type.TOKEN) | ||
public class TokenRequestResponseFilter implements OidcRequestFilter, OidcResponseFilter { | ||
private static final Logger LOG = Logger.getLogger(TokenRequestResponseFilter.class); | ||
|
||
private ConcurrentHashMap<String, Instant> instants = new ConcurrentHashMap<>(); | ||
|
||
@Override | ||
public void filter(OidcRequestContext rc) { | ||
final Instant now = Instant.now(); | ||
instants.put(rc.contextProperties().get(OidcUtils.TENANT_ID_ATTRIBUTE), now); | ||
rc.contextProperties().put("instant", now); | ||
} | ||
|
||
@Override | ||
public void filter(OidcResponseContext rc) { | ||
Instant instant1 = instants.remove(rc.requestProperties().get(OidcUtils.TENANT_ID_ATTRIBUTE)); | ||
Instant instant2 = rc.requestProperties().get("instant"); | ||
boolean instantsAreTheSame = instant1 == instant2; | ||
if (rc.statusCode() == 200 | ||
&& instantsAreTheSame | ||
&& rc.responseHeaders().get("Content-Type").equals("application/json") | ||
&& OidcConstants.AUTHORIZATION_CODE.equals(rc.requestProperties().get(OidcConstants.GRANT_TYPE)) | ||
&& "code-flow-user-info-github-cached-in-idtoken" | ||
.equals(rc.requestProperties().get(OidcUtils.TENANT_ID_ATTRIBUTE))) { | ||
LOG.debug("Authorization code completed for tenant 'code-flow-user-info-github-cached-in-idtoken' in an instant: " | ||
+ instantsAreTheSame); | ||
} | ||
} | ||
|
||
} |
31 changes: 0 additions & 31 deletions
31
...gration-tests/oidc-wiremock/src/main/java/io/quarkus/it/keycloak/TokenResponseFilter.java
This file was deleted.
Oops, something went wrong.
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