java shiro 扫码登录_如何使用Shiro对用户进行身份验证?

我想通了 It is each Realm's responsibility to match submitted credentials with those stored in the Realm's backing data store from here . 但那怎么办?

以下是我尝试过的,但结果仍然是无效的身份验证 .

的LoginController

@RequestMapping(value = "/login.htm", method = RequestMethod.POST)

protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object cmd, BindException errors) throws Exception {

LoginCommand command = (LoginCommand) cmd;

UsernamePasswordToken token = new UsernamePasswordToken(command.getUsername(), command.getPassword());

System.out.println("onSubmit");

System.out.println(token.getUsername());

System.out.println(token.getPassword());

try

{

SecurityUtils.getSubject().login(token);

} catch (AuthenticationException e) {

errors.reject("error.invalidLogin", "The username or password was not correct.");

}

if (errors.hasErrors()) {

return showForm(request, response, errors);

} else {

return new ModelAndView("accessTest");

}

}

领域

protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authcToken) throws AuthenticationException {

UsernamePasswordToken token = (UsernamePasswordToken) authcToken;

System.out.println("doGetAuthenticationInfo");

System.out.println(user.getUsername());

System.out.println(user.getPassword());

// user is a test object in place of a database

if( user != null ) {

return new SimpleAuthenticationInfo(user.getUsername(), user.getPassword(), getName());

} else {

return null;

}

}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值