[KEYCLOAK-17442] - Upgrade to Quarkus 1.12.2

This commit is contained in:
Pedro Igor 2021-03-17 10:45:04 -03:00
parent cd44b99eb9
commit cbb118c013
7 changed files with 128 additions and 13 deletions

View file

@ -17,6 +17,7 @@
package org.keycloak.quarkus.deployment;
import static java.util.Collections.emptyList;
import static org.keycloak.configuration.Configuration.getPropertyNames;
import static org.keycloak.configuration.Configuration.getRawValue;
import static org.keycloak.representations.provider.ScriptProviderDescriptor.AUTHENTICATORS;
@ -147,7 +148,7 @@ class KeycloakProcessor {
@Record(ExecutionTime.STATIC_INIT)
@BuildStep
void configureHibernate(KeycloakRecorder recorder, HibernateOrmConfig config, List<PersistenceUnitDescriptorBuildItem> descriptors) {
PersistenceUnitDescriptor unit = descriptors.get(0).asOutputPersistenceUnitDefinition().getActualHibernateDescriptor();
PersistenceUnitDescriptor unit = descriptors.get(0).asOutputPersistenceUnitDefinition(emptyList()).getActualHibernateDescriptor();
unit.getProperties().setProperty(AvailableSettings.DIALECT, config.defaultPersistenceUnit.dialect.dialect.orElse(null));
unit.getProperties().setProperty(AvailableSettings.JPA_TRANSACTION_TYPE, PersistenceUnitTransactionType.JTA.name());

View file

@ -31,13 +31,13 @@
<packaging>pom</packaging>
<properties>
<quarkus.version>1.10.0.CR1</quarkus.version>
<resteasy.version>4.5.8.Final</resteasy.version>
<jackson.version>2.11.3</jackson.version>
<quarkus.version>1.12.2.Final</quarkus.version>
<resteasy.version>4.5.9.Final</resteasy.version>
<jackson.version>2.12.1</jackson.version>
<jackson.databind.version>${jackson.version}</jackson.databind.version>
<hibernate.version>5.4.23.Final</hibernate.version>
<mysql-connector-java.version>8.0.22</mysql-connector-java.version>
<picocli.version>4.5.2</picocli.version>
<hibernate.version>5.4.28.Final</hibernate.version>
<mysql-connector-java.version>8.0.23</mysql-connector-java.version>
<picocli.version>4.6.1</picocli.version>
<snakeyaml.version>1.27</snakeyaml.version>
<surefire-plugin.version>3.0.0-M5</surefire-plugin.version>
<wildfly.common.format.version>1.5.4.Final-format-001</wildfly.common.format.version>

View file

@ -0,0 +1,47 @@
/*
*
* * Copyright 2021 Red Hat, Inc. and/or its affiliates
* * and other contributors as indicated by the @author tags.
* *
* * Licensed under the Apache License, Version 2.0 (the "License");
* * you may not use this file except in compliance with the License.
* * You may obtain a copy of the License at
* *
* * http://www.apache.org/licenses/LICENSE-2.0
* *
* * Unless required by applicable law or agreed to in writing, software
* * distributed under the License is distributed on an "AS IS" BASIS,
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* * See the License for the specific language governing permissions and
* * limitations under the License.
*
*/
package org.keycloak.provider.quarkus;
import javax.ws.rs.ext.Provider;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
import org.jboss.resteasy.spi.ContextInjector;
import org.keycloak.common.ClientConnection;
import org.keycloak.common.util.Resteasy;
/**
* <p>This {@link ContextInjector} allows injecting {@link ClientConnection} to JAX-RS resources.
*
* <p>Due to the latest changes in Quarkus, the context map is cleared prior to dispatching to JAX-RS resources, so we need
* to delegate to the {@link ResteasyVertxProvider} provider the lookup of Keycloak contextual objects.
*
* @see QuarkusRequestFilter
* @see ResteasyVertxProvider
*
* @author <a href="mailto:psilva@redhat.com">Pedro Igor</a>
*/
@Provider
public class ClientConnectionContextInjector implements ContextInjector<ClientConnection, ClientConnection> {
@Override
public ClientConnection resolve(Class rawType, Type genericType, Annotation[] annotations) {
return Resteasy.getContextData(ClientConnection.class);
}
}

View file

@ -0,0 +1,47 @@
/*
*
* * Copyright 2021 Red Hat, Inc. and/or its affiliates
* * and other contributors as indicated by the @author tags.
* *
* * Licensed under the Apache License, Version 2.0 (the "License");
* * you may not use this file except in compliance with the License.
* * You may obtain a copy of the License at
* *
* * http://www.apache.org/licenses/LICENSE-2.0
* *
* * Unless required by applicable law or agreed to in writing, software
* * distributed under the License is distributed on an "AS IS" BASIS,
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* * See the License for the specific language governing permissions and
* * limitations under the License.
*
*/
package org.keycloak.provider.quarkus;
import javax.ws.rs.ext.Provider;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
import org.jboss.resteasy.spi.ContextInjector;
import org.keycloak.common.util.Resteasy;
import org.keycloak.models.KeycloakSession;
/**
* <p>This {@link ContextInjector} allows injecting {@link KeycloakSession} to JAX-RS resources.
*
* <p>Due to the latest changes in Quarkus, the context map is cleared prior to dispatching to JAX-RS resources, so we need
* to delegate to the {@link ResteasyVertxProvider} provider the lookup of Keycloak contextual objects.
*
* @see QuarkusRequestFilter
* @see ResteasyVertxProvider
*
* @author <a href="mailto:psilva@redhat.com">Pedro Igor</a>
*/
@Provider
public class KeycloakContextInjector implements ContextInjector<KeycloakSession, KeycloakSession> {
@Override
public KeycloakSession resolve(Class rawType, Type genericType, Annotation[] annotations) {
return Resteasy.getContextData(KeycloakSession.class);
}
}

View file

@ -17,9 +17,8 @@
package org.keycloak.provider.quarkus;
import java.util.function.Predicate;
import org.keycloak.common.ClientConnection;
import org.keycloak.models.KeycloakSession;
import org.keycloak.services.filters.AbstractRequestFilter;
import io.vertx.core.AsyncResult;
@ -45,8 +44,12 @@ public class QuarkusRequestFilter extends AbstractRequestFilter implements Handl
// our code should always be run as blocking until we don't provide a better support for running non-blocking code
// in the event loop
context.vertx().executeBlocking(promise -> {
filter(createClientConnection(context.request()), (session) -> {
ClientConnection connection = createClientConnection(context.request());
filter(connection, (session) -> {
try {
configureContextualData(context, connection, session);
// we need to close the session before response is sent to the client, otherwise subsequent requests could
// not get the latest state because the session from the previous request is still being closed
// other methods from Vert.x to add a handler to the response works asynchronously
@ -62,6 +65,13 @@ public class QuarkusRequestFilter extends AbstractRequestFilter implements Handl
}, false, EMPTY_RESULT);
}
private void configureContextualData(RoutingContext context, ClientConnection connection, KeycloakSession session) {
// quarkus-resteasy changed and clears the context map before dispatching
// need to push keycloak contextual objects into the routing context for retrieving it later
context.data().put(KeycloakSession.class.getName(), session);
context.data().put(ClientConnection.class.getName(), connection);
}
@Override
protected boolean isAutoClose() {
return false;

View file

@ -17,14 +17,24 @@
package org.keycloak.provider.quarkus;
import io.vertx.ext.web.RoutingContext;
import org.jboss.resteasy.core.ResteasyContext;
import org.keycloak.common.util.ResteasyProvider;
public class Resteasy4Provider implements ResteasyProvider {
/**
* TODO: we should probably rely on the vert.x routing context instead of resteasy context data
*/
public class ResteasyVertxProvider implements ResteasyProvider {
@Override
public <R> R getContextData(Class<R> type) {
return ResteasyContext.getContextData(type);
R data = ResteasyContext.getContextData(type);
if (data == null) {
return (R) ResteasyContext.getContextData(RoutingContext.class).data().get(type.getName());
}
return data;
}
@Override

View file

@ -1 +1 @@
org.keycloak.provider.quarkus.Resteasy4Provider
org.keycloak.provider.quarkus.ResteasyVertxProvider