Results 1 to 3 of 3

Thread: Translate messages

  1. #1

    Default Translate messages

    Hi

    I found out how to translate some messages for exampel

    Code:
    AbstractUserDetailsAuthenticationProvider.badCredentials
    My problem is that I got this message below that I would like to translate. I searched in the message.properties file of Spring Security but there is no such message.

    https://fisheye.springsource.org/browse/~br=master/spring-security/core/src/main/resources/org/springframework/security/messages.properties?r=59ac4c8b964c8ffa86084e53b99f c56fe1415516&r=6db747292815b626f8c6f94bc8e48c2d85c c3f53&r=6db747292815b626f8c6f94bc8e48c2d85cc3f53&r =6db747292815b626f8c6f94bc8e48c2d85cc3f53&r=6db747 292815b626f8c6f94bc8e48c2d85cc3f53&r=59ac4c8b964c8 ffa86084e53b99fc56fe1415516

    How can I make a custom translation of the error below?

    Code:
    UserDetailsService returned null, which is an interface contract violation
    I also looked into the actual AbstractUserDetailsAuthenticationProvider class and the only clue is this but can't find anything similar in message.properties.

    Assert.notNull(user, "retrieveUser returned null - a violation of the interface contract");

  2. #2
    Join Date
    Jan 2008
    Posts
    1,826

    Default

    Not all Exceptions can be modified (only messages that are intended to be displayed to users). Exceptions that are displayed to an admin or developer are not translated (this is one such case).
    Rob Winch - @rob_winch
    Spring Security Lead
    Pivotal

  3. #3

    Default

    Thank you. I did not throw the exception before. Now I do and everything works as expected.

    Code:
    @Override
    	@Transactional(readOnly = true)
    	public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException, DataAccessException {
    		User person = personService.getPersonByEmail(username);
                    //this is new
    		if (person == null) {
    			throw new UsernameNotFoundException("User " + username + " not found!");
    		}
    		return person;
    	}

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •