From b8cf83c3cf4310f3224ef34ccdc32c0684f93596 Mon Sep 17 00:00:00 2001 From: Stian Thorgersen Date: Mon, 17 Feb 2014 14:51:32 +0000 Subject: [PATCH] Added app name to 'back to app' link in acct mngmt --- .../account/freemarker/FreeMarkerAccount.java | 12 +++++++--- .../freemarker/model/ReferrerBean.java | 24 +++++++++++++++++++ .../account/freemarker/model/UrlBean.java | 8 +------ .../resources/theme/account/base/template.ftl | 2 +- 4 files changed, 35 insertions(+), 11 deletions(-) create mode 100644 forms/account-freemarker/src/main/java/org/keycloak/account/freemarker/model/ReferrerBean.java diff --git a/forms/account-freemarker/src/main/java/org/keycloak/account/freemarker/FreeMarkerAccount.java b/forms/account-freemarker/src/main/java/org/keycloak/account/freemarker/FreeMarkerAccount.java index 9c5a687dc2..64f41354ad 100644 --- a/forms/account-freemarker/src/main/java/org/keycloak/account/freemarker/FreeMarkerAccount.java +++ b/forms/account-freemarker/src/main/java/org/keycloak/account/freemarker/FreeMarkerAccount.java @@ -5,6 +5,7 @@ import org.keycloak.account.Account; import org.keycloak.account.AccountPages; import org.keycloak.account.freemarker.model.AccountBean; import org.keycloak.account.freemarker.model.MessageBean; +import org.keycloak.account.freemarker.model.ReferrerBean; import org.keycloak.account.freemarker.model.TotpBean; import org.keycloak.account.freemarker.model.UrlBean; import org.keycloak.freemarker.FreeMarkerException; @@ -80,7 +81,12 @@ public class FreeMarkerAccount implements Account { attributes.put("message", new MessageBean(messages.containsKey(message) ? messages.getProperty(message) : message, messageType)); } - attributes.put("url", new UrlBean(realm, theme, baseUri, getReferrerUri())); + ApplicationModel referrerApp = getReferrer(); + if (referrerApp != null) { + attributes.put("referrer", new ReferrerBean(referrerApp)); + } + + attributes.put("url", new UrlBean(realm, theme, baseUri)); switch (page) { case ACCOUNT: @@ -100,11 +106,11 @@ public class FreeMarkerAccount implements Account { } } - private String getReferrerUri() { + private ApplicationModel getReferrer() { if (referrer != null) { ApplicationModel app = realm.getApplicationByName(referrer); if (app != null) { - return app.getBaseUrl(); + return app; } } return null; diff --git a/forms/account-freemarker/src/main/java/org/keycloak/account/freemarker/model/ReferrerBean.java b/forms/account-freemarker/src/main/java/org/keycloak/account/freemarker/model/ReferrerBean.java new file mode 100644 index 0000000000..8904bf663f --- /dev/null +++ b/forms/account-freemarker/src/main/java/org/keycloak/account/freemarker/model/ReferrerBean.java @@ -0,0 +1,24 @@ +package org.keycloak.account.freemarker.model; + +import org.keycloak.models.ApplicationModel; + +/** + * @author Stian Thorgersen + */ +public class ReferrerBean { + + private ApplicationModel referrer; + + public ReferrerBean(ApplicationModel referrer) { + this.referrer = referrer; + } + + public String getName() { + return referrer.getName(); + } + + public String getBaseUrl() { + return referrer.getBaseUrl(); + } + +} diff --git a/forms/account-freemarker/src/main/java/org/keycloak/account/freemarker/model/UrlBean.java b/forms/account-freemarker/src/main/java/org/keycloak/account/freemarker/model/UrlBean.java index 46dbb4ee50..53dde7cd66 100644 --- a/forms/account-freemarker/src/main/java/org/keycloak/account/freemarker/model/UrlBean.java +++ b/forms/account-freemarker/src/main/java/org/keycloak/account/freemarker/model/UrlBean.java @@ -14,13 +14,11 @@ public class UrlBean { private String realm; private Theme theme; private URI baseURI; - private String referrerURI; - public UrlBean(RealmModel realm, Theme theme, URI baseURI, String referrerURI) { + public UrlBean(RealmModel realm, Theme theme, URI baseURI) { this.realm = realm.getName(); this.theme = theme; this.baseURI = baseURI; - this.referrerURI = referrerURI; } public String getAccessUrl() { @@ -51,10 +49,6 @@ public class UrlBean { return Urls.accountLogout(baseURI, realm).toString(); } - public String getReferrerURI() { - return referrerURI; - } - public String getResourcesPath() { URI uri = Urls.themeRoot(baseURI); return uri.getPath() + "/" + theme.getType().toString().toLowerCase() +"/" + theme.getName(); diff --git a/forms/common-themes/src/main/resources/theme/account/base/template.ftl b/forms/common-themes/src/main/resources/theme/account/base/template.ftl index 66da0f8e78..355b58304d 100644 --- a/forms/common-themes/src/main/resources/theme/account/base/template.ftl +++ b/forms/common-themes/src/main/resources/theme/account/base/template.ftl @@ -29,7 +29,7 @@