keycloak-memoizeit

KEYCLOAK-1187

4/14/2015 2:36:19 AM

Details

diff --git a/connections/jpa-liquibase/src/main/resources/META-INF/jpa-changelog-1.2.0.RC1.xml b/connections/jpa-liquibase/src/main/resources/META-INF/jpa-changelog-1.2.0.RC1.xml
index a61d520..3477168 100755
--- a/connections/jpa-liquibase/src/main/resources/META-INF/jpa-changelog-1.2.0.RC1.xml
+++ b/connections/jpa-liquibase/src/main/resources/META-INF/jpa-changelog-1.2.0.RC1.xml
@@ -58,5 +58,13 @@
 
         <renameTable oldTableName="APP_NODE_REGISTRATIONS" newTableName="CLIENT_NODE_REGISTRATIONS"/>
         <renameColumn tableName="CLIENT_NODE_REGISTRATIONS" newColumnName="CLIENT_ID" oldColumnName="APPLICATION_ID"/>
+
+        <renameColumn tableName="KEYCLOAK_ROLE" newColumnName="CLIENT" oldColumnName="APPLICATION"/>
+        <renameColumn tableName="KEYCLOAK_ROLE" newColumnName="CLIENT_ROLE" oldColumnName="APPLICATION_ROLE"/>
+        <renameColumn tableName="KEYCLOAK_ROLE" newColumnName="CLIENT_REALM_CONSTRAINT" oldColumnName="APP_REALM_CONSTRAINT"/>
+
+        <dropUniqueConstraint tableName="KEYCLOAK_ROLE" constraintName="UK_J3RWUVD56ONTGSUHOGM184WW2"/>
+        <addUniqueConstraint columnNames="NAME,CLIENT_REALM_CONSTRAINT" constraintName="UK_J3RWUVD56ONTGSUHOGM184WW2-2" tableName="KEYCLOAK_ROLE"/>
+
     </changeSet>
 </databaseChangeLog>
diff --git a/model/jpa/src/main/java/org/keycloak/models/jpa/ClientAdapter.java b/model/jpa/src/main/java/org/keycloak/models/jpa/ClientAdapter.java
index b04a92c..7ebb242 100755
--- a/model/jpa/src/main/java/org/keycloak/models/jpa/ClientAdapter.java
+++ b/model/jpa/src/main/java/org/keycloak/models/jpa/ClientAdapter.java
@@ -545,9 +545,9 @@ public class ClientAdapter implements ClientModel {
 
     @Override
     public RoleModel getRole(String name) {
-        TypedQuery<RoleEntity> query = em.createNamedQuery("getAppRoleByName", RoleEntity.class);
+        TypedQuery<RoleEntity> query = em.createNamedQuery("getClientRoleByName", RoleEntity.class);
         query.setParameter("name", name);
-        query.setParameter("application", entity);
+        query.setParameter("client", entity);
         List<RoleEntity> roles = query.getResultList();
         if (roles.size() == 0) return null;
         return new RoleAdapter(realm, em, roles.get(0));
@@ -563,8 +563,8 @@ public class ClientAdapter implements ClientModel {
         RoleEntity roleEntity = new RoleEntity();
         roleEntity.setId(id);
         roleEntity.setName(name);
-        roleEntity.setApplication(entity);
-        roleEntity.setApplicationRole(true);
+        roleEntity.setClient(entity);
+        roleEntity.setClientRole(true);
         roleEntity.setRealmId(realm.getId());
         em.persist(roleEntity);
         entity.getRoles().add(roleEntity);
@@ -581,13 +581,13 @@ public class ClientAdapter implements ClientModel {
 
         session.users().preRemove(getRealm(), roleModel);
         RoleEntity role = RoleAdapter.toRoleEntity(roleModel, em);
-        if (!role.isApplicationRole()) return false;
+        if (!role.isClientRole()) return false;
 
         entity.getRoles().remove(role);
         entity.getDefaultRoles().remove(role);
         em.createNativeQuery("delete from COMPOSITE_ROLE where CHILD_ROLE = :role").setParameter("role", role).executeUpdate();
         em.createNamedQuery("deleteScopeMappingByRole").setParameter("role", role).executeUpdate();
-        role.setApplication(null);
+        role.setClient(null);
         em.flush();
         em.remove(role);
         em.flush();
diff --git a/model/jpa/src/main/java/org/keycloak/models/jpa/entities/ClientEntity.java b/model/jpa/src/main/java/org/keycloak/models/jpa/entities/ClientEntity.java
index 4705847..26322d4 100755
--- a/model/jpa/src/main/java/org/keycloak/models/jpa/entities/ClientEntity.java
+++ b/model/jpa/src/main/java/org/keycloak/models/jpa/entities/ClientEntity.java
@@ -96,7 +96,7 @@ public class ClientEntity {
     @Column(name="NODE_REREG_TIMEOUT")
     private int nodeReRegistrationTimeout;
 
-    @OneToMany(fetch = FetchType.EAGER, cascade ={CascadeType.REMOVE}, orphanRemoval = true, mappedBy = "application")
+    @OneToMany(fetch = FetchType.EAGER, cascade ={CascadeType.REMOVE}, orphanRemoval = true, mappedBy = "client")
     Collection<RoleEntity> roles = new ArrayList<RoleEntity>();
 
     @OneToMany(fetch = FetchType.LAZY, cascade ={CascadeType.REMOVE}, orphanRemoval = true)
diff --git a/model/jpa/src/main/java/org/keycloak/models/jpa/entities/RoleEntity.java b/model/jpa/src/main/java/org/keycloak/models/jpa/entities/RoleEntity.java
index ffbd711..262a469 100755
--- a/model/jpa/src/main/java/org/keycloak/models/jpa/entities/RoleEntity.java
+++ b/model/jpa/src/main/java/org/keycloak/models/jpa/entities/RoleEntity.java
@@ -21,11 +21,11 @@ import java.util.Collection;
  */
 @Entity
 @Table(name="KEYCLOAK_ROLE", uniqueConstraints = {
-        @UniqueConstraint(columnNames = { "NAME", "APP_REALM_CONSTRAINT" })
+        @UniqueConstraint(columnNames = { "NAME", "CLIENT_REALM_CONSTRAINT" })
 })
 @NamedQueries({
-        @NamedQuery(name="getAppRoleByName", query="select role from RoleEntity role where role.name = :name and role.application = :application"),
-        @NamedQuery(name="getRealmRoleByName", query="select role from RoleEntity role where role.applicationRole = false and role.name = :name and role.realm = :realm")
+        @NamedQuery(name="getClientRoleByName", query="select role from RoleEntity role where role.name = :name and role.client = :client"),
+        @NamedQuery(name="getRealmRoleByName", query="select role from RoleEntity role where role.clientRole = false and role.name = :name and role.realm = :realm")
 })
 
 public class RoleEntity {
@@ -46,16 +46,16 @@ public class RoleEntity {
     @JoinColumn(name = "REALM")
     private RealmEntity realm;
 
-    @Column(name="APPLICATION_ROLE")
-    private boolean applicationRole;
+    @Column(name="CLIENT_ROLE")
+    private boolean clientRole;
 
     @ManyToOne(fetch = FetchType.LAZY)
-    @JoinColumn(name = "APPLICATION")
-    private ClientEntity application;
+    @JoinColumn(name = "CLIENT")
+    private ClientEntity client;
 
-    // Hack to ensure that either name+application or name+realm are unique. Needed due to MS-SQL as it don't allow multiple NULL values in the column, which is part of constraint
-    @Column(name="APP_REALM_CONSTRAINT", length = 36)
-    private String appRealmConstraint;
+    // Hack to ensure that either name+client or name+realm are unique. Needed due to MS-SQL as it don't allow multiple NULL values in the column, which is part of constraint
+    @Column(name="CLIENT_REALM_CONSTRAINT", length = 36)
+    private String clientRealmConstraint;
 
     @ManyToMany(fetch = FetchType.LAZY, cascade = {})
     @JoinTable(name = "COMPOSITE_ROLE", joinColumns = @JoinColumn(name = "COMPOSITE"), inverseJoinColumns = @JoinColumn(name = "CHILD_ROLE"))
@@ -101,12 +101,12 @@ public class RoleEntity {
         this.compositeRoles = compositeRoles;
     }
 
-    public boolean isApplicationRole() {
-        return applicationRole;
+    public boolean isClientRole() {
+        return clientRole;
     }
 
-    public void setApplicationRole(boolean applicationRole) {
-        this.applicationRole = applicationRole;
+    public void setClientRole(boolean clientRole) {
+        this.clientRole = clientRole;
     }
 
     public RealmEntity getRealm() {
@@ -115,26 +115,26 @@ public class RoleEntity {
 
     public void setRealm(RealmEntity realm) {
         this.realm = realm;
-        this.appRealmConstraint = realm.getId();
+        this.clientRealmConstraint = realm.getId();
     }
 
-    public ClientEntity getApplication() {
-        return application;
+    public ClientEntity getClient() {
+        return client;
     }
 
-    public void setApplication(ClientEntity application) {
-        this.application = application;
-        if (application != null) {
-            this.appRealmConstraint = application.getId();
+    public void setClient(ClientEntity client) {
+        this.client = client;
+        if (client != null) {
+            this.clientRealmConstraint = client.getId();
         }
     }
 
-    public String getAppRealmConstraint() {
-        return appRealmConstraint;
+    public String getClientRealmConstraint() {
+        return clientRealmConstraint;
     }
 
-    public void setAppRealmConstraint(String appRealmConstraint) {
-        this.appRealmConstraint = appRealmConstraint;
+    public void setClientRealmConstraint(String clientRealmConstraint) {
+        this.clientRealmConstraint = clientRealmConstraint;
     }
 
     @Override
diff --git a/model/jpa/src/main/java/org/keycloak/models/jpa/RoleAdapter.java b/model/jpa/src/main/java/org/keycloak/models/jpa/RoleAdapter.java
index 1687855..4a8e258 100755
--- a/model/jpa/src/main/java/org/keycloak/models/jpa/RoleAdapter.java
+++ b/model/jpa/src/main/java/org/keycloak/models/jpa/RoleAdapter.java
@@ -104,8 +104,8 @@ public class RoleAdapter implements RoleModel {
 
     @Override
     public RoleContainerModel getContainer() {
-        if (role.isApplicationRole()) {
-            return realm.getClientById(role.getApplication().getId());
+        if (role.isClientRole()) {
+            return realm.getClientById(role.getClient().getId());
 
         } else {
             return realm;