标签:system uri generated gets instance 实现 信息 java nbsp
package cn.mldn.test; import org.apache.shiro.subject.Subject; import org.apache.shiro.SecurityUtils; import org.apache.shiro.authc.UsernamePasswordToken; import org.apache.shiro.config.IniSecurityManagerFactory; import org.apache.shiro.mgt.SecurityManager; import org.apache.shiro.util.Factory; public class TestLoginDemo { public static void main(String[] args) { // TODO Auto-generated method stub //取得了factory的接口对象, Factory<SecurityManager> factory = new IniSecurityManagerFactory("classpath:shiro.ini"); // 取得里面的所有的认证信息。 SecurityManager securityManager = factory.getInstance() ; //利用一个专门的认证操作处理类,实现认证处理的具体的实现 SecurityUtils.setSecurityManager(securityManager); //获取用户名和密码认证的接口对象 Subject subject = SecurityUtils.getSubject() ; //定义一个Token,里面保存用户名密码 UsernamePasswordToken token = new UsernamePasswordToken("mldn","java") ; //实现用户登录处理 subject.login(token); System.out.println(subject.getPrincipal()); } }
shiro.ini
[users] admin=hello mldn=java
标签:system uri generated gets instance 实现 信息 java nbsp
原文地址:https://www.cnblogs.com/blog-747674599/p/9893363.html