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之后页面这样:

bVSBGs?w=845&h=318

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值