diff --git a/dxp-oidc-filter/src/main/java/nl/finalist/liferay/oidc/OpenIDConnectFilter.java b/dxp-oidc-filter/src/main/java/nl/finalist/liferay/oidc/OpenIDConnectFilter.java index cfc6fe4..6817357 100644 --- a/dxp-oidc-filter/src/main/java/nl/finalist/liferay/oidc/OpenIDConnectFilter.java +++ b/dxp-oidc-filter/src/main/java/nl/finalist/liferay/oidc/OpenIDConnectFilter.java @@ -24,8 +24,7 @@ "dispatcher=REQUEST", "servlet-context-name=", "servlet-filter-name=SSO OpenID Connect Filter", - "url-pattern=/c/portal/login", - "url-pattern=/c/portal/logout" + "url-pattern=/*" }, service = Filter.class ) diff --git a/oidc-hook/src/main/webapp/WEB-INF/liferay-hook.xml b/oidc-hook/src/main/webapp/WEB-INF/liferay-hook.xml index 8a08c3f..d5e2438 100644 --- a/oidc-hook/src/main/webapp/WEB-INF/liferay-hook.xml +++ b/oidc-hook/src/main/webapp/WEB-INF/liferay-hook.xml @@ -8,7 +8,6 @@ OpenID Connect SSO Filter - /c/portal/login - /c/portal/logout + /* \ No newline at end of file diff --git a/oidc-lib/src/main/java/nl/finalist/liferay/oidc/LibFilter.java b/oidc-lib/src/main/java/nl/finalist/liferay/oidc/LibFilter.java index c9c199a..a9e3037 100644 --- a/oidc-lib/src/main/java/nl/finalist/liferay/oidc/LibFilter.java +++ b/oidc-lib/src/main/java/nl/finalist/liferay/oidc/LibFilter.java @@ -1,16 +1,19 @@ package nl.finalist.liferay.oidc; +import com.fasterxml.jackson.databind.ObjectMapper; + import java.io.IOException; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import java.nio.charset.StandardCharsets; import java.util.HashMap; import java.util.Map; + import javax.servlet.FilterChain; +import javax.servlet.http.Cookie; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import com.fasterxml.jackson.databind.ObjectMapper; import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.lang3.StringUtils; import org.apache.oltu.oauth2.client.OAuthClient; @@ -245,6 +248,37 @@ protected void exchangeCodeForAccessToken(HttpServletRequest request) throws IOE protected void redirectToLogin(HttpServletRequest request, HttpServletResponse response, String clientId) throws IOException { try { + String ui_locales = null; + + Cookie[] cookies = request.getCookies(); // look for GUEST_LANGUAGE_ID + if (null != cookies) { + for (Cookie cookie : cookies) { + liferay.trace("redirectToLogin: cookie: " + cookie.getName() + " = " + cookie.getValue()); + if ("GUEST_LANGUAGE_ID".equals(cookie.getName())) { + String guestLanguageId = cookie.getValue(); + String[] guestLocale = guestLanguageId.split("_"); + ui_locales = guestLanguageId; // full locale, just as-is: 3-zone OR 2-zone OR 1-zone locale + if (guestLocale.length > 2) { // we got 3-zone locale: language_COUNTRY_REGION: Add "langauge_COUNTRY" + ui_locales += " " + guestLocale[0] + "_" + guestLocale[1]; + } + if (guestLocale.length > 1) { // we got (3- or) 2-zone locale: language_COUNTRY: Add "language" + ui_locales += " " + guestLocale[0]; + } + liferay.trace("redirectToLogin: use for ui_locales: " + ui_locales); + } + } + } + + if (null == ui_locales) { // no GUEST_LANGUAGE_ID cookie available: + ui_locales = request.getServletPath().substring(1); // may be /c (default locale, useless) or /en (requested locale, useful) or /xy (useful) ... + } + + if (null == ui_locales || ui_locales.length() < 2) { // skip values being too short to meet https://tools.ietf.org/html/rfc5646 + // TODO: Improve locale recognition according to syntax given in RFC-5646 + ui_locales = request.getLocale().getLanguage(); + } + liferay.trace("redirectToLogin: ui_locales: " + ui_locales); + OAuthClientRequest oAuthRequest = OAuthClientRequest .authorizationLocation(AUTHORIZATION_LOCATION) .setClientId(clientId) @@ -252,6 +286,7 @@ protected void redirectToLogin(HttpServletRequest request, HttpServletResponse r .setResponseType("code") .setScope(SCOPE) .setState(generateStateParam(request)) + .setParameter("ui_locales", ui_locales) // see http://openid.net/specs/openid-connect-core-1_0.html#AuthRequest .buildQueryMessage(); liferay.debug("Redirecting to URL: " + oAuthRequest.getLocationUri()); response.sendRedirect(oAuthRequest.getLocationUri());