Make AccountStatusUserDetailsChecker implement MessageSourceAware

Fixes: gh-3980
This commit is contained in:
Wessel Nieboer 2018-12-04 08:45:26 +01:00 committed by Rob Winch
parent 98a8467e4c
commit 6f5fa1b610
2 changed files with 14 additions and 2 deletions

View File

@ -15,17 +15,20 @@
*/
package org.springframework.security.authentication;
import org.springframework.context.MessageSource;
import org.springframework.context.MessageSourceAware;
import org.springframework.security.core.SpringSecurityMessageSource;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsChecker;
import org.springframework.context.support.MessageSourceAccessor;
import org.springframework.util.Assert;
/**
* @author Luke Taylor
*/
public class AccountStatusUserDetailsChecker implements UserDetailsChecker {
public class AccountStatusUserDetailsChecker implements UserDetailsChecker, MessageSourceAware {
protected final MessageSourceAccessor messages = SpringSecurityMessageSource
protected MessageSourceAccessor messages = SpringSecurityMessageSource
.getAccessor();
public void check(UserDetails user) {
@ -51,4 +54,13 @@ public class AccountStatusUserDetailsChecker implements UserDetailsChecker {
"User credentials have expired"));
}
}
/**
* @since 5.2
*/
@Override
public void setMessageSource(MessageSource messageSource) {
Assert.notNull(messageSource, "messageSource cannot be null");
this.messages = new MessageSourceAccessor(messageSource);
}
}