From a1f223735c87551261ccfc6e4023eb32a147da2b Mon Sep 17 00:00:00 2001 From: Stian Thorgersen Date: Tue, 30 Sep 2014 14:47:22 +0200 Subject: [PATCH] Fixes to JPA user session provider --- .../keycloak/models/sessions/jpa/ClientSessionAdapter.java | 4 +--- .../keycloak/models/sessions/jpa/JpaUserSessionProvider.java | 5 ++--- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/model/sessions-jpa/src/main/java/org/keycloak/models/sessions/jpa/ClientSessionAdapter.java b/model/sessions-jpa/src/main/java/org/keycloak/models/sessions/jpa/ClientSessionAdapter.java index 8dd976392d..7e6a73f9d6 100755 --- a/model/sessions-jpa/src/main/java/org/keycloak/models/sessions/jpa/ClientSessionAdapter.java +++ b/model/sessions-jpa/src/main/java/org/keycloak/models/sessions/jpa/ClientSessionAdapter.java @@ -103,16 +103,14 @@ public class ClientSessionAdapter implements ClientSessionModel { @Override public void setRoles(Set roles) { if (roles != null) { - List roleEntities = new LinkedList(); for (String r : roles) { ClientSessionRoleEntity roleEntity = new ClientSessionRoleEntity(); roleEntity.setClientSession(entity); roleEntity.setRoleId(r); em.persist(roleEntity); - roleEntities.add(roleEntity); + entity.getRoles().add(roleEntity); } - entity.setRoles(roleEntities); } } diff --git a/model/sessions-jpa/src/main/java/org/keycloak/models/sessions/jpa/JpaUserSessionProvider.java b/model/sessions-jpa/src/main/java/org/keycloak/models/sessions/jpa/JpaUserSessionProvider.java index a3e7297462..b1ec11b02b 100755 --- a/model/sessions-jpa/src/main/java/org/keycloak/models/sessions/jpa/JpaUserSessionProvider.java +++ b/model/sessions-jpa/src/main/java/org/keycloak/models/sessions/jpa/JpaUserSessionProvider.java @@ -51,7 +51,7 @@ public class JpaUserSessionProvider implements UserSessionProvider { @Override public ClientSessionModel getClientSession(RealmModel realm, String id) { ClientSessionEntity clientSession = em.find(ClientSessionEntity.class, id); - if (clientSession != null && clientSession.getSession().getRealmId().equals(realm.getId())) { + if (clientSession != null && clientSession.getRealmId().equals(realm.getId())) { return new ClientSessionAdapter(session, em, realm, clientSession); } return null; @@ -69,8 +69,7 @@ public class JpaUserSessionProvider implements UserSessionProvider { @Override public UsernameLoginFailureModel getUserLoginFailure(RealmModel realm, String username) { - String id = username + "-" + realm; - UsernameLoginFailureEntity entity = em.find(UsernameLoginFailureEntity.class, id); + UsernameLoginFailureEntity entity = em.find(UsernameLoginFailureEntity.class, new UsernameLoginFailureEntity.Key(realm.getId(), username)); if (entity == null) return null; return new UsernameLoginFailureAdapter(entity); }