use of org.springframework.context.support.MessageSourceAccessor in project spring-security by spring-projects.
the class AbstractLdapAuthenticator method setMessageSource.
public void setMessageSource(MessageSource messageSource) {
Assert.notNull(messageSource, "Message source must not be null");
this.messages = new MessageSourceAccessor(messageSource);
}
use of org.springframework.context.support.MessageSourceAccessor in project gocd by gocd.
the class LocalizerTest method shouldLocalizeDurations.
@Test
public void shouldLocalizeDurations() {
CurrentLocale locale = new CurrentLocale();
ReloadableResourceBundleMessageSource source = new ReloadableResourceBundleMessageSource();
source.setBasename("test_message");
MessageSourceAccessor accessor = new MessageSourceAccessor(source);
Localizer localizer = new Localizer(accessor, locale);
assertThat(localizer.localize(new Duration(1000)), is("1 second"));
assertThat(localizer.localize(new Duration(0)), is(""));
locale.setLocaleString(Localizer.LOCALE_KANNADA);
assertThat(localizer.localize(new Duration(1000)), is("1 second"));
}
use of org.springframework.context.support.MessageSourceAccessor in project spring-security by spring-projects.
the class ConcurrentSessionControlAuthenticationStrategy method setMessageSource.
/**
* Sets the {@link MessageSource} used for reporting errors back to the user when the
* user has exceeded the maximum number of authentications.
*/
public void setMessageSource(MessageSource messageSource) {
Assert.notNull(messageSource, "messageSource cannot be null");
this.messages = new MessageSourceAccessor(messageSource);
}
use of org.springframework.context.support.MessageSourceAccessor in project spring-security by spring-projects.
the class DefaultLoginPageGeneratingFilterTests method handlesNonIso8859CharsInErrorMessage.
/* SEC-1111 */
@Test
public void handlesNonIso8859CharsInErrorMessage() throws Exception {
DefaultLoginPageGeneratingFilter filter = new DefaultLoginPageGeneratingFilter(new UsernamePasswordAuthenticationFilter());
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/login");
request.addParameter("login_error", "true");
MessageSourceAccessor messages = SpringSecurityMessageSource.getAccessor();
String message = messages.getMessage("AbstractUserDetailsAuthenticationProvider.badCredentials", "Bad credentials", Locale.KOREA);
request.getSession().setAttribute(WebAttributes.AUTHENTICATION_EXCEPTION, new BadCredentialsException(message));
filter.doFilter(request, new MockHttpServletResponse(), chain);
}
use of org.springframework.context.support.MessageSourceAccessor in project gocd by gocd.
the class LocalizerTest method shouldReturnTheFormattedLocalizedMessage.
@Test
public void shouldReturnTheFormattedLocalizedMessage() {
CurrentLocale locale = new CurrentLocale();
ReloadableResourceBundleMessageSource source = new ReloadableResourceBundleMessageSource();
source.setBasename("test_message");
MessageSourceAccessor accessor = new MessageSourceAccessor(source);
Localizer localizer = new Localizer(accessor, locale);
assertThat(localizer.localize("hello_world"), is("Hello World"));
locale.setLocaleString(Localizer.LOCALE_ENGLISH_US);
assertThat(localizer.localize("MY_HOME", "San Francisco"), is("My home is San Francisco"));
locale.setLocaleString(Localizer.LOCALE_KANNADA);
assertThat(localizer.localize("MY_HOME", "ಬೆಂಗಳೂರು"), is("ನಮ್ಮ ಊರು ಬೆಂಗಳೂರು"));
locale.setLocaleString(Localizer.LOCALE_KANNADA);
assertThat(localizer.localize("MY_BIRTHDAY", new DateTime(1984, 12, 23, 14, 0, 0, 0, DateTimeZone.UTC).toDate()), is("ನನ್ನ ಹುಟ್ಟು ಹಬ್ಬ 12/23/84"));
locale.setLocaleString(Localizer.LOCALE_ENGLISH_US);
assertThat(localizer.localize("MY_BIRTHDAY", new DateTime(1984, 12, 23, 14, 0, 0, 0, DateTimeZone.UTC).toDate()), is("My birthday is 12/23/84"));
}
Aggregations