java - 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 默认会使用这些消息。
解决方案
推荐阅读
- c++ - 是否有任何用于移动设备的 C++ 图形库?
- flutter - Flutter Cupertino 开关
- node.js - 是否有用于 Nest.js 的 Open API 代码生成器的模块
- python - 将股票指标添加到 Pandas DataFrame - ValueError:系列的真值不明确。使用 a.empty、a.bool()、a.item()、a.any() 或
- python - 如何从 restful api django 获取详细信息?
- javascript - 如何让 javascript 将类添加到 LI 标记
- python - 根据与另一个数据框的匹配在数据框中创建新列
- python - 在 Dataframe 列中查找特定字符串
- optimization - 在 Anaconda GUI 上使用 Pyomo、GLPK 和 Spyder——这可能吗?如果是这样,为什么这对我不起作用?
- javascript - 如何将日期和时间值加入日期时间并将其设置为单元格?