[spring-extensions] branch main updated: IDP-1597 Change of language incomplete when switching locale

Rod Widdowson rdw at steadingsoftware.com
Tue Sep 29 12:44:02 UTC 2020


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

rdw pushed a commit to branch main
in repository spring-extensions.

View the commit online:
http://git.shibboleth.net/view/?p=spring-extensions.git;a=commit;h=bb6ae44146432697d29b5c194eef331f1ac9c44d

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

commit bb6ae44146432697d29b5c194eef331f1ac9c44d
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Tue Sep 29 13:19:05 2020 +0100

    IDP-1597 Change of language incomplete when switching locale
    
    https://issues.shibboleth.net/jira/browse/IDP-1597
    
    Add a new helper method which returns what the browser it set to,
    but with Spring's idea of the "one true locale" prepended.
    
    This allows the flexibility of falling back through the
    browser alternative lamguages when Spring's "one true locale"
    isn't known about.
    
    It also makes for mimimal changes upstream.
---
 .../shibboleth/ext/spring/util/SpringSupport.java  | 23 ++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/src/main/java/net/shibboleth/ext/spring/util/SpringSupport.java b/src/main/java/net/shibboleth/ext/spring/util/SpringSupport.java
index d9f3c7d..8861a9b 100644
--- a/src/main/java/net/shibboleth/ext/spring/util/SpringSupport.java
+++ b/src/main/java/net/shibboleth/ext/spring/util/SpringSupport.java
@@ -19,10 +19,14 @@ package net.shibboleth.ext.spring.util;
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
+import java.util.ArrayList;
 import java.util.Collection;
+import java.util.List;
+import java.util.Locale.LanguageRange;
 
 import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
+import javax.servlet.http.HttpServletRequest;
 import javax.xml.namespace.QName;
 
 import org.slf4j.Logger;
@@ -37,6 +41,7 @@ import org.springframework.beans.factory.support.ManagedList;
 import org.springframework.beans.factory.xml.ParserContext;
 import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
 import org.springframework.context.support.GenericApplicationContext;
+import org.springframework.web.servlet.support.RequestContextUtils;
 import org.w3c.dom.Attr;
 import org.w3c.dom.Element;
 import org.w3c.dom.Node;
@@ -46,7 +51,9 @@ import com.google.common.base.Strings;
 
 import net.shibboleth.ext.spring.context.FilesystemGenericApplicationContext;
 import net.shibboleth.utilities.java.support.annotation.constraint.NonnullElements;
+import net.shibboleth.utilities.java.support.annotation.constraint.Unmodifiable;
 import net.shibboleth.utilities.java.support.logic.Constraint;
+import net.shibboleth.utilities.java.support.net.HttpServletSupport;
 import net.shibboleth.utilities.java.support.primitive.StringSupport;
 import net.shibboleth.utilities.java.support.xml.SerializeSupport;
 import net.shibboleth.utilities.java.support.xml.XMLConstants;
@@ -316,4 +323,20 @@ public final class SpringSupport {
         return result;
     }
 
+    /** Return the {@link LanguageRange} associated with this request prepended with
+     * the Spring preferred locale.  This allows external (non browser) control of
+     * the language.
+     * @param request the request to process
+     * @return The range returned from {@link HttpServletSupport#getLanguageRange(HttpServletRequest)}
+     * with the Locale from {@link RequestContextUtils#getLocale(HttpServletRequest)} prepended
+     */
+    @Nonnull @NonnullElements @Unmodifiable
+    public static List<LanguageRange> getLanguageRange(final HttpServletRequest request) {
+        final List<LanguageRange> fromBrowser = HttpServletSupport.getLanguageRange(request);
+        final List<LanguageRange> outList = new ArrayList<>(1+fromBrowser.size());
+
+        outList.add(new LanguageRange(RequestContextUtils.getLocale(request).getLanguage()));
+        outList.addAll(fromBrowser);
+        return List.copyOf(outList);        
+    }
 }
\ 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