diff --git a/core/src/main/java/org/keycloak/representations/idm/RealmRepresentation.java b/core/src/main/java/org/keycloak/representations/idm/RealmRepresentation.java index a91f9e25ff..ceb22a87c5 100755 --- a/core/src/main/java/org/keycloak/representations/idm/RealmRepresentation.java +++ b/core/src/main/java/org/keycloak/representations/idm/RealmRepresentation.java @@ -46,6 +46,7 @@ public class RealmRepresentation { protected String codeSecret; protected RolesRepresentation roles; protected List defaultRoles; + @Deprecated protected Set requiredCredentials; protected String passwordPolicy; protected List users; @@ -78,6 +79,7 @@ public class RealmRepresentation { protected String defaultLocale; protected List authenticationFlows; protected List authenticatorConfig; + protected List requiredActions; @Deprecated protected Boolean social; @@ -187,11 +189,11 @@ public class RealmRepresentation { scopeMappings.add(mapping); return mapping; } - + @Deprecated public Set getRequiredCredentials() { return requiredCredentials; } - + @Deprecated public void setRequiredCredentials(Set requiredCredentials) { this.requiredCredentials = requiredCredentials; } @@ -643,4 +645,12 @@ public class RealmRepresentation { public void setAuthenticatorConfig(List authenticatorConfig) { this.authenticatorConfig = authenticatorConfig; } + + public List getRequiredActions() { + return requiredActions; + } + + public void setRequiredActions(List requiredActions) { + this.requiredActions = requiredActions; + } } 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 8219edca31..ebe4ed3bdf 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 @@ -11,6 +11,7 @@ import org.keycloak.models.IdentityProviderModel; import org.keycloak.models.ModelException; import org.keycloak.models.ProtocolMapperModel; import org.keycloak.models.RealmModel; +import org.keycloak.models.RequiredActionProviderModel; import org.keycloak.models.RequiredCredentialModel; import org.keycloak.models.RoleModel; import org.keycloak.models.UserConsentModel; @@ -31,6 +32,7 @@ import org.keycloak.representations.idm.IdentityProviderRepresentation; import org.keycloak.representations.idm.ProtocolMapperRepresentation; import org.keycloak.representations.idm.RealmEventsConfigRepresentation; import org.keycloak.representations.idm.RealmRepresentation; +import org.keycloak.representations.idm.RequiredActionProviderRepresentation; import org.keycloak.representations.idm.RoleRepresentation; import org.keycloak.representations.idm.UserConsentRepresentation; import org.keycloak.representations.idm.UserFederationMapperRepresentation; @@ -193,6 +195,7 @@ public class ModelToRepresentation { rep.setDefaultLocale(realm.getDefaultLocale()); if (internal) { exportAuthenticationFlows(realm, rep); + exportRequiredActions(realm, rep); } return rep; } @@ -210,6 +213,14 @@ public class ModelToRepresentation { } + public static void exportRequiredActions(RealmModel realm, RealmRepresentation rep) { + rep.setRequiredActions(new LinkedList()); + for (RequiredActionProviderModel model : realm.getRequiredActionProviders()) { + RequiredActionProviderRepresentation action = toRepresentation(model); + rep.getRequiredActions().add(action); + } + } + public static RealmEventsConfigRepresentation toEventsConfigReprensetation(RealmModel realm) { RealmEventsConfigRepresentation rep = new RealmEventsConfigRepresentation(); @@ -468,5 +479,20 @@ public class ModelToRepresentation { return rep; } + public static RequiredActionProviderRepresentation toRepresentation(RequiredActionProviderModel model) { + RequiredActionProviderRepresentation rep = new RequiredActionProviderRepresentation(); + rep.setAlias(model.getAlias()); + rep.setDefaultAction(model.isDefaultAction()); + rep.setEnabled(model.isEnabled()); + rep.setConfig(model.getConfig()); + rep.setName(model.getName()); + rep.setProviderId(model.getProviderId()); + 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 6aa322171d..0e87282d11 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 @@ -18,6 +18,7 @@ import org.keycloak.models.ModelException; import org.keycloak.models.PasswordPolicy; import org.keycloak.models.ProtocolMapperModel; import org.keycloak.models.RealmModel; +import org.keycloak.models.RequiredActionProviderModel; import org.keycloak.models.RoleModel; import org.keycloak.models.UserConsentModel; import org.keycloak.models.UserCredentialModel; @@ -38,6 +39,7 @@ import org.keycloak.representations.idm.IdentityProviderRepresentation; import org.keycloak.representations.idm.OAuthClientRepresentation; import org.keycloak.representations.idm.ProtocolMapperRepresentation; import org.keycloak.representations.idm.RealmRepresentation; +import org.keycloak.representations.idm.RequiredActionProviderRepresentation; import org.keycloak.representations.idm.RoleRepresentation; import org.keycloak.representations.idm.ScopeMappingRepresentation; import org.keycloak.representations.idm.SocialLinkRepresentation; @@ -297,6 +299,14 @@ public class RepresentationToModel { } importAuthenticationFlows(newRealm, rep); + if (rep.getRequiredActions() != null) { + for (RequiredActionProviderRepresentation action : rep.getRequiredActions()) { + RequiredActionProviderModel model = toModel(action); + newRealm.addRequiredActionProvider(model); + } + } else { + DefaultRequiredActions.addActions(newRealm); + } } public static void importAuthenticationFlows(RealmModel newRealm, RealmRepresentation rep) { @@ -1075,5 +1085,16 @@ public class RepresentationToModel { return model; } + public static RequiredActionProviderModel toModel(RequiredActionProviderRepresentation rep) { + RequiredActionProviderModel model = new RequiredActionProviderModel(); + model.setConfig(rep.getConfig()); + model.setDefaultAction(rep.isDefaultAction()); + model.setEnabled(rep.isEnabled()); + model.setProviderId(rep.getProviderId()); + model.setName(rep.getName()); + model.setAlias(rep.getAlias()); + return model; + } + }