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 c2300ef05b..5c1b468f87 100755 --- a/model/api/src/main/java/org/keycloak/models/RealmModel.java +++ b/model/api/src/main/java/org/keycloak/models/RealmModel.java @@ -2,6 +2,7 @@ package org.keycloak.models; import java.security.PrivateKey; import java.security.PublicKey; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Set; @@ -136,4 +137,12 @@ public interface RealmModel extends RoleContainerModel, RoleMapperModel, ScopeMa OAuthClientModel getOAuthClient(String name); List getOAuthClients(); + + HashMap getSmtpConfig(); + + void setSmtpConfig(HashMap smtpConfig); + + HashMap getSocialConfig(); + + void setSocialConfig(HashMap socialConfig); } diff --git a/model/jpa/src/main/java/org/keycloak/models/jpa/entities/RealmEntity.java b/model/jpa/src/main/java/org/keycloak/models/jpa/entities/RealmEntity.java index 7712490a5b..4a8ea65949 100755 --- a/model/jpa/src/main/java/org/keycloak/models/jpa/entities/RealmEntity.java +++ b/model/jpa/src/main/java/org/keycloak/models/jpa/entities/RealmEntity.java @@ -3,6 +3,7 @@ package org.keycloak.models.jpa.entities; import javax.persistence.*; import java.util.Collection; +import java.util.HashMap; /** * @author Bill Burke @@ -24,6 +25,10 @@ public class RealmEntity { @Column(length = 2048) protected String privateKeyPem; protected String[] defaultRoles; + @Lob + protected HashMap smtpConfig; + @Lob + protected HashMap socialConfig; @OneToMany(cascade ={CascadeType.REMOVE}, orphanRemoval = true) Collection requiredCredentials; diff --git a/model/picketlink/src/main/java/org/keycloak/models/picketlink/RealmAdapter.java b/model/picketlink/src/main/java/org/keycloak/models/picketlink/RealmAdapter.java index c6959f031c..d3268d2fa9 100755 --- a/model/picketlink/src/main/java/org/keycloak/models/picketlink/RealmAdapter.java +++ b/model/picketlink/src/main/java/org/keycloak/models/picketlink/RealmAdapter.java @@ -679,7 +679,7 @@ public class RealmAdapter implements RealmModel { @Override public void addScopeMapping(UserModel agent, RoleModel role) { ScopeRelationship scope = new ScopeRelationship(); - scope.setClient(((UserAdapter)agent).getUser()); + scope.setClient(((UserAdapter) agent).getUser()); scope.setScope(((RoleAdapter)role).getRole()); getRelationshipManager().add(scope); } @@ -873,4 +873,26 @@ public class RealmAdapter implements RealmModel { } return userModels; } + + @Override + public HashMap getSmtpConfig() { + return realm.getSmtpConfig(); + } + + @Override + public void setSmtpConfig(HashMap smtpConfig) { + realm.setSmtpConfig(smtpConfig); + updateRealm(); + } + + @Override + public HashMap getSocialConfig() { + return realm.getSocialConfig(); + } + + @Override + public void setSocialConfig(HashMap socialConfig) { + realm.setSocialConfig(socialConfig); + updateRealm(); + } } diff --git a/model/picketlink/src/main/java/org/keycloak/models/picketlink/mappings/RealmData.java b/model/picketlink/src/main/java/org/keycloak/models/picketlink/mappings/RealmData.java index 8329e28672..24e1f03ca7 100755 --- a/model/picketlink/src/main/java/org/keycloak/models/picketlink/mappings/RealmData.java +++ b/model/picketlink/src/main/java/org/keycloak/models/picketlink/mappings/RealmData.java @@ -3,6 +3,9 @@ package org.keycloak.models.picketlink.mappings; import org.picketlink.idm.model.AbstractPartition; import org.picketlink.idm.model.annotation.AttributeProperty; +import java.io.Serializable; +import java.util.HashMap; + /** * @author Bill Burke * @version $Revision: 1 $ @@ -23,6 +26,8 @@ public class RealmData extends AbstractPartition { private String publicKeyPem; private String privateKeyPem; private String[] defaultRoles; + private HashMap smtpConfig; + private HashMap socialConfig; public RealmData() { super(null); @@ -163,4 +168,22 @@ public class RealmData extends AbstractPartition { public void setDefaultRoles(String[] defaultRoles) { this.defaultRoles = defaultRoles; } + + @AttributeProperty + public HashMap getSmtpConfig() { + return smtpConfig; + } + + public void setSmtpConfig(HashMap smtpConfig) { + this.smtpConfig = smtpConfig; + } + + @AttributeProperty + public HashMap getSocialConfig() { + return socialConfig; + } + + public void setSocialConfig(HashMap socialConfig) { + this.socialConfig = socialConfig; + } } diff --git a/model/picketlink/src/main/java/org/keycloak/models/picketlink/mappings/RealmEntity.java b/model/picketlink/src/main/java/org/keycloak/models/picketlink/mappings/RealmEntity.java index b44c218faa..74a3f09e6d 100755 --- a/model/picketlink/src/main/java/org/keycloak/models/picketlink/mappings/RealmEntity.java +++ b/model/picketlink/src/main/java/org/keycloak/models/picketlink/mappings/RealmEntity.java @@ -5,11 +5,9 @@ import org.picketlink.idm.jpa.annotations.OwnerReference; import org.picketlink.idm.jpa.annotations.entity.IdentityManaged; import org.picketlink.idm.jpa.model.sample.simple.PartitionTypeEntity; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.OneToOne; +import javax.persistence.*; import java.io.Serializable; +import java.util.HashMap; /** * @author Bill Burke @@ -56,6 +54,12 @@ public class RealmEntity implements Serializable { private String privateKeyPem; @AttributeValue private String[] defaultRoles; + @AttributeValue + @Lob + private HashMap smtpConfig; + @AttributeValue + @Lob + private HashMap socialConfig; public PartitionTypeEntity getPartitionTypeEntity() { @@ -177,4 +181,20 @@ public class RealmEntity implements Serializable { public void setPrivateKeyPem(String privateKeyPem) { this.privateKeyPem = privateKeyPem; } + + public HashMap getSmtpConfig() { + return smtpConfig; + } + + public void setSmtpConfig(HashMap smtpConfig) { + this.smtpConfig = smtpConfig; + } + + public HashMap getSocialConfig() { + return socialConfig; + } + + public void setSocialConfig(HashMap socialConfig) { + this.socialConfig = socialConfig; + } } diff --git a/services/src/main/java/org/keycloak/services/managers/RealmManager.java b/services/src/main/java/org/keycloak/services/managers/RealmManager.java index bae0cc2709..fdb8ea7162 100755 --- a/services/src/main/java/org/keycloak/services/managers/RealmManager.java +++ b/services/src/main/java/org/keycloak/services/managers/RealmManager.java @@ -96,6 +96,14 @@ public class RealmManager { } else { disableAccountManagement(realm); } + + if (rep.getSmtpServer() != null) { + realm.setSmtpConfig(new HashMap(rep.getSmtpServer())); + } + + if (rep.getSocialProviders() != null) { + realm.setSocialConfig(new HashMap(rep.getSocialProviders())); + } } private void enableAccountManagement(RealmModel realm) { @@ -248,6 +256,14 @@ public class RealmManager { if (rep.isAccountManagement() != null && rep.isAccountManagement()) { enableAccountManagement(newRealm); } + + if (rep.getSmtpServer() != null) { + newRealm.setSmtpConfig(new HashMap(rep.getSmtpServer())); + } + + if (rep.getSocialProviders() != null) { + newRealm.setSocialConfig(new HashMap(rep.getSocialProviders())); + } } public void createRole(RealmModel newRealm, RoleRepresentation roleRep) { @@ -403,6 +419,8 @@ public class RealmManager { rep.setTokenLifespan(realm.getTokenLifespan()); rep.setAccessCodeLifespan(realm.getAccessCodeLifespan()); rep.setAccessCodeLifespanUserAction(realm.getAccessCodeLifespanUserAction()); + rep.setSmtpServer(realm.getSmtpConfig()); + rep.setSocialProviders(realm.getSocialConfig()); ApplicationModel accountManagementApplication = realm.getApplicationNameMap().get(Constants.ACCOUNT_MANAGEMENT_APPLICATION); rep.setAccountManagement(accountManagementApplication != null && accountManagementApplication.isEnabled()); diff --git a/services/src/test/java/org/keycloak/test/ModelTest.java b/services/src/test/java/org/keycloak/test/ModelTest.java index a75fa76147..9f9400c55a 100755 --- a/services/src/test/java/org/keycloak/test/ModelTest.java +++ b/services/src/test/java/org/keycloak/test/ModelTest.java @@ -1,7 +1,9 @@ package org.keycloak.test; +import java.util.HashMap; import java.util.Iterator; import java.util.List; +import java.util.Map; import org.junit.After; import org.junit.Assert; @@ -51,6 +53,16 @@ public class ModelTest extends AbstractKeycloakServerTest { realm.setPrivateKeyPem("1234234"); realm.addDefaultRole("default-role"); + HashMap smtp = new HashMap(); + smtp.put("from", "auto@keycloak"); + smtp.put("hostname", "localhost"); + realm.setSmtpConfig(smtp); + + HashMap social = new HashMap(); + social.put("google.key", "1234"); + social.put("google.secret", "5678"); + realm.setSmtpConfig(social); + RealmModel peristed = manager.getRealm(realm.getId()); assertEquals(realm, peristed); @@ -75,6 +87,9 @@ public class ModelTest extends AbstractKeycloakServerTest { Assert.assertEquals(expected.getPrivateKeyPem(), actual.getPrivateKeyPem()); assertEquals(expected.getDefaultRoles(), actual.getDefaultRoles()); + + Assert.assertEquals(expected.getSmtpConfig(), actual.getSmtpConfig()); + Assert.assertEquals(expected.getSocialConfig(), actual.getSocialConfig()); } public static void assertEquals(List expected, List actual) {