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;
|
package org.mitre.openid.connect.config;
|
||||||
|
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
import javax.annotation.PostConstruct;
|
import javax.annotation.PostConstruct;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
@ -47,6 +49,8 @@ public class ConfigurationPropertiesBean {
|
||||||
|
|
||||||
private boolean forceHttps = false;
|
private boolean forceHttps = false;
|
||||||
|
|
||||||
|
private Locale locale = Locale.getDefault();
|
||||||
|
|
||||||
public ConfigurationPropertiesBean() {
|
public ConfigurationPropertiesBean() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -131,4 +135,18 @@ public class ConfigurationPropertiesBean {
|
||||||
public void setForceHttps(boolean forceHttps) {
|
public void setForceHttps(boolean forceHttps) {
|
||||||
this.forceHttps = 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:message-converters>
|
||||||
</mvc:annotation-driven>
|
</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>
|
<mvc:interceptors>
|
||||||
<!-- Inject the UserInfo into the current context -->
|
<!-- Inject the UserInfo into the response -->
|
||||||
<ref bean="localeChangeInterceptor"/>
|
|
||||||
<bean id="userInfoInterceptor" class="org.mitre.openid.connect.web.UserInfoInterceptor" />
|
<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" />
|
<bean id="serverConfigInterceptor" class="org.mitre.openid.connect.web.ServerConfigInterceptor" />
|
||||||
</mvc:interceptors>
|
</mvc:interceptors>
|
||||||
|
|
||||||
|
@ -208,17 +202,19 @@
|
||||||
|
|
||||||
<bean id="clientAssertionAuthenticationProvider" class="org.mitre.openid.connect.assertion.JwtBearerAuthenticationProvider" />
|
<bean id="clientAssertionAuthenticationProvider" class="org.mitre.openid.connect.assertion.JwtBearerAuthenticationProvider" />
|
||||||
|
|
||||||
<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
|
<!-- Configure locale information -->
|
||||||
<property name="basenames">
|
<bean id="messageSource"
|
||||||
<list>
|
class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
|
||||||
<value>classpath:custom_messages</value>
|
<property name="basenames">
|
||||||
<value>classpath:messages</value>
|
<list>
|
||||||
</list>
|
<value>classpath:custom_messages</value>
|
||||||
</property>
|
<value>classpath:messages</value>
|
||||||
<property name="fallbackToSystemLocale" value="false" />
|
</list>
|
||||||
<property name="cacheSeconds" value="180" />
|
</property>
|
||||||
<property name="defaultEncoding" value="UTF-8" />
|
<property name="fallbackToSystemLocale" value="false" />
|
||||||
<property name="useCodeAsDefaultMessage" value="true" />
|
<property name="cacheSeconds" value="180" />
|
||||||
|
<property name="defaultEncoding" value="UTF-8" />
|
||||||
|
<property name="useCodeAsDefaultMessage" value="true" />
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
<!-- user services -->
|
<!-- user services -->
|
||||||
|
|
|
@ -46,6 +46,9 @@
|
||||||
<!-- This property forces the issuer value to start with "https" -->
|
<!-- This property forces the issuer value to start with "https" -->
|
||||||
<!-- <property name="forceHttps" value="true" /> -->
|
<!-- <property name="forceHttps" value="true" /> -->
|
||||||
|
|
||||||
|
<!-- This property sets the locale for server text -->
|
||||||
|
<!-- <property name="locale" value="sv" /> -->
|
||||||
|
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
</beans>
|
</beans>
|
||||||
|
|
Loading…
Reference in New Issue