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
parent
7861300d72
commit
d25602fbe7
|
@ -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");
|
||||
}
|
||||
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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,17 +202,19 @@
|
|||
|
||||
<bean id="clientAssertionAuthenticationProvider" class="org.mitre.openid.connect.assertion.JwtBearerAuthenticationProvider" />
|
||||
|
||||
<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
|
||||
<property name="basenames">
|
||||
<list>
|
||||
<value>classpath:custom_messages</value>
|
||||
<value>classpath:messages</value>
|
||||
</list>
|
||||
</property>
|
||||
<property name="fallbackToSystemLocale" value="false" />
|
||||
<property name="cacheSeconds" value="180" />
|
||||
<property name="defaultEncoding" value="UTF-8" />
|
||||
<property name="useCodeAsDefaultMessage" value="true" />
|
||||
<!-- Configure locale information -->
|
||||
<bean id="messageSource"
|
||||
class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
|
||||
<property name="basenames">
|
||||
<list>
|
||||
<value>classpath:custom_messages</value>
|
||||
<value>classpath:messages</value>
|
||||
</list>
|
||||
</property>
|
||||
<property name="fallbackToSystemLocale" value="false" />
|
||||
<property name="cacheSeconds" value="180" />
|
||||
<property name="defaultEncoding" value="UTF-8" />
|
||||
<property name="useCodeAsDefaultMessage" value="true" />
|
||||
</bean>
|
||||
|
||||
<!-- user services -->
|
||||
|
|
|
@ -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>
|
||||
|
|
Loading…
Reference in New Issue