From 01830fd7f37cdad2d44c00fbebcc524d71cdd3f4 Mon Sep 17 00:00:00 2001 From: mposolda Date: Fri, 22 Jul 2016 18:16:46 +0200 Subject: [PATCH] KEYCLOAK-3319 More OIDC tests. Minor refactoring --- .../protocol/oidc/OIDCLoginProtocol.java | 1 + .../oidc/endpoints/AuthorizationEndpoint.java | 3 +++ .../keycloak/services/util/LocaleHelper.java | 6 +++--- .../oidc/OIDCAdvancedRequestParamsTest.java | 18 +++++++++++++++++- 4 files changed, 24 insertions(+), 4 deletions(-) diff --git a/services/src/main/java/org/keycloak/protocol/oidc/OIDCLoginProtocol.java b/services/src/main/java/org/keycloak/protocol/oidc/OIDCLoginProtocol.java index a68dae860e..3105122cf1 100755 --- a/services/src/main/java/org/keycloak/protocol/oidc/OIDCLoginProtocol.java +++ b/services/src/main/java/org/keycloak/protocol/oidc/OIDCLoginProtocol.java @@ -65,6 +65,7 @@ public class OIDCLoginProtocol implements LoginProtocol { public static final String LOGIN_HINT_PARAM = "login_hint"; public static final String REQUEST_PARAM = "request"; public static final String REQUEST_URI_PARAM = "request_uri"; + public static final String UI_LOCALES_PARAM = OAuth2Constants.UI_LOCALES_PARAM; public static final String LOGOUT_REDIRECT_URI = "OIDC_LOGOUT_REDIRECT_URI"; public static final String ISSUER = "iss"; diff --git a/services/src/main/java/org/keycloak/protocol/oidc/endpoints/AuthorizationEndpoint.java b/services/src/main/java/org/keycloak/protocol/oidc/endpoints/AuthorizationEndpoint.java index 1d88ac71c1..95aa9a6f56 100755 --- a/services/src/main/java/org/keycloak/protocol/oidc/endpoints/AuthorizationEndpoint.java +++ b/services/src/main/java/org/keycloak/protocol/oidc/endpoints/AuthorizationEndpoint.java @@ -100,6 +100,9 @@ public class AuthorizationEndpoint extends AuthorizationEndpointBase { KNOWN_REQ_PARAMS.add(AdapterConstants.KC_IDP_HINT); KNOWN_REQ_PARAMS.add(OIDCLoginProtocol.NONCE_PARAM); KNOWN_REQ_PARAMS.add(OIDCLoginProtocol.MAX_AGE_PARAM); + KNOWN_REQ_PARAMS.add(OIDCLoginProtocol.UI_LOCALES_PARAM); + KNOWN_REQ_PARAMS.add(OIDCLoginProtocol.REQUEST_PARAM); + KNOWN_REQ_PARAMS.add(OIDCLoginProtocol.REQUEST_URI_PARAM); } private enum Action { diff --git a/services/src/main/java/org/keycloak/services/util/LocaleHelper.java b/services/src/main/java/org/keycloak/services/util/LocaleHelper.java index b60ecf5124..4c419b3c0d 100755 --- a/services/src/main/java/org/keycloak/services/util/LocaleHelper.java +++ b/services/src/main/java/org/keycloak/services/util/LocaleHelper.java @@ -16,6 +16,7 @@ */ package org.keycloak.services.util; +import org.keycloak.OAuth2Constants; import org.keycloak.models.KeycloakContext; import org.keycloak.models.KeycloakSession; import org.keycloak.models.RealmModel; @@ -33,7 +34,6 @@ import java.util.Set; public class LocaleHelper { private static final String LOCALE_COOKIE = "KEYCLOAK_LOCALE"; - private static final String UI_LOCALES_PARAM = "ui_locales"; private static final String KC_LOCALE_PARAM = "kc_locale"; public static Locale getLocale(KeycloakSession session, RealmModel realm, UserModel user) { @@ -104,8 +104,8 @@ public class LocaleHelper { } // ui_locales query parameter - if (uriInfo != null && uriInfo.getQueryParameters().containsKey(UI_LOCALES_PARAM)) { - String localeString = uriInfo.getQueryParameters().getFirst(UI_LOCALES_PARAM); + if (uriInfo != null && uriInfo.getQueryParameters().containsKey(OAuth2Constants.UI_LOCALES_PARAM)) { + String localeString = uriInfo.getQueryParameters().getFirst(OAuth2Constants.UI_LOCALES_PARAM); Locale locale = findLocale(realm.getSupportedLocales(), localeString.split(" ")); if (locale != null) { return locale; diff --git a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/oidc/OIDCAdvancedRequestParamsTest.java b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/oidc/OIDCAdvancedRequestParamsTest.java index db691b2476..2296908243 100644 --- a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/oidc/OIDCAdvancedRequestParamsTest.java +++ b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/oidc/OIDCAdvancedRequestParamsTest.java @@ -28,6 +28,7 @@ import org.keycloak.OAuthErrorException; import org.keycloak.common.util.Time; import org.keycloak.events.Details; import org.keycloak.models.Constants; +import org.keycloak.protocol.oidc.OIDCLoginProtocol; import org.keycloak.representations.IDToken; import org.keycloak.representations.idm.EventRepresentation; import org.keycloak.representations.idm.RealmRepresentation; @@ -323,7 +324,7 @@ public class OIDCAdvancedRequestParamsTest extends TestRealmKeycloakTest { @Test public void nonSupportedParams() { - driver.navigate().to(oauth.getLoginFormUrl() + "&display=popup&foo=foobar"); + driver.navigate().to(oauth.getLoginFormUrl() + "&display=popup&foo=foobar&claims_locales=fr"); loginPage.assertCurrent(); loginPage.login("test-user@localhost", "password"); @@ -363,4 +364,19 @@ public class OIDCAdvancedRequestParamsTest extends TestRealmKeycloakTest { Assert.assertEquals(OAuthErrorException.REQUEST_URI_NOT_SUPPORTED, resp.getError()); } + // LOGIN_HINT + + @Test + public void loginHint() { + // Assert need to re-authenticate with prompt=login + driver.navigate().to(oauth.getLoginFormUrl() + "&" + OIDCLoginProtocol.LOGIN_HINT_PARAM + "=test-user%40localhost"); + + loginPage.assertCurrent(); + Assert.assertEquals("test-user@localhost", loginPage.getUsername()); + loginPage.login("password"); + Assert.assertEquals(AppPage.RequestType.AUTH_RESPONSE, appPage.getRequestType()); + + events.expectLogin().detail(Details.USERNAME, "test-user@localhost").assertEvent(); + } + }