shiro作为安全框架,提供了各种安全策略,此处记录身份认证Authentication的简单搭建步骤:
(1)创建SecurityManagerFactory,读取shiro.ini配置文件
Factory<securitymanager> factory=new Inisecuritymanagerfactory("classpath:shiro.ini");
(2)实例化securitymanager
ScurityManager scuritymanager=new factory.getinstance();
(3)绑定securitymanager到SecurityUtils
ScurityUtils.getsecuritymanager(securitymanager);
(4)获取subject
Subject subject=new securityutils.getsubject();
(5)根据提交的用户名生成token
UsernamepasswordToken token=new usernamepasswordtoken(”张三”,“123”);
(6)验证身份
sibject.login(token);
(7)退出验证
subject.logout;