Skip to content

Commit

Permalink
All tests now passing except broker tests and ImportExportTest.
Browse files Browse the repository at this point in the history
  • Loading branch information
ssilvert authored and stianst committed Mar 10, 2015
1 parent b1d3411 commit cb4c2cc
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 190 deletions.
Expand Up @@ -221,7 +221,7 @@ public List<UserModel> searchForUserByAttributes(Map<String, String> attributes,

@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) {
Expand All @@ -239,7 +239,7 @@ public Set<FederatedIdentityModel> getFederatedIdentities(UserModel userModel, R

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;
Expand Down
Expand Up @@ -84,7 +84,7 @@ static InMemoryModel getModelForSession(KeycloakSession session) {
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;
Expand All @@ -106,7 +106,7 @@ private void readModelFile() {
} 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) {
Expand All @@ -124,7 +124,7 @@ void writeModelFile() {
} 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) {
Expand Down Expand Up @@ -202,8 +202,8 @@ public boolean removeUser(String realmId, String userId) {
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());
}
}

Expand All @@ -213,11 +213,11 @@ public void begin() {

// 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;
Expand All @@ -226,9 +226,9 @@ public void commit() {
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);}
Expand All @@ -239,7 +239,7 @@ public void commit() {
public void rollback() {
synchronized (allModels) {
allModels.remove(session);
System.out.println("rollback(): Session count=" + allModels.size());
//logger.info("rollback(): Session count=" + allModels.size());
}
}

Expand Down
Expand Up @@ -36,6 +36,7 @@
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.
Expand Down Expand Up @@ -286,27 +287,102 @@ public Map<String, String> getAttributes() {
@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 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 removeProtocolMappers(Set<String> mapperIds) {
clientEntity.getProtocolMappers().removeAll(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 void setProtocolMappers(Set<String> mapperIds) {
clientEntity.getProtocolMappers().clear();
clientEntity.getProtocolMappers().addAll(mapperIds);
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
Expand Down

0 comments on commit cb4c2cc

Please sign in to comment.