diff --git a/admin-ui/src/main/resources/META-INF/resources/admin/js/app.js b/admin-ui/src/main/resources/META-INF/resources/admin/js/app.js
index 58c51467ae..17cbe664ef 100755
--- a/admin-ui/src/main/resources/META-INF/resources/admin/js/app.js
+++ b/admin-ui/src/main/resources/META-INF/resources/admin/js/app.js
@@ -349,18 +349,6 @@ module.config([ '$routeProvider', function($routeProvider) {
},
controller : 'ApplicationInstallationCtrl'
})
- .when('/realms/:realm/applications/:application/sessions', {
- templateUrl : 'partials/application-sessions.html',
- resolve : {
- realm : function(RealmLoader) {
- return RealmLoader();
- },
- application : function(ApplicationLoader) {
- return ApplicationLoader();
- }
- },
- controller : 'ApplicationSessionsCtrl'
- })
.when('/create/application/:realm', {
templateUrl : 'partials/application-detail.html',
resolve : {
diff --git a/admin-ui/src/main/resources/META-INF/resources/admin/js/controllers/applications.js b/admin-ui/src/main/resources/META-INF/resources/admin/js/controllers/applications.js
index 8bcacd1f62..5bfb651767 100755
--- a/admin-ui/src/main/resources/META-INF/resources/admin/js/controllers/applications.js
+++ b/admin-ui/src/main/resources/META-INF/resources/admin/js/controllers/applications.js
@@ -3,6 +3,10 @@ module.controller('ApplicationRoleListCtrl', function($scope, $location, realm,
$scope.roles = roles;
$scope.application = application;
+ for (var i = 0; i < roles.length; i++) {
+ console.log("role.id: " + roles[i].id + " role.name: " + roles[i].name);
+ }
+
$scope.$watch(function() {
return $location.path();
}, function() {
@@ -39,11 +43,6 @@ module.controller('ApplicationCredentialsCtrl', function($scope, $location, real
});
});
-module.controller('ApplicationSessionsCtrl', function($scope, $location, realm, application) {
- $scope.realm = realm;
- $scope.application = application;
-});
-
module.controller('ApplicationClaimsCtrl', function($scope, realm, application, claims,
ApplicationClaims,
$http, $location, Dialog, Notifications) {
diff --git a/admin-ui/src/main/resources/META-INF/resources/admin/js/controllers/realm.js b/admin-ui/src/main/resources/META-INF/resources/admin/js/controllers/realm.js
index 0a123bc9de..c83ddbc245 100755
--- a/admin-ui/src/main/resources/META-INF/resources/admin/js/controllers/realm.js
+++ b/admin-ui/src/main/resources/META-INF/resources/admin/js/controllers/realm.js
@@ -510,7 +510,7 @@ module.controller('RealmDefaultRolesCtrl', function ($scope, Realm, realm, appli
// Update/save the selected application with new default roles.
Application.update({
realm: $scope.realm.realm,
- id: $scope.application.name
+ application: $scope.application.name
}, $scope.application, function () {
Notifications.success("Your changes have been saved to the application.");
});
@@ -534,7 +534,7 @@ module.controller('RealmDefaultRolesCtrl', function ($scope, Realm, realm, appli
// Update/save the selected application with new default roles.
Application.update({
realm: $scope.realm.realm,
- id: $scope.application.name
+ application: $scope.application.name
}, $scope.application, function () {
Notifications.success("Your changes have been saved to the application.");
});
diff --git a/admin-ui/src/main/resources/META-INF/resources/admin/partials/application-claims.html b/admin-ui/src/main/resources/META-INF/resources/admin/partials/application-claims.html
index d20118563f..72ba62f22f 100755
--- a/admin-ui/src/main/resources/META-INF/resources/admin/partials/application-claims.html
+++ b/admin-ui/src/main/resources/META-INF/resources/admin/partials/application-claims.html
@@ -7,7 +7,6 @@
Roles
Claims
Scope
- Sessions
diff --git a/admin-ui/src/main/resources/META-INF/resources/admin/partials/application-credentials.html b/admin-ui/src/main/resources/META-INF/resources/admin/partials/application-credentials.html
index eda151816c..d7045ee8d6 100755
--- a/admin-ui/src/main/resources/META-INF/resources/admin/partials/application-credentials.html
+++ b/admin-ui/src/main/resources/META-INF/resources/admin/partials/application-credentials.html
@@ -7,7 +7,6 @@
- Roles
- Claims
- Scope
- - Sessions
diff --git a/admin-ui/src/main/resources/META-INF/resources/admin/partials/application-detail.html b/admin-ui/src/main/resources/META-INF/resources/admin/partials/application-detail.html
index 70491bb186..84e188cf16 100755
--- a/admin-ui/src/main/resources/META-INF/resources/admin/partials/application-detail.html
+++ b/admin-ui/src/main/resources/META-INF/resources/admin/partials/application-detail.html
@@ -7,7 +7,6 @@
- Roles
- Claims
- Scope
- - Sessions
diff --git a/admin-ui/src/main/resources/META-INF/resources/admin/partials/application-installation.html b/admin-ui/src/main/resources/META-INF/resources/admin/partials/application-installation.html
index d6ffd1edae..e446a1cd37 100755
--- a/admin-ui/src/main/resources/META-INF/resources/admin/partials/application-installation.html
+++ b/admin-ui/src/main/resources/META-INF/resources/admin/partials/application-installation.html
@@ -8,7 +8,6 @@
- Roles
- Claims
- Scope
- - Sessions
diff --git a/admin-ui/src/main/resources/META-INF/resources/admin/partials/application-role-detail.html b/admin-ui/src/main/resources/META-INF/resources/admin/partials/application-role-detail.html
index 3a93fc66e8..2e0f892a78 100755
--- a/admin-ui/src/main/resources/META-INF/resources/admin/partials/application-role-detail.html
+++ b/admin-ui/src/main/resources/META-INF/resources/admin/partials/application-role-detail.html
@@ -7,7 +7,6 @@
- Roles
- Claims
- Scope
-
- Sessions
diff --git a/admin-ui/src/main/resources/META-INF/resources/admin/partials/application-role-list.html b/admin-ui/src/main/resources/META-INF/resources/admin/partials/application-role-list.html
index 40e8d4d859..0bc76e786f 100755
--- a/admin-ui/src/main/resources/META-INF/resources/admin/partials/application-role-list.html
+++ b/admin-ui/src/main/resources/META-INF/resources/admin/partials/application-role-list.html
@@ -8,7 +8,6 @@
- Roles
- Claims
- Scope
-
- Sessions
diff --git a/admin-ui/src/main/resources/META-INF/resources/admin/partials/application-scope-mappings.html b/admin-ui/src/main/resources/META-INF/resources/admin/partials/application-scope-mappings.html
index 98fa8ea6cc..64a755bf83 100755
--- a/admin-ui/src/main/resources/META-INF/resources/admin/partials/application-scope-mappings.html
+++ b/admin-ui/src/main/resources/META-INF/resources/admin/partials/application-scope-mappings.html
@@ -8,7 +8,6 @@
- Roles
- Claims
- Scope
-
- Sessions
diff --git a/admin-ui/src/main/resources/META-INF/resources/admin/partials/application-sessions.html b/admin-ui/src/main/resources/META-INF/resources/admin/partials/application-sessions.html
deleted file mode 100755
index 432ae2aea1..0000000000
--- a/admin-ui/src/main/resources/META-INF/resources/admin/partials/application-sessions.html
+++ /dev/null
@@ -1,23 +0,0 @@
-
-
-
-
-
-
-
- - {{realm.realm}}
- - Applications
- - {{application.name}}
- - Sessions
-
-
{{application.name}} Sessions (Placeholder Page)
-
-
diff --git a/model/api/src/main/java/org/keycloak/models/ClientModel.java b/model/api/src/main/java/org/keycloak/models/ClientModel.java
index cc7eaff85a..46a71031dd 100755
--- a/model/api/src/main/java/org/keycloak/models/ClientModel.java
+++ b/model/api/src/main/java/org/keycloak/models/ClientModel.java
@@ -49,4 +49,6 @@ public interface ClientModel {
boolean validateSecret(String secret);
String getSecret();
public void setSecret(String secret);
+
+ RealmModel getRealm();
}
diff --git a/model/api/src/main/java/org/keycloak/models/RealmModel.java b/model/api/src/main/java/org/keycloak/models/RealmModel.java
index 43dda29a6d..89592e8b2e 100755
--- a/model/api/src/main/java/org/keycloak/models/RealmModel.java
+++ b/model/api/src/main/java/org/keycloak/models/RealmModel.java
@@ -101,6 +101,8 @@ public interface RealmModel extends RoleContainerModel, RoleMapperModel, ScopeMa
boolean removeUser(String name);
+ RoleModel getRoleById(String id);
+
List
getDefaultRoles();
void addDefaultRole(String name);
@@ -182,4 +184,6 @@ public interface RealmModel extends RoleContainerModel, RoleMapperModel, ScopeMa
int getNotBefore();
void setNotBefore(int notBefore);
+
+ boolean removeRoleById(String id);
}
diff --git a/model/api/src/main/java/org/keycloak/models/RoleContainerModel.java b/model/api/src/main/java/org/keycloak/models/RoleContainerModel.java
index bd8bfab1e7..62ecfdb7f4 100755
--- a/model/api/src/main/java/org/keycloak/models/RoleContainerModel.java
+++ b/model/api/src/main/java/org/keycloak/models/RoleContainerModel.java
@@ -12,9 +12,8 @@ public interface RoleContainerModel {
RoleModel addRole(String name);
- boolean removeRoleById(String id);
+ boolean removeRole(RoleModel role);
Set getRoles();
- RoleModel getRoleById(String id);
}
diff --git a/model/api/src/main/java/org/keycloak/models/SocialLinkModel.java b/model/api/src/main/java/org/keycloak/models/SocialLinkModel.java
index a484477b9d..742da1112e 100755
--- a/model/api/src/main/java/org/keycloak/models/SocialLinkModel.java
+++ b/model/api/src/main/java/org/keycloak/models/SocialLinkModel.java
@@ -1,31 +1,31 @@
-package org.keycloak.models;
-
-/**
- * @author Marek Posolda
- */
-public class SocialLinkModel {
-
- private String socialUsername;
- private String socialProvider;
-
- public SocialLinkModel(String socialProvider, String socialUsername) {
- this.socialUsername = socialUsername;
- this.socialProvider = socialProvider;
- }
-
- public String getSocialUsername() {
- return socialUsername;
- }
-
- public void setSocialUsername(String socialUsername) {
- this.socialUsername = socialUsername;
- }
-
- public String getSocialProvider() {
- return socialProvider;
- }
-
- public void setSocialProvider(String socialProvider) {
- this.socialProvider = socialProvider;
- }
-}
+package org.keycloak.models;
+
+/**
+ * @author Marek Posolda
+ */
+public class SocialLinkModel {
+
+ private String socialUsername;
+ private String socialProvider;
+
+ public SocialLinkModel(String socialProvider, String socialUsername) {
+ this.socialUsername = socialUsername;
+ this.socialProvider = socialProvider;
+ }
+
+ public String getSocialUsername() {
+ return socialUsername;
+ }
+
+ public void setSocialUsername(String socialUsername) {
+ this.socialUsername = socialUsername;
+ }
+
+ public String getSocialProvider() {
+ return socialProvider;
+ }
+
+ public void setSocialProvider(String socialProvider) {
+ this.socialProvider = socialProvider;
+ }
+}
diff --git a/model/api/src/main/java/org/keycloak/models/UserCredentialModel.java b/model/api/src/main/java/org/keycloak/models/UserCredentialModel.java
index 510f852249..d096b97320 100755
--- a/model/api/src/main/java/org/keycloak/models/UserCredentialModel.java
+++ b/model/api/src/main/java/org/keycloak/models/UserCredentialModel.java
@@ -1,69 +1,69 @@
-package org.keycloak.models;
-
-import java.util.UUID;
-
-/**
- * @author Bill Burke
- * @version $Revision: 1 $
- */
-public class UserCredentialModel {
- public static final String PASSWORD = "password";
-
- // Secret is same as password but it is not hashed
- public static final String SECRET = "secret";
- public static final String TOTP = "totp";
- public static final String CLIENT_CERT = "cert";
-
- protected String type;
- protected String value;
- protected String device;
-
- public UserCredentialModel() {
- }
-
- public static UserCredentialModel password(String password) {
- UserCredentialModel model = new UserCredentialModel();
- model.setType(PASSWORD);
- model.setValue(password);
- return model;
- }
-
- public static UserCredentialModel secret(String password) {
- UserCredentialModel model = new UserCredentialModel();
- model.setType(SECRET);
- model.setValue(password);
- return model;
- }
-
- public static UserCredentialModel generateSecret() {
- UserCredentialModel model = new UserCredentialModel();
- model.setType(SECRET);
- model.setValue(UUID.randomUUID().toString());
- return model;
- }
-
-
- public String getType() {
- return type;
- }
-
- public void setType(String type) {
- this.type = type;
- }
-
- public String getValue() {
- return value;
- }
-
- public void setValue(String value) {
- this.value = value;
- }
-
- public String getDevice() {
- return device;
- }
-
- public void setDevice(String device) {
- this.device = device;
- }
-}
+package org.keycloak.models;
+
+import java.util.UUID;
+
+/**
+ * @author Bill Burke
+ * @version $Revision: 1 $
+ */
+public class UserCredentialModel {
+ public static final String PASSWORD = "password";
+
+ // Secret is same as password but it is not hashed
+ public static final String SECRET = "secret";
+ public static final String TOTP = "totp";
+ public static final String CLIENT_CERT = "cert";
+
+ protected String type;
+ protected String value;
+ protected String device;
+
+ public UserCredentialModel() {
+ }
+
+ public static UserCredentialModel password(String password) {
+ UserCredentialModel model = new UserCredentialModel();
+ model.setType(PASSWORD);
+ model.setValue(password);
+ return model;
+ }
+
+ public static UserCredentialModel secret(String password) {
+ UserCredentialModel model = new UserCredentialModel();
+ model.setType(SECRET);
+ model.setValue(password);
+ return model;
+ }
+
+ public static UserCredentialModel generateSecret() {
+ UserCredentialModel model = new UserCredentialModel();
+ model.setType(SECRET);
+ model.setValue(UUID.randomUUID().toString());
+ return model;
+ }
+
+
+ public String getType() {
+ return type;
+ }
+
+ public void setType(String type) {
+ this.type = type;
+ }
+
+ public String getValue() {
+ return value;
+ }
+
+ public void setValue(String value) {
+ this.value = value;
+ }
+
+ public String getDevice() {
+ return device;
+ }
+
+ public void setDevice(String device) {
+ this.device = device;
+ }
+}
diff --git a/model/jpa/src/main/java/org/keycloak/models/jpa/ApplicationAdapter.java b/model/jpa/src/main/java/org/keycloak/models/jpa/ApplicationAdapter.java
index 69c30ec4eb..371a43a54e 100755
--- a/model/jpa/src/main/java/org/keycloak/models/jpa/ApplicationAdapter.java
+++ b/model/jpa/src/main/java/org/keycloak/models/jpa/ApplicationAdapter.java
@@ -24,10 +24,9 @@ public class ApplicationAdapter extends ClientAdapter implements ApplicationMode
protected EntityManager em;
protected ApplicationEntity applicationEntity;
- protected RealmModel realm;
public ApplicationAdapter(RealmModel realm, EntityManager em, ApplicationEntity applicationEntity) {
- super(applicationEntity);
+ super(realm, applicationEntity);
this.realm = realm;
this.em = em;
this.applicationEntity = applicationEntity;
@@ -48,7 +47,6 @@ public class ApplicationAdapter extends ClientAdapter implements ApplicationMode
entity.setName(name);
}
-
@Override
public boolean isSurrogateAuthRequired() {
return applicationEntity.isSurrogateAuthRequired();
@@ -103,11 +101,14 @@ public class ApplicationAdapter extends ClientAdapter implements ApplicationMode
}
@Override
- public boolean removeRoleById(String id) {
- RoleAdapter roleAdapter = getRoleById(id);
+ public boolean removeRole(RoleModel roleModel) {
+ RoleAdapter roleAdapter = (RoleAdapter)roleModel;
if (roleAdapter == null) {
return false;
}
+ if (!roleAdapter.getContainer().equals(this)) return false;
+
+ if (!(roleAdapter.getRole() instanceof ApplicationRoleEntity)) return false;
ApplicationRoleEntity role = (ApplicationRoleEntity)roleAdapter.getRole();
@@ -134,16 +135,6 @@ public class ApplicationAdapter extends ClientAdapter implements ApplicationMode
return list;
}
- @Override
- public RoleAdapter getRoleById(String id) {
- RoleEntity entity = em.find(RoleEntity.class, id);
-
- // Check if it's application role and belongs to this application
- if (entity == null || !(entity instanceof ApplicationRoleEntity)) return null;
- ApplicationRoleEntity appRoleEntity = (ApplicationRoleEntity)entity;
- return (appRoleEntity.getApplication().equals(this.entity)) ? new RoleAdapter(this.realm, em, appRoleEntity) : null;
- }
-
@Override
public Set getApplicationRoleMappings(UserModel user) {
Set roleMappings = realm.getRoleMappings(user);
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 2ec95ec59c..7dcd3d9232 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
@@ -1,6 +1,7 @@
package org.keycloak.models.jpa;
import org.keycloak.models.ClientModel;
+import org.keycloak.models.RealmModel;
import org.keycloak.models.jpa.entities.ClientEntity;
import org.keycloak.models.jpa.entities.OAuthClientEntity;
@@ -13,8 +14,10 @@ import java.util.Set;
*/
public class ClientAdapter implements ClientModel {
protected ClientEntity entity;
+ protected RealmModel realm;
- public ClientAdapter(ClientEntity entity) {
+ public ClientAdapter(RealmModel realm, ClientEntity entity) {
+ this.realm = realm;
this.entity = entity;
}
@@ -22,75 +25,111 @@ public class ClientAdapter implements ClientModel {
return entity;
}
+ @Override
public String getId() {
return entity.getId();
}
+ @Override
+ public RealmModel getRealm() {
+ return realm;
+ }
+
+ @Override
public String getClientId() {
return entity.getName();
}
+ @Override
public boolean isEnabled() {
return entity.isEnabled();
}
+ @Override
public void setEnabled(boolean enabled) {
entity.setEnabled(enabled);
}
+ @Override
public long getAllowedClaimsMask() {
return entity.getAllowedClaimsMask();
}
+ @Override
public void setAllowedClaimsMask(long mask) {
entity.setAllowedClaimsMask(mask);
}
+ @Override
public Set getWebOrigins() {
Set result = new HashSet();
result.addAll(entity.getWebOrigins());
return result;
}
+ @Override
public void setWebOrigins(Set webOrigins) {
entity.setWebOrigins(webOrigins);
}
+ @Override
public void addWebOrigin(String webOrigin) {
entity.getWebOrigins().add(webOrigin);
}
+ @Override
public void removeWebOrigin(String webOrigin) {
entity.getWebOrigins().remove(webOrigin);
}
+ @Override
public Set getRedirectUris() {
Set result = new HashSet();
result.addAll(entity.getRedirectUris());
return result;
}
+ @Override
public void setRedirectUris(Set redirectUris) {
entity.setRedirectUris(redirectUris);
}
+ @Override
public void addRedirectUri(String redirectUri) {
entity.getRedirectUris().add(redirectUri);
}
+ @Override
public void removeRedirectUri(String redirectUri) {
entity.getRedirectUris().remove(redirectUri);
}
+ @Override
public String getSecret() {
return entity.getSecret();
}
+ @Override
public void setSecret(String secret) {
entity.setSecret(secret);
}
+ @Override
public boolean validateSecret(String secret) {
return secret.equals(entity.getSecret());
}
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (!this.getClass().equals(o.getClass())) return false;
+
+ ClientAdapter that = (ClientAdapter) o;
+ return that.getId().equals(getId());
+ }
+
+ @Override
+ public int hashCode() {
+ return entity.getId().hashCode();
+ }
}
diff --git a/model/jpa/src/main/java/org/keycloak/models/jpa/OAuthClientAdapter.java b/model/jpa/src/main/java/org/keycloak/models/jpa/OAuthClientAdapter.java
index 692a4e1102..29d643d084 100755
--- a/model/jpa/src/main/java/org/keycloak/models/jpa/OAuthClientAdapter.java
+++ b/model/jpa/src/main/java/org/keycloak/models/jpa/OAuthClientAdapter.java
@@ -1,6 +1,7 @@
package org.keycloak.models.jpa;
import org.keycloak.models.OAuthClientModel;
+import org.keycloak.models.RealmModel;
import org.keycloak.models.UserModel;
import org.keycloak.models.jpa.entities.OAuthClientEntity;
@@ -13,7 +14,9 @@ import java.util.Set;
*/
public class OAuthClientAdapter extends ClientAdapter implements OAuthClientModel {
- public OAuthClientAdapter(OAuthClientEntity entity) {
- super(entity);
+ public OAuthClientAdapter(RealmModel realm, OAuthClientEntity entity) {
+ super(realm, entity);
}
+
+
}
diff --git a/model/jpa/src/main/java/org/keycloak/models/jpa/RealmAdapter.java b/model/jpa/src/main/java/org/keycloak/models/jpa/RealmAdapter.java
index d81b2a027b..f7e17ce17b 100755
--- a/model/jpa/src/main/java/org/keycloak/models/jpa/RealmAdapter.java
+++ b/model/jpa/src/main/java/org/keycloak/models/jpa/RealmAdapter.java
@@ -3,6 +3,7 @@ package org.keycloak.models.jpa;
import org.keycloak.models.ClientModel;
import org.keycloak.models.RoleContainerModel;
import org.keycloak.models.jpa.entities.ApplicationEntity;
+import org.keycloak.models.jpa.entities.ApplicationRoleEntity;
import org.keycloak.models.jpa.entities.CredentialEntity;
import org.keycloak.models.jpa.entities.OAuthClientEntity;
import org.keycloak.models.jpa.entities.RealmEntity;
@@ -496,7 +497,7 @@ public class RealmAdapter implements RealmModel {
if (application == null) return false;
for (RoleModel role : application.getRoles()) {
- application.removeRoleById(role.getId());
+ application.removeRole(role);
}
ApplicationEntity applicationEntity = null;
@@ -673,12 +674,14 @@ public class RealmAdapter implements RealmModel {
data.setRealm(realm);
em.persist(data);
em.flush();
- return new OAuthClientAdapter(data);
+ return new OAuthClientAdapter(this, data);
}
@Override
public boolean removeOAuthClient(String id) {
- OAuthClientEntity client = em.find(OAuthClientEntity.class, id);
+ OAuthClientModel oauth = getOAuthClientById(id);
+ if (oauth == null) return false;
+ OAuthClientEntity client = (OAuthClientEntity)((OAuthClientAdapter)oauth).getEntity();
em.createQuery("delete from " + ScopeMappingEntity.class.getSimpleName() + " where client = :client").setParameter("client", client).executeUpdate();
em.remove(client);
return true;
@@ -692,7 +695,7 @@ public class RealmAdapter implements RealmModel {
query.setParameter("realm", realm);
List entities = query.getResultList();
if (entities.size() == 0) return null;
- return new OAuthClientAdapter(entities.get(0));
+ return new OAuthClientAdapter(this, entities.get(0));
}
@Override
@@ -700,8 +703,8 @@ public class RealmAdapter implements RealmModel {
OAuthClientEntity client = em.find(OAuthClientEntity.class, id);
// Check if client belongs to this realm
- if (client == null || !this.realm.equals(client.getRealm())) return null;
- return new OAuthClientAdapter(client);
+ if (client == null || !this.realm.getId().equals(client.getRealm().getId())) return null;
+ return new OAuthClientAdapter(this, client);
}
@@ -711,7 +714,7 @@ public class RealmAdapter implements RealmModel {
query.setParameter("realm", realm);
List entities = query.getResultList();
List list = new ArrayList();
- for (OAuthClientEntity entity : entities) list.add(new OAuthClientAdapter(entity));
+ for (OAuthClientEntity entity : entities) list.add(new OAuthClientAdapter(this, entity));
return list;
}
@@ -761,12 +764,12 @@ public class RealmAdapter implements RealmModel {
}
@Override
- public boolean removeRoleById(String id) {
- RoleModel role = getRoleById(id);
-
+ public boolean removeRole(RoleModel role) {
if (role == null) {
return false;
}
+ if (!role.getContainer().equals(this)) return false;
+
RoleEntity roleEntity = ((RoleAdapter)role).getRole();
realm.getRoles().remove(role);
realm.getDefaultRoles().remove(role);
@@ -793,11 +796,22 @@ public class RealmAdapter implements RealmModel {
@Override
public RoleModel getRoleById(String id) {
RoleEntity entity = em.find(RoleEntity.class, id);
+ if (entity == null) return null;
+ if (entity instanceof RealmRoleEntity) {
+ RealmRoleEntity roleEntity = (RealmRoleEntity)entity;
+ if (!roleEntity.getRealm().getId().equals(getId())) return null;
+ } else {
+ ApplicationRoleEntity roleEntity = (ApplicationRoleEntity)entity;
+ if (!roleEntity.getApplication().getRealm().getId().equals(getId())) return null;
+ }
+ return new RoleAdapter(this, em, entity);
+ }
- // Check if it's realm role and belongs to this realm
- if (entity == null || !(entity instanceof RealmRoleEntity)) return null;
- RealmRoleEntity realmRoleEntity = (RealmRoleEntity)entity;
- return (realmRoleEntity.getRealm().equals(this.realm)) ? new RoleAdapter(this, em, realmRoleEntity) : null;
+ @Override
+ public boolean removeRoleById(String id) {
+ RoleModel role = getRoleById(id);
+ if (role == null) return false;
+ return role.getContainer().removeRole(role);
}
@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 e418441de2..421cffad3d 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
@@ -124,13 +124,13 @@ public class RoleAdapter implements RoleModel {
RoleAdapter that = (RoleAdapter) o;
- if (!role.equals(that.role)) return false;
+ if (!role.getId().equals(that.role.getId())) return false;
return true;
}
@Override
public int hashCode() {
- return role.hashCode();
+ return role.getId().hashCode();
}
}
diff --git a/model/jpa/src/test/resources/META-INF/persistence.xml b/model/jpa/src/test/resources/META-INF/persistence.xml
index 8fa01f2dfd..b6b99bb4b4 100755
--- a/model/jpa/src/test/resources/META-INF/persistence.xml
+++ b/model/jpa/src/test/resources/META-INF/persistence.xml
@@ -1,66 +1,66 @@
-
-
- org.hibernate.ejb.HibernatePersistence
-
- org.keycloak.models.jpa.entities.ApplicationEntity
- org.keycloak.models.jpa.entities.CredentialEntity
- org.keycloak.models.jpa.entities.OAuthClientEntity
- org.keycloak.models.jpa.entities.RealmEntity
- org.keycloak.models.jpa.entities.RequiredCredentialEntity
- org.keycloak.models.jpa.entities.ApplicationRoleEntity
- org.keycloak.models.jpa.entities.RealmRoleEntity
- org.keycloak.models.jpa.entities.SocialLinkEntity
- org.keycloak.models.jpa.entities.UserEntity
- org.keycloak.models.jpa.entities.UserRoleMappingEntity
- org.keycloak.models.jpa.entities.ScopeMappingEntity
-
- true
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+ org.hibernate.ejb.HibernatePersistence
+
+ org.keycloak.models.jpa.entities.ApplicationEntity
+ org.keycloak.models.jpa.entities.CredentialEntity
+ org.keycloak.models.jpa.entities.OAuthClientEntity
+ org.keycloak.models.jpa.entities.RealmEntity
+ org.keycloak.models.jpa.entities.RequiredCredentialEntity
+ org.keycloak.models.jpa.entities.ApplicationRoleEntity
+ org.keycloak.models.jpa.entities.RealmRoleEntity
+ org.keycloak.models.jpa.entities.SocialLinkEntity
+ org.keycloak.models.jpa.entities.UserEntity
+ org.keycloak.models.jpa.entities.UserRoleMappingEntity
+ org.keycloak.models.jpa.entities.ScopeMappingEntity
+
+ true
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/model/mongo/pom.xml b/model/mongo/pom.xml
index 417249ba39..2ed8d457f5 100755
--- a/model/mongo/pom.xml
+++ b/model/mongo/pom.xml
@@ -1,138 +1,138 @@
-
-
-
- keycloak-parent
- org.keycloak
- 1.0-alpha-3-SNAPSHOT
- ../../pom.xml
-
- 4.0.0
-
- keycloak-model-mongo
- Keycloak Model Mongo
-
-
-
-
- org.bouncycastle
- bcprov-jdk16
- provided
-
-
- org.keycloak
- keycloak-core
- ${project.version}
- provided
-
-
- org.keycloak
- keycloak-model-api
- ${project.version}
-
-
- org.jboss.logging
- jboss-logging
- provided
-
-
- org.picketlink
- picketlink-common
- provided
-
-
- org.mongodb
- mongo-java-driver
- provided
-
-
-
- org.keycloak
- keycloak-model-tests
- ${project.version}
- tests
- test
-
-
-
-
- localhost
- 27018
- keycloak
- true
-
-
-
-
-
- org.apache.maven.plugins
- maven-compiler-plugin
-
-
- 1.6
-
-
-
-
-
- org.apache.maven.plugins
- maven-surefire-plugin
-
-
- test
- integration-test
-
- test
-
-
-
- ${keycloak.mongo.host}
- ${keycloak.mongo.port}
- ${keycloak.mongo.db}
- ${keycloak.mongo.clearOnStartup}
-
-
- org.keycloak:keycloak-model-tests
-
-
-
-
- default-test
-
- true
-
-
-
-
-
-
-
- com.github.joelittlejohn.embedmongo
- embedmongo-maven-plugin
-
-
- start-mongodb
- pre-integration-test
-
- start
-
-
- ${keycloak.mongo.port}
- file
- ${project.build.directory}/mongodb.log
-
-
-
- stop-mongodb
- post-integration-test
-
- stop
-
-
-
-
-
-
-
+
+
+
+ keycloak-parent
+ org.keycloak
+ 1.0-alpha-3-SNAPSHOT
+ ../../pom.xml
+
+ 4.0.0
+
+ keycloak-model-mongo
+ Keycloak Model Mongo
+
+
+
+
+ org.bouncycastle
+ bcprov-jdk16
+ provided
+
+
+ org.keycloak
+ keycloak-core
+ ${project.version}
+ provided
+
+
+ org.keycloak
+ keycloak-model-api
+ ${project.version}
+
+
+ org.jboss.logging
+ jboss-logging
+ provided
+
+
+ org.picketlink
+ picketlink-common
+ provided
+
+
+ org.mongodb
+ mongo-java-driver
+ provided
+
+
+
+ org.keycloak
+ keycloak-model-tests
+ ${project.version}
+ tests
+ test
+
+
+
+
+ localhost
+ 27018
+ keycloak
+ true
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+
+
+ 1.6
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+
+
+ test
+ integration-test
+
+ test
+
+
+
+ ${keycloak.mongo.host}
+ ${keycloak.mongo.port}
+ ${keycloak.mongo.db}
+ ${keycloak.mongo.clearOnStartup}
+
+
+ org.keycloak:keycloak-model-tests
+
+
+
+
+ default-test
+
+ true
+
+
+
+
+
+
+
+ com.github.joelittlejohn.embedmongo
+ embedmongo-maven-plugin
+
+
+ start-mongodb
+ pre-integration-test
+
+ start
+
+
+ ${keycloak.mongo.port}
+ file
+ ${project.build.directory}/mongodb.log
+
+
+
+ stop-mongodb
+ post-integration-test
+
+ stop
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/model/mongo/src/main/java/org/keycloak/models/mongo/api/MongoStore.java b/model/mongo/src/main/java/org/keycloak/models/mongo/api/MongoStore.java
index 9da25e5b4e..f16400c26d 100755
--- a/model/mongo/src/main/java/org/keycloak/models/mongo/api/MongoStore.java
+++ b/model/mongo/src/main/java/org/keycloak/models/mongo/api/MongoStore.java
@@ -1,43 +1,43 @@
-package org.keycloak.models.mongo.api;
-
-import com.mongodb.DBObject;
-import org.keycloak.models.mongo.api.context.MongoStoreInvocationContext;
-
-import java.util.List;
-
-/**
- * @author Marek Posolda
- */
-public interface MongoStore {
-
- /**
- * Insert new entity
- *
- * @param entity to insert
- */
- void insertEntity(MongoIdentifiableEntity entity, MongoStoreInvocationContext context);
-
- /**
- * Update existing entity
- *
- * @param entity to update
- */
- void updateEntity(MongoIdentifiableEntity entity, MongoStoreInvocationContext context);
-
-
- T loadEntity(Class type, String id, MongoStoreInvocationContext context);
-
- T loadSingleEntity(Class type, DBObject query, MongoStoreInvocationContext context);
-
- List loadEntities(Class type, DBObject query, MongoStoreInvocationContext context);
-
- boolean removeEntity(MongoIdentifiableEntity entity, MongoStoreInvocationContext context);
-
- boolean removeEntity(Class extends MongoIdentifiableEntity> type, String id, MongoStoreInvocationContext context);
-
- boolean removeEntities(Class extends MongoIdentifiableEntity> type, DBObject query, MongoStoreInvocationContext context);
-
- boolean pushItemToList(MongoIdentifiableEntity entity, String listPropertyName, S itemToPush, boolean skipIfAlreadyPresent, MongoStoreInvocationContext context);
-
- boolean pullItemFromList(MongoIdentifiableEntity entity, String listPropertyName, S itemToPull, MongoStoreInvocationContext context);
-}
+package org.keycloak.models.mongo.api;
+
+import com.mongodb.DBObject;
+import org.keycloak.models.mongo.api.context.MongoStoreInvocationContext;
+
+import java.util.List;
+
+/**
+ * @author Marek Posolda
+ */
+public interface MongoStore {
+
+ /**
+ * Insert new entity
+ *
+ * @param entity to insert
+ */
+ void insertEntity(MongoIdentifiableEntity entity, MongoStoreInvocationContext context);
+
+ /**
+ * Update existing entity
+ *
+ * @param entity to update
+ */
+ void updateEntity(MongoIdentifiableEntity entity, MongoStoreInvocationContext context);
+
+
+ T loadEntity(Class type, String id, MongoStoreInvocationContext context);
+
+ T loadSingleEntity(Class type, DBObject query, MongoStoreInvocationContext context);
+
+ List loadEntities(Class type, DBObject query, MongoStoreInvocationContext context);
+
+ boolean removeEntity(MongoIdentifiableEntity entity, MongoStoreInvocationContext context);
+
+ boolean removeEntity(Class extends MongoIdentifiableEntity> type, String id, MongoStoreInvocationContext context);
+
+ boolean removeEntities(Class extends MongoIdentifiableEntity> type, DBObject query, MongoStoreInvocationContext context);
+
+ boolean pushItemToList(MongoIdentifiableEntity entity, String listPropertyName, S itemToPush, boolean skipIfAlreadyPresent, MongoStoreInvocationContext context);
+
+ boolean pullItemFromList(MongoIdentifiableEntity entity, String listPropertyName, S itemToPull, MongoStoreInvocationContext context);
+}
diff --git a/model/mongo/src/main/java/org/keycloak/models/mongo/api/types/MapperRegistry.java b/model/mongo/src/main/java/org/keycloak/models/mongo/api/types/MapperRegistry.java
index 6da24b7e2b..d48fa589bc 100755
--- a/model/mongo/src/main/java/org/keycloak/models/mongo/api/types/MapperRegistry.java
+++ b/model/mongo/src/main/java/org/keycloak/models/mongo/api/types/MapperRegistry.java
@@ -1,111 +1,111 @@
-package org.keycloak.models.mongo.api.types;
-
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * Registry of mappers, which allow to convert application object to database objects. MapperRegistry is main entry point to be used by application.
- * Application can create instance of MapperRegistry and then register required Mapper objects.
- *
- * @author Marek Posolda
- */
-public class MapperRegistry {
-
- // TODO: Thread-safety support (maybe...)
- // Mappers of Application objects to DB objects
- private Map, Mapper, ?>> appObjectMappers = new HashMap, Mapper, ?>>();
-
- // Mappers of DB objects to Application objects
- private Map, Map, Mapper, ?>>> dbObjectMappers = new HashMap, Map, Mapper,?>>>();
-
-
- /**
- * Add mapper for converting application objects to DB objects
- *
- * @param mapper
- */
- public void addAppObjectMapper(Mapper, ?> mapper) {
- appObjectMappers.put(mapper.getTypeOfObjectToConvert(), mapper);
- }
-
-
- /**
- * Add mapper for converting DB objects to application objects
- *
- * @param mapper
- */
- public void addDBObjectMapper(Mapper, ?> mapper) {
- Class> dbObjectType = mapper.getTypeOfObjectToConvert();
- Class> appObjectType = mapper.getExpectedReturnType();
- Map, Mapper, ?>> appObjects = dbObjectMappers.get(dbObjectType);
- if (appObjects == null) {
- appObjects = new HashMap, Mapper, ?>>();
- dbObjectMappers.put(dbObjectType, appObjects);
- }
- appObjects.put(appObjectType, mapper);
- }
-
-
- public S convertDBObjectToApplicationObject(MapperContext