Search in sources :

Example 6 with MessageSourceAccessor

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);
}
Also used : MessageSourceAccessor(org.springframework.context.support.MessageSourceAccessor)

Example 7 with MessageSourceAccessor

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"));
}
Also used : MessageSourceAccessor(org.springframework.context.support.MessageSourceAccessor) ReloadableResourceBundleMessageSource(org.springframework.context.support.ReloadableResourceBundleMessageSource) Duration(org.joda.time.Duration) Test(org.junit.Test)

Example 8 with MessageSourceAccessor

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);
}
Also used : MessageSourceAccessor(org.springframework.context.support.MessageSourceAccessor)

Example 9 with MessageSourceAccessor

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);
}
Also used : DefaultLoginPageGeneratingFilter(org.springframework.security.web.authentication.ui.DefaultLoginPageGeneratingFilter) MessageSourceAccessor(org.springframework.context.support.MessageSourceAccessor) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) BadCredentialsException(org.springframework.security.authentication.BadCredentialsException) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 10 with MessageSourceAccessor

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"));
}
Also used : MessageSourceAccessor(org.springframework.context.support.MessageSourceAccessor) ReloadableResourceBundleMessageSource(org.springframework.context.support.ReloadableResourceBundleMessageSource) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Aggregations

MessageSourceAccessor (org.springframework.context.support.MessageSourceAccessor)11 Test (org.junit.Test)6 ReloadableResourceBundleMessageSource (org.springframework.context.support.ReloadableResourceBundleMessageSource)3 Locale (java.util.Locale)2 DateTime (org.joda.time.DateTime)1 Duration (org.joda.time.Duration)1 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)1 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)1 BadCredentialsException (org.springframework.security.authentication.BadCredentialsException)1 DefaultLoginPageGeneratingFilter (org.springframework.security.web.authentication.ui.DefaultLoginPageGeneratingFilter)1