diff --git a/services/src/main/java/org/keycloak/services/resources/AccountService.java b/services/src/main/java/org/keycloak/services/resources/AccountService.java
index 90080ebc48..26738ee41f 100755
--- a/services/src/main/java/org/keycloak/services/resources/AccountService.java
+++ b/services/src/main/java/org/keycloak/services/resources/AccountService.java
@@ -788,7 +788,11 @@ public class AccountService extends AbstractSecuredLocalService {
}
if (referrerUri != null) {
- return new String[]{referrerClient.getName(), referrerUri};
+ String referrerName = referrerClient.getName();
+ if (Validation.isBlank(referrerName)) {
+ referrerName = referrer;
+ }
+ return new String[]{referrerName, referrerUri};
}
} else if (referrerUri != null) {
referrerClient = realm.getClientByClientId(referrer);
diff --git a/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/pages/AccountUpdateProfilePage.java b/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/pages/AccountUpdateProfilePage.java
index 2a77847fac..9748a9f114 100755
--- a/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/pages/AccountUpdateProfilePage.java
+++ b/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/pages/AccountUpdateProfilePage.java
@@ -20,6 +20,7 @@ package org.keycloak.testsuite.pages;
import org.keycloak.models.Constants;
import org.keycloak.services.resources.RealmsResource;
import org.openqa.selenium.By;
+import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
@@ -143,6 +144,24 @@ public class AccountUpdateProfilePage extends AbstractAccountPage {
public void backToApplication() {
backToApplicationLink.click();
}
+
+ public String getBackToApplicationLinkText() {
+ try {
+ // Optional screen element, may not be present
+ return backToApplicationLink.getText();
+ } catch (NoSuchElementException ignored) {
+ return null;
+ }
+ }
+
+ public String getBackToApplicationLinkHref() {
+ try {
+ // Optional screen element, may not be present
+ return backToApplicationLink.getAttribute("href");
+ } catch (NoSuchElementException ignored) {
+ return null;
+ }
+ }
public String getSuccess(){
return successMessage.getText();
diff --git a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/account/AccountTest.java b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/account/AccountTest.java
index 90bf62bd8b..c8f264a1ff 100755
--- a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/account/AccountTest.java
+++ b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/account/AccountTest.java
@@ -16,16 +16,26 @@
*/
package org.keycloak.testsuite.account;
+import static org.hamcrest.Matchers.containsInAnyOrder;
+
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+import javax.ws.rs.core.UriBuilder;
+
import org.jboss.arquillian.drone.api.annotation.Drone;
import org.jboss.arquillian.graphene.page.Page;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
+import org.keycloak.admin.client.resource.RealmResource;
import org.keycloak.events.Details;
import org.keycloak.events.Errors;
import org.keycloak.events.EventType;
import org.keycloak.models.utils.TimeBasedOTP;
+import org.keycloak.representations.idm.ClientRepresentation;
import org.keycloak.representations.idm.EventRepresentation;
import org.keycloak.representations.idm.RealmRepresentation;
import org.keycloak.representations.idm.UserRepresentation;
@@ -53,13 +63,6 @@ import org.keycloak.testsuite.util.UserBuilder;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
-import javax.ws.rs.core.UriBuilder;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-
-import static org.hamcrest.Matchers.*;
-
/**
* @author Stian Thorgersen
* @author Stan Silvert ssilvert@redhat.com (C) 2016 Red Hat Inc.
@@ -829,4 +832,40 @@ public class AccountTest extends TestRealmKeycloakTest {
events.clear();
}
+
+ @Test
+ public void testReferrerLinkContents() {
+ RealmResource testRealm = testRealm();
+ List foundClients = testRealm.clients().findByClientId("named-test-app");
+ if (foundClients.isEmpty()) {
+ Assert.fail("Unable to find named-test-app");
+ }
+ ClientRepresentation namedClient = foundClients.get(0);
+
+ driver.navigate().to(profilePage.getPath() + "?referrer=" + namedClient.getClientId());
+ loginPage.login("test-user@localhost", "password");
+ Assert.assertTrue(profilePage.isCurrent());
+ // When a client has a name provided, the name should be available to the back link
+ Assert.assertEquals("Back to " + namedClient.getName(), profilePage.getBackToApplicationLinkText());
+ Assert.assertEquals(namedClient.getBaseUrl(), profilePage.getBackToApplicationLinkHref());
+
+ foundClients = testRealm.clients().findByClientId("test-app");
+ if (foundClients.isEmpty()) {
+ Assert.fail("Unable to find test-app");
+ }
+ ClientRepresentation namelessClient = foundClients.get(0);
+
+ driver.navigate().to(profilePage.getPath() + "?referrer=" + namelessClient.getClientId());
+ Assert.assertTrue(profilePage.isCurrent());
+ // When a client has no name provided, the client-id should be available to the back link
+ Assert.assertEquals("Back to " + namelessClient.getClientId(), profilePage.getBackToApplicationLinkText());
+ Assert.assertEquals(namelessClient.getBaseUrl(), profilePage.getBackToApplicationLinkHref());
+
+ driver.navigate().to(profilePage.getPath() + "?referrer=test-invalid");
+ Assert.assertTrue(profilePage.isCurrent());
+ // When a client is invalid, the back link should not exist
+ Assert.assertNull(profilePage.getBackToApplicationLinkText());
+
+ events.clear();
+ }
}
diff --git a/testsuite/integration-arquillian/tests/base/src/test/resources/testrealm.json b/testsuite/integration-arquillian/tests/base/src/test/resources/testrealm.json
index b0e87679b3..6ec90bff1e 100644
--- a/testsuite/integration-arquillian/tests/base/src/test/resources/testrealm.json
+++ b/testsuite/integration-arquillian/tests/base/src/test/resources/testrealm.json
@@ -304,6 +304,17 @@
"/test-app-authz/*"
],
"secret": "secret"
+ },
+ {
+ "clientId": "named-test-app",
+ "name": "My Named Test App",
+ "enabled": true,
+ "baseUrl": "http://localhost:8180/namedapp/base",
+ "redirectUris": [
+ "http://localhost:8180/namedapp/base/*"
+ ],
+ "adminUrl": "http://localhost:8180/namedapp/base/admin",
+ "secret": "password"
}
],
"roles" : {