shiro认证

1.特点shiro认证只是对用户名的认证,通过doAuthenticate()方法来验证2.doAuthenticate方法此方法是用来获取用户名进行认证的3.doCredentialsMatch()方法此方法是获取密码的自定义realm(数据源),继承AuthorizingRealm 类(先认证后授权)其中,protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToke
摘要由CSDN通过智能技术生成

1.特点

shiro认证只是对用户名的认证,通过doAuthenticate()方法来验证

2.doAuthenticate方法

此方法是用来获取用户名进行认证的

3.doCredentialsMatch()方法

此方法是获取密码的

自定义realm(数据源),继承AuthorizingRealm 类

(先认证后授权)
其中,

protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken) throws AuthenticationException {
   
    //获取用户名
        String username = (String)authenticationToken.getPrincipal();
        //获取密码
        //authenticationToken.getCredentials();
        Employee employee = employeeService.selectByUserName(username);
        if(employee==null){
   //如果为空,说明没有此用户,登录失败
            return null;
        }
//employee 真实名称,用户登录时输入的用户名,由于运行到这里用户输入的用户名为真,所以对象中的用户名就是用户输入的姓名                                                                              //employee.getPassword() 真实密码(数据库中对应用户的真实密码)
//this.getName()  数据源名称(Realm对象)
        SimpleAuthenticationInfo info= new SimpleAuthenticationInfo(employee,employee.getPassword(),this.getName());
        return info;//info中装有所对应用户的所有信息
    }

此方法为认证方法

添加依赖

<properties>
<!--版本-->
	<shiro.version>1.5.2</shiro.version>
</properties>
<!--依赖-->
<!--shiro 核心-->
<dependency>
    <groupId>org.apache.shiro</groupId>
    <artifactId>shiro-core</artifactId>
    <version>${shiro.version}</version>
</dependency>
<!--shiro 的 Web 模块-->
<dependency>
    <groupId>org.apache.shiro</groupId>
    <artifactId>shiro-web</artifactId>
    <
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值