From d74d93a522d597e33919571bcb5e7193cc37ac8e Mon Sep 17 00:00:00 2001 From: Bill Burke Date: Wed, 15 Jul 2015 14:54:14 -0400 Subject: [PATCH] fix problems --- ...AuthenticationExecutionRepresentation.java | 10 ++--- .../idm/AuthenticationFlowRepresentation.java | 9 ----- .../AuthenticatorConfigRepresentation.java | 9 ----- .../java/org/keycloak/models/RealmModel.java | 1 + .../models/utils/ModelToRepresentation.java | 27 ++++++++------ .../models/utils/RepresentationToModel.java | 37 +++++++++++-------- .../models/file/adapter/RealmAdapter.java | 11 ++++++ .../keycloak/models/cache/RealmAdapter.java | 11 ++++++ .../org/keycloak/models/jpa/RealmAdapter.java | 9 +++++ .../mongo/keycloak/adapters/RealmAdapter.java | 11 ++++++ 10 files changed, 85 insertions(+), 50 deletions(-) diff --git a/core/src/main/java/org/keycloak/representations/idm/AuthenticationExecutionRepresentation.java b/core/src/main/java/org/keycloak/representations/idm/AuthenticationExecutionRepresentation.java index 8ca78d4e2c..89b2c412ce 100755 --- a/core/src/main/java/org/keycloak/representations/idm/AuthenticationExecutionRepresentation.java +++ b/core/src/main/java/org/keycloak/representations/idm/AuthenticationExecutionRepresentation.java @@ -12,7 +12,7 @@ public class AuthenticationExecutionRepresentation implements Serializable { private String authenticatorConfig; private String authenticator; - private String flowId; + private String flowAlias; private boolean autheticatorFlow; private String requirement; private boolean userSetupAllowed; @@ -63,12 +63,12 @@ public class AuthenticationExecutionRepresentation implements Serializable { * * @return */ - public String getFlowId() { - return flowId; + public String getFlowAlias() { + return flowAlias; } - public void setFlowId(String flowId) { - this.flowId = flowId; + public void setFlowAlias(String flowId) { + this.flowAlias = flowId; } /** diff --git a/core/src/main/java/org/keycloak/representations/idm/AuthenticationFlowRepresentation.java b/core/src/main/java/org/keycloak/representations/idm/AuthenticationFlowRepresentation.java index a6ad705fae..e7bd3a0a19 100755 --- a/core/src/main/java/org/keycloak/representations/idm/AuthenticationFlowRepresentation.java +++ b/core/src/main/java/org/keycloak/representations/idm/AuthenticationFlowRepresentation.java @@ -10,7 +10,6 @@ import java.util.List; public class AuthenticationFlowRepresentation implements Serializable { private static final long serialVersionUID = 1L; - private String id; private String alias; private String description; private String providerId; @@ -18,14 +17,6 @@ public class AuthenticationFlowRepresentation implements Serializable { private boolean builtIn; protected List authenticationExecutions; - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - public String getAlias() { return alias; } diff --git a/core/src/main/java/org/keycloak/representations/idm/AuthenticatorConfigRepresentation.java b/core/src/main/java/org/keycloak/representations/idm/AuthenticatorConfigRepresentation.java index e3f48e09f7..e3e292bb3f 100755 --- a/core/src/main/java/org/keycloak/representations/idm/AuthenticatorConfigRepresentation.java +++ b/core/src/main/java/org/keycloak/representations/idm/AuthenticatorConfigRepresentation.java @@ -11,19 +11,10 @@ import java.util.Map; public class AuthenticatorConfigRepresentation implements Serializable { private static final long serialVersionUID = 1L; - private String id; private String alias; private Map config = new HashMap(); - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - public String getAlias() { return alias; } 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 27af04ef83..4f3c13c9c8 100755 --- a/model/api/src/main/java/org/keycloak/models/RealmModel.java +++ b/model/api/src/main/java/org/keycloak/models/RealmModel.java @@ -198,6 +198,7 @@ public interface RealmModel extends RoleContainerModel { void updateAuthenticatorConfig(AuthenticatorConfigModel model); void removeAuthenticatorConfig(AuthenticatorConfigModel model); AuthenticatorConfigModel getAuthenticatorConfigById(String id); + AuthenticatorConfigModel getAuthenticatorConfigByAlias(String alias); List getRequiredActionProviders(); RequiredActionProviderModel addRequiredActionProvider(RequiredActionProviderModel model); diff --git a/model/api/src/main/java/org/keycloak/models/utils/ModelToRepresentation.java b/model/api/src/main/java/org/keycloak/models/utils/ModelToRepresentation.java index 19c4e81594..3c634b256d 100755 --- a/model/api/src/main/java/org/keycloak/models/utils/ModelToRepresentation.java +++ b/model/api/src/main/java/org/keycloak/models/utils/ModelToRepresentation.java @@ -37,7 +37,6 @@ import org.keycloak.representations.idm.UserFederationMapperRepresentation; import org.keycloak.representations.idm.UserFederationProviderRepresentation; import org.keycloak.representations.idm.UserRepresentation; import org.keycloak.representations.idm.UserSessionRepresentation; -import org.keycloak.util.MultivaluedHashMap; import org.keycloak.util.Time; import java.util.ArrayList; @@ -199,11 +198,7 @@ public class ModelToRepresentation { rep.setAuthenticationFlows(new LinkedList()); rep.setAuthenticatorConfig(new LinkedList()); for (AuthenticationFlowModel model : realm.getAuthenticationFlows()) { - AuthenticationFlowRepresentation flowRep = toRepresentation(model); - flowRep.setAuthenticationExecutions(new LinkedList()); - for (AuthenticationExecutionModel execution : realm.getAuthenticationExecutions(model.getId())) { - flowRep.getAuthenticationExecutions().add(toRepresentation(execution)); - } + AuthenticationFlowRepresentation flowRep = toRepresentation(realm, model); rep.getAuthenticationFlows().add(flowRep); } for (AuthenticatorConfigModel model : realm.getAuthenticatorConfigs()) { @@ -430,24 +425,33 @@ public class ModelToRepresentation { return consentRep; } - public static AuthenticationFlowRepresentation toRepresentation(AuthenticationFlowModel model) { + public static AuthenticationFlowRepresentation toRepresentation(RealmModel realm, AuthenticationFlowModel model) { AuthenticationFlowRepresentation rep = new AuthenticationFlowRepresentation(); rep.setBuiltIn(model.isBuiltIn()); rep.setTopLevel(model.isTopLevel()); rep.setProviderId(model.getProviderId()); - rep.setId(model.getId()); rep.setAlias(model.getAlias()); rep.setDescription(model.getDescription()); + rep.setAuthenticationExecutions(new LinkedList()); + for (AuthenticationExecutionModel execution : realm.getAuthenticationExecutions(model.getId())) { + rep.getAuthenticationExecutions().add(toRepresentation(realm, execution)); + } return rep; } - public static AuthenticationExecutionRepresentation toRepresentation(AuthenticationExecutionModel model) { + public static AuthenticationExecutionRepresentation toRepresentation(RealmModel realm, AuthenticationExecutionModel model) { AuthenticationExecutionRepresentation rep = new AuthenticationExecutionRepresentation(); - rep.setAuthenticatorConfig(model.getAuthenticatorConfig()); + if (model.getAuthenticatorConfig() != null) { + AuthenticatorConfigModel config = realm.getAuthenticatorConfigById(model.getAuthenticatorConfig()); + rep.setAuthenticatorConfig(config.getAlias()); + } rep.setAuthenticator(model.getAuthenticator()); rep.setAutheticatorFlow(model.isAutheticatorFlow()); - rep.setFlowId(model.getFlowId()); + if (model.getFlowId() != null) { + AuthenticationFlowModel flow = realm.getAuthenticationFlowById(model.getFlowId()); + rep.setFlowAlias(flow.getAlias()); + } rep.setPriority(model.getPriority()); rep.setUserSetupAllowed(model.isUserSetupAllowed()); rep.setRequirement(model.getRequirement().name()); @@ -456,7 +460,6 @@ public class ModelToRepresentation { public static AuthenticatorConfigRepresentation toRepresentation(AuthenticatorConfigModel model) { AuthenticatorConfigRepresentation rep = new AuthenticatorConfigRepresentation(); - rep.setId(model.getId()); rep.setAlias(model.getAlias()); rep.setConfig(model.getConfig()); return rep; diff --git a/model/api/src/main/java/org/keycloak/models/utils/RepresentationToModel.java b/model/api/src/main/java/org/keycloak/models/utils/RepresentationToModel.java index e0a328e87f..3bdaffdb8b 100755 --- a/model/api/src/main/java/org/keycloak/models/utils/RepresentationToModel.java +++ b/model/api/src/main/java/org/keycloak/models/utils/RepresentationToModel.java @@ -303,20 +303,23 @@ public class RepresentationToModel { // assume this is an old version being imported DefaultAuthenticationFlows.addFlows(newRealm); } else { - for (AuthenticationFlowRepresentation flowRep : rep.getAuthenticationFlows()) { - AuthenticationFlowModel model = toModel(flowRep); - model = newRealm.addAuthenticationFlow(model); - for (AuthenticationExecutionRepresentation exeRep : flowRep.getAuthenticationExecutions()) { - AuthenticationExecutionModel execution = toModel(exeRep); - execution.setParentFlow(model.getId()); - newRealm.addAuthenticatorExecution(execution); - } - } for (AuthenticatorConfigRepresentation configRep : rep.getAuthenticatorConfig()) { AuthenticatorConfigModel model = toModel(configRep); newRealm.addAuthenticatorConfig(model); } - } + for (AuthenticationFlowRepresentation flowRep : rep.getAuthenticationFlows()) { + AuthenticationFlowModel model = toModel(flowRep); + model = newRealm.addAuthenticationFlow(model); + } + for (AuthenticationFlowRepresentation flowRep : rep.getAuthenticationFlows()) { + AuthenticationFlowModel model = newRealm.getFlowByAlias(flowRep.getAlias()); + for (AuthenticationExecutionRepresentation exeRep : flowRep.getAuthenticationExecutions()) { + AuthenticationExecutionModel execution = toModel(newRealm, exeRep); + execution.setParentFlow(model.getId()); + newRealm.addAuthenticatorExecution(execution); + } + } + } } @@ -1044,19 +1047,24 @@ public class RepresentationToModel { model.setBuiltIn(rep.isBuiltIn()); model.setTopLevel(rep.isTopLevel()); model.setProviderId(rep.getProviderId()); - model.setId(rep.getId()); model.setAlias(rep.getAlias()); model.setDescription(rep.getDescription()); return model; } - public static AuthenticationExecutionModel toModel(AuthenticationExecutionRepresentation rep) { + public static AuthenticationExecutionModel toModel(RealmModel realm, AuthenticationExecutionRepresentation rep) { AuthenticationExecutionModel model = new AuthenticationExecutionModel(); - model.setAuthenticatorConfig(rep.getAuthenticatorConfig()); + if (rep.getAuthenticatorConfig() != null) { + AuthenticatorConfigModel config = realm.getAuthenticatorConfigByAlias(rep.getAuthenticatorConfig()); + model.setAuthenticatorConfig(config.getId()); + } model.setAuthenticator(rep.getAuthenticator()); model.setAutheticatorFlow(rep.isAutheticatorFlow()); - model.setFlowId(rep.getFlowId()); + if (rep.getFlowAlias() != null) { + AuthenticationFlowModel flow = realm.getFlowByAlias(rep.getFlowAlias()); + model.setFlowId(flow.getId()); + } model.setPriority(rep.getPriority()); model.setUserSetupAllowed(rep.isUserSetupAllowed()); model.setRequirement(AuthenticationExecutionModel.Requirement.valueOf(rep.getRequirement())); @@ -1065,7 +1073,6 @@ public class RepresentationToModel { public static AuthenticatorConfigModel toModel(AuthenticatorConfigRepresentation rep) { AuthenticatorConfigModel model = new AuthenticatorConfigModel(); - model.setId(rep.getId()); model.setAlias(rep.getAlias()); model.setConfig(rep.getConfig()); return model; diff --git a/model/file/src/main/java/org/keycloak/models/file/adapter/RealmAdapter.java b/model/file/src/main/java/org/keycloak/models/file/adapter/RealmAdapter.java index 086541e7e7..09d43042d7 100755 --- a/model/file/src/main/java/org/keycloak/models/file/adapter/RealmAdapter.java +++ b/model/file/src/main/java/org/keycloak/models/file/adapter/RealmAdapter.java @@ -1398,6 +1398,17 @@ public class RealmAdapter implements RealmModel { return authenticators; } + @Override + public AuthenticatorConfigModel getAuthenticatorConfigByAlias(String alias) { + for (AuthenticatorConfigModel config : getAuthenticatorConfigs()) { + if (config.getAlias().equals(alias)) { + return config; + } + } + return null; + } + + @Override public AuthenticatorConfigModel addAuthenticatorConfig(AuthenticatorConfigModel model) { AuthenticatorConfigEntity auth = new AuthenticatorConfigEntity(); diff --git a/model/invalidation-cache/model-adapters/src/main/java/org/keycloak/models/cache/RealmAdapter.java b/model/invalidation-cache/model-adapters/src/main/java/org/keycloak/models/cache/RealmAdapter.java index b620f18d73..03ceceddd4 100755 --- a/model/invalidation-cache/model-adapters/src/main/java/org/keycloak/models/cache/RealmAdapter.java +++ b/model/invalidation-cache/model-adapters/src/main/java/org/keycloak/models/cache/RealmAdapter.java @@ -1035,6 +1035,17 @@ public class RealmAdapter implements RealmModel { return null; } + @Override + public AuthenticatorConfigModel getAuthenticatorConfigByAlias(String alias) { + for (AuthenticatorConfigModel config : getAuthenticatorConfigs()) { + if (config.getAlias().equals(alias)) { + return config; + } + } + return null; + } + + @Override public AuthenticationFlowModel addAuthenticationFlow(AuthenticationFlowModel model) { getDelegateForUpdate(); 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 eb83947884..51148f0558 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 @@ -1537,6 +1537,15 @@ public class RealmAdapter implements RealmModel { return null; } + @Override + public AuthenticatorConfigModel getAuthenticatorConfigByAlias(String alias) { + for (AuthenticatorConfigModel config : getAuthenticatorConfigs()) { + if (config.getAlias().equals(alias)) { + return config; + } + } + return null; + } protected AuthenticationFlowModel entityToModel(AuthenticationFlowEntity entity) { AuthenticationFlowModel model = new AuthenticationFlowModel(); diff --git a/model/mongo/src/main/java/org/keycloak/models/mongo/keycloak/adapters/RealmAdapter.java b/model/mongo/src/main/java/org/keycloak/models/mongo/keycloak/adapters/RealmAdapter.java index a3ebacedc1..2766eceb2f 100755 --- a/model/mongo/src/main/java/org/keycloak/models/mongo/keycloak/adapters/RealmAdapter.java +++ b/model/mongo/src/main/java/org/keycloak/models/mongo/keycloak/adapters/RealmAdapter.java @@ -1477,6 +1477,17 @@ public class RealmAdapter extends AbstractMongoAdapter impleme return authenticators; } + @Override + public AuthenticatorConfigModel getAuthenticatorConfigByAlias(String alias) { + for (AuthenticatorConfigModel config : getAuthenticatorConfigs()) { + if (config.getAlias().equals(alias)) { + return config; + } + } + return null; + } + + @Override public AuthenticatorConfigModel addAuthenticatorConfig(AuthenticatorConfigModel model) { AuthenticatorConfigEntity auth = new AuthenticatorConfigEntity();