Merge pull request #492 from patriot1burke/master
model fix for caching
This commit is contained in:
commit
0abd93417a
4 changed files with 24 additions and 13 deletions
|
@ -130,15 +130,14 @@ public class ApplicationAdapter extends ClientAdapter implements ApplicationMode
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean removeRole(RoleModel roleModel) {
|
public boolean removeRole(RoleModel roleModel) {
|
||||||
RoleAdapter roleAdapter = (RoleAdapter)roleModel;
|
|
||||||
if (roleModel == null) {
|
if (roleModel == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!roleAdapter.getContainer().equals(this)) return false;
|
if (!roleModel.getContainer().equals(this)) return false;
|
||||||
|
|
||||||
if (!roleAdapter.getRole().isApplicationRole()) return false;
|
RoleEntity role = RoleAdapter.toRoleEntity(roleModel, em);
|
||||||
|
if (!role.isApplicationRole()) return false;
|
||||||
|
|
||||||
RoleEntity role = roleAdapter.getRole();
|
|
||||||
|
|
||||||
applicationEntity.getRoles().remove(role);
|
applicationEntity.getRoles().remove(role);
|
||||||
applicationEntity.getDefaultRoles().remove(role);
|
applicationEntity.getDefaultRoles().remove(role);
|
||||||
|
@ -209,7 +208,8 @@ public class ApplicationAdapter extends ClientAdapter implements ApplicationMode
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
entities.add(((RoleAdapter) role).getRole());
|
RoleEntity roleEntity = RoleAdapter.toRoleEntity(role, em);
|
||||||
|
entities.add(roleEntity);
|
||||||
em.flush();
|
em.flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,7 @@ import org.keycloak.models.RoleModel;
|
||||||
import org.keycloak.models.UserSessionModel;
|
import org.keycloak.models.UserSessionModel;
|
||||||
import org.keycloak.models.jpa.entities.ClientEntity;
|
import org.keycloak.models.jpa.entities.ClientEntity;
|
||||||
import org.keycloak.models.jpa.entities.ClientUserSessionAssociationEntity;
|
import org.keycloak.models.jpa.entities.ClientUserSessionAssociationEntity;
|
||||||
|
import org.keycloak.models.jpa.entities.RoleEntity;
|
||||||
import org.keycloak.models.jpa.entities.ScopeMappingEntity;
|
import org.keycloak.models.jpa.entities.ScopeMappingEntity;
|
||||||
|
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
|
@ -215,7 +216,8 @@ public abstract class ClientAdapter implements ClientModel {
|
||||||
if (hasScope(role)) return;
|
if (hasScope(role)) return;
|
||||||
ScopeMappingEntity entity = new ScopeMappingEntity();
|
ScopeMappingEntity entity = new ScopeMappingEntity();
|
||||||
entity.setClient(getEntity());
|
entity.setClient(getEntity());
|
||||||
entity.setRole(((RoleAdapter) role).getRole());
|
RoleEntity roleEntity = RoleAdapter.toRoleEntity(role, em);
|
||||||
|
entity.setRole(roleEntity);
|
||||||
em.persist(entity);
|
em.persist(entity);
|
||||||
em.flush();
|
em.flush();
|
||||||
em.detach(entity);
|
em.detach(entity);
|
||||||
|
@ -223,7 +225,7 @@ public abstract class ClientAdapter implements ClientModel {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void deleteScopeMapping(RoleModel role) {
|
public void deleteScopeMapping(RoleModel role) {
|
||||||
TypedQuery<ScopeMappingEntity> query = getRealmScopeMappingQuery((RoleAdapter) role);
|
TypedQuery<ScopeMappingEntity> query = getRealmScopeMappingQuery(role);
|
||||||
List<ScopeMappingEntity> results = query.getResultList();
|
List<ScopeMappingEntity> results = query.getResultList();
|
||||||
if (results.size() == 0) return;
|
if (results.size() == 0) return;
|
||||||
for (ScopeMappingEntity entity : results) {
|
for (ScopeMappingEntity entity : results) {
|
||||||
|
@ -231,10 +233,11 @@ public abstract class ClientAdapter implements ClientModel {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected TypedQuery<ScopeMappingEntity> getRealmScopeMappingQuery(RoleAdapter role) {
|
protected TypedQuery<ScopeMappingEntity> getRealmScopeMappingQuery(RoleModel role) {
|
||||||
TypedQuery<ScopeMappingEntity> query = em.createNamedQuery("hasScope", ScopeMappingEntity.class);
|
TypedQuery<ScopeMappingEntity> query = em.createNamedQuery("hasScope", ScopeMappingEntity.class);
|
||||||
query.setParameter("client", getEntity());
|
query.setParameter("client", getEntity());
|
||||||
query.setParameter("role", ((RoleAdapter) role).getRole());
|
RoleEntity roleEntity = RoleAdapter.toRoleEntity(role, em);
|
||||||
|
query.setParameter("role", roleEntity);
|
||||||
return query;
|
return query;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -527,7 +527,8 @@ public class RealmAdapter implements RealmModel {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
entities.add(((RoleAdapter) role).getRole());
|
RoleEntity roleEntity = RoleAdapter.toRoleEntity(role, em);
|
||||||
|
entities.add(roleEntity);
|
||||||
em.flush();
|
em.flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -924,7 +925,7 @@ public class RealmAdapter implements RealmModel {
|
||||||
}
|
}
|
||||||
if (!role.getContainer().equals(this)) return false;
|
if (!role.getContainer().equals(this)) return false;
|
||||||
|
|
||||||
RoleEntity roleEntity = ((RoleAdapter) role).getRole();
|
RoleEntity roleEntity = RoleAdapter.toRoleEntity(role, em);
|
||||||
realm.getRoles().remove(role);
|
realm.getRoles().remove(role);
|
||||||
realm.getDefaultRoles().remove(role);
|
realm.getDefaultRoles().remove(role);
|
||||||
|
|
||||||
|
|
|
@ -66,7 +66,7 @@ public class RoleAdapter implements RoleModel {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addCompositeRole(RoleModel role) {
|
public void addCompositeRole(RoleModel role) {
|
||||||
RoleEntity entity = ((RoleAdapter)role).getRole();
|
RoleEntity entity = RoleAdapter.toRoleEntity(role, em);
|
||||||
for (RoleEntity composite : getRole().getCompositeRoles()) {
|
for (RoleEntity composite : getRole().getCompositeRoles()) {
|
||||||
if (composite.equals(entity)) return;
|
if (composite.equals(entity)) return;
|
||||||
}
|
}
|
||||||
|
@ -76,7 +76,7 @@ public class RoleAdapter implements RoleModel {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removeCompositeRole(RoleModel role) {
|
public void removeCompositeRole(RoleModel role) {
|
||||||
RoleEntity entity = ((RoleAdapter)role).getRole();
|
RoleEntity entity = RoleAdapter.toRoleEntity(role, em);
|
||||||
Iterator<RoleEntity> it = getRole().getCompositeRoles().iterator();
|
Iterator<RoleEntity> it = getRole().getCompositeRoles().iterator();
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
if (it.next().equals(entity)) it.remove();
|
if (it.next().equals(entity)) it.remove();
|
||||||
|
@ -125,4 +125,11 @@ public class RoleAdapter implements RoleModel {
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return getId().hashCode();
|
return getId().hashCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static RoleEntity toRoleEntity(RoleModel model, EntityManager em) {
|
||||||
|
if (model instanceof RoleAdapter) {
|
||||||
|
return ((RoleAdapter)model).getRole();
|
||||||
|
}
|
||||||
|
return em.getReference(RoleEntity.class, model.getId());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue