Merge pull request #1767 from mposolda/master

KEYCLOAK-1999 KC server doesn't start on EAP 6.4 in local mode on Pos…
This commit is contained in:
Marek Posolda 2015-10-22 15:08:54 +02:00
commit fa6b99eaab
3 changed files with 29 additions and 21 deletions

View file

@ -188,32 +188,32 @@ public class JpaUserSessionPersisterProvider implements UserSessionPersisterProv
userSessionIds.add(entity.getUserSessionId()); userSessionIds.add(entity.getUserSessionId());
} }
TypedQuery<PersistentClientSessionEntity> query2 = em.createNamedQuery("findClientSessionsByUserSessions", PersistentClientSessionEntity.class); if (!userSessionIds.isEmpty()) {
query2.setParameter("userSessionIds", userSessionIds); TypedQuery<PersistentClientSessionEntity> query2 = em.createNamedQuery("findClientSessionsByUserSessions", PersistentClientSessionEntity.class);
query2.setParameter("offline", offlineStr); query2.setParameter("userSessionIds", userSessionIds);
List<PersistentClientSessionEntity> clientSessions = query2.getResultList(); query2.setParameter("offline", offlineStr);
List<PersistentClientSessionEntity> clientSessions = query2.getResultList();
// Assume both userSessions and clientSessions ordered by userSessionId // Assume both userSessions and clientSessions ordered by userSessionId
int j=0; int j = 0;
for (UserSessionModel ss : result) { for (UserSessionModel ss : result) {
PersistentUserSessionAdapter userSession = (PersistentUserSessionAdapter) ss; PersistentUserSessionAdapter userSession = (PersistentUserSessionAdapter) ss;
List<ClientSessionModel> currentClientSessions = userSession.getClientSessions(); // This is empty now and we want to fill it List<ClientSessionModel> currentClientSessions = userSession.getClientSessions(); // This is empty now and we want to fill it
boolean next = true; boolean next = true;
while (next && j<clientSessions.size()) { while (next && j < clientSessions.size()) {
PersistentClientSessionEntity clientSession = clientSessions.get(j); PersistentClientSessionEntity clientSession = clientSessions.get(j);
if (clientSession.getUserSessionId().equals(userSession.getId())) { if (clientSession.getUserSessionId().equals(userSession.getId())) {
PersistentClientSessionAdapter clientSessAdapter = toAdapter(userSession.getRealm(), userSession, clientSession); PersistentClientSessionAdapter clientSessAdapter = toAdapter(userSession.getRealm(), userSession, clientSession);
currentClientSessions.add(clientSessAdapter); currentClientSessions.add(clientSessAdapter);
j++; j++;
} else { } else {
next = false; next = false;
}
} }
} }
} }
return result; return result;
} }

View file

@ -39,7 +39,7 @@ public class SimpleUserSessionInitializer {
public void run(KeycloakSession session) { public void run(KeycloakSession session) {
int count = sessionLoader.getSessionsCount(session); int count = sessionLoader.getSessionsCount(session);
for (int i=0 ; i<=count ; i+=sessionsPerSegment) { for (int i=0 ; i<count ; i+=sessionsPerSegment) {
sessionLoader.loadSessions(session, i, sessionsPerSegment); sessionLoader.loadSessions(session, i, sessionsPerSegment);
} }
} }

View file

@ -290,6 +290,14 @@ public class UserSessionPersisterProviderTest {
realmMgr.removeRealm(realmMgr.getRealm("foo")); realmMgr.removeRealm(realmMgr.getRealm("foo"));
} }
// KEYCLOAK-1999
@Test
public void testNoSessions() {
UserSessionPersisterProvider persister = session.getProvider(UserSessionPersisterProvider.class);
List<UserSessionModel> sessions = persister.loadUserSessions(0, 1, true);
Assert.assertEquals(0, sessions.size());
}
private ClientSessionModel createClientSession(ClientModel client, UserSessionModel userSession, String redirect, String state, Set<String> roles, Set<String> protocolMappers) { private ClientSessionModel createClientSession(ClientModel client, UserSessionModel userSession, String redirect, String state, Set<String> roles, Set<String> protocolMappers) {
ClientSessionModel clientSession = session.sessions().createClientSession(realm, client); ClientSessionModel clientSession = session.sessions().createClientSession(realm, client);