shiro的Helloworld
Posted 老邱2
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了shiro的Helloworld相关的知识,希望对你有一定的参考价值。
1 package shiro; 2 3 import org.apache.shiro.SecurityUtils; 4 import org.apache.shiro.authc.UsernamePasswordToken; 5 import org.apache.shiro.config.IniSecurityManagerFactory; 6 import org.apache.shiro.util.Factory; 7 import org.apache.shiro.mgt.SecurityManager; 8 import org.apache.shiro.subject.Subject; 9 10 public class ShiroTest { 11 12 public static void main(String[] args) { 13 //初始化工厂 14 Factory<SecurityManager> factory=new IniSecurityManagerFactory("classpath:shiro/shiro.ini"); 15 SecurityManager securityManager=factory.getInstance(); 16 SecurityUtils.setSecurityManager(securityManager); 17 Subject subject=SecurityUtils.getSubject(); 18 UsernamePasswordToken token=new UsernamePasswordToken("tom1","123"); 19 try { 20 subject.login(token); 21 System.out.println("登陆成功"); 22 } catch (Exception e) { 23 e.printStackTrace(); 24 System.out.println("登陆失败"); 25 } 26 subject.logout(); 27 } 28 }
shiro
se4j
以上是关于shiro的Helloworld的主要内容,如果未能解决你的问题,请参考以下文章