KEYCLOAK-653 Add theme support to welcome-pages
|
@ -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`).
|
||||
|
|
50
examples/themes/welcome/logo-example/resources/index.html
Executable file
|
@ -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>
|
BIN
examples/themes/welcome/logo-example/resources/red-hat-logo.png
Normal file
After Width: | Height: | Size: 2.9 KiB |
1
examples/themes/welcome/logo-example/theme.properties
Executable file
|
@ -0,0 +1 @@
|
|||
parent=keycloak
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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:
|
||||
|
|
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 1.1 KiB |
Before Width: | Height: | Size: 2.7 KiB After Width: | Height: | Size: 2.7 KiB |
Before Width: | Height: | Size: 22 KiB After Width: | Height: | Size: 22 KiB |
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
|
@ -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);
|
||||
|
|
|
@ -41,7 +41,8 @@
|
|||
"cacheThemes": "${keycloak.theme.cacheThemes:true}",
|
||||
"folder": {
|
||||
"dir": "${keycloak.theme.dir}"
|
||||
}
|
||||
},
|
||||
"welcomeTheme": "logo-example"
|
||||
},
|
||||
|
||||
"login": {
|
||||
|
|