Search in sources :

Example 11 with UnknownAccountException

use of org.apache.shiro.authc.UnknownAccountException in project Workload by amoxu.

the class CustomExceptionResolver method resolveException.

public ModelAndView resolveException(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, Exception e) {
    ModelAndView modelAndView = new ModelAndView();
    com.hfut.exception.CustomException customException;
    e.printStackTrace();
    if (e instanceof CustomException) {
        customException = (CustomException) e;
    } else if (e instanceof UnknownAccountException) {
        // 用户名错误异常
        modelAndView.addObject("message", "{\"status\":1,\"msg\":\"用户不存在\"}");
        modelAndView.setViewName("error");
        return modelAndView;
    } else if (e instanceof IncorrectCredentialsException) {
        // 用户名密码异常
        modelAndView.addObject("message", "{\"status\":1,\"msg\":\"密码错误\"}");
        modelAndView.setViewName("error");
        return modelAndView;
    } else if (e instanceof NullPointerException) {
        customException = new com.hfut.exception.CustomException("必填选项不能为空!");
        e.printStackTrace();
    } else {
        customException = new com.hfut.exception.CustomException("未知错误");
        e.printStackTrace();
    }
    // 错误信息
    String message = customException.getMessage();
    // 错误信息传递和错误页面跳转
    modelAndView.addObject("message", message);
    modelAndView.setViewName("error");
    return modelAndView;
}
Also used : IncorrectCredentialsException(org.apache.shiro.authc.IncorrectCredentialsException) UnknownAccountException(org.apache.shiro.authc.UnknownAccountException) ModelAndView(org.springframework.web.servlet.ModelAndView)

Aggregations

UnknownAccountException (org.apache.shiro.authc.UnknownAccountException)11 UsernamePasswordToken (org.apache.shiro.authc.UsernamePasswordToken)9 AuthenticationException (org.apache.shiro.authc.AuthenticationException)7 IncorrectCredentialsException (org.apache.shiro.authc.IncorrectCredentialsException)7 LockedAccountException (org.apache.shiro.authc.LockedAccountException)6 DisabledAccountException (org.apache.shiro.authc.DisabledAccountException)5 ExcessiveAttemptsException (org.apache.shiro.authc.ExcessiveAttemptsException)4 SimpleAuthenticationInfo (org.apache.shiro.authc.SimpleAuthenticationInfo)4 Subject (org.apache.shiro.subject.Subject)3 AccountException (org.apache.shiro.authc.AccountException)2 ExpiredCredentialsException (org.apache.shiro.authc.ExpiredCredentialsException)2 AjaxJson (com.cdeledu.common.base.AjaxJson)1 SysUser (com.cdeledu.model.rbac.SysUser)1 Users (io.github.tesla.authz.domain.Users)1 Connection (java.sql.Connection)1 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1 AccountLockedException (javax.security.auth.login.AccountLockedException)1 AccountNotFoundException (javax.security.auth.login.AccountNotFoundException)1 CredentialExpiredException (javax.security.auth.login.CredentialExpiredException)1