Java Code Examples for org.apache.shiro.authc.AuthenticationException#getMessage()

The following examples show how to use org.apache.shiro.authc.AuthenticationException#getMessage() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SysLoginController.java    From supplierShop with MIT License 6 votes vote down vote up
@PostMapping("/login")
@ResponseBody
public AjaxResult ajaxLogin(String username, String password, Boolean rememberMe)
{
    UsernamePasswordToken token = new UsernamePasswordToken(username, password, rememberMe);
    Subject subject = SecurityUtils.getSubject();
    try
    {
        subject.login(token);
        return success();
    }
    catch (AuthenticationException e)
    {
        String msg = "用户或密码错误";
        if (StringUtils.isNotEmpty(e.getMessage()))
        {
            msg = e.getMessage();
        }
        return error(msg);
    }
}
 
Example 2
Source File: FormAuthenticationFilter.java    From frpMgr with MIT License 6 votes vote down vote up
/**
 * 登录失败调用事件
 */
@Override
protected boolean onLoginFailure(AuthenticationToken token, AuthenticationException e, ServletRequest request, ServletResponse response) {
	String className = e.getClass().getName(), message = "";
	if (IncorrectCredentialsException.class.getName().equals(className) || UnknownAccountException.class.getName().equals(className)) {
		message = Global.getText("sys.login.failure");
	} else if (e.getMessage() != null && StringUtils.startsWith(e.getMessage(), "msg:")) {
		message = StringUtils.replace(e.getMessage(), "msg:", "");
	} else {
		message = Global.getText("sys.login.error");
		logger.error(message, e); // 输出到日志文件
	}
	request.setAttribute(getFailureKeyAttribute(), className);
	request.setAttribute(DEFAULT_MESSAGE_PARAM, message);
	return true;
}
 
Example 3
Source File: SysLoginController.java    From ruoyiplus with MIT License 6 votes vote down vote up
@PostMapping("/login")
@ResponseBody
public AjaxResult ajaxLogin(String username, String password, Boolean rememberMe)
{
    if(rememberMe == null) rememberMe =false;
    UsernamePasswordToken token = new UsernamePasswordToken(username, password, rememberMe);
    Subject subject = SecurityUtils.getSubject();
    try
    {
        subject.login(token);
        return success();
    }
    catch (AuthenticationException e)
    {
        String msg = "用户或密码错误";
        if (StringUtils.isNotEmpty(e.getMessage()))
        {
            msg = e.getMessage();
        }
        return error(msg);
    }
}
 
Example 4
Source File: LoginController.java    From v-mock with MIT License 6 votes vote down vote up
@PostMapping("/login")
@ResponseBody
public Result<Void> ajaxLogin(String username, String password) {
    UsernamePasswordToken token = new UsernamePasswordToken(username, password, true);
    Subject subject = SecurityUtils.getSubject();
    try {
        subject.login(token);
        return success();
    } catch (AuthenticationException e) {
        String msg = "用户或密码错误";
        if (StrUtil.isNotEmpty(e.getMessage())) {
            msg = e.getMessage();
        }
        return error(msg);
    }
}
 
Example 5
Source File: SysLoginController.java    From RuoYi with Apache License 2.0 6 votes vote down vote up
@PostMapping("/login")
@ResponseBody
public AjaxResult ajaxLogin(String username, String password, Boolean rememberMe) {
    UsernamePasswordToken token = new UsernamePasswordToken(username, password, rememberMe);
    Subject subject = SecurityUtils.getSubject();
    try {
        subject.login(token);
        return success();
    } catch (AuthenticationException e) {
        String msg = "用户或密码错误";
        if (StrUtil.isNotEmpty(e.getMessage())) {
            msg = e.getMessage();
        }
        return error(msg);
    }
}
 
Example 6
Source File: LoginController.java    From LuckyFrameWeb with GNU Affero General Public License v3.0 6 votes vote down vote up
@PostMapping("/login")
@ResponseBody
public AjaxResult ajaxLogin(String username, String password, Boolean rememberMe)
{
    UsernamePasswordToken token = new UsernamePasswordToken(username, password, rememberMe);
    Subject subject = SecurityUtils.getSubject();
    try
    {
        subject.login(token);            
        return success();
    }
    catch (AuthenticationException e)
    {
        String msg = "用户或密码错误";
        if (StringUtils.isNotEmpty(e.getMessage()))
        {
            msg = e.getMessage();
        }
        return error(msg);
    }
}
 
Example 7
Source File: FormAuthenticationFilter.java    From easyweb with Apache License 2.0 6 votes vote down vote up
/**
 * 登录失败调用事件
 */
@Override
protected boolean onLoginFailure(AuthenticationToken token,
                                    AuthenticationException e, ServletRequest request, ServletResponse response) {
	String className = e.getClass().getName(), message = "";
	if (IncorrectCredentialsException.class.getName().equals(className)
			|| UnknownAccountException.class.getName().equals(className)){
		message = "用户或密码错误, 请重试.";
	}
	else if (e.getMessage() != null && StringUtils.startsWith(e.getMessage(), "msg:")){
		message = StringUtils.replace(e.getMessage(), "msg:", "");
	}
	else{
		message = "系统出现点问题,请稍后再试!";
		e.printStackTrace(); // 输出到控制台
	}
       request.setAttribute(getFailureKeyAttribute(), className);
       request.setAttribute(getMessageParam(), message);
       return true;
}
 
Example 8
Source File: FormAuthenticationFilter.java    From Shop-for-JavaWeb with MIT License 5 votes vote down vote up
protected void setFailureAttribute(ServletRequest request, AuthenticationException ae) {
  	request.setAttribute(getFailureKeyAttribute(), ae.getClass().getName());
if (ae.getMessage() != null && StringUtils.startsWith(ae.getMessage(), "msg:")){
	String message = StringUtils.replace(ae.getMessage(), "msg:", "");
       request.setAttribute(getMessageParam(), message);
}
  }