Skip to content

Commit

Permalink
fix problems
Browse files Browse the repository at this point in the history
  • Loading branch information
patriot1burke committed Jul 15, 2015
1 parent b3eadcc commit d74d93a
Show file tree
Hide file tree
Showing 10 changed files with 81 additions and 46 deletions.
Expand Up @@ -12,7 +12,7 @@ public class AuthenticationExecutionRepresentation implements Serializable {


private String authenticatorConfig; private String authenticatorConfig;
private String authenticator; private String authenticator;
private String flowId; private String flowAlias;
private boolean autheticatorFlow; private boolean autheticatorFlow;
private String requirement; private String requirement;
private boolean userSetupAllowed; private boolean userSetupAllowed;
Expand Down Expand Up @@ -63,12 +63,12 @@ public void setUserSetupAllowed(boolean userSetupAllowed) {
* *
* @return * @return
*/ */
public String getFlowId() { public String getFlowAlias() {
return flowId; return flowAlias;
} }


public void setFlowId(String flowId) { public void setFlowAlias(String flowId) {
this.flowId = flowId; this.flowAlias = flowId;
} }


/** /**
Expand Down
Expand Up @@ -10,22 +10,13 @@
public class AuthenticationFlowRepresentation implements Serializable { public class AuthenticationFlowRepresentation implements Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;


private String id;
private String alias; private String alias;
private String description; private String description;
private String providerId; private String providerId;
private boolean topLevel; private boolean topLevel;
private boolean builtIn; private boolean builtIn;
protected List<AuthenticationExecutionRepresentation> authenticationExecutions; protected List<AuthenticationExecutionRepresentation> authenticationExecutions;


public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}

public String getAlias() { public String getAlias() {
return alias; return alias;
} }
Expand Down
Expand Up @@ -11,19 +11,10 @@
public class AuthenticatorConfigRepresentation implements Serializable { public class AuthenticatorConfigRepresentation implements Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;


private String id;
private String alias; private String alias;
private Map<String, String> config = new HashMap<String, String>(); private Map<String, String> config = new HashMap<String, String>();




public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}

public String getAlias() { public String getAlias() {
return alias; return alias;
} }
Expand Down
Expand Up @@ -198,6 +198,7 @@ interface UserFederationMapperEvent extends ProviderEvent {
void updateAuthenticatorConfig(AuthenticatorConfigModel model); void updateAuthenticatorConfig(AuthenticatorConfigModel model);
void removeAuthenticatorConfig(AuthenticatorConfigModel model); void removeAuthenticatorConfig(AuthenticatorConfigModel model);
AuthenticatorConfigModel getAuthenticatorConfigById(String id); AuthenticatorConfigModel getAuthenticatorConfigById(String id);
AuthenticatorConfigModel getAuthenticatorConfigByAlias(String alias);


List<RequiredActionProviderModel> getRequiredActionProviders(); List<RequiredActionProviderModel> getRequiredActionProviders();
RequiredActionProviderModel addRequiredActionProvider(RequiredActionProviderModel model); RequiredActionProviderModel addRequiredActionProvider(RequiredActionProviderModel model);
Expand Down
Expand Up @@ -37,7 +37,6 @@
import org.keycloak.representations.idm.UserFederationProviderRepresentation; import org.keycloak.representations.idm.UserFederationProviderRepresentation;
import org.keycloak.representations.idm.UserRepresentation; import org.keycloak.representations.idm.UserRepresentation;
import org.keycloak.representations.idm.UserSessionRepresentation; import org.keycloak.representations.idm.UserSessionRepresentation;
import org.keycloak.util.MultivaluedHashMap;
import org.keycloak.util.Time; import org.keycloak.util.Time;


import java.util.ArrayList; import java.util.ArrayList;
Expand Down Expand Up @@ -199,11 +198,7 @@ public static void exportAuthenticationFlows(RealmModel realm, RealmRepresentati
rep.setAuthenticationFlows(new LinkedList<AuthenticationFlowRepresentation>()); rep.setAuthenticationFlows(new LinkedList<AuthenticationFlowRepresentation>());
rep.setAuthenticatorConfig(new LinkedList<AuthenticatorConfigRepresentation>()); rep.setAuthenticatorConfig(new LinkedList<AuthenticatorConfigRepresentation>());
for (AuthenticationFlowModel model : realm.getAuthenticationFlows()) { for (AuthenticationFlowModel model : realm.getAuthenticationFlows()) {
AuthenticationFlowRepresentation flowRep = toRepresentation(model); AuthenticationFlowRepresentation flowRep = toRepresentation(realm, model);
flowRep.setAuthenticationExecutions(new LinkedList<AuthenticationExecutionRepresentation>());
for (AuthenticationExecutionModel execution : realm.getAuthenticationExecutions(model.getId())) {
flowRep.getAuthenticationExecutions().add(toRepresentation(execution));
}
rep.getAuthenticationFlows().add(flowRep); rep.getAuthenticationFlows().add(flowRep);
} }
for (AuthenticatorConfigModel model : realm.getAuthenticatorConfigs()) { for (AuthenticatorConfigModel model : realm.getAuthenticatorConfigs()) {
Expand Down Expand Up @@ -430,24 +425,33 @@ public static UserConsentRepresentation toRepresentation(UserConsentModel model)
return consentRep; return consentRep;
} }


public static AuthenticationFlowRepresentation toRepresentation(AuthenticationFlowModel model) { public static AuthenticationFlowRepresentation toRepresentation(RealmModel realm, AuthenticationFlowModel model) {
AuthenticationFlowRepresentation rep = new AuthenticationFlowRepresentation(); AuthenticationFlowRepresentation rep = new AuthenticationFlowRepresentation();
rep.setBuiltIn(model.isBuiltIn()); rep.setBuiltIn(model.isBuiltIn());
rep.setTopLevel(model.isTopLevel()); rep.setTopLevel(model.isTopLevel());
rep.setProviderId(model.getProviderId()); rep.setProviderId(model.getProviderId());
rep.setId(model.getId());
rep.setAlias(model.getAlias()); rep.setAlias(model.getAlias());
rep.setDescription(model.getDescription()); rep.setDescription(model.getDescription());
rep.setAuthenticationExecutions(new LinkedList<AuthenticationExecutionRepresentation>());
for (AuthenticationExecutionModel execution : realm.getAuthenticationExecutions(model.getId())) {
rep.getAuthenticationExecutions().add(toRepresentation(realm, execution));
}
return rep; return rep;


} }


public static AuthenticationExecutionRepresentation toRepresentation(AuthenticationExecutionModel model) { public static AuthenticationExecutionRepresentation toRepresentation(RealmModel realm, AuthenticationExecutionModel model) {
AuthenticationExecutionRepresentation rep = new AuthenticationExecutionRepresentation(); 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.setAuthenticator(model.getAuthenticator());
rep.setAutheticatorFlow(model.isAutheticatorFlow()); 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.setPriority(model.getPriority());
rep.setUserSetupAllowed(model.isUserSetupAllowed()); rep.setUserSetupAllowed(model.isUserSetupAllowed());
rep.setRequirement(model.getRequirement().name()); rep.setRequirement(model.getRequirement().name());
Expand All @@ -456,7 +460,6 @@ public static AuthenticationExecutionRepresentation toRepresentation(Authenticat


public static AuthenticatorConfigRepresentation toRepresentation(AuthenticatorConfigModel model) { public static AuthenticatorConfigRepresentation toRepresentation(AuthenticatorConfigModel model) {
AuthenticatorConfigRepresentation rep = new AuthenticatorConfigRepresentation(); AuthenticatorConfigRepresentation rep = new AuthenticatorConfigRepresentation();
rep.setId(model.getId());
rep.setAlias(model.getAlias()); rep.setAlias(model.getAlias());
rep.setConfig(model.getConfig()); rep.setConfig(model.getConfig());
return rep; return rep;
Expand Down
Expand Up @@ -303,20 +303,23 @@ public static void importAuthenticationFlows(RealmModel newRealm, RealmRepresent
// assume this is an old version being imported // assume this is an old version being imported
DefaultAuthenticationFlows.addFlows(newRealm); DefaultAuthenticationFlows.addFlows(newRealm);
} else { } else {
for (AuthenticatorConfigRepresentation configRep : rep.getAuthenticatorConfig()) {
AuthenticatorConfigModel model = toModel(configRep);
newRealm.addAuthenticatorConfig(model);
}
for (AuthenticationFlowRepresentation flowRep : rep.getAuthenticationFlows()) { for (AuthenticationFlowRepresentation flowRep : rep.getAuthenticationFlows()) {
AuthenticationFlowModel model = toModel(flowRep); AuthenticationFlowModel model = toModel(flowRep);
model = newRealm.addAuthenticationFlow(model); model = newRealm.addAuthenticationFlow(model);
}
for (AuthenticationFlowRepresentation flowRep : rep.getAuthenticationFlows()) {
AuthenticationFlowModel model = newRealm.getFlowByAlias(flowRep.getAlias());
for (AuthenticationExecutionRepresentation exeRep : flowRep.getAuthenticationExecutions()) { for (AuthenticationExecutionRepresentation exeRep : flowRep.getAuthenticationExecutions()) {
AuthenticationExecutionModel execution = toModel(exeRep); AuthenticationExecutionModel execution = toModel(newRealm, exeRep);
execution.setParentFlow(model.getId()); execution.setParentFlow(model.getId());
newRealm.addAuthenticatorExecution(execution); newRealm.addAuthenticatorExecution(execution);
} }
} }
for (AuthenticatorConfigRepresentation configRep : rep.getAuthenticatorConfig()) { }
AuthenticatorConfigModel model = toModel(configRep);
newRealm.addAuthenticatorConfig(model);
}
}


} }


Expand Down Expand Up @@ -1044,19 +1047,24 @@ public static AuthenticationFlowModel toModel(AuthenticationFlowRepresentation r
model.setBuiltIn(rep.isBuiltIn()); model.setBuiltIn(rep.isBuiltIn());
model.setTopLevel(rep.isTopLevel()); model.setTopLevel(rep.isTopLevel());
model.setProviderId(rep.getProviderId()); model.setProviderId(rep.getProviderId());
model.setId(rep.getId());
model.setAlias(rep.getAlias()); model.setAlias(rep.getAlias());
model.setDescription(rep.getDescription()); model.setDescription(rep.getDescription());
return model; return model;


} }


public static AuthenticationExecutionModel toModel(AuthenticationExecutionRepresentation rep) { public static AuthenticationExecutionModel toModel(RealmModel realm, AuthenticationExecutionRepresentation rep) {
AuthenticationExecutionModel model = new AuthenticationExecutionModel(); 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.setAuthenticator(rep.getAuthenticator());
model.setAutheticatorFlow(rep.isAutheticatorFlow()); 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.setPriority(rep.getPriority());
model.setUserSetupAllowed(rep.isUserSetupAllowed()); model.setUserSetupAllowed(rep.isUserSetupAllowed());
model.setRequirement(AuthenticationExecutionModel.Requirement.valueOf(rep.getRequirement())); model.setRequirement(AuthenticationExecutionModel.Requirement.valueOf(rep.getRequirement()));
Expand All @@ -1065,7 +1073,6 @@ public static AuthenticationExecutionModel toModel(AuthenticationExecutionRepres


public static AuthenticatorConfigModel toModel(AuthenticatorConfigRepresentation rep) { public static AuthenticatorConfigModel toModel(AuthenticatorConfigRepresentation rep) {
AuthenticatorConfigModel model = new AuthenticatorConfigModel(); AuthenticatorConfigModel model = new AuthenticatorConfigModel();
model.setId(rep.getId());
model.setAlias(rep.getAlias()); model.setAlias(rep.getAlias());
model.setConfig(rep.getConfig()); model.setConfig(rep.getConfig());
return model; return model;
Expand Down
Expand Up @@ -1398,6 +1398,17 @@ public List<AuthenticatorConfigModel> getAuthenticatorConfigs() {
return authenticators; return authenticators;
} }


@Override
public AuthenticatorConfigModel getAuthenticatorConfigByAlias(String alias) {
for (AuthenticatorConfigModel config : getAuthenticatorConfigs()) {
if (config.getAlias().equals(alias)) {
return config;
}
}
return null;
}


@Override @Override
public AuthenticatorConfigModel addAuthenticatorConfig(AuthenticatorConfigModel model) { public AuthenticatorConfigModel addAuthenticatorConfig(AuthenticatorConfigModel model) {
AuthenticatorConfigEntity auth = new AuthenticatorConfigEntity(); AuthenticatorConfigEntity auth = new AuthenticatorConfigEntity();
Expand Down
Expand Up @@ -1035,6 +1035,17 @@ public AuthenticationFlowModel getFlowByAlias(String alias) {
return null; return null;
} }


@Override
public AuthenticatorConfigModel getAuthenticatorConfigByAlias(String alias) {
for (AuthenticatorConfigModel config : getAuthenticatorConfigs()) {
if (config.getAlias().equals(alias)) {
return config;
}
}
return null;
}


@Override @Override
public AuthenticationFlowModel addAuthenticationFlow(AuthenticationFlowModel model) { public AuthenticationFlowModel addAuthenticationFlow(AuthenticationFlowModel model) {
getDelegateForUpdate(); getDelegateForUpdate();
Expand Down
Expand Up @@ -1537,6 +1537,15 @@ public AuthenticationFlowModel getFlowByAlias(String alias) {
return null; 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) { protected AuthenticationFlowModel entityToModel(AuthenticationFlowEntity entity) {
AuthenticationFlowModel model = new AuthenticationFlowModel(); AuthenticationFlowModel model = new AuthenticationFlowModel();
Expand Down
Expand Up @@ -1477,6 +1477,17 @@ public List<AuthenticatorConfigModel> getAuthenticatorConfigs() {
return authenticators; return authenticators;
} }


@Override
public AuthenticatorConfigModel getAuthenticatorConfigByAlias(String alias) {
for (AuthenticatorConfigModel config : getAuthenticatorConfigs()) {
if (config.getAlias().equals(alias)) {
return config;
}
}
return null;
}


@Override @Override
public AuthenticatorConfigModel addAuthenticatorConfig(AuthenticatorConfigModel model) { public AuthenticatorConfigModel addAuthenticatorConfig(AuthenticatorConfigModel model) {
AuthenticatorConfigEntity auth = new AuthenticatorConfigEntity(); AuthenticatorConfigEntity auth = new AuthenticatorConfigEntity();
Expand Down

0 comments on commit d74d93a

Please sign in to comment.