KEYCLOAK-581 Add login_hint query param to login

This commit is contained in:
Stian Thorgersen 2014-07-30 13:43:46 +01:00
parent e338f1af15
commit 614c718304
3 changed files with 39 additions and 3 deletions

View file

@ -2,6 +2,7 @@ package org.keycloak.services.resources;
import org.jboss.logging.Logger; import org.jboss.logging.Logger;
import org.jboss.resteasy.annotations.cache.NoCache; import org.jboss.resteasy.annotations.cache.NoCache;
import org.jboss.resteasy.specimpl.MultivaluedMapImpl;
import org.jboss.resteasy.spi.BadRequestException; import org.jboss.resteasy.spi.BadRequestException;
import org.jboss.resteasy.spi.HttpRequest; import org.jboss.resteasy.spi.HttpRequest;
import org.jboss.resteasy.spi.HttpResponse; import org.jboss.resteasy.spi.HttpResponse;
@ -789,7 +790,8 @@ public class TokenService {
@GET @GET
public Response loginPage(final @QueryParam("response_type") String responseType, public Response loginPage(final @QueryParam("response_type") String responseType,
@QueryParam("redirect_uri") String redirect, final @QueryParam("client_id") String clientId, @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"); logger.info("TokenService.loginPage");
audit.event(EventType.LOGIN).client(clientId).detail(Details.REDIRECT_URI, redirect).detail(Details.RESPONSE_TYPE, "code"); 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")) { if (prompt != null && prompt.equals("none")) {
return oauth.redirectError(client, "access_denied", state, redirect); 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<String, String> formData = new MultivaluedMapImpl<String, String>();
formData.add(AuthenticationManager.FORM_USERNAME, loginHint);
forms.setFormData(formData);
}
return forms.createLogin();
} }
/** /**

View file

@ -120,6 +120,20 @@ public class LoginTest {
events.expectLogin().user(userId).detail(Details.USERNAME, "login-test").assertEvent(); 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 @Test
public void loginWithEmailSuccess() { public void loginWithEmailSuccess() {
loginPage.open(); loginPage.open();

View file

@ -75,6 +75,17 @@ public class LoginPage extends AbstractPage {
submitButton.click(); submitButton.click();
} }
public void login(String password) {
passwordInput.clear();
passwordInput.sendKeys(password);
submitButton.click();
}
public String getUsername() {
return usernameInput.getAttribute("value");
}
public void cancel() { public void cancel() {
cancelButton.click(); cancelButton.click();
} }