Merge pull request #717 from stianst/master

Fixes to JPA user session provider
This commit is contained in:
Stian Thorgersen 2014-09-30 14:47:45 +02:00
commit 0f307afd16
2 changed files with 3 additions and 6 deletions

View file

@ -103,16 +103,14 @@ public class ClientSessionAdapter implements ClientSessionModel {
@Override @Override
public void setRoles(Set<String> roles) { public void setRoles(Set<String> roles) {
if (roles != null) { if (roles != null) {
List<ClientSessionRoleEntity> roleEntities = new LinkedList<ClientSessionRoleEntity>();
for (String r : roles) { for (String r : roles) {
ClientSessionRoleEntity roleEntity = new ClientSessionRoleEntity(); ClientSessionRoleEntity roleEntity = new ClientSessionRoleEntity();
roleEntity.setClientSession(entity); roleEntity.setClientSession(entity);
roleEntity.setRoleId(r); roleEntity.setRoleId(r);
em.persist(roleEntity); em.persist(roleEntity);
roleEntities.add(roleEntity); entity.getRoles().add(roleEntity);
} }
entity.setRoles(roleEntities);
} }
} }

View file

@ -51,7 +51,7 @@ public class JpaUserSessionProvider implements UserSessionProvider {
@Override @Override
public ClientSessionModel getClientSession(RealmModel realm, String id) { public ClientSessionModel getClientSession(RealmModel realm, String id) {
ClientSessionEntity clientSession = em.find(ClientSessionEntity.class, 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 new ClientSessionAdapter(session, em, realm, clientSession);
} }
return null; return null;
@ -69,8 +69,7 @@ public class JpaUserSessionProvider implements UserSessionProvider {
@Override @Override
public UsernameLoginFailureModel getUserLoginFailure(RealmModel realm, String username) { public UsernameLoginFailureModel getUserLoginFailure(RealmModel realm, String username) {
String id = username + "-" + realm; UsernameLoginFailureEntity entity = em.find(UsernameLoginFailureEntity.class, new UsernameLoginFailureEntity.Key(realm.getId(), username));
UsernameLoginFailureEntity entity = em.find(UsernameLoginFailureEntity.class, id);
if (entity == null) return null; if (entity == null) return null;
return new UsernameLoginFailureAdapter(entity); return new UsernameLoginFailureAdapter(entity);
} }