Merge pull request #3015 from martin-kanis/master

KEYCLOAK-3096 Remove leading/trailing spaces from username/email
This commit is contained in:
Stian Thorgersen 2016-07-12 10:03:55 +02:00 committed by GitHub
commit 19e5ddeba5
2 changed files with 26 additions and 0 deletions

View file

@ -119,6 +119,10 @@ public abstract class AbstractUsernameFormAuthenticator extends AbstractFormAuth
context.failureChallenge(AuthenticationFlowError.INVALID_USER, challengeResponse); context.failureChallenge(AuthenticationFlowError.INVALID_USER, challengeResponse);
return false; return false;
} }
// remove leading and trailing whitespace
username = username.trim();
context.getEvent().detail(Details.USERNAME, username); context.getEvent().detail(Details.USERNAME, username);
context.getClientSession().setNote(AbstractUsernameFormAuthenticator.ATTEMPTED_USERNAME, username); context.getClientSession().setNote(AbstractUsernameFormAuthenticator.ATTEMPTED_USERNAME, username);

View file

@ -305,6 +305,28 @@ public class LoginTest extends TestRealmKeycloakTest {
events.expectLogin().user(userId).detail(Details.USERNAME, "login-test").assertEvent(); events.expectLogin().user(userId).detail(Details.USERNAME, "login-test").assertEvent();
} }
@Test
public void loginWithWhitespaceSuccess() {
loginPage.open();
loginPage.login(" login-test \t ", "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 loginWithEmailWhitespaceSuccess() {
loginPage.open();
loginPage.login(" login@test.com ", "password");
Assert.assertEquals(RequestType.AUTH_RESPONSE, appPage.getRequestType());
Assert.assertNotNull(oauth.getCurrentQuery().get(OAuth2Constants.CODE));
events.expectLogin().user(userId).assertEvent();
}
@Test @Test
public void loginPromptNone() { public void loginPromptNone() {
driver.navigate().to(oauth.getLoginFormUrl().toString() + "&prompt=none"); driver.navigate().to(oauth.getLoginFormUrl().toString() + "&prompt=none");