Added app name to 'back to app' link in acct mngmt

This commit is contained in:
Stian Thorgersen 2014-02-17 14:51:32 +00:00
parent 695eb05d66
commit b8cf83c3cf
4 changed files with 35 additions and 11 deletions

View file

@ -5,6 +5,7 @@ import org.keycloak.account.Account;
import org.keycloak.account.AccountPages; import org.keycloak.account.AccountPages;
import org.keycloak.account.freemarker.model.AccountBean; import org.keycloak.account.freemarker.model.AccountBean;
import org.keycloak.account.freemarker.model.MessageBean; 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.TotpBean;
import org.keycloak.account.freemarker.model.UrlBean; import org.keycloak.account.freemarker.model.UrlBean;
import org.keycloak.freemarker.FreeMarkerException; 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("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) { switch (page) {
case ACCOUNT: case ACCOUNT:
@ -100,11 +106,11 @@ public class FreeMarkerAccount implements Account {
} }
} }
private String getReferrerUri() { private ApplicationModel getReferrer() {
if (referrer != null) { if (referrer != null) {
ApplicationModel app = realm.getApplicationByName(referrer); ApplicationModel app = realm.getApplicationByName(referrer);
if (app != null) { if (app != null) {
return app.getBaseUrl(); return app;
} }
} }
return null; return null;

View file

@ -0,0 +1,24 @@
package org.keycloak.account.freemarker.model;
import org.keycloak.models.ApplicationModel;
/**
* @author <a href="mailto:sthorger@redhat.com">Stian Thorgersen</a>
*/
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();
}
}

View file

@ -14,13 +14,11 @@ public class UrlBean {
private String realm; private String realm;
private Theme theme; private Theme theme;
private URI baseURI; 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.realm = realm.getName();
this.theme = theme; this.theme = theme;
this.baseURI = baseURI; this.baseURI = baseURI;
this.referrerURI = referrerURI;
} }
public String getAccessUrl() { public String getAccessUrl() {
@ -51,10 +49,6 @@ public class UrlBean {
return Urls.accountLogout(baseURI, realm).toString(); return Urls.accountLogout(baseURI, realm).toString();
} }
public String getReferrerURI() {
return referrerURI;
}
public String getResourcesPath() { public String getResourcesPath() {
URI uri = Urls.themeRoot(baseURI); URI uri = Urls.themeRoot(baseURI);
return uri.getPath() + "/" + theme.getType().toString().toLowerCase() +"/" + theme.getName(); return uri.getPath() + "/" + theme.getType().toString().toLowerCase() +"/" + theme.getName();

View file

@ -29,7 +29,7 @@
<div class="navbar-collapse"> <div class="navbar-collapse">
<ul class="nav navbar-nav navbar-utility"> <ul class="nav navbar-nav navbar-utility">
<#if url.referrerURI??><li><a href="${url.referrerURI}">Back to application</a></li></#if> <#if referrer?has_content><li><a href="${referrer.baseUrl}">Back to ${referrer.name}</a></li></#if>
<li><a href="${url.logoutUrl}">Sign Out</a></li> <li><a href="${url.logoutUrl}">Sign Out</a></li>
</ul> </ul>
</div> </div>