From d25602fbe76e09bbb40f20e2b0eea337442b81e4 Mon Sep 17 00:00:00 2001 From: Justin Richer Date: Mon, 16 Feb 2015 10:11:40 -0500 Subject: [PATCH] created a locale resolved tied in with the existing server configuration bean, removed locale interceptor (it doesn't work with fixed resolvers), cleaned up comments and files --- .../ConfigurationBeanLocaleResolver.java | 60 +++++++++++++++++++ .../config/ConfigurationPropertiesBean.java | 18 ++++++ .../webapp/WEB-INF/application-context.xml | 34 +++++------ .../src/main/webapp/WEB-INF/server-config.xml | 3 + 4 files changed, 96 insertions(+), 19 deletions(-) create mode 100644 openid-connect-common/src/main/java/org/mitre/openid/connect/config/ConfigurationBeanLocaleResolver.java diff --git a/openid-connect-common/src/main/java/org/mitre/openid/connect/config/ConfigurationBeanLocaleResolver.java b/openid-connect-common/src/main/java/org/mitre/openid/connect/config/ConfigurationBeanLocaleResolver.java new file mode 100644 index 000000000..c64bb6e56 --- /dev/null +++ b/openid-connect-common/src/main/java/org/mitre/openid/connect/config/ConfigurationBeanLocaleResolver.java @@ -0,0 +1,60 @@ +/** + * + */ +package org.mitre.openid.connect.config; + +import java.util.Locale; +import java.util.TimeZone; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.i18n.LocaleContext; +import org.springframework.context.i18n.TimeZoneAwareLocaleContext; +import org.springframework.stereotype.Component; +import org.springframework.web.servlet.i18n.AbstractLocaleContextResolver; +import org.springframework.web.servlet.i18n.FixedLocaleResolver; + +/** + * + * Resolve the server's locale from the injected ConfigurationPropertiesBean. + * + * @author jricher + * + */ +@Component("localeResolver") +public class ConfigurationBeanLocaleResolver extends AbstractLocaleContextResolver { + + @Autowired + private ConfigurationPropertiesBean config; + + @Override + protected Locale getDefaultLocale() { + if (config.getLocale() != null) { + return config.getLocale(); + } else { + return super.getDefaultLocale(); + } + } + + @Override + public LocaleContext resolveLocaleContext(HttpServletRequest request) { + return new TimeZoneAwareLocaleContext() { + @Override + public Locale getLocale() { + return getDefaultLocale(); + } + @Override + public TimeZone getTimeZone() { + return getDefaultTimeZone(); + } + }; + } + + @Override + public void setLocaleContext(HttpServletRequest request, HttpServletResponse response, LocaleContext localeContext) { + throw new UnsupportedOperationException("Cannot change fixed locale - use a different locale resolution strategy"); + } + +} diff --git a/openid-connect-common/src/main/java/org/mitre/openid/connect/config/ConfigurationPropertiesBean.java b/openid-connect-common/src/main/java/org/mitre/openid/connect/config/ConfigurationPropertiesBean.java index 2b6ec53ba..274c049b0 100644 --- a/openid-connect-common/src/main/java/org/mitre/openid/connect/config/ConfigurationPropertiesBean.java +++ b/openid-connect-common/src/main/java/org/mitre/openid/connect/config/ConfigurationPropertiesBean.java @@ -16,6 +16,8 @@ ******************************************************************************/ package org.mitre.openid.connect.config; +import java.util.Locale; + import javax.annotation.PostConstruct; import org.slf4j.Logger; @@ -46,6 +48,8 @@ public class ConfigurationPropertiesBean { private Long regTokenLifeTime; private boolean forceHttps = false; + + private Locale locale = Locale.getDefault(); public ConfigurationPropertiesBean() { @@ -131,4 +135,18 @@ public class ConfigurationPropertiesBean { public void setForceHttps(boolean forceHttps) { this.forceHttps = forceHttps; } + + /** + * @return the locale + */ + public Locale getLocale() { + return locale; + } + + /** + * @param locale the locale to set + */ + public void setLocale(Locale locale) { + this.locale = locale; + } } diff --git a/openid-connect-server-webapp/src/main/webapp/WEB-INF/application-context.xml b/openid-connect-server-webapp/src/main/webapp/WEB-INF/application-context.xml index 1670b44a9..a4f833f10 100644 --- a/openid-connect-server-webapp/src/main/webapp/WEB-INF/application-context.xml +++ b/openid-connect-server-webapp/src/main/webapp/WEB-INF/application-context.xml @@ -41,16 +41,10 @@ - - - - - - - - + + @@ -208,17 +202,19 @@ - - - - classpath:custom_messages - classpath:messages - - - - - - + + + + + classpath:custom_messages + classpath:messages + + + + + + diff --git a/openid-connect-server-webapp/src/main/webapp/WEB-INF/server-config.xml b/openid-connect-server-webapp/src/main/webapp/WEB-INF/server-config.xml index 7cfe4adc8..8077c1526 100644 --- a/openid-connect-server-webapp/src/main/webapp/WEB-INF/server-config.xml +++ b/openid-connect-server-webapp/src/main/webapp/WEB-INF/server-config.xml @@ -45,6 +45,9 @@ + + +