From 6522455b440fc0b6db81a45e236cb1fae9e2d7ff Mon Sep 17 00:00:00 2001 From: mposolda Date: Tue, 7 Oct 2014 18:38:08 +0200 Subject: [PATCH] KEYCLOAK-738 Possible NPE in MemUserSessionProvider.getUserSessions --- .../sessions/mem/MemUserSessionProvider.java | 2 +- .../keycloak/testsuite/adapter/AdapterTest.java | 17 ++++++++--------- .../adapter/RelativeUriAdapterTest.java | 17 ++++++++--------- 3 files changed, 17 insertions(+), 19 deletions(-) diff --git a/model/sessions-mem/src/main/java/org/keycloak/models/sessions/mem/MemUserSessionProvider.java b/model/sessions-mem/src/main/java/org/keycloak/models/sessions/mem/MemUserSessionProvider.java index 26ddb0a933..b43f827607 100755 --- a/model/sessions-mem/src/main/java/org/keycloak/models/sessions/mem/MemUserSessionProvider.java +++ b/model/sessions-mem/src/main/java/org/keycloak/models/sessions/mem/MemUserSessionProvider.java @@ -121,7 +121,7 @@ public class MemUserSessionProvider implements UserSessionProvider { for (ClientSessionEntity s : clientSessions.values()) { String realmId = realm.getId(); String clientId = client.getId(); - if (s.getSession().getRealm().equals(realmId) && s.getClientId().equals(clientId)) { + if (s.getSession() != null && s.getSession().getRealm().equals(realmId) && s.getClientId().equals(clientId)) { if (!userSessionEntities.contains(s.getSession())) { userSessionEntities.add(s.getSession()); } diff --git a/testsuite/integration/src/test/java/org/keycloak/testsuite/adapter/AdapterTest.java b/testsuite/integration/src/test/java/org/keycloak/testsuite/adapter/AdapterTest.java index b410f39dbe..10bf32171c 100755 --- a/testsuite/integration/src/test/java/org/keycloak/testsuite/adapter/AdapterTest.java +++ b/testsuite/integration/src/test/java/org/keycloak/testsuite/adapter/AdapterTest.java @@ -40,7 +40,6 @@ import org.keycloak.models.UserSessionModel; import org.keycloak.protocol.oidc.OpenIDConnectService; import org.keycloak.protocol.oidc.TokenManager; import org.keycloak.representations.AccessToken; -import org.keycloak.representations.adapters.action.SessionStats; import org.keycloak.representations.idm.RealmRepresentation; import org.keycloak.services.managers.RealmManager; import org.keycloak.services.resources.admin.AdminRoot; @@ -158,17 +157,17 @@ public class AdapterTest { Client client = ClientBuilder.newClient(); UriBuilder authBase = UriBuilder.fromUri("http://localhost:8081/auth"); WebTarget adminTarget = client.target(AdminRoot.realmsUrl(authBase)).path("demo"); - Map stats = adminTarget.path("session-stats").request() + Map stats = adminTarget.path("application-session-stats").request() .header(HttpHeaders.AUTHORIZATION, "Bearer " + adminToken) - .get(new GenericType>() { + .get(new GenericType>() { }); - SessionStats custStats = stats.get("customer-portal"); - Assert.assertNotNull(custStats); - Assert.assertEquals(1, custStats.getActiveSessions()); - SessionStats prodStats = stats.get("product-portal"); - Assert.assertNotNull(prodStats); - Assert.assertEquals(1, prodStats.getActiveSessions()); + Integer custSessionsCount = stats.get("customer-portal"); + Assert.assertNotNull(custSessionsCount); + Assert.assertTrue(1 == custSessionsCount); + Integer prodStatsCount = stats.get("product-portal"); + Assert.assertNotNull(prodStatsCount); + Assert.assertTrue(1 == prodStatsCount); client.close(); diff --git a/testsuite/integration/src/test/java/org/keycloak/testsuite/adapter/RelativeUriAdapterTest.java b/testsuite/integration/src/test/java/org/keycloak/testsuite/adapter/RelativeUriAdapterTest.java index 228461c083..0c3dfb8d93 100755 --- a/testsuite/integration/src/test/java/org/keycloak/testsuite/adapter/RelativeUriAdapterTest.java +++ b/testsuite/integration/src/test/java/org/keycloak/testsuite/adapter/RelativeUriAdapterTest.java @@ -35,7 +35,6 @@ import org.keycloak.models.UserSessionModel; import org.keycloak.protocol.oidc.OpenIDConnectService; import org.keycloak.protocol.oidc.TokenManager; import org.keycloak.representations.AccessToken; -import org.keycloak.representations.adapters.action.SessionStats; import org.keycloak.representations.idm.RealmRepresentation; import org.keycloak.services.managers.RealmManager; import org.keycloak.services.resources.admin.AdminRoot; @@ -132,16 +131,16 @@ public class RelativeUriAdapterTest { Client client = ClientBuilder.newClient(); UriBuilder authBase = UriBuilder.fromUri("http://localhost:8081/auth"); WebTarget adminTarget = client.target(AdminRoot.realmsUrl(authBase)).path("demo"); - Map stats = adminTarget.path("session-stats").request() + Map stats = adminTarget.path("application-session-stats").request() .header(HttpHeaders.AUTHORIZATION, "Bearer " + adminToken) - .get(new GenericType>(){}); + .get(new GenericType>(){}); - SessionStats custStats = stats.get("customer-portal"); - Assert.assertNotNull(custStats); - Assert.assertEquals(1, custStats.getActiveSessions()); - SessionStats prodStats = stats.get("product-portal"); - Assert.assertNotNull(prodStats); - Assert.assertEquals(1, prodStats.getActiveSessions()); + Integer custSessionsCount = stats.get("customer-portal"); + Assert.assertNotNull(custSessionsCount); + Assert.assertTrue(1 == custSessionsCount); + Integer prodStatsCount = stats.get("product-portal"); + Assert.assertNotNull(prodStatsCount); + Assert.assertTrue(1 == prodStatsCount); client.close();