Fix testsuite with Mongo
This commit is contained in:
parent
15968e9783
commit
e85c2c9826
3 changed files with 14 additions and 23 deletions
|
@ -126,7 +126,9 @@ public class ApplicationAdapter extends AbstractAdapter implements ApplicationMo
|
|||
@Override
|
||||
public RoleModel getRoleById(String id) {
|
||||
RoleEntity role = getMongoStore().loadEntity(RoleEntity.class, id, invocationContext);
|
||||
if (role == null) {
|
||||
|
||||
// Check that role belongs to this application
|
||||
if (role == null || !getId().equals(role.getApplicationId())) {
|
||||
return null;
|
||||
} else {
|
||||
return new RoleAdapter(role, this, invocationContext);
|
||||
|
|
|
@ -316,13 +316,10 @@ public class RealmAdapter extends AbstractAdapter implements RealmModel {
|
|||
|
||||
@Override
|
||||
public UserModel getUserById(String id) {
|
||||
DBObject query = new QueryBuilder()
|
||||
.and("id").is(id)
|
||||
.and("realmId").is(getId())
|
||||
.get();
|
||||
UserEntity user = getMongoStore().loadSingleEntity(UserEntity.class, query, invocationContext);
|
||||
UserEntity user = getMongoStore().loadEntity(UserEntity.class, id, invocationContext);
|
||||
|
||||
if (user == null) {
|
||||
// Check that it's user from this realm
|
||||
if (user == null || !getId().equals(user.getRealmId())) {
|
||||
return null;
|
||||
} else {
|
||||
return new UserAdapter(user, invocationContext);
|
||||
|
@ -426,7 +423,7 @@ public class RealmAdapter extends AbstractAdapter implements RealmModel {
|
|||
@Override
|
||||
public RoleModel getRoleById(String id) {
|
||||
RoleEntity role = getMongoStore().loadEntity(RoleEntity.class, id, invocationContext);
|
||||
if (role == null) {
|
||||
if (role == null || !getId().equals(role.getRealmId())) {
|
||||
return null;
|
||||
} else {
|
||||
return new RoleAdapter(role, this, invocationContext);
|
||||
|
@ -660,7 +657,10 @@ public class RealmAdapter extends AbstractAdapter implements RealmModel {
|
|||
@Override
|
||||
public OAuthClientModel getOAuthClientById(String id) {
|
||||
OAuthClientEntity clientEntity = getMongoStore().loadEntity(OAuthClientEntity.class, id, invocationContext);
|
||||
if (clientEntity == null) return null;
|
||||
|
||||
// Check if client belongs to this realm
|
||||
if (clientEntity == null || !getId().equals(clientEntity.getRealmId())) return null;
|
||||
|
||||
return new OAuthClientAdapter(clientEntity, invocationContext);
|
||||
}
|
||||
|
||||
|
|
|
@ -3,13 +3,8 @@ package org.keycloak.model.test;
|
|||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.keycloak.models.RealmModel;
|
||||
import org.keycloak.models.RoleModel;
|
||||
import org.keycloak.models.UserModel;
|
||||
import org.keycloak.models.UserModel.RequiredAction;
|
||||
import org.keycloak.services.managers.RealmManager;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:sthorger@redhat.com">Stian Thorgersen</a>
|
||||
|
@ -36,6 +31,9 @@ public class UserModelTest extends AbstractModelTest {
|
|||
UserModel persisted = realmManager.getRealm(realm.getId()).getUser("user");
|
||||
|
||||
assertEquals(user, persisted);
|
||||
|
||||
UserModel persisted2 = realmManager.getRealm(realm.getId()).getUserById(user.getId());
|
||||
assertEquals(user, persisted2);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -108,14 +106,5 @@ public class UserModelTest extends AbstractModelTest {
|
|||
Assert.assertArrayEquals(expected.getWebOrigins().toArray(), actual.getWebOrigins().toArray());
|
||||
}
|
||||
|
||||
public static void assertEquals(List<RoleModel> expected, List<RoleModel> actual) {
|
||||
Assert.assertEquals(expected.size(), actual.size());
|
||||
Iterator<RoleModel> exp = expected.iterator();
|
||||
Iterator<RoleModel> act = actual.iterator();
|
||||
while (exp.hasNext()) {
|
||||
Assert.assertEquals(exp.next().getName(), act.next().getName());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue