我已经制作了AngularJs + Spring Security应用程序,我想个性化' UsernameNotFoundException'消息。
我去了那么远。
My Spring Security代码:
@Override
@Transactional
public UserDetails loadUserByUsername(final String login) {
log.debug("Authenticating {}", login);
String lowercaseLogin = login.toLowerCase();
Optional<User> userFromDatabase = userRepository.findOneByEmail(lowercaseLogin);
return userFromDatabase.map(
user -> {
List<GrantedAuthority> grantedAuthorities = user.getAuthorities().stream()
.map(authority -> new SimpleGrantedAuthority(authority.getName()))
.collect(Collectors.toList());
return new org.springframework.security.core.userdetails.User(lowercaseLogin, user
.getPassword(), grantedAuthorities);
}).orElseThrow(
() -> new UsernameNotFoundException("User " + lowercaseLogin + " was not found in the database"));
}
异常类:
public class UsernameNotFoundException extends AuthenticationException {
public UsernameNotFoundException(String msg) {
super(msg);
}
}
我的控制器:
$scope.login = function (event,validForm) {
Auth.login({
username: $scope.username,
password: $scope.password,
}).then(function success(data) {
[...]
}, function error(data) {
console.log(data);
});
当异常被抛出时,我在console.log上得到了这个:
Object {data: Object, status: 400, config: Object, statusText: "Bad Request"}
config: Object
data: Object
headers: (name)
status: 400
statusText: "Bad Request"
__proto__: Object
但我无法找到定制的信息。有什么想法吗?