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

Rod Widdowson rdw at steadingsoftware.com
Fri Apr 9 10:31:11 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=58ffc62cf627dc45cb10137e9815323c9db7bd35

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

commit 58ffc62cf627dc45cb10137e9815323c9db7bd35
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Fri Apr 9 11:24:47 2021 +0100

    IDP-1597 Change of language incomplete when switching locale
    
    https://issues.shibboleth.net/jira/browse/IDP-1597
    
    make RelyingPartyUIContext#getBrowserLanguages() dynamic
    to allow for changes in the HttpRequest mid flow
---
 ...InitializeAdministrativeProfileContextTree.java |  2 +-
 .../test/resources/metadata/example-metadata.xml   | 12 +++++---
 .../idp/ui/context/RelyingPartyUIContext.java      | 33 ++++++++++++++++++----
 .../shibboleth/idp/ui/impl/SetRPUIInformation.java |  3 +-
 .../idp/ui/context/RelyingPartyUIContextTest.java  |  6 +---
 5 files changed, 38 insertions(+), 18 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 720a58e40..a50d13e45 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
@@ -121,7 +121,7 @@ public class InitializeAdministrativeProfileContextTree extends AbstractProfileA
         
         final RelyingPartyUIContext uiCtx = rpCtx.getSubcontext(RelyingPartyUIContext.class, true);
         uiCtx.setRPUInfo(flowDescriptor.getUIInfo());
-        uiCtx.setBrowserLanguageRanges(SpringSupport.getLanguageRange(getHttpServletRequest()));
+        uiCtx.setHttpServletRequest(getHttpServletRequest());
         
         if (null != fallbackLanguages) {
             uiCtx.setFallbackLanguages(fallbackLanguages);
diff --git a/idp-conf/src/test/resources/metadata/example-metadata.xml b/idp-conf/src/test/resources/metadata/example-metadata.xml
index 4fae4f2cb..94e2de5cb 100644
--- a/idp-conf/src/test/resources/metadata/example-metadata.xml
+++ b/idp-conf/src/test/resources/metadata/example-metadata.xml
@@ -40,6 +40,10 @@
                 TEST SP (description)Lorem ipsum dolor sit amet, consectetur adipiscing elit. 
                 Donec a diam lectus. Sed sit amet ipsum mauris. Maecenas congue ligula ac quam viverra nec consectetur ante hendrerit.
                 </mdui:Description>
+                <mdui:Description xml:lang="de">Wer reitet so spät durch Nacht und Wind?
+Es ist der Vater mit seinem Kind;
+Er hat den Knaben wohl in dem Arm,
+Er faßt ihn sicher, er hält ihn warm.</mdui:Description>
                 <mdui:InformationURL xml:lang="en">https://www.example.org</mdui:InformationURL>
                 <mdui:PrivacyStatementURL xml:lang="en">https://www.example.org/privacy</mdui:PrivacyStatementURL>
                 <mdui:Logo height="65" width="150">https://shibboleth.net/images/shibboleth.png</mdui:Logo>
@@ -119,9 +123,9 @@ h+XNZ5oAql/cjrwDWw==
         <AttributeConsumingService isDefault="true" index="1">
         
             <ServiceName xml:lang="en">Name of Service</ServiceName>
-            <ServiceName xml:lang="en">Service Name</ServiceName>
+            <ServiceName xml:lang="de">Der Service Name</ServiceName>
             <ServiceDescription xml:lang="en">Lorem Ispum</ServiceDescription>
-            <ServiceDescription xml:lang="en">Ipsum Lorem</ServiceDescription>
+            <ServiceDescription xml:lang="fr">Wer reitet so spät durch Nacht und Wind?</ServiceDescription>
             <RequestedAttribute FriendlyName="displayName"
                 Name="urn:mace:dir:attribute-def:displayName" NameFormat="urn:mace:shibboleth:1.0:attributeNamespace:uri" />
             <RequestedAttribute FriendlyName="displayName" isRequired="true"
@@ -155,9 +159,9 @@ h+XNZ5oAql/cjrwDWw==
     </SPSSODescriptor>    
     <Organization>
         <OrganizationName xml:lang="en">TC</OrganizationName>
-        <OrganizationName xml:lang="en">TSC</OrganizationName>
-        <OrganizationDisplayName xml:lang="en">The Shibboleth Consortium</OrganizationDisplayName>
+        <OrganizationName xml:lang="de">Das TSC</OrganizationName>
         <OrganizationDisplayName xml:lang="en">The Shibboleth Consortium</OrganizationDisplayName>
+        <OrganizationDisplayName xml:lang="de">Das Shibboleth-Konsortium</OrganizationDisplayName>
         <OrganizationURL xml:lang="en">http://shibboleth.net/</OrganizationURL>
         <OrganizationURL xml:lang="en">http://shibboleth.net/</OrganizationURL>
     </Organization>
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 89d03cf1a..0e2b5adca 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
@@ -31,6 +31,7 @@ import java.util.stream.Collectors;
 
 import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
+import javax.servlet.http.HttpServletRequest;
 
 import org.opensaml.core.xml.XMLObject;
 import org.opensaml.messaging.context.BaseContext;
@@ -45,6 +46,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.attribute.AttributesMapContainer;
 import net.shibboleth.idp.saml.metadata.ACSUIInfo;
 import net.shibboleth.idp.saml.metadata.IdPUIInfo;
@@ -55,8 +57,8 @@ import net.shibboleth.utilities.java.support.annotation.constraint.NotLive;
 import net.shibboleth.utilities.java.support.annotation.constraint.Unmodifiable;
 import net.shibboleth.utilities.java.support.logic.Constraint;
 import net.shibboleth.utilities.java.support.primitive.DeprecationSupport;
-import net.shibboleth.utilities.java.support.primitive.StringSupport;
 import net.shibboleth.utilities.java.support.primitive.DeprecationSupport.ObjectType;
+import net.shibboleth.utilities.java.support.primitive.StringSupport;
 
 /**
  * The context which carries the user interface information.
@@ -79,11 +81,14 @@ public final class RelyingPartyUIContext extends BaseContext {
     @Nullable private IdPUIInfo rpUIInfo;
 
     /** The languages that this browser wants to know about. */
-    @Nonnull @NonnullElements private List<LanguageRange> browserLanguages;
+    @Nullable @Deprecated @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;
+    
     /** Constructor. */
     public RelyingPartyUIContext() {
         browserLanguages = Collections.emptyList();
@@ -220,18 +225,27 @@ public final class RelyingPartyUIContext extends BaseContext {
         return this;
     }
 
+    /** Set the Servlet Request.
+     * @param what what to set.
+     * @return this context
+     */
+    public RelyingPartyUIContext setHttpServletRequest(@Nonnull final HttpServletRequest what) {
+        httpServletRequest = what;
+        return this;
+    }
+
     /**
      * Set the browser languages.
      *
      * @param languages the languages to set
-     * @deprecated use {@link #setBrowserLanguageRanges(List)}
+     * @deprecated use {@link #setHttpServletRequest(HttpServletRequest)}
      * @return this context
      */
     @Deprecated(since="4.0.0", forRemoval=true)
     @Nonnull public RelyingPartyUIContext setBrowserLanguages(@Nonnull @NonnullElements final List<String> languages) {
         Constraint.isNotNull(languages, "Language List cannot be null");
-        // The replacement was created in V4.0
-        DeprecationSupport.warnOnce(ObjectType.METHOD, "setBrowserLanguages", null, "setBrowserLanguageRanges");
+        // The replacement was created in V4.1.1
+        DeprecationSupport.warnOnce(ObjectType.METHOD, "setBrowserLanguages", null, "setHttpServletResponse");
         browserLanguages = languages.
                 stream().
                 filter(e -> e != null).
@@ -244,10 +258,14 @@ 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
+        DeprecationSupport.warnOnce(ObjectType.METHOD, "setBrowserLanguageRanges", null, "setHttpServletResponse");
         browserLanguages = Constraint.isNotNull(ranges, "Language Range cannot be null");
         return this;
     }
@@ -259,7 +277,10 @@ public final class RelyingPartyUIContext extends BaseContext {
      * @return the languages.
      */
     @Nonnull @NonnullElements protected List<LanguageRange> getBrowserLanguages() {
-        return browserLanguages;
+        if (httpServletRequest == null) {
+            return browserLanguages;
+        }
+        return SpringSupport.getLanguageRange(httpServletRequest);
     }
 
     /**
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 10675aa2b..ab7ee0b29 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
@@ -39,7 +39,6 @@ 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;
@@ -213,7 +212,7 @@ public class SetRPUIInformation extends AbstractProfileAction {
         rpUIContext.setRPSPSSODescriptor(spSSODescriptor);
         rpUIContext.setRPAttributeConsumingService(acsDesriptor);
         rpUIContext.setRPUInfo(getRPUInfo());
-        rpUIContext.setBrowserLanguageRanges(SpringSupport.getLanguageRange(getHttpServletRequest()));
+        rpUIContext.setHttpServletRequest(getHttpServletRequest());
     }
 
 }
\ No newline at end of file
diff --git a/idp-ui/src/test/java/net/shibboleth/idp/ui/context/RelyingPartyUIContextTest.java b/idp-ui/src/test/java/net/shibboleth/idp/ui/context/RelyingPartyUIContextTest.java
index ac855209a..952003389 100644
--- a/idp-ui/src/test/java/net/shibboleth/idp/ui/context/RelyingPartyUIContextTest.java
+++ b/idp-ui/src/test/java/net/shibboleth/idp/ui/context/RelyingPartyUIContextTest.java
@@ -31,9 +31,7 @@ import org.testng.Assert;
 import org.testng.annotations.BeforeClass;
 import org.testng.annotations.Test;
 
-/**
- *
- */
+ at SuppressWarnings({"javadoc", "removal"})
 public class RelyingPartyUIContextTest extends XMLObjectBaseTestCase {
 
     private EntityDescriptor[] theEntities = new EntityDescriptor[4];
@@ -160,7 +158,6 @@ public class RelyingPartyUIContextTest extends XMLObjectBaseTestCase {
         Assert.assertEquals(ctx.getPrivacyStatementURL(), null);
     }
 
-    @SuppressWarnings("deprecation")
     @Test public void logo() {
         RelyingPartyUIContext ctx = getContext();
         
@@ -172,7 +169,6 @@ public class RelyingPartyUIContextTest extends XMLObjectBaseTestCase {
 
     }
     
-    @SuppressWarnings("deprecation")
     @Test public void fallbackLanguage() {
         RelyingPartyUIContext ctx = getContext();
         

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


More information about the commits mailing list