keycloak-uncached

Details

diff --git a/docbook/reference/en/en-US/modules/jboss-adapter.xml b/docbook/reference/en/en-US/modules/jboss-adapter.xml
index c89d9b1..3995447 100755
--- a/docbook/reference/en/en-US/modules/jboss-adapter.xml
+++ b/docbook/reference/en/en-US/modules/jboss-adapter.xml
@@ -14,10 +14,17 @@
         the Keycloak download site.  They are also available as a maven artifact.
     </para>
     <para>
-        Install on Wildfly:
+        Install on Wildfly 9:
 <programlisting>
 $ cd $WILDFLY_HOME
-$ unzip keycloak-wildfly-adapter-dist.zip
+$ unzip keycloak-wf9-adapter-dist.zip
+</programlisting>
+    </para>
+    <para>
+        Install on Wildfly 8:
+<programlisting>
+$ cd $WILDFLY_HOME
+$ unzip keycloak-wf8-adapter-dist.zip
 </programlisting>
     </para>
     <para>
@@ -56,7 +63,6 @@ $ unzip keycloak-as7-adapter-dist.zip
     </profile>
 ]]>
 </programlisting>
-<note>For AS7, the extension module is org.keycloak.keycloak-as7-subsystem.</note>
     </para>
         <para>
             Finally, you must specify a shared keycloak security domain.
diff --git a/docbook/reference/en/en-US/modules/MigrationFromOlderVersions.xml b/docbook/reference/en/en-US/modules/MigrationFromOlderVersions.xml
index 68e48b4..f4fdec2 100755
--- a/docbook/reference/en/en-US/modules/MigrationFromOlderVersions.xml
+++ b/docbook/reference/en/en-US/modules/MigrationFromOlderVersions.xml
@@ -102,6 +102,27 @@
                     to newer version and upgrade few methods, which has changed signature. Changes are really minor, but were needed to improve performance of federation.
                 </para>
             </simplesect>
+            <simplesect>
+                <title>WildFly 9.0.0.CR2</title>
+                <para>
+                    Following on from the distribution changes that was done in the last release the standalone download
+                    of Keycloak is now based on WildFly 9.0.0.CR2. This als affects the overlay which can only be deployed
+                    to WildFly 9.0.0.CR2 or JBoss EAP 6.4.0.GA. WildFly 8.2.0.Final is no longer supported for the server.
+                </para>
+            </simplesect>
+            <simplesect>
+                <title>WildFly, JBoss EAP and JBoss AS7 adapters</title>
+                <para>
+                    There are now 3 separate adapter downloads for WildFly, JBoss EAP and JBoss AS7:
+                    <itemizedlist>
+                        <listitem><literal>eap6</literal> - for JBoss EAP 6.x</listitem>
+                        <listitem><literal>wf9</literal> - for WildFly 9.x</listitem>
+                        <listitem><literal>wf8</literal> - for WildFly 8.x</listitem>
+                        <listitem><literal>as7</literal> - for JBoss AS 7.x</listitem>
+                    </itemizedlist>
+                    Make sure you grab the correct one.
+                </para>
+            </simplesect>
         </section>
         <section>
             <title>Migrating from 1.2.0.Beta1 to 1.2.0.RC1</title>
diff --git a/docbook/reference/en/en-US/modules/server-installation.xml b/docbook/reference/en/en-US/modules/server-installation.xml
index 9c321a2..214d88a 100755
--- a/docbook/reference/en/en-US/modules/server-installation.xml
+++ b/docbook/reference/en/en-US/modules/server-installation.xml
@@ -43,9 +43,9 @@
 
 
         <section id="overlay_install">
-            <title>Install on existing WildFly 8.2.0.Final</title>
+            <title>Install on existing WildFly 9.0.0.CR2</title>
             <para>
-                Keycloak can be installed into an existing WildFly 8.2.0.Final server. To do this download
+                Keycloak can be installed into an existing WildFly 9.0.0.CR2 server. To do this download
                 <literal>keycloak-overlay-&project.version;.zip</literal> or  <literal>keycloak-overlay-&project.version;.tar.gz</literal>.
                 Once downloaded extract into the root directory of your WildFly installation. To start WildFly with Keycloak
                 run:
@@ -72,32 +72,9 @@
             </para>
         </section>
         <section>
-            <title>Install on existing EAP 6.4.0.GA</title>
+            <title>Install on existing JBoss EAP 6.4.0.GA</title>
             <para>
-                Keycloak can be installed into an existing EAP 6.4.0.GA server. To do this download
-                <literal>keycloak-overlay-&project.version;.zip</literal> or  <literal>keycloak-overlay-&project.version;.tar.gz</literal>.
-                Once downloaded extract into the root directory of your EAP installation.
-            </para>
-            <para>
-                To add Keycloak to the a EAP sever configurations (standalone.xml, standalone-ha.xml, etc.) open
-                <literal>standalone/configuration/standalone-keycloak.xml</literal> and the configuration you want to add it
-                to, for example <literal>standalone/configuration/standalone.xml</literal>. From <literal>standalone-keycloak.xml</literal>
-                you need to copy 3 elements:
-                <itemizedlist>
-                    <listitem><literal>&lt;extension module="org.keycloak.keycloak-subsystem"/&gt;</literal></listitem>
-                    <listitem><literal>&lt;datasource jndi-name="java:jboss/datasources/KeycloakDS" ...&gt;</literal></listitem>
-                    <listitem><literal>&lt;subsystem xmlns="urn:jboss:domain:keycloak:1.0" ...&gt;</literal></listitem>
-                </itemizedlist>
-                <note>
-                    <literal>standalone-keycloak.xml</literal> is aimed at WildFly and won't work with EAP so you need to
-                    copy the required configuration
-                </note>
-            </para>
-            <para>
-                Once the server is started log into the admin console at
-                <ulink url="http://localhost:8080/auth/admin/index.html">http://localhost:8080/auth/admin/index.html</ulink>
-                (username: <emphasis>admin</emphasis> and password: <emphasis>admin</emphasis>). Keycloak will then prompt you to
-                enter in a new password.
+                Same procedure as JBoss EAP 6.4.0.GA, but download <literal>keycloak-overlay-eap6-&project.version;.zip</literal> or  <literal>keycloak-overlay-eap6-&project.version;.tar.gz</literal>.
             </para>
         </section>
         <section>
@@ -107,7 +84,7 @@
                 To install it first download <literal>keycloak-demo-&project.version;.zip</literal> or
                 <literal>keycloak-demo-&project.version;.tar.gz</literal>. Once downloaded extract it inside
                 <literal>keycloak-demo-&project.version;</literal> you'll find <literal>keycloak</literal> which contains
-                a full WildFly 8.2.0.Final server with Keycloak Server and Adapters included. You'll also find <literal>docs</literal>
+                a full WildFly 9.0.0.CR2 server with Keycloak Server and Adapters included. You'll also find <literal>docs</literal>
                 and <literal>examples</literal> which contains everything you need to get started developing applications that use Keycloak.
             </para>
             <para>
diff --git a/model/invalidation-cache/model-adapters/src/main/java/org/keycloak/models/cache/DefaultCacheUserProvider.java b/model/invalidation-cache/model-adapters/src/main/java/org/keycloak/models/cache/DefaultCacheUserProvider.java
index a37e2a4..2f766e0 100755
--- a/model/invalidation-cache/model-adapters/src/main/java/org/keycloak/models/cache/DefaultCacheUserProvider.java
+++ b/model/invalidation-cache/model-adapters/src/main/java/org/keycloak/models/cache/DefaultCacheUserProvider.java
@@ -31,9 +31,9 @@ public class DefaultCacheUserProvider implements CacheUserProvider {
     protected boolean transactionActive;
     protected boolean setRollbackOnly;
 
-    protected Map<String, String> userInvalidations = new HashMap<String, String>();
-    protected Set<String> realmInvalidations = new HashSet<String>();
-    protected Map<String, UserModel> managedUsers = new HashMap<String, UserModel>();
+    protected Map<String, String> userInvalidations = new HashMap<>();
+    protected Set<String> realmInvalidations = new HashSet<>();
+    protected Map<String, UserModel> managedUsers = new HashMap<>();
 
     protected boolean clearAll;
 
@@ -131,6 +131,7 @@ public class DefaultCacheUserProvider implements CacheUserProvider {
         if (cached == null) {
             UserModel model = getDelegate().getUserById(id, realm);
             if (model == null) return null;
+            if (managedUsers.containsKey(id)) return managedUsers.get(id);
             if (userInvalidations.containsKey(id)) return model;
             cached = new CachedUser(realm, model);
             cache.addCachedUser(realm.getId(), cached);
@@ -155,6 +156,7 @@ public class DefaultCacheUserProvider implements CacheUserProvider {
         if (cached == null) {
             UserModel model = getDelegate().getUserByUsername(username, realm);
             if (model == null) return null;
+            if (managedUsers.containsKey(model.getId())) return managedUsers.get(model.getId());
             if (userInvalidations.containsKey(model.getId())) return model;
             cached = new CachedUser(realm, model);
             cache.addCachedUser(realm.getId(), cached);
@@ -181,6 +183,7 @@ public class DefaultCacheUserProvider implements CacheUserProvider {
         if (cached == null) {
             UserModel model = getDelegate().getUserByEmail(email, realm);
             if (model == null) return null;
+            if (managedUsers.containsKey(model.getId())) return managedUsers.get(model.getId());
             if (userInvalidations.containsKey(model.getId())) return model;
             cached = new CachedUser(realm, model);
             cache.addCachedUser(realm.getId(), cached);
@@ -251,12 +254,16 @@ public class DefaultCacheUserProvider implements CacheUserProvider {
 
     @Override
     public UserModel addUser(RealmModel realm, String id, String username, boolean addDefaultRoles) {
-        return getDelegate().addUser(realm, id, username, addDefaultRoles);
+        UserModel user = getDelegate().addUser(realm, id, username, addDefaultRoles);
+        managedUsers.put(user.getId(), user);
+        return user;
     }
 
     @Override
     public UserModel addUser(RealmModel realm, String username) {
-        return getDelegate().addUser(realm, username);
+        UserModel user = getDelegate().addUser(realm, username);
+        managedUsers.put(user.getId(), user);
+        return user;
     }
 
     @Override
diff --git a/testsuite/integration/src/test/java/org/keycloak/testsuite/model/CacheTest.java b/testsuite/integration/src/test/java/org/keycloak/testsuite/model/CacheTest.java
index e16ae05..5f8371c 100755
--- a/testsuite/integration/src/test/java/org/keycloak/testsuite/model/CacheTest.java
+++ b/testsuite/integration/src/test/java/org/keycloak/testsuite/model/CacheTest.java
@@ -5,11 +5,11 @@ import java.util.List;
 import org.junit.Assert;
 import org.junit.ClassRule;
 import org.junit.Test;
-import org.keycloak.models.ClientModel;
-import org.keycloak.models.KeycloakSession;
-import org.keycloak.models.RealmModel;
+import org.keycloak.models.*;
 import org.keycloak.testsuite.rule.KeycloakRule;
 
+import static org.junit.Assert.assertNotNull;
+
 /**
  * @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
  * @version $Revision: 1 $
@@ -26,7 +26,7 @@ public class CacheTest {
             KeycloakSession session = kc.startSession();
             RealmModel realm = session.realms().getRealmByName("test");
             ClientModel testApp = realm.getClientByClientId("test-app");
-            Assert.assertNotNull(testApp);
+            assertNotNull(testApp);
             appId = testApp.getId();
             Assert.assertTrue(testApp.isEnabled());
             kc.stopSession(session, true);
@@ -48,7 +48,7 @@ public class CacheTest {
             Assert.assertTrue(realm instanceof org.keycloak.models.cache.RealmAdapter);
             realm.setAccessCodeLifespanLogin(200);
             ClientModel testApp = realm.getClientByClientId("test-app");
-            Assert.assertNotNull(testApp);
+            assertNotNull(testApp);
             testApp.setEnabled(false);
             kc.stopSession(session, true);
         }
@@ -65,4 +65,27 @@ public class CacheTest {
 
 
     }
+
+    @Test
+    public void testAddUserNotAddedToCache() {
+        KeycloakSession session = kc.startSession();
+        try {
+            RealmModel realm = session.realms().getRealmByName("test");
+
+            UserModel user = session.users().addUser(realm, "testAddUserNotAddedToCache");
+            user.setFirstName("firstName");
+            user.addRequiredAction(UserModel.RequiredAction.CONFIGURE_TOTP);
+
+            UserSessionModel userSession = session.sessions().createUserSession(realm, user, "testAddUserNotAddedToCache", "127.0.0.1", "auth", false, null, null);
+            UserModel user2 = userSession.getUser();
+
+            user.setLastName("lastName");
+
+            assertNotNull(user2.getLastName());
+        } finally {
+            session.getTransaction().commit();
+            session.close();
+        }
+    }
+
 }