From d0ead0f0a026b2ab38e611d07d380bc114954b3b Mon Sep 17 00:00:00 2001 From: mposolda Date: Thu, 2 Apr 2015 15:26:47 +0200 Subject: [PATCH 1/2] More logging --- .../keycloak/adapters/tomcat/CatalinaUserSessionManagement.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integration/tomcat/tomcat-core/src/main/java/org/keycloak/adapters/tomcat/CatalinaUserSessionManagement.java b/integration/tomcat/tomcat-core/src/main/java/org/keycloak/adapters/tomcat/CatalinaUserSessionManagement.java index b0e6caec54..2b302fc064 100755 --- a/integration/tomcat/tomcat-core/src/main/java/org/keycloak/adapters/tomcat/CatalinaUserSessionManagement.java +++ b/integration/tomcat/tomcat-core/src/main/java/org/keycloak/adapters/tomcat/CatalinaUserSessionManagement.java @@ -56,7 +56,7 @@ public class CatalinaUserSessionManagement implements SessionListener { try { session.expire(); } catch (Exception e) { - log.warnf("Session not present or already invalidated."); + log.warn("Session not present or already invalidated.", e); } } From 2ba2e7768dfe52873d0ebfd9e91ecf1f9665fafd Mon Sep 17 00:00:00 2001 From: mposolda Date: Tue, 7 Apr 2015 10:27:44 +0200 Subject: [PATCH 2/2] KEYCLOAK-1181 Running Liquibase updates via maven plugin doesn't work --- connections/jpa-liquibase/pom.xml | 6 +++++- .../liquibase/custom/CustomKeycloakTask.java | 16 +++++++++++++++- .../main/module.xml | 1 + 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/connections/jpa-liquibase/pom.xml b/connections/jpa-liquibase/pom.xml index 3642f74c96..cf520671c2 100755 --- a/connections/jpa-liquibase/pom.xml +++ b/connections/jpa-liquibase/pom.xml @@ -38,7 +38,11 @@ org.jboss.logging jboss-logging - + + org.keycloak + keycloak-services + ${project.version} + diff --git a/connections/jpa-liquibase/src/main/java/org/keycloak/connections/jpa/updater/liquibase/custom/CustomKeycloakTask.java b/connections/jpa-liquibase/src/main/java/org/keycloak/connections/jpa/updater/liquibase/custom/CustomKeycloakTask.java index 40d71cb7b8..1b63bdb281 100644 --- a/connections/jpa-liquibase/src/main/java/org/keycloak/connections/jpa/updater/liquibase/custom/CustomKeycloakTask.java +++ b/connections/jpa-liquibase/src/main/java/org/keycloak/connections/jpa/updater/liquibase/custom/CustomKeycloakTask.java @@ -15,14 +15,18 @@ import liquibase.resource.ResourceAccessor; import liquibase.snapshot.SnapshotGeneratorFactory; import liquibase.statement.SqlStatement; import liquibase.structure.core.Table; +import org.jboss.logging.Logger; import org.keycloak.connections.jpa.updater.liquibase.ThreadLocalSessionContext; import org.keycloak.models.KeycloakSession; +import org.keycloak.services.DefaultKeycloakSessionFactory; /** * @author Marek Posolda */ public abstract class CustomKeycloakTask implements CustomSqlChange { + private final Logger logger = Logger.getLogger(getClass()); + protected KeycloakSession kcSession; protected Database database; @@ -49,8 +53,18 @@ public abstract class CustomKeycloakTask implements CustomSqlChange { @Override public void setUp() throws SetupException { this.kcSession = ThreadLocalSessionContext.getCurrentSession(); + if (this.kcSession == null) { - throw new SetupException("No KeycloakSession provided in ThreadLocal"); + // Probably running Liquibase from maven plugin. Try to create kcSession programmatically + logger.info("No KeycloakSession provided in ThreadLocal. Initializing KeycloakSessionFactory"); + + try { + DefaultKeycloakSessionFactory factory = new DefaultKeycloakSessionFactory(); + factory.init(); + this.kcSession = factory.create(); + } catch (Exception e) { + throw new SetupException("Exception when initializing factory", e); + } } } diff --git a/distribution/modules/src/main/resources/modules/org/keycloak/keycloak-connections-jpa-liquibase/main/module.xml b/distribution/modules/src/main/resources/modules/org/keycloak/keycloak-connections-jpa-liquibase/main/module.xml index f52bc84788..c5b7d85166 100755 --- a/distribution/modules/src/main/resources/modules/org/keycloak/keycloak-connections-jpa-liquibase/main/module.xml +++ b/distribution/modules/src/main/resources/modules/org/keycloak/keycloak-connections-jpa-liquibase/main/module.xml @@ -10,6 +10,7 @@ +