keycloak-aplcache
Changes
examples/themes/README.md 18(+16 -2)
Details
examples/themes/README.md 18(+16 -2)
diff --git a/examples/themes/README.md b/examples/themes/README.md
index 0bf5f65..fccb847 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 0000000..f13c512
--- /dev/null
+++ b/examples/themes/welcome/logo-example/resources/index.html
@@ -0,0 +1,50 @@
+<!--
+ ~ JBoss, Home of Professional Open Source.
+ ~ Copyright (c) 2011, Red Hat, Inc., and individual contributors
+ ~ as indicated by the @author tags. See the copyright.txt file in the
+ ~ distribution for a full listing of individual contributors.
+ ~
+ ~ This is free software; you can redistribute it and/or modify it
+ ~ under the terms of the GNU Lesser General Public License as
+ ~ published by the Free Software Foundation; either version 2.1 of
+ ~ the License, or (at your option) any later version.
+ ~
+ ~ This software is distributed in the hope that it will be useful,
+ ~ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ ~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ ~ Lesser General Public License for more details.
+ ~
+ ~ You should have received a copy of the GNU Lesser General Public
+ ~ License along with this software; if not, write to the Free
+ ~ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ ~ 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ -->
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+
+<html>
+<head>
+ <title>Welcome to Keycloak</title>
+ <link rel="shortcut icon" href="welcome-content/favicon.ico" type="image/x-icon">
+ <link rel="StyleSheet" href="welcome-content/keycloak.css" type="text/css">
+</head>
+
+<body>
+<div class="wrapper">
+ <div class="content">
+ <div class="logo">
+ <img src="welcome-content/red-hat-logo.png" alt="Red Hat" border="0" />
+ </div>
+ <h1>Welcome to Keycloak</h1>
+
+ <h3>Your Keycloak is running.</h3>
+
+ <p><a href="http://www.keycloak.org/docs">Documentation</a> | <a href="admin/">Administration Console</a> </p>
+
+ <p><a href="http://www.keycloak.org">Keycloak Project</a> |
+ <a href="https://lists.jboss.org/mailman/listinfo/keycloak-user">Mailing List</a> |
+ <a href="https://issues.jboss.org/browse/KEYCLOAK">Report an issue</a></p>
+ <p class="logos"><a href="http://www.jboss.org"><img src="welcome-content/jboss_community.png" alt="JBoss and JBoss Community" width="254" height="31" border="0"></a></p>
+ </div>
+</div>
+</body>
+</html>
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 0000000..0b01b1a
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 0000000..512d633
--- /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 14794fb..dff92ee 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 31f2831..a2776c5 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<String> LOGIN_THEMES = new HashSet<String>();
private static Set<String> ADMIN_THEMES = new HashSet<String>();
private static Set<String> EMAIL_THEMES = new HashSet<String>();
+ private static Set<String> WELCOME_THEMES = new HashSet<String>();
private static Set<String> COMMON_THEMES = new HashSet<String>();
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/java/org/keycloak/services/resources/WelcomeResource.java b/services/src/main/java/org/keycloak/services/resources/WelcomeResource.java
index 9716ff6..5158e67 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 48af349..11de430 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 2c70fb1..9b0c200 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 6e90fa1..5aa1bac 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": {