我正在尝试创建一个异常子类,AuthenticationException
如下所示:
public class RegistrationNotCompleteException extends AuthenticationException {
public RegistrationNotCompleteException(String msg) {
super(msg);
}
}
在loadUserByUsername
我的UserDetailsService
课堂上,我做了以下检查:
if (!user.getHasRegistered()) {
System.out.println("######## User: " + username
+ " has not completed the registration");
throw new RegistrationNotCompleteException(
"User has not completed registration");
}
AuthenticationFailureHandler
因此用户按预期转发到班级。
但是当试图在onAuthenticationFailure
方法中获取异常类时如下:
public void onAuthenticationFailure(HttpServletRequest request,
HttpServletResponse response, AuthenticationException exception)
throws IOException, ServletException {
UsernamePasswordAuthenticationToken token =
(UsernamePasswordAuthenticationToken) exception.getAuthentication();
String username = token.getName();
String credentials = token.getCredentials().toString();
System.out.println("Exception class: " + exception.getClass());
它打印出异常类AuthenticationException
不是RegistrationNotCompleteException
。
我想验证异常类是RegistrationNotCompleteException
.
请告知如何做到这一点。