[java-identity-provider] 10/11: IDP-1464 Change UI code to use non deprecated Locale handling.
Rod Widdowson
rdw at steadingsoftware.com
Tue Jun 11 09:38:28 EDT 2019
This is an automated email from the git hooks/post-receive script.
rdw pushed a commit to branch master
in repository java-identity-provider.
View the commit online:
http://git.shibboleth.net/view/?p=java-identity-provider.git;a=commit;h=95beab14b168137335a8ba99cd1bbf3f7ee63beb
commit 95beab14b168137335a8ba99cd1bbf3f7ee63beb
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Tue Jun 11 10:59:15 2019 +0100
IDP-1464 Change UI code to use non deprecated Locale handling.
https://issues.shibboleth.net/jira/browse/IDP-1464
---
...InitializeAdministrativeProfileContextTree.java | 43 +++++-----------------
.../idp/profile/RequestContextBuilder.java | 5 ++-
.../shibboleth/idp/ui/impl/SetRPUIInformation.java | 23 +-----------
3 files changed, 16 insertions(+), 55 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 48db62c..39deb23 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,22 +18,11 @@
package net.shibboleth.idp.admin.impl;
import java.util.ArrayList;
-import java.util.Enumeration;
import java.util.List;
-import java.util.Locale;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
-import net.shibboleth.idp.admin.AdministrativeFlowDescriptor;
-import net.shibboleth.idp.profile.AbstractProfileAction;
-import net.shibboleth.idp.profile.IdPEventIds;
-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.collection.LazyList;
-import net.shibboleth.utilities.java.support.component.ComponentSupport;
-
import org.opensaml.profile.action.ActionSupport;
import org.opensaml.profile.context.ProfileRequestContext;
import org.slf4j.Logger;
@@ -42,6 +31,15 @@ import org.slf4j.LoggerFactory;
import com.google.common.base.Predicates;
import com.google.common.collect.Collections2;
+import net.shibboleth.idp.admin.AdministrativeFlowDescriptor;
+import net.shibboleth.idp.profile.AbstractProfileAction;
+import net.shibboleth.idp.profile.IdPEventIds;
+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.HttpServletSupport;
+
/**
* An action that processes settings from a supplied {@link AdministrativeFlowDescriptor} to prepare
* the profile context tree for subsequent use by an administrative profile flow.
@@ -127,31 +125,10 @@ public class InitializeAdministrativeProfileContextTree extends AbstractProfileA
final RelyingPartyUIContext uiCtx = rpCtx.getSubcontext(RelyingPartyUIContext.class, true);
uiCtx.setRPUInfo(flowDescriptor.getUIInfo());
- uiCtx.setBrowserLanguages(getBrowserLanguages());
+ uiCtx.setBrowserLanguageRanges(HttpServletSupport.getLanguageRange(getHttpServletRequest()));
if (null != fallbackLanguages) {
uiCtx.setFallbackLanguages(fallbackLanguages);
}
}
-
- /**
- * Pluck the languages from the browser.
- *
- * @return the two letter language
- */
- @Nonnull @NonnullElements private List<String> getBrowserLanguages() {
-
- final Enumeration<Locale> locales = getHttpServletRequest().getLocales();
-
- final List<String> languages = new LazyList<>();
-
- while (locales.hasMoreElements()) {
- final Locale locale = locales.nextElement();
- if (null != locale.getLanguage()) {
- languages.add(locale.getLanguage());
- }
- }
- return languages;
- }
-
}
\ No newline at end of file
diff --git a/idp-profile-api/src/test/java/net/shibboleth/idp/profile/RequestContextBuilder.java b/idp-profile-api/src/test/java/net/shibboleth/idp/profile/RequestContextBuilder.java
index 03a41bf..73d2a45 100644
--- a/idp-profile-api/src/test/java/net/shibboleth/idp/profile/RequestContextBuilder.java
+++ b/idp-profile-api/src/test/java/net/shibboleth/idp/profile/RequestContextBuilder.java
@@ -20,6 +20,7 @@ package net.shibboleth.idp.profile;
import java.time.Instant;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.Locale;
import java.util.Map;
import java.util.Objects;
@@ -312,7 +313,9 @@ public class RequestContextBuilder {
}
if (httpRequest == null) {
- httpRequest = new MockHttpServletRequest();
+ final MockHttpServletRequest hdr = new MockHttpServletRequest();
+ hdr.addHeader("Accept-Language", Locale.ENGLISH.getLanguage());
+ httpRequest = hdr;
}
if (httpResponse == null) {
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 107f0a7..5382846 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
@@ -34,6 +34,7 @@ import net.shibboleth.utilities.java.support.annotation.constraint.NonnullElemen
import net.shibboleth.utilities.java.support.collection.LazyList;
import net.shibboleth.utilities.java.support.component.ComponentSupport;
import net.shibboleth.utilities.java.support.logic.Constraint;
+import net.shibboleth.utilities.java.support.net.HttpServletSupport;
import org.opensaml.core.xml.XMLObject;
import org.opensaml.messaging.context.navigate.ChildContextLookup;
@@ -177,26 +178,6 @@ public class SetRPUIInformation extends AbstractProfileAction {
return null;
}
- /**
- * Pluck the languages from the browser.
- *
- * @return the two letter language
- */
- @Nonnull @NonnullElements protected List<String> getBrowserLanguages() {
-
- final Enumeration<Locale> locales = getHttpServletRequest().getLocales();
-
- final List<String> languages = new LazyList<>();
-
- while (locales.hasMoreElements()) {
- final Locale locale = locales.nextElement();
- if (null != locale.getLanguage()) {
- languages.add(locale.getLanguage());
- }
- }
- return languages;
- }
-
/** {@inheritDoc} */
@Override protected boolean doPreExecute(final ProfileRequestContext profileRequestContext) {
@@ -242,7 +223,7 @@ public class SetRPUIInformation extends AbstractProfileAction {
rpUIContext.setRPSPSSODescriptor(spSSODescriptor);
rpUIContext.setRPAttributeConsumingService(acsDesriptor);
rpUIContext.setRPUInfo(getRPUInfo());
- rpUIContext.setBrowserLanguages(getBrowserLanguages());
+ rpUIContext.setBrowserLanguageRanges(HttpServletSupport.getLanguageRange(getHttpServletRequest()));
}
}
\ 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