ajax shiro认证,shiro实现简单登陆认证
在实现shiro简单登陆认证后出现问题,不使用ajax请求登陆,当点击登陆访问一个controller方法,securityUils.getSubject.login(token)访问提交后找不到地址,登陆时候不需要在对密码进行加密操作了吧?
//这是controller
@RequestMapping(“/checkLogin.do”)
private void login(HttpServletRequest request) throws UserException{
String account = request.getParameter(“account”);
String password = request.getParameter(“password”);
UsernamePasswordToken token = new UsernamePasswordToken(account,password);
Subject currentUser = SecurityUtils.getSubject();
try{
if(!currentUser.isAuthenticated()){
currentUser.login(token);
}
}catch(UnknownAccountException uae){
//用户名/密码错误
throw new UserAccountException(“用户名或密码错误!”);
}catch(IncorrectCredentialsException ice){
//用户名/密码错误
throw new UserCredentialsException(“用户名或密码错误!”);
}catch(ExcessiveAttemptsException eae){
//登陆次数异常,账户锁定
throw new UserAttemptsException(“登陆次数超过5次,账户被锁定!”);
}catch(AuthenticationException ae){
//其他异常
throw new UserException(“登陆失败!”);
}
}
}
//这是realm
@Override
protected AuthenticationInfo doGetAuthenticationInfo(
AuthenticationToken token) throws AuthenticationException {
//基于用户名和密码的令牌
//这个令牌是从registController的currentUser.login(token)传来的
UsernamePasswordToken uptoken = (UsernamePasswordToken)token;
//调用service通过用户账户查询用户
UserAuthDTO userAuth = userService.getUserAuthByAccount((String)uptoken.getPrincipal());
if(userAuth == null){
return null;
}
String identity = userAuth.getAccount();
String password = userAuth.getPassword();
String salt = userAuth.getSalt();
if(userAuth.getIsLocked() != null && userAuth.getIsLocked() == 1){
throw new AuthenticationException(“该账户已被锁定!”);
}
AuthenticationInfo authInfo = new SimpleAuthenticationInfo(userAuth
, password, ByteSource.Util.bytes(identity+salt), this.getName());
System.out.println(“realm登陆认证结束!”);
return authInfo;
}
}
//这是shiro配置
/regist.jsp = anon
/login.jsp = anon
最后点击登陆出现这个问题
HTTP Status 404 - /web-templet/user/user/checkLogin
type Status report
message /web-templet/user/user/checkLogin
description The requested resource is not available.
Apache Tomcat/8.0.44
在登陆页面直接点击登陆会报账号密码错误,如果只填账号点击登陆realm就会查到该用户返回authenticationInfo之后页面这样:
还没有评论,来说两句吧...