ajax shiro认证,shiro实现简单登陆认证

ゝ一纸荒年。 2022-09-03 06:21 366阅读 0赞

在实现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 条评论,366人围观)

还没有评论,来说两句吧...

相关阅读

    相关 shiro实现认证

    1,基本概念 1,身份验证 即在应用中谁能证明他就是他本人。一般提供如他们的身份ID 一些标识信息来 表明他就是他本人,如提供身份证,用户名/密码来证明。

    相关 shiro架构&认证 -Shiro

    一、权限的管理 1.1 什么是权限管理 基本上涉及到用户参与的系统都要进行权限管理,权限管理属于系统安全的范畴,权限管理实现`对用户访问系统的控制`,按照安全规则或

    相关 shiro实现认证

    1,基本概念 1,身份验证 即在应用中谁能证明他就是他本人。一般提供如他们的身份ID 一些标识信息来 表明他就是他本人,如提供身份证,用户名/密码来证明。

    相关 Shiro 认证

    认证流程 1、获取当前的Subject,调用SecurityUtils.getSubject(); 2、测试当前用户是否已经认证,即是否已经登录。调用Subject的isA

    相关 Shiro认证

    【知识回顾】     在上篇博客中,通过对Shiro架构及其组件的总结学习,对Shiro有了一个整体的认识。     本篇博客将进一步学习其认证组件,Authen