All tests now passing except broker tests and ImportExportTest.
This commit is contained in:
1 parent
b1d341155d
commit
cb4c2cc5e3
6 files changed
+118
-190
No files matched your search
@@ -221,7 +221,7 @@ public class FileUserProvider implements UserProvider {
|
||||
|
||||
@Override
|
||||
public Set<FederatedIdentityModel> getFederatedIdentities(UserModel userModel, RealmModel realm) {
|
||||
UserEntity userEntity = ((UserAdapter) userModel).getUserEntity();
|
||||
UserEntity userEntity = ((UserAdapter)getUserById(userModel.getId(), realm)).getUserEntity();
|
||||
List<FederatedIdentityEntity> linkEntities = userEntity.getFederatedIdentities();
|
||||
|
||||
if (linkEntities == null) {
|
||||
@@ -239,7 +239,7 @@ public class FileUserProvider implements UserProvider {
|
||||
|
||||
private FederatedIdentityEntity findSocialLink(UserModel userModel, String socialProvider, RealmModel realm) {
|
||||
UserModel user = getUserById(userModel.getId(), realm);
|
||||
UserEntity userEntity = ((UserAdapter) user).getUserEntity();
|
||||
UserEntity userEntity = ((UserAdapter)getUserById(userModel.getId(), realm)).getUserEntity();
|
||||
List<FederatedIdentityEntity> linkEntities = userEntity.getFederatedIdentities();
|
||||
if (linkEntities == null) {
|
||||
return null;
|
||||
|
||||
@@ -84,7 +84,7 @@ public class InMemoryModel implements KeycloakTransaction {
|
||||
allModels.put(session, model);
|
||||
session.getTransaction().enlist(model);
|
||||
model.readModelFile();
|
||||
logger.info("Added session " + session.hashCode() + " total sessions=" + allModels.size());
|
||||
//logger.info("Added session " + session.hashCode() + " total sessions=" + allModels.size());
|
||||
}
|
||||
|
||||
return model;
|
||||
@@ -106,7 +106,7 @@ public class InMemoryModel implements KeycloakTransaction {
|
||||
} catch (IOException ioe) {
|
||||
logger.error("Unable to read model file " + kcdata.getAbsolutePath(), ioe);
|
||||
} finally {
|
||||
logger.info("Read model file for session=" + session.hashCode());
|
||||
//logger.info("Read model file for session=" + session.hashCode());
|
||||
try {
|
||||
if (fis != null) fis.close();
|
||||
} catch (IOException e) {
|
||||
@@ -124,7 +124,7 @@ public class InMemoryModel implements KeycloakTransaction {
|
||||
} catch (IOException e) {
|
||||
logger.error("Unable to write model file " + keycloakModelFile.getAbsolutePath(), e);
|
||||
} finally {
|
||||
logger.info("Wrote model file for session=" + session.hashCode());
|
||||
//logger.info("Wrote model file for session=" + session.hashCode());
|
||||
try {
|
||||
if (outStream != null) outStream.close();
|
||||
} catch (IOException e) {
|
||||
@@ -202,8 +202,8 @@ public class InMemoryModel implements KeycloakTransaction {
|
||||
void sessionClosed(KeycloakSession session) {
|
||||
synchronized (allModels) {
|
||||
allModels.remove(session);
|
||||
logger.info("Removed session " + session.hashCode());
|
||||
logger.info("sessionClosed: Session count=" + allModels.size());
|
||||
//logger.info("Removed session " + session.hashCode());
|
||||
//logger.info("sessionClosed: Session count=" + allModels.size());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -213,11 +213,11 @@ public class InMemoryModel implements KeycloakTransaction {
|
||||
|
||||
// commitCount is used for debugging. This allows you to easily run a test
|
||||
// to a particular point and then examine the JSON file.
|
||||
private static int commitCount = 0;
|
||||
//private static int commitCount = 0;
|
||||
|
||||
@Override
|
||||
public void commit() {
|
||||
commitCount++;
|
||||
//commitCount++;
|
||||
synchronized (allModels) {
|
||||
// in case commit was somehow called twice on the same session
|
||||
if (!allModels.containsKey(session)) return;
|
||||
@@ -226,9 +226,9 @@ public class InMemoryModel implements KeycloakTransaction {
|
||||
writeModelFile();
|
||||
} finally {
|
||||
allModels.remove(session);
|
||||
logger.info("Removed session " + session.hashCode());
|
||||
logger.info("*** commitCount=" + commitCount);
|
||||
logger.info("commit(): Session count=" + allModels.size());
|
||||
//logger.info("Removed session " + session.hashCode());
|
||||
//logger.info("*** commitCount=" + commitCount);
|
||||
//logger.info("commit(): Session count=" + allModels.size());
|
||||
}
|
||||
|
||||
// if (commitCount == 16) {Thread.dumpStack();System.exit(0);}
|
||||
@@ -239,7 +239,7 @@ public class InMemoryModel implements KeycloakTransaction {
|
||||
public void rollback() {
|
||||
synchronized (allModels) {
|
||||
allModels.remove(session);
|
||||
System.out.println("rollback(): Session count=" + allModels.size());
|
||||
//logger.info("rollback(): Session count=" + allModels.size());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -36,6 +36,7 @@ import org.keycloak.models.ClientIdentityProviderMappingModel;
|
||||
import org.keycloak.models.ProtocolMapperModel;
|
||||
import org.keycloak.models.entities.ClientIdentityProviderMappingEntity;
|
||||
import org.keycloak.models.entities.ProtocolMapperEntity;
|
||||
import org.keycloak.models.utils.KeycloakModelUtils;
|
||||
|
||||
/**
|
||||
* ClientModel for JSON persistence.
|
||||
@@ -286,27 +287,102 @@ public abstract class ClientAdapter implements ClientModel {
|
||||
@Override
|
||||
public Set<ProtocolMapperModel> getProtocolMappers() {
|
||||
Set<ProtocolMapperModel> result = new HashSet<ProtocolMapperModel>();
|
||||
for (String id : clientEntity.getProtocolMappers()) {
|
||||
ProtocolMapperModel model = getRealm().getProtocolMapperById(id);
|
||||
for (ProtocolMapperEntity entity : clientEntity.getProtocolMappers()) {
|
||||
ProtocolMapperModel model = getProtocolMapperById(entity.getId());
|
||||
if (model != null) result.add(model);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addProtocolMappers(Set<String> mapperIds) {
|
||||
clientEntity.getProtocolMappers().addAll(mapperIds);
|
||||
public ProtocolMapperModel addProtocolMapper(ProtocolMapperModel model) {
|
||||
if (getProtocolMapperByName(model.getProtocol(), model.getName()) != null) {
|
||||
throw new RuntimeException("protocol mapper name must be unique per protocol");
|
||||
}
|
||||
ProtocolMapperEntity entity = new ProtocolMapperEntity();
|
||||
entity.setId(KeycloakModelUtils.generateId());
|
||||
entity.setProtocol(model.getProtocol());
|
||||
entity.setName(model.getName());
|
||||
entity.setProtocolMapper(model.getProtocolMapper());
|
||||
entity.setConfig(model.getConfig());
|
||||
entity.setConsentRequired(model.isConsentRequired());
|
||||
entity.setConsentText(model.getConsentText());
|
||||
clientEntity.getProtocolMappers().add(entity);
|
||||
return entityToModel(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeProtocolMappers(Set<String> mapperIds) {
|
||||
clientEntity.getProtocolMappers().removeAll(mapperIds);
|
||||
public void removeProtocolMapper(ProtocolMapperModel mapping) {
|
||||
ProtocolMapperEntity toBeRemoved = null;
|
||||
for (ProtocolMapperEntity entity : clientEntity.getProtocolMappers()) {
|
||||
if (entity.getId().equals(mapping.getId())) {
|
||||
toBeRemoved = entity;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
clientEntity.getProtocolMappers().remove(toBeRemoved);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setProtocolMappers(Set<String> mapperIds) {
|
||||
clientEntity.getProtocolMappers().clear();
|
||||
clientEntity.getProtocolMappers().addAll(mapperIds);
|
||||
public void updateProtocolMapper(ProtocolMapperModel mapping) {
|
||||
ProtocolMapperEntity entity = getProtocolMapperEntityById(mapping.getId());
|
||||
entity.setProtocolMapper(mapping.getProtocolMapper());
|
||||
entity.setConsentRequired(mapping.isConsentRequired());
|
||||
entity.setConsentText(mapping.getConsentText());
|
||||
if (entity.getConfig() != null) {
|
||||
entity.getConfig().clear();
|
||||
entity.getConfig().putAll(mapping.getConfig());
|
||||
} else {
|
||||
entity.setConfig(mapping.getConfig());
|
||||
}
|
||||
}
|
||||
|
||||
protected ProtocolMapperEntity getProtocolMapperEntityById(String id) {
|
||||
for (ProtocolMapperEntity entity : clientEntity.getProtocolMappers()) {
|
||||
if (entity.getId().equals(id)) {
|
||||
return entity;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected ProtocolMapperEntity getProtocolMapperEntityByName(String protocol, String name) {
|
||||
for (ProtocolMapperEntity entity : clientEntity.getProtocolMappers()) {
|
||||
if (entity.getProtocol().equals(protocol) && entity.getName().equals(name)) {
|
||||
return entity;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProtocolMapperModel getProtocolMapperById(String id) {
|
||||
ProtocolMapperEntity entity = getProtocolMapperEntityById(id);
|
||||
if (entity == null) return null;
|
||||
return entityToModel(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProtocolMapperModel getProtocolMapperByName(String protocol, String name) {
|
||||
ProtocolMapperEntity entity = getProtocolMapperEntityByName(protocol, name);
|
||||
if (entity == null) return null;
|
||||
return entityToModel(entity);
|
||||
}
|
||||
|
||||
protected ProtocolMapperModel entityToModel(ProtocolMapperEntity entity) {
|
||||
ProtocolMapperModel mapping = new ProtocolMapperModel();
|
||||
mapping.setId(entity.getId());
|
||||
mapping.setName(entity.getName());
|
||||
mapping.setProtocol(entity.getProtocol());
|
||||
mapping.setProtocolMapper(entity.getProtocolMapper());
|
||||
mapping.setConsentRequired(entity.isConsentRequired());
|
||||
mapping.setConsentText(entity.getConsentText());
|
||||
Map<String, String> config = new HashMap<String, String>();
|
||||
if (entity.getConfig() != null) config.putAll(entity.getConfig());
|
||||
mapping.setConfig(config);
|
||||
return mapping;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -46,16 +46,11 @@ import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import org.keycloak.models.ClaimTypeModel;
|
||||
import org.keycloak.models.ModelDuplicateException;
|
||||
import org.keycloak.models.ProtocolMapperModel;
|
||||
import org.keycloak.models.UserModel;
|
||||
import org.keycloak.models.entities.ApplicationEntity;
|
||||
import org.keycloak.models.entities.ClaimTypeEntity;
|
||||
import org.keycloak.models.entities.ClientEntity;
|
||||
import org.keycloak.models.entities.IdentityProviderEntity;
|
||||
import org.keycloak.models.entities.OAuthClientEntity;
|
||||
import org.keycloak.models.entities.ProtocolMapperEntity;
|
||||
import org.keycloak.models.entities.RealmEntity;
|
||||
import org.keycloak.models.entities.RoleEntity;
|
||||
import org.keycloak.models.file.InMemoryModel;
|
||||
@@ -652,7 +647,19 @@ public class RealmAdapter implements RealmModel {
|
||||
clientEntity.setRealmId(getId());
|
||||
clientEntity.setEnabled(true);
|
||||
|
||||
ApplicationModel app = new ApplicationAdapter(session, this, appEntity, clientEntity, inMemoryModel);
|
||||
final ApplicationModel app = new ApplicationAdapter(session, this, appEntity, clientEntity, inMemoryModel);
|
||||
session.getKeycloakSessionFactory().publish(new ApplicationCreationEvent() {
|
||||
@Override
|
||||
public ApplicationModel getCreatedApplication() {
|
||||
return app;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClientModel getCreatedClient() {
|
||||
return app;
|
||||
}
|
||||
});
|
||||
|
||||
allApps.put(id, app);
|
||||
|
||||
return app;
|
||||
@@ -1037,168 +1044,13 @@ public class RealmAdapter implements RealmModel {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<ProtocolMapperModel> getProtocolMappers() {
|
||||
Set<ProtocolMapperModel> result = new HashSet<ProtocolMapperModel>();
|
||||
for (ProtocolMapperEntity entity : realm.getProtocolMappers()) {
|
||||
ProtocolMapperModel mapping = new ProtocolMapperModel();
|
||||
mapping.setId(entity.getId());
|
||||
mapping.setName(entity.getName());
|
||||
mapping.setProtocol(entity.getProtocol());
|
||||
mapping.setAppliedByDefault(entity.isAppliedByDefault());
|
||||
mapping.setConsentRequired(entity.isConsentRequired());
|
||||
mapping.setConsentText(entity.getConsentText());
|
||||
Map<String, String> config = new HashMap<String, String>();
|
||||
if (entity.getConfig() != null) {
|
||||
config.putAll(entity.getConfig());
|
||||
}
|
||||
mapping.setConfig(config);
|
||||
}
|
||||
return result;
|
||||
public int getAccessCodeLifespanLogin() {
|
||||
return realm.getAccessCodeLifespanLogin();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProtocolMapperModel addProtocolMapper(ProtocolMapperModel model) {
|
||||
if (getProtocolMapperByName(model.getProtocol(), model.getName()) != null) {
|
||||
throw new RuntimeException("protocol mapper name must be unique per protocol");
|
||||
}
|
||||
ProtocolMapperEntity entity = new ProtocolMapperEntity();
|
||||
entity.setId(KeycloakModelUtils.generateId());
|
||||
entity.setProtocol(model.getProtocol());
|
||||
entity.setName(model.getName());
|
||||
entity.setAppliedByDefault(model.isAppliedByDefault());
|
||||
entity.setProtocolMapper(model.getProtocolMapper());
|
||||
entity.setConfig(model.getConfig());
|
||||
entity.setConsentRequired(model.isConsentRequired());
|
||||
entity.setConsentText(model.getConsentText());
|
||||
realm.getProtocolMappers().add(entity);
|
||||
return entityToModel(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeProtocolMapper(ProtocolMapperModel mapping) {
|
||||
for (ProtocolMapperEntity entity : realm.getProtocolMappers()) {
|
||||
if (entity.getId().equals(mapping.getId())) {
|
||||
realm.getProtocolMappers().remove(entity);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected ProtocolMapperEntity getProtocolMapperyEntityById(String id) {
|
||||
for (ProtocolMapperEntity entity : realm.getProtocolMappers()) {
|
||||
if (entity.getId().equals(id)) {
|
||||
return entity;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
protected ProtocolMapperEntity getProtocolMapperEntityByName(String protocol, String name) {
|
||||
for (ProtocolMapperEntity entity : realm.getProtocolMappers()) {
|
||||
if (entity.getProtocol().equals(protocol) && entity.getName().equals(name)) {
|
||||
return entity;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateProtocolMapper(ProtocolMapperModel mapping) {
|
||||
ProtocolMapperEntity entity = getProtocolMapperyEntityById(mapping.getId());
|
||||
entity.setAppliedByDefault(mapping.isAppliedByDefault());
|
||||
entity.setProtocolMapper(mapping.getProtocolMapper());
|
||||
entity.setConsentRequired(mapping.isConsentRequired());
|
||||
entity.setConsentText(mapping.getConsentText());
|
||||
if (entity.getConfig() != null) {
|
||||
entity.getConfig().clear();
|
||||
entity.getConfig().putAll(mapping.getConfig());
|
||||
} else {
|
||||
entity.setConfig(mapping.getConfig());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProtocolMapperModel getProtocolMapperById(String id) {
|
||||
ProtocolMapperEntity entity = getProtocolMapperyEntityById(id);
|
||||
if (entity == null) return null;
|
||||
return entityToModel(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProtocolMapperModel getProtocolMapperByName(String protocol, String name) {
|
||||
ProtocolMapperEntity entity = getProtocolMapperEntityByName(protocol, name);
|
||||
if (entity == null) return null;
|
||||
return entityToModel(entity);
|
||||
}
|
||||
|
||||
protected ProtocolMapperModel entityToModel(ProtocolMapperEntity entity) {
|
||||
ProtocolMapperModel mapping = new ProtocolMapperModel();
|
||||
mapping.setId(entity.getId());
|
||||
mapping.setName(entity.getName());
|
||||
mapping.setProtocol(entity.getProtocol());
|
||||
mapping.setAppliedByDefault(entity.isAppliedByDefault());
|
||||
mapping.setProtocolMapper(entity.getProtocolMapper());
|
||||
mapping.setConsentRequired(entity.isConsentRequired());
|
||||
mapping.setConsentText(entity.getConsentText());
|
||||
Map<String, String> config = new HashMap<String, String>();
|
||||
if (entity.getConfig() != null) config.putAll(entity.getConfig());
|
||||
mapping.setConfig(config);
|
||||
return mapping;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<ClaimTypeModel> getClaimTypes() {
|
||||
Set<ClaimTypeModel> result = new HashSet<ClaimTypeModel>();
|
||||
for (ClaimTypeEntity entity : realm.getClaimTypes()) {
|
||||
result.add(new ClaimTypeModel(entity.getId(), entity.getName(), entity.isBuiltIn(), entity.getType()));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClaimTypeModel addClaimType(ClaimTypeModel model) {
|
||||
String id = model.getId() == null ? KeycloakModelUtils.generateId() : model.getId();
|
||||
ClaimTypeModel claim = new ClaimTypeModel(id, model.getName(), model.isBuiltIn(), model.getType());
|
||||
ClaimTypeEntity entity = new ClaimTypeEntity();
|
||||
entity.setId(claim.getId());
|
||||
entity.setType(model.getType());
|
||||
entity.setBuiltIn(model.isBuiltIn());
|
||||
entity.setName(model.getName());
|
||||
realm.getClaimTypes().add(entity);
|
||||
return claim;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeClaimType(ClaimTypeModel claimType) {
|
||||
for (ClaimTypeEntity entity : realm.getClaimTypes()) {
|
||||
if (entity.getId().equals(claimType.getId())) {
|
||||
realm.getClaimTypes().remove(entity);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClaimTypeModel getClaimType(String name) {
|
||||
for (ClaimTypeModel claimType : getClaimTypes()) {
|
||||
if (claimType.getName().equals(name)) return claimType;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateClaimType(ClaimTypeModel claimType) {
|
||||
for (ClaimTypeEntity entity : realm.getClaimTypes()) {
|
||||
if (entity.getId().equals(claimType.getId())) {
|
||||
entity.setName(claimType.getName());
|
||||
entity.setBuiltIn(claimType.isBuiltIn());
|
||||
entity.setType(claimType.getType());
|
||||
break;
|
||||
}
|
||||
}
|
||||
public void setAccessCodeLifespanLogin(int accessCodeLifespanLogin) {
|
||||
realm.setAccessCodeLifespanLogin(accessCodeLifespanLogin);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in new issue
Block a user