Add email theme config for realm
This commit is contained in:
parent
ebea9e9270
commit
8d1149dc07
12 changed files with 72 additions and 8 deletions
|
@ -18,10 +18,6 @@ import java.util.Collections;
|
||||||
*/
|
*/
|
||||||
public class MongoAuditProviderFactory implements AuditProviderFactory {
|
public class MongoAuditProviderFactory implements AuditProviderFactory {
|
||||||
|
|
||||||
private static final String MONGO_HOST = "keycloak.audit.mongo.host";
|
|
||||||
private static final String MONGO_PORT = "keycloak.audit.mongo.port";
|
|
||||||
private static final String MONGO_DB_NAME = "keycloak.audit.mongo.db";
|
|
||||||
|
|
||||||
public static final String ID = "mongo";
|
public static final String ID = "mongo";
|
||||||
private MongoClient client;
|
private MongoClient client;
|
||||||
private DB db;
|
private DB db;
|
||||||
|
|
|
@ -57,6 +57,7 @@ public class RealmRepresentation {
|
||||||
protected String loginTheme;
|
protected String loginTheme;
|
||||||
protected String accountTheme;
|
protected String accountTheme;
|
||||||
protected String adminTheme;
|
protected String adminTheme;
|
||||||
|
protected String emailTheme;
|
||||||
protected boolean auditEnabled;
|
protected boolean auditEnabled;
|
||||||
protected long auditExpiration;
|
protected long auditExpiration;
|
||||||
protected List<String> auditListeners;
|
protected List<String> auditListeners;
|
||||||
|
@ -377,6 +378,14 @@ public class RealmRepresentation {
|
||||||
this.adminTheme = adminTheme;
|
this.adminTheme = adminTheme;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getEmailTheme() {
|
||||||
|
return emailTheme;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEmailTheme(String emailTheme) {
|
||||||
|
this.emailTheme = emailTheme;
|
||||||
|
}
|
||||||
|
|
||||||
public Integer getNotBefore() {
|
public Integer getNotBefore() {
|
||||||
return notBefore;
|
return notBefore;
|
||||||
}
|
}
|
||||||
|
|
|
@ -111,6 +111,18 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label class="col-sm-2 control-label" for="emailTheme">Email Theme</label>
|
||||||
|
<div class="col-sm-4">
|
||||||
|
<div class="select-kc">
|
||||||
|
<select id="emailTheme"
|
||||||
|
ng-model="realm.emailTheme"
|
||||||
|
ng-options="o as o for o in serverInfo.themes.email">
|
||||||
|
<option value="" disabled selected>Select one...</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
|
|
||||||
<div class="pull-right form-actions" data-ng-show="createRealm && access.manageRealm">
|
<div class="pull-right form-actions" data-ng-show="createRealm && access.manageRealm">
|
||||||
|
|
|
@ -68,7 +68,7 @@ public class FreeMarkerEmailProvider implements EmailProvider {
|
||||||
private void send(String subjectKey, String template, Map<String, Object> attributes) throws EmailException {
|
private void send(String subjectKey, String template, Map<String, Object> attributes) throws EmailException {
|
||||||
try {
|
try {
|
||||||
ExtendingThemeManager themeManager = new ExtendingThemeManager(session);
|
ExtendingThemeManager themeManager = new ExtendingThemeManager(session);
|
||||||
Theme theme = themeManager.createTheme(realm.getAccountTheme(), Theme.Type.EMAIL);
|
Theme theme = themeManager.createTheme(realm.getEmailTheme(), Theme.Type.EMAIL);
|
||||||
|
|
||||||
String subject = theme.getMessages().getProperty(subjectKey);
|
String subject = theme.getMessages().getProperty(subjectKey);
|
||||||
String body = FreeMarkerUtil.processTemplate(attributes, template, theme);
|
String body = FreeMarkerUtil.processTemplate(attributes, template, theme);
|
||||||
|
|
|
@ -222,6 +222,10 @@ public interface RealmModel extends RoleContainerModel, RoleMapperModel, ScopeMa
|
||||||
|
|
||||||
void setAdminTheme(String name);
|
void setAdminTheme(String name);
|
||||||
|
|
||||||
|
String getEmailTheme();
|
||||||
|
|
||||||
|
void setEmailTheme(String name);
|
||||||
|
|
||||||
boolean hasScope(ClientModel client, RoleModel role);
|
boolean hasScope(ClientModel client, RoleModel role);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -43,6 +43,7 @@ public class RealmEntity extends AbstractIdentifiableEntity {
|
||||||
private String loginTheme;
|
private String loginTheme;
|
||||||
private String accountTheme;
|
private String accountTheme;
|
||||||
private String adminTheme;
|
private String adminTheme;
|
||||||
|
private String emailTheme;
|
||||||
|
|
||||||
// We are using names of defaultRoles (not ids)
|
// We are using names of defaultRoles (not ids)
|
||||||
private List<String> defaultRoles = new ArrayList<String>();
|
private List<String> defaultRoles = new ArrayList<String>();
|
||||||
|
@ -284,6 +285,14 @@ public class RealmEntity extends AbstractIdentifiableEntity {
|
||||||
this.adminTheme = adminTheme;
|
this.adminTheme = adminTheme;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getEmailTheme() {
|
||||||
|
return emailTheme;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEmailTheme(String emailTheme) {
|
||||||
|
this.emailTheme = emailTheme;
|
||||||
|
}
|
||||||
|
|
||||||
public List<String> getDefaultRoles() {
|
public List<String> getDefaultRoles() {
|
||||||
return defaultRoles;
|
return defaultRoles;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1351,6 +1351,17 @@ public class RealmAdapter implements RealmModel {
|
||||||
em.flush();
|
em.flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getEmailTheme() {
|
||||||
|
return realm.getEmailTheme();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setEmailTheme(String name) {
|
||||||
|
realm.setEmailTheme(name);
|
||||||
|
em.flush();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isAuditEnabled() {
|
public boolean isAuditEnabled() {
|
||||||
return realm.isAuditEnabled();
|
return realm.isAuditEnabled();
|
||||||
|
|
|
@ -75,6 +75,7 @@ public class RealmEntity {
|
||||||
protected String loginTheme;
|
protected String loginTheme;
|
||||||
protected String accountTheme;
|
protected String accountTheme;
|
||||||
protected String adminTheme;
|
protected String adminTheme;
|
||||||
|
protected String emailTheme;
|
||||||
|
|
||||||
@OneToMany(cascade ={CascadeType.REMOVE}, orphanRemoval = true)
|
@OneToMany(cascade ={CascadeType.REMOVE}, orphanRemoval = true)
|
||||||
@JoinTable(name="User_RequiredCreds")
|
@JoinTable(name="User_RequiredCreds")
|
||||||
|
@ -360,6 +361,14 @@ public class RealmEntity {
|
||||||
this.adminTheme = adminTheme;
|
this.adminTheme = adminTheme;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getEmailTheme() {
|
||||||
|
return emailTheme;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEmailTheme(String emailTheme) {
|
||||||
|
this.emailTheme = emailTheme;
|
||||||
|
}
|
||||||
|
|
||||||
public int getNotBefore() {
|
public int getNotBefore() {
|
||||||
return notBefore;
|
return notBefore;
|
||||||
}
|
}
|
||||||
|
|
|
@ -420,6 +420,17 @@ public class RealmAdapter extends AbstractMongoAdapter<MongoRealmEntity> impleme
|
||||||
updateRealm();
|
updateRealm();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getEmailTheme() {
|
||||||
|
return realm.getEmailTheme();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setEmailTheme(String name) {
|
||||||
|
realm.setEmailTheme(name);
|
||||||
|
updateRealm();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UserAdapter getUser(String name) {
|
public UserAdapter getUser(String name) {
|
||||||
DBObject query = new QueryBuilder()
|
DBObject query = new QueryBuilder()
|
||||||
|
|
|
@ -103,6 +103,7 @@ public class ModelToRepresentation {
|
||||||
rep.setAccountTheme(realm.getAccountTheme());
|
rep.setAccountTheme(realm.getAccountTheme());
|
||||||
rep.setLoginTheme(realm.getLoginTheme());
|
rep.setLoginTheme(realm.getLoginTheme());
|
||||||
rep.setAdminTheme(realm.getAdminTheme());
|
rep.setAdminTheme(realm.getAdminTheme());
|
||||||
|
rep.setEmailTheme(realm.getEmailTheme());
|
||||||
if (realm.getPasswordPolicy() != null) {
|
if (realm.getPasswordPolicy() != null) {
|
||||||
rep.setPasswordPolicy(realm.getPasswordPolicy().toString());
|
rep.setPasswordPolicy(realm.getPasswordPolicy().toString());
|
||||||
}
|
}
|
||||||
|
|
|
@ -194,6 +194,7 @@ public class RealmManager {
|
||||||
if (rep.getLoginTheme() != null) realm.setLoginTheme(rep.getLoginTheme());
|
if (rep.getLoginTheme() != null) realm.setLoginTheme(rep.getLoginTheme());
|
||||||
if (rep.getAccountTheme() != null) realm.setAccountTheme(rep.getAccountTheme());
|
if (rep.getAccountTheme() != null) realm.setAccountTheme(rep.getAccountTheme());
|
||||||
if (rep.getAdminTheme() != null) realm.setAdminTheme(rep.getAdminTheme());
|
if (rep.getAdminTheme() != null) realm.setAdminTheme(rep.getAdminTheme());
|
||||||
|
if (rep.getEmailTheme() != null) realm.setEmailTheme(rep.getEmailTheme());
|
||||||
|
|
||||||
if (rep.getPasswordPolicy() != null) realm.setPasswordPolicy(new PasswordPolicy(rep.getPasswordPolicy()));
|
if (rep.getPasswordPolicy() != null) realm.setPasswordPolicy(new PasswordPolicy(rep.getPasswordPolicy()));
|
||||||
|
|
||||||
|
@ -344,7 +345,8 @@ public class RealmManager {
|
||||||
}
|
}
|
||||||
if (rep.getLoginTheme() != null) newRealm.setLoginTheme(rep.getLoginTheme());
|
if (rep.getLoginTheme() != null) newRealm.setLoginTheme(rep.getLoginTheme());
|
||||||
if (rep.getAccountTheme() != null) newRealm.setAccountTheme(rep.getAccountTheme());
|
if (rep.getAccountTheme() != null) newRealm.setAccountTheme(rep.getAccountTheme());
|
||||||
if (rep.getAdminTheme() != null) newRealm.setAdminTheme(rep.getAccountTheme());
|
if (rep.getAdminTheme() != null) newRealm.setAdminTheme(rep.getAdminTheme());
|
||||||
|
if (rep.getEmailTheme() != null) newRealm.setEmailTheme(rep.getEmailTheme());
|
||||||
|
|
||||||
Map<String, UserModel> userMap = new HashMap<String, UserModel>();
|
Map<String, UserModel> userMap = new HashMap<String, UserModel>();
|
||||||
|
|
||||||
|
|
|
@ -37,11 +37,11 @@ public class ServerInfoAdminResource {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setThemes(ServerInfoRepresentation info) {
|
private void setThemes(ServerInfoRepresentation info) {
|
||||||
Iterable<ThemeProvider> providers = ProviderLoader.load(ThemeProvider.class);
|
Set<ThemeProvider> themeProviders = providers.getAllProviders(ThemeProvider.class);
|
||||||
info.themes = new HashMap<String, List<String>>();
|
info.themes = new HashMap<String, List<String>>();
|
||||||
for (Theme.Type type : Theme.Type.values()) {
|
for (Theme.Type type : Theme.Type.values()) {
|
||||||
List<String> themes = new LinkedList<String>();
|
List<String> themes = new LinkedList<String>();
|
||||||
for (ThemeProvider p : providers) {
|
for (ThemeProvider p : themeProviders) {
|
||||||
themes.addAll(p.nameSet(type));
|
themes.addAll(p.nameSet(type));
|
||||||
}
|
}
|
||||||
Collections.sort(themes);
|
Collections.sort(themes);
|
||||||
|
|
Loading…
Reference in a new issue