diff --git a/examples/themes/README.md b/examples/themes/README.md index 0bf5f659fe..fccb847942 100644 --- a/examples/themes/README.md +++ b/examples/themes/README.md @@ -12,8 +12,22 @@ To use the theme copy `login/sunrise` to `standalone/configuration/themes/login/ Change Logo Theme ----------------- -Example themes for login forms, account management and admin console that changes the Keycloak logo. +Example themes for login forms, account management, admin console and welcome pages that changes the Keycloak logo. -To use the themes copy `account/logo-example` to `standalone/configuration/themes/account/`, `login/logo-example` to `standalone/configuration/themes/login/` and `admin/logo-example` to `standalone/configuration/themes/admin/`. Open the admin console, select your realm, click on `Theme`. In the dropdowns for `Login Theme`, `Account Theme` and `Admin Console Theme` select `logo-example`. Click `Save` and login to the realm to see the new theme in action. +To use the themes copy: + +* `account/logo-example` to `standalone/configuration/themes/account/` +* `login/logo-example` to `standalone/configuration/themes/login/` +* `admin/logo-example` to `standalone/configuration/themes/admin/` +* `welcome/logo-example` to `standalone/configuration/themes/welcome/` + +Open the admin console, select your realm, click on `Theme`. In the dropdowns for `Login Theme`, `Account Theme` and `Admin Console Theme` select `logo-example`. Click `Save` and login to the realm to see the new theme in action. + +To change the theme for the welcome pages open `standalone/configuration/keycloak-server.json` find the config for `theme` and add 'welcomeTheme': + + "theme": { + ... + "welcomeTheme": "logo-example" + }, One thing to note is that to change the admin console for the master admin console (`/auth/admin`) you need to change the theme for the master realm. Changing the admin console theme for any other realms will only change the admin console for that specific realm (for example `/auth/admin/myrealm/console`). diff --git a/examples/themes/welcome/logo-example/resources/index.html b/examples/themes/welcome/logo-example/resources/index.html new file mode 100755 index 0000000000..f13c512662 --- /dev/null +++ b/examples/themes/welcome/logo-example/resources/index.html @@ -0,0 +1,50 @@ + + + + + + Welcome to Keycloak + + + + + +
+
+ +

Welcome to Keycloak

+ +

Your Keycloak is running.

+ +

Documentation | Administration Console

+ +

Keycloak Project | + Mailing List | + Report an issue

+

JBoss and JBoss Community

+
+
+ + diff --git a/examples/themes/welcome/logo-example/resources/red-hat-logo.png b/examples/themes/welcome/logo-example/resources/red-hat-logo.png new file mode 100644 index 0000000000..0b01b1a445 Binary files /dev/null and b/examples/themes/welcome/logo-example/resources/red-hat-logo.png differ diff --git a/examples/themes/welcome/logo-example/theme.properties b/examples/themes/welcome/logo-example/theme.properties new file mode 100755 index 0000000000..512d63324a --- /dev/null +++ b/examples/themes/welcome/logo-example/theme.properties @@ -0,0 +1 @@ +parent=keycloak \ No newline at end of file diff --git a/forms/common-freemarker/src/main/java/org/keycloak/freemarker/Theme.java b/forms/common-freemarker/src/main/java/org/keycloak/freemarker/Theme.java index 14794fbcc8..dff92ee861 100644 --- a/forms/common-freemarker/src/main/java/org/keycloak/freemarker/Theme.java +++ b/forms/common-freemarker/src/main/java/org/keycloak/freemarker/Theme.java @@ -10,7 +10,7 @@ import java.util.Properties; */ public interface Theme { - public enum Type { LOGIN, ACCOUNT, ADMIN, EMAIL, COMMON }; + public enum Type { LOGIN, ACCOUNT, ADMIN, EMAIL, WELCOME, COMMON }; public String getName(); diff --git a/forms/common-themes/src/main/java/org/keycloak/theme/DefaultKeycloakThemeProvider.java b/forms/common-themes/src/main/java/org/keycloak/theme/DefaultKeycloakThemeProvider.java index 31f2831e82..a2776c5062 100644 --- a/forms/common-themes/src/main/java/org/keycloak/theme/DefaultKeycloakThemeProvider.java +++ b/forms/common-themes/src/main/java/org/keycloak/theme/DefaultKeycloakThemeProvider.java @@ -21,6 +21,7 @@ public class DefaultKeycloakThemeProvider implements ThemeProvider { private static Set LOGIN_THEMES = new HashSet(); private static Set ADMIN_THEMES = new HashSet(); private static Set EMAIL_THEMES = new HashSet(); + private static Set WELCOME_THEMES = new HashSet(); private static Set COMMON_THEMES = new HashSet(); static { @@ -28,6 +29,7 @@ public class DefaultKeycloakThemeProvider implements ThemeProvider { Collections.addAll(LOGIN_THEMES, BASE, PATTERNFLY, KEYCLOAK); Collections.addAll(ADMIN_THEMES, BASE, PATTERNFLY, KEYCLOAK); Collections.addAll(EMAIL_THEMES, KEYCLOAK); + Collections.addAll(WELCOME_THEMES, KEYCLOAK); Collections.addAll(COMMON_THEMES, KEYCLOAK); } @@ -56,6 +58,8 @@ public class DefaultKeycloakThemeProvider implements ThemeProvider { return ADMIN_THEMES; case EMAIL: return EMAIL_THEMES; + case WELCOME: + return WELCOME_THEMES; case COMMON: return COMMON_THEMES; default: diff --git a/services/src/main/resources/welcome-content/favicon.ico b/forms/common-themes/src/main/resources/theme/welcome/keycloak/resources/favicon.ico similarity index 100% rename from services/src/main/resources/welcome-content/favicon.ico rename to forms/common-themes/src/main/resources/theme/welcome/keycloak/resources/favicon.ico diff --git a/services/src/main/resources/welcome-content/index.html b/forms/common-themes/src/main/resources/theme/welcome/keycloak/resources/index.html similarity index 100% rename from services/src/main/resources/welcome-content/index.html rename to forms/common-themes/src/main/resources/theme/welcome/keycloak/resources/index.html diff --git a/services/src/main/resources/welcome-content/jboss_community.png b/forms/common-themes/src/main/resources/theme/welcome/keycloak/resources/jboss_community.png similarity index 100% rename from services/src/main/resources/welcome-content/jboss_community.png rename to forms/common-themes/src/main/resources/theme/welcome/keycloak/resources/jboss_community.png diff --git a/services/src/main/resources/welcome-content/keycloak.css b/forms/common-themes/src/main/resources/theme/welcome/keycloak/resources/keycloak.css similarity index 100% rename from services/src/main/resources/welcome-content/keycloak.css rename to forms/common-themes/src/main/resources/theme/welcome/keycloak/resources/keycloak.css diff --git a/services/src/main/resources/welcome-content/keycloak_logo.png b/forms/common-themes/src/main/resources/theme/welcome/keycloak/resources/keycloak_logo.png similarity index 100% rename from services/src/main/resources/welcome-content/keycloak_logo.png rename to forms/common-themes/src/main/resources/theme/welcome/keycloak/resources/keycloak_logo.png diff --git a/services/src/main/java/org/keycloak/services/resources/WelcomeResource.java b/services/src/main/java/org/keycloak/services/resources/WelcomeResource.java index 9716ff65b4..5158e67d84 100755 --- a/services/src/main/java/org/keycloak/services/resources/WelcomeResource.java +++ b/services/src/main/java/org/keycloak/services/resources/WelcomeResource.java @@ -1,9 +1,19 @@ package org.keycloak.services.resources; +import org.jboss.logging.Logger; +import org.keycloak.Config; +import org.keycloak.freemarker.BrowserSecurityHeaderSetup; +import org.keycloak.freemarker.Theme; +import org.keycloak.freemarker.ThemeProvider; +import org.keycloak.models.KeycloakSession; + +import javax.activation.FileTypeMap; +import javax.activation.MimetypesFileTypeMap; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; +import javax.ws.rs.core.CacheControl; import javax.ws.rs.core.Context; import javax.ws.rs.core.Response; import javax.ws.rs.core.UriInfo; @@ -17,9 +27,16 @@ import java.net.URISyntaxException; @Path("/") public class WelcomeResource { + private static final Logger logger = Logger.getLogger(WelcomeResource.class); + + private static FileTypeMap mimeTypes = MimetypesFileTypeMap.getDefaultFileTypeMap(); + @Context private UriInfo uriInfo; + @Context + protected KeycloakSession session; + /** * Welcome page of Keycloak * @@ -40,18 +57,34 @@ public class WelcomeResource { /** * Resources for welcome page * - * @param name + * @param path * @return */ @GET - @Path("/welcome-content/{name}") + @Path("/welcome-content/{path}") @Produces("text/html") - public Response getResource(@PathParam("name") String name) { - InputStream inputStream = getClass().getClassLoader().getResourceAsStream("welcome-content/" + name); - if (inputStream != null) { - return Response.ok(inputStream).build(); - } else { - return Response.status(Response.Status.NOT_FOUND).build(); + public Response getResource(@PathParam("path") String path) { + try { + Config.Scope config = Config.scope("theme"); + + ThemeProvider themeProvider = session.getProvider(ThemeProvider.class, "extending"); + Theme theme = themeProvider.getTheme(config.get("welcomeTheme"), Theme.Type.WELCOME); + InputStream resource = theme.getResourceAsStream(path); + if (resource != null) { + String contentType = mimeTypes.getContentType(path); + + CacheControl cacheControl = new CacheControl(); + cacheControl.setNoTransform(false); + cacheControl.setMaxAge(config.getInt("staticMaxAge", -1)); + + Response.ResponseBuilder builder = Response.ok(resource).type(contentType).cacheControl(cacheControl); + return builder.build(); + } else { + return Response.status(Response.Status.NOT_FOUND).build(); + } + } catch (Exception e) { + logger.warn("Failed to get theme resource", e); + return Response.serverError().build(); } } diff --git a/services/src/main/resources/META-INF/mime.types b/services/src/main/resources/META-INF/mime.types index 48af349f68..11de430b04 100755 --- a/services/src/main/resources/META-INF/mime.types +++ b/services/src/main/resources/META-INF/mime.types @@ -1,5 +1,6 @@ text/css css CSS text/javascript js JS text/javascript js JS +image/png png PNG image/svg+xml svg SVG text/html html htm HTML HTM \ No newline at end of file diff --git a/testsuite/integration/src/main/java/org/keycloak/testutils/KeycloakServer.java b/testsuite/integration/src/main/java/org/keycloak/testutils/KeycloakServer.java index 2c70fb11e3..9b0c200e20 100755 --- a/testsuite/integration/src/main/java/org/keycloak/testutils/KeycloakServer.java +++ b/testsuite/integration/src/main/java/org/keycloak/testutils/KeycloakServer.java @@ -296,7 +296,7 @@ public class KeycloakServer { di.setDeploymentName("Keycloak"); di.setDefaultServletConfig(new DefaultServletConfig(true)); - di.addWelcomePage("welcome-content/index.html"); + di.addWelcomePage("theme/welcome/keycloak/resources/index.html"); FilterInfo filter = Servlets.filter("SessionFilter", KeycloakSessionServletFilter.class); di.addFilter(filter); diff --git a/testsuite/integration/src/main/resources/META-INF/keycloak-server.json b/testsuite/integration/src/main/resources/META-INF/keycloak-server.json index 6e90fa12df..5aa1bacb54 100755 --- a/testsuite/integration/src/main/resources/META-INF/keycloak-server.json +++ b/testsuite/integration/src/main/resources/META-INF/keycloak-server.json @@ -41,7 +41,8 @@ "cacheThemes": "${keycloak.theme.cacheThemes:true}", "folder": { "dir": "${keycloak.theme.dir}" - } + }, + "welcomeTheme": "logo-example" }, "login": {