首页 > 解决方案 > Spring Security 自定义 AuthenticationException

问题描述

我正在使用 Spring Security。我想从message.property文件中实现我的自定义异常消息,就像Spring Security 使用的UsernameNotFoundException一样AbstractUserDetailsAuthenticationProvider.badCredentials=Bad credentials

我的自定义异常如下:

public class CustomUsernameNotFoundException extends AuthenticationException {
public CustomUsernameNotFoundException(String msg) {
    super(msg);
}
public CustomUsernameNotFoundException(String msg, Throwable t) {
    super(msg, t);
}

}

如何在 Spring Security 中配置和处理自定义异常。

注意:请不要建议在messages.properties 上更新消息,spring security 默认会使用这些消息。

标签: javaspringspring-securityexception-handlingspring-security-oauth2

解决方案


推荐阅读