Added maps for social config and smtp server to realm
This commit is contained in:
parent
36662fb5ca
commit
a88dcace3d
7 changed files with 117 additions and 5 deletions
|
@ -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<OAuthClientModel> getOAuthClients();
|
||||
|
||||
HashMap<String, String> getSmtpConfig();
|
||||
|
||||
void setSmtpConfig(HashMap<String, String> smtpConfig);
|
||||
|
||||
HashMap<String, String> getSocialConfig();
|
||||
|
||||
void setSocialConfig(HashMap<String, String> socialConfig);
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package org.keycloak.models.jpa.entities;
|
|||
|
||||
import javax.persistence.*;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
|
||||
|
@ -24,6 +25,10 @@ public class RealmEntity {
|
|||
@Column(length = 2048)
|
||||
protected String privateKeyPem;
|
||||
protected String[] defaultRoles;
|
||||
@Lob
|
||||
protected HashMap<String, String> smtpConfig;
|
||||
@Lob
|
||||
protected HashMap<String, String> socialConfig;
|
||||
|
||||
@OneToMany(cascade ={CascadeType.REMOVE}, orphanRemoval = true)
|
||||
Collection<RequiredCredentailEntity> requiredCredentials;
|
||||
|
|
|
@ -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<String, String> getSmtpConfig() {
|
||||
return realm.getSmtpConfig();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSmtpConfig(HashMap<String, String> smtpConfig) {
|
||||
realm.setSmtpConfig(smtpConfig);
|
||||
updateRealm();
|
||||
}
|
||||
|
||||
@Override
|
||||
public HashMap<String, String> getSocialConfig() {
|
||||
return realm.getSocialConfig();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSocialConfig(HashMap<String, String> socialConfig) {
|
||||
realm.setSocialConfig(socialConfig);
|
||||
updateRealm();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 <a href="mailto:bill@burkecentral.com">Bill Burke</a>
|
||||
* @version $Revision: 1 $
|
||||
|
@ -23,6 +26,8 @@ public class RealmData extends AbstractPartition {
|
|||
private String publicKeyPem;
|
||||
private String privateKeyPem;
|
||||
private String[] defaultRoles;
|
||||
private HashMap<String, String> smtpConfig;
|
||||
private HashMap<String, String> 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<String, String> getSmtpConfig() {
|
||||
return smtpConfig;
|
||||
}
|
||||
|
||||
public void setSmtpConfig(HashMap<String, String> smtpConfig) {
|
||||
this.smtpConfig = smtpConfig;
|
||||
}
|
||||
|
||||
@AttributeProperty
|
||||
public HashMap<String, String> getSocialConfig() {
|
||||
return socialConfig;
|
||||
}
|
||||
|
||||
public void setSocialConfig(HashMap<String, String> socialConfig) {
|
||||
this.socialConfig = socialConfig;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 <a href="mailto:bill@burkecentral.com">Bill Burke</a>
|
||||
|
@ -56,6 +54,12 @@ public class RealmEntity implements Serializable {
|
|||
private String privateKeyPem;
|
||||
@AttributeValue
|
||||
private String[] defaultRoles;
|
||||
@AttributeValue
|
||||
@Lob
|
||||
private HashMap<String, String> smtpConfig;
|
||||
@AttributeValue
|
||||
@Lob
|
||||
private HashMap<String, String> socialConfig;
|
||||
|
||||
|
||||
public PartitionTypeEntity getPartitionTypeEntity() {
|
||||
|
@ -177,4 +181,20 @@ public class RealmEntity implements Serializable {
|
|||
public void setPrivateKeyPem(String privateKeyPem) {
|
||||
this.privateKeyPem = privateKeyPem;
|
||||
}
|
||||
|
||||
public HashMap<String, String> getSmtpConfig() {
|
||||
return smtpConfig;
|
||||
}
|
||||
|
||||
public void setSmtpConfig(HashMap<String, String> smtpConfig) {
|
||||
this.smtpConfig = smtpConfig;
|
||||
}
|
||||
|
||||
public HashMap<String, String> getSocialConfig() {
|
||||
return socialConfig;
|
||||
}
|
||||
|
||||
public void setSocialConfig(HashMap<String, String> socialConfig) {
|
||||
this.socialConfig = socialConfig;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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<String, String> smtp = new HashMap<String,String>();
|
||||
smtp.put("from", "auto@keycloak");
|
||||
smtp.put("hostname", "localhost");
|
||||
realm.setSmtpConfig(smtp);
|
||||
|
||||
HashMap<String, String> social = new HashMap<String,String>();
|
||||
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<RoleModel> expected, List<RoleModel> actual) {
|
||||
|
|
Loading…
Reference in a new issue