[java-identity-provider] branch main updated: IDP-1597 Change of language incomplete when switching locale

Rod Widdowson rdw at steadingsoftware.com
Sat Apr 10 15:18:26 UTC 2021


This is an automated email from the git hooks/post-receive script.

rdw pushed a commit to branch main
in repository java-identity-provider.

View the commit online:
http://git.shibboleth.net/view/?p=java-identity-provider.git;a=commit;h=07d5bc44181817de10edb78cc041c4bb6edaad6d

The following commit(s) were added to refs/heads/main by this push:
       new  07d5bc441 IDP-1597 Change of language incomplete when switching locale
07d5bc441 is described below

commit 07d5bc44181817de10edb78cc041c4bb6edaad6d
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Sat Apr 10 16:15:05 2021 +0100

    IDP-1597 Change of language incomplete when switching locale
    
    https://issues.shibboleth.net/jira/browse/IDP-1597
    
    Rather than injecting an HttpServletRequest (which could go stale,
    inject a Supplier - thich indicates the fact that the rpUIcontext
    could outlive the request.
    
    In fact we normally end up injecting the same thing because the
    usual request is a ThreadLocalHttpServletRequestProxy which is
    already delegating to TLS
---
 ...InitializeAdministrativeProfileContextTree.java | 16 ++++++++++++--
 .../idp/ui/context/RelyingPartyUIContext.java      | 25 +++++++++++-----------
 .../shibboleth/idp/ui/impl/SetRPUIInformation.java | 19 +++++++++++++---
 3 files changed, 43 insertions(+), 17 deletions(-)

diff --git a/idp-admin-impl/src/main/java/net/shibboleth/idp/admin/impl/InitializeAdministrativeProfileContextTree.java b/idp-admin-impl/src/main/java/net/shibboleth/idp/admin/impl/InitializeAdministrativeProfileContextTree.java
index a50d13e45..2d226f82c 100644
--- a/idp-admin-impl/src/main/java/net/shibboleth/idp/admin/impl/InitializeAdministrativeProfileContextTree.java
+++ b/idp-admin-impl/src/main/java/net/shibboleth/idp/admin/impl/InitializeAdministrativeProfileContextTree.java
@@ -18,9 +18,11 @@
 package net.shibboleth.idp.admin.impl;
 
 import java.util.List;
+import java.util.function.Supplier;
 
 import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
+import javax.servlet.http.HttpServletRequest;
 
 import org.opensaml.profile.action.ActionSupport;
 import org.opensaml.profile.context.ProfileRequestContext;
@@ -35,6 +37,7 @@ import net.shibboleth.idp.profile.context.RelyingPartyContext;
 import net.shibboleth.idp.ui.context.RelyingPartyUIContext;
 import net.shibboleth.utilities.java.support.annotation.constraint.NonnullElements;
 import net.shibboleth.utilities.java.support.component.ComponentSupport;
+import net.shibboleth.utilities.java.support.net.ThreadLocalHttpServletRequestProxy;
 
 /**
  * An action that processes settings from a supplied {@link AdministrativeFlowDescriptor} to prepare
@@ -121,10 +124,19 @@ public class InitializeAdministrativeProfileContextTree extends AbstractProfileA
         
         final RelyingPartyUIContext uiCtx = rpCtx.getSubcontext(RelyingPartyUIContext.class, true);
         uiCtx.setRPUInfo(flowDescriptor.getUIInfo());
-        uiCtx.setHttpServletRequest(getHttpServletRequest());
+        final HttpServletRequest request = getHttpServletRequest();
+        uiCtx.setBrowserLanguageRanges(SpringSupport.getLanguageRange(request));
+        if (request instanceof ThreadLocalHttpServletRequestProxy) {
+            // The request is delegated so can be put into a Supplier
+            uiCtx.setRequestSupplier(new Supplier<HttpServletRequest>() {
+                public HttpServletRequest get() {
+                    return request;
+                }
+            });
+        }
         
         if (null != fallbackLanguages) {
             uiCtx.setFallbackLanguages(fallbackLanguages);
         }
     }
-}
\ No newline at end of file
+}
diff --git a/idp-ui/src/main/java/net/shibboleth/idp/ui/context/RelyingPartyUIContext.java b/idp-ui/src/main/java/net/shibboleth/idp/ui/context/RelyingPartyUIContext.java
index 0e2b5adca..6484abc44 100644
--- a/idp-ui/src/main/java/net/shibboleth/idp/ui/context/RelyingPartyUIContext.java
+++ b/idp-ui/src/main/java/net/shibboleth/idp/ui/context/RelyingPartyUIContext.java
@@ -27,6 +27,7 @@ import java.util.List;
 import java.util.Locale;
 import java.util.Locale.LanguageRange;
 import java.util.Map;
+import java.util.function.Supplier;
 import java.util.stream.Collectors;
 
 import javax.annotation.Nonnull;
@@ -80,14 +81,15 @@ public final class RelyingPartyUIContext extends BaseContext {
     /** The appropriate {@link IdPUIInfo}. */
     @Nullable private IdPUIInfo rpUIInfo;
 
-    /** The languages that this browser wants to know about. */
-    @Nullable @Deprecated @NonnullElements private List<LanguageRange> browserLanguages;
+    /** The (statically defined) languages that this user wants to know about. */
+    @Nullable @NonnullElements private List<LanguageRange> browserLanguages;
     
     /** The languages that this the Operator want to fall back to. */
     @Nonnull private List<LanguageRange> fallbackLanguages;
     
-    /** Current HTTP request, if available. */
-    @Nullable private HttpServletRequest httpServletRequest;
+    /** A way of getting the current HTTP request, if available.
+     *  Used to define dynamically selected languages. */
+    @Nullable private Supplier<HttpServletRequest> requestSupplier;
     
     /** Constructor. */
     public RelyingPartyUIContext() {
@@ -229,8 +231,8 @@ public final class RelyingPartyUIContext extends BaseContext {
      * @param what what to set.
      * @return this context
      */
-    public RelyingPartyUIContext setHttpServletRequest(@Nonnull final HttpServletRequest what) {
-        httpServletRequest = what;
+    public RelyingPartyUIContext setRequestSupplier(@Nonnull final Supplier<HttpServletRequest> what) {
+        requestSupplier = what;
         return this;
     }
 
@@ -238,7 +240,7 @@ public final class RelyingPartyUIContext extends BaseContext {
      * Set the browser languages.
      *
      * @param languages the languages to set
-     * @deprecated use {@link #setHttpServletRequest(HttpServletRequest)}
+     * @deprecated use {@link #setBrowserLanguageRanges(List)}
      * @return this context
      */
     @Deprecated(since="4.0.0", forRemoval=true)
@@ -258,10 +260,8 @@ public final class RelyingPartyUIContext extends BaseContext {
      * Set the browser languages.
      * 
      * @param ranges the languages to set
-     * @deprecated use {@link #setHttpServletRequest(HttpServletRequest)}
      * @return this context
      */
-    @Deprecated(since="4.1.1", forRemoval=true)
     @Nonnull public RelyingPartyUIContext setBrowserLanguageRanges(
             @Nonnull @NonnullElements final List<LanguageRange> ranges) {
         // The replacement was created in V4.1.1
@@ -272,15 +272,16 @@ public final class RelyingPartyUIContext extends BaseContext {
 
 
     /**
-     * Get the browser languages.
+     * Get the browser languages.  Interrogate the http Request (if available)
+     * otherwise got for the statically defined values.
      * 
      * @return the languages.
      */
     @Nonnull @NonnullElements protected List<LanguageRange> getBrowserLanguages() {
-        if (httpServletRequest == null) {
+        if (requestSupplier == null || requestSupplier.get() == null) {
             return browserLanguages;
         }
-        return SpringSupport.getLanguageRange(httpServletRequest);
+        return SpringSupport.getLanguageRange(requestSupplier.get());
     }
 
     /**
diff --git a/idp-ui/src/main/java/net/shibboleth/idp/ui/impl/SetRPUIInformation.java b/idp-ui/src/main/java/net/shibboleth/idp/ui/impl/SetRPUIInformation.java
index ab7ee0b29..156f3d045 100644
--- a/idp-ui/src/main/java/net/shibboleth/idp/ui/impl/SetRPUIInformation.java
+++ b/idp-ui/src/main/java/net/shibboleth/idp/ui/impl/SetRPUIInformation.java
@@ -19,9 +19,11 @@ package net.shibboleth.idp.ui.impl;
 
 import java.util.List;
 import java.util.function.Function;
+import java.util.function.Supplier;
 
 import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
+import javax.servlet.http.HttpServletRequest;
 
 import org.opensaml.core.xml.XMLObject;
 import org.opensaml.messaging.context.navigate.ChildContextLookup;
@@ -39,6 +41,7 @@ import org.opensaml.saml.saml2.metadata.SPSSODescriptor;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import net.shibboleth.ext.spring.util.SpringSupport;
 import net.shibboleth.idp.authn.context.AuthenticationContext;
 import net.shibboleth.idp.profile.AbstractProfileAction;
 import net.shibboleth.idp.saml.profile.context.navigate.SAMLMetadataContextLookupFunction;
@@ -46,6 +49,7 @@ import net.shibboleth.idp.ui.context.RelyingPartyUIContext;
 import net.shibboleth.utilities.java.support.annotation.constraint.NonnullElements;
 import net.shibboleth.utilities.java.support.component.ComponentSupport;
 import net.shibboleth.utilities.java.support.logic.Constraint;
+import net.shibboleth.utilities.java.support.net.ThreadLocalHttpServletRequestProxy;
 import net.shibboleth.utilities.java.support.primitive.StringSupport;
 
 /**
@@ -212,7 +216,16 @@ public class SetRPUIInformation extends AbstractProfileAction {
         rpUIContext.setRPSPSSODescriptor(spSSODescriptor);
         rpUIContext.setRPAttributeConsumingService(acsDesriptor);
         rpUIContext.setRPUInfo(getRPUInfo());
-        rpUIContext.setHttpServletRequest(getHttpServletRequest());
-    }
+        final HttpServletRequest request = getHttpServletRequest();
+        rpUIContext.setBrowserLanguageRanges(SpringSupport.getLanguageRange(request));
+        if (request instanceof ThreadLocalHttpServletRequestProxy) {
+            // The request is delegated so can be put into a Supplier
+            rpUIContext.setRequestSupplier(new Supplier<HttpServletRequest>() {
+                public HttpServletRequest get() {
+                    return request;
+                }
+            });
+        }
+   }
 
-}
\ No newline at end of file
+}

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the commits mailing list