From 614c718304452fe95b1069b42d74af21f1d6a552 Mon Sep 17 00:00:00 2001 From: Stian Thorgersen Date: Wed, 30 Jul 2014 13:43:46 +0100 Subject: [PATCH] KEYCLOAK-581 Add login_hint query param to login --- .../services/resources/TokenService.java | 17 ++++++++++++++--- .../org/keycloak/testsuite/forms/LoginTest.java | 14 ++++++++++++++ .../org/keycloak/testsuite/pages/LoginPage.java | 11 +++++++++++ 3 files changed, 39 insertions(+), 3 deletions(-) diff --git a/services/src/main/java/org/keycloak/services/resources/TokenService.java b/services/src/main/java/org/keycloak/services/resources/TokenService.java index 926cb39d6e..d2e0e3d759 100755 --- a/services/src/main/java/org/keycloak/services/resources/TokenService.java +++ b/services/src/main/java/org/keycloak/services/resources/TokenService.java @@ -2,6 +2,7 @@ package org.keycloak.services.resources; import org.jboss.logging.Logger; import org.jboss.resteasy.annotations.cache.NoCache; +import org.jboss.resteasy.specimpl.MultivaluedMapImpl; import org.jboss.resteasy.spi.BadRequestException; import org.jboss.resteasy.spi.HttpRequest; import org.jboss.resteasy.spi.HttpResponse; @@ -789,7 +790,8 @@ public class TokenService { @GET public Response loginPage(final @QueryParam("response_type") String responseType, @QueryParam("redirect_uri") String redirect, final @QueryParam("client_id") String clientId, - final @QueryParam("scope") String scopeParam, final @QueryParam("state") String state, final @QueryParam("prompt") String prompt) { + final @QueryParam("scope") String scopeParam, final @QueryParam("state") String state, final @QueryParam("prompt") String prompt, + final @QueryParam("login_hint") String loginHint) { logger.info("TokenService.loginPage"); audit.event(EventType.LOGIN).client(clientId).detail(Details.REDIRECT_URI, redirect).detail(Details.RESPONSE_TYPE, "code"); @@ -845,8 +847,17 @@ public class TokenService { if (prompt != null && prompt.equals("none")) { return oauth.redirectError(client, "access_denied", state, redirect); } - logger.info("createLogin() now..."); - return Flows.forms(session, realm, uriInfo).createLogin(); + + LoginFormsProvider forms = Flows.forms(session, realm, uriInfo); + + if (loginHint != null) { + MultivaluedMap formData = new MultivaluedMapImpl(); + formData.add(AuthenticationManager.FORM_USERNAME, loginHint); + + forms.setFormData(formData); + } + + return forms.createLogin(); } /** diff --git a/testsuite/integration/src/test/java/org/keycloak/testsuite/forms/LoginTest.java b/testsuite/integration/src/test/java/org/keycloak/testsuite/forms/LoginTest.java index ad0a4c1075..c406bfb456 100755 --- a/testsuite/integration/src/test/java/org/keycloak/testsuite/forms/LoginTest.java +++ b/testsuite/integration/src/test/java/org/keycloak/testsuite/forms/LoginTest.java @@ -120,6 +120,20 @@ public class LoginTest { events.expectLogin().user(userId).detail(Details.USERNAME, "login-test").assertEvent(); } + @Test + public void loginLoginHint() { + String loginFormUrl = oauth.getLoginFormUrl() + "&login_hint=login-test"; + driver.navigate().to(loginFormUrl); + + Assert.assertEquals("login-test", loginPage.getUsername()); + loginPage.login("password"); + + Assert.assertEquals(RequestType.AUTH_RESPONSE, appPage.getRequestType()); + Assert.assertNotNull(oauth.getCurrentQuery().get(OAuth2Constants.CODE)); + + events.expectLogin().user(userId).detail(Details.USERNAME, "login-test").assertEvent(); + } + @Test public void loginWithEmailSuccess() { loginPage.open(); diff --git a/testsuite/integration/src/test/java/org/keycloak/testsuite/pages/LoginPage.java b/testsuite/integration/src/test/java/org/keycloak/testsuite/pages/LoginPage.java index a266b8a0c2..25e36a83c7 100644 --- a/testsuite/integration/src/test/java/org/keycloak/testsuite/pages/LoginPage.java +++ b/testsuite/integration/src/test/java/org/keycloak/testsuite/pages/LoginPage.java @@ -75,6 +75,17 @@ public class LoginPage extends AbstractPage { submitButton.click(); } + public void login(String password) { + passwordInput.clear(); + passwordInput.sendKeys(password); + + submitButton.click(); + } + + public String getUsername() { + return usernameInput.getAttribute("value"); + } + public void cancel() { cancelButton.click(); }