Merge pull request #733 from stianst/master
KEYCLOAK-701 Use built-in themes if specified theme is not found
This commit is contained in:
commit
98f9c798f0
1 changed files with 13 additions and 10 deletions
|
@ -1,5 +1,6 @@
|
||||||
package org.keycloak.freemarker;
|
package org.keycloak.freemarker;
|
||||||
|
|
||||||
|
import org.jboss.logging.Logger;
|
||||||
import org.keycloak.Config;
|
import org.keycloak.Config;
|
||||||
import org.keycloak.models.KeycloakSession;
|
import org.keycloak.models.KeycloakSession;
|
||||||
|
|
||||||
|
@ -21,17 +22,17 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||||
*/
|
*/
|
||||||
public class ExtendingThemeManager implements ThemeProvider {
|
public class ExtendingThemeManager implements ThemeProvider {
|
||||||
|
|
||||||
|
private static final Logger log = Logger.getLogger(ExtendingThemeManager.class);
|
||||||
|
|
||||||
private final KeycloakSession session;
|
private final KeycloakSession session;
|
||||||
private final ConcurrentHashMap<ExtendingThemeManagerFactory.ThemeKey, Theme> themeCache;
|
private final ConcurrentHashMap<ExtendingThemeManagerFactory.ThemeKey, Theme> themeCache;
|
||||||
private List<ThemeProvider> providers;
|
private List<ThemeProvider> providers;
|
||||||
private String defaultTheme;
|
private String defaultTheme;
|
||||||
private int staticMaxAge;
|
|
||||||
|
|
||||||
public ExtendingThemeManager(KeycloakSession session, ConcurrentHashMap<ExtendingThemeManagerFactory.ThemeKey, Theme> themeCache) {
|
public ExtendingThemeManager(KeycloakSession session, ConcurrentHashMap<ExtendingThemeManagerFactory.ThemeKey, Theme> themeCache) {
|
||||||
this.session = session;
|
this.session = session;
|
||||||
this.themeCache = themeCache;
|
this.themeCache = themeCache;
|
||||||
this.defaultTheme = Config.scope("theme").get("default", "keycloak");
|
this.defaultTheme = Config.scope("theme").get("default", "keycloak");
|
||||||
this.staticMaxAge = Config.scope("theme").getInt("staticMaxAge", -1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<ThemeProvider> getProviders() {
|
private List<ThemeProvider> getProviders() {
|
||||||
|
@ -57,10 +58,6 @@ public class ExtendingThemeManager implements ThemeProvider {
|
||||||
return providers;
|
return providers;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getStaticMaxAge() {
|
|
||||||
return staticMaxAge;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getProviderPriority() {
|
public int getProviderPriority() {
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -77,7 +74,13 @@ public class ExtendingThemeManager implements ThemeProvider {
|
||||||
Theme theme = themeCache.get(key);
|
Theme theme = themeCache.get(key);
|
||||||
if (theme == null) {
|
if (theme == null) {
|
||||||
theme = loadTheme(name, type);
|
theme = loadTheme(name, type);
|
||||||
if (themeCache.putIfAbsent(key, theme) != null) {
|
if (theme == null) {
|
||||||
|
theme = loadTheme("keycloak", type);
|
||||||
|
if (theme == null) {
|
||||||
|
theme = loadTheme("base", type);
|
||||||
|
}
|
||||||
|
log.errorv("Failed to find {0} theme {1}, using built-in themes", type, name);
|
||||||
|
} else if (themeCache.putIfAbsent(key, theme) != null) {
|
||||||
theme = themeCache.get(key);
|
theme = themeCache.get(key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -89,7 +92,7 @@ public class ExtendingThemeManager implements ThemeProvider {
|
||||||
|
|
||||||
private Theme loadTheme(String name, Theme.Type type) throws IOException {
|
private Theme loadTheme(String name, Theme.Type type) throws IOException {
|
||||||
Theme theme = findTheme(name, type);
|
Theme theme = findTheme(name, type);
|
||||||
if (theme.getParentName() != null) {
|
if (theme != null && theme.getParentName() != null) {
|
||||||
List<Theme> themes = new LinkedList<Theme>();
|
List<Theme> themes = new LinkedList<Theme>();
|
||||||
themes.add(theme);
|
themes.add(theme);
|
||||||
|
|
||||||
|
@ -144,11 +147,11 @@ public class ExtendingThemeManager implements ThemeProvider {
|
||||||
try {
|
try {
|
||||||
return p.getTheme(name, type);
|
return p.getTheme(name, type);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException("Failed to create " + type.toString().toLowerCase() + " theme", e);
|
log.errorv(e, p.getClass() + " failed to load theme, type={0}, name={1}", type, name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw new RuntimeException(type.toString().toLowerCase() + " theme '" + name + "' not found");
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class ExtendingTheme implements Theme {
|
public static class ExtendingTheme implements Theme {
|
||||||
|
|
Loading…
Reference in a new issue