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

Make OidcRequestContextProperties modifiable #44203

Merged
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 @@ -19,22 +19,57 @@ public OidcRequestContextProperties(Map<String, Object> properties) {
this.properties = properties;
}

/**
* Get property value
*
* @param name property name
* @return property value
*/
public <T> T get(String name) {
@SuppressWarnings("unchecked")
T value = (T) properties.get(name);
return value;
}

/**
* Get property value as String
*
* @param name property name
* @return property value as String
*/
public String getString(String name) {
return (String) get(name);
}

/**
* Get typed property value
*
* @param name property name
* @param type property type
* @return typed property value
*/
public <T> T get(String name, Class<T> type) {
return type.cast(get(name));
}

/**
* Get an unmodifiable view of the current context properties.
*
* @return all properties
*/
public Map<String, Object> getAll() {
return Collections.unmodifiableMap(properties);
}

/**
* Set the property
*
* @param name property name
* @param value property value
* @return this OidcRequestContextProperties instance
*/
public OidcRequestContextProperties put(String name, Object value) {
properties.put(name, value);
return this;
}
}
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);
}
}

}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,8 @@ quarkus.log.category."io.quarkus.oidc.runtime.OidcProviderClient".min-level=TRAC
quarkus.log.category."io.quarkus.oidc.runtime.OidcProviderClient".level=TRACE
quarkus.log.category."io.quarkus.it.keycloak.SignedUserInfoResponseFilter".min-level=TRACE
quarkus.log.category."io.quarkus.it.keycloak.SignedUserInfoResponseFilter".level=TRACE
quarkus.log.category."io.quarkus.it.keycloak.TokenResponseFilter".min-level=TRACE
quarkus.log.category."io.quarkus.it.keycloak.TokenResponseFilter".level=TRACE
quarkus.log.category."io.quarkus.it.keycloak.TokenRequestResponseFilter".min-level=TRACE
quarkus.log.category."io.quarkus.it.keycloak.TokenRequestResponseFilter".level=TRACE
quarkus.log.file.enable=true
quarkus.log.file.format=%C - %s%n

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ public void run() throws Throwable {
} else if (line.contains("Response contains signed UserInfo")) {
signedUserInfoResponseFilterMessageDetected = true;
} else if (line.contains(
"Authorization code completed for tenant 'code-flow-user-info-github-cached-in-idtoken'")) {
"Authorization code completed for tenant 'code-flow-user-info-github-cached-in-idtoken' in an instant: true")) {
codeFlowCompletedResponseFilterMessageDetected = true;
}
if (lineConfirmingVerificationDetected
Expand Down