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

pull/779/head
Justin Richer 2015-02-16 10:11:40 -05:00
parent 7861300d72
commit d25602fbe7
4 changed files with 96 additions and 19 deletions

View File

@ -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");
}
}

View File

@ -16,6 +16,8 @@
******************************************************************************/
package org.mitre.openid.connect.config;
import java.util.Locale;
import javax.annotation.PostConstruct;
import org.slf4j.Logger;
@ -47,6 +49,8 @@ public class ConfigurationPropertiesBean {
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;
}
}

View File

@ -41,16 +41,10 @@
</mvc:message-converters>
</mvc:annotation-driven>
<bean id="localeResolver" class="org.springframework.web.servlet.i18n.FixedLocaleResolver">
<property name="defaultLocale" value="en" />
</bean>
<bean id="localeChangeInterceptor" class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor" />
<mvc:interceptors>
<!-- Inject the UserInfo into the current context -->
<ref bean="localeChangeInterceptor"/>
<!-- Inject the UserInfo into the response -->
<bean id="userInfoInterceptor" class="org.mitre.openid.connect.web.UserInfoInterceptor" />
<!-- Inject the server configuration into the response -->
<bean id="serverConfigInterceptor" class="org.mitre.openid.connect.web.ServerConfigInterceptor" />
</mvc:interceptors>
@ -208,7 +202,9 @@
<bean id="clientAssertionAuthenticationProvider" class="org.mitre.openid.connect.assertion.JwtBearerAuthenticationProvider" />
<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<!-- Configure locale information -->
<bean id="messageSource"
class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="basenames">
<list>
<value>classpath:custom_messages</value>

View File

@ -46,6 +46,9 @@
<!-- This property forces the issuer value to start with "https" -->
<!-- <property name="forceHttps" value="true" /> -->
<!-- This property sets the locale for server text -->
<!-- <property name="locale" value="sv" /> -->
</bean>
</beans>