码迷,mamicode.com
首页 > 其他好文 > 详细

shiro的Helloworld

时间:2017-01-08 07:41:29      阅读:180      评论:0      收藏:0      [点我收藏+]

标签:pat   ini   span   失败   cat   oid   man   classpath   sys   

技术分享
 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 }
View Code

 shiro

se4j

shiro的Helloworld

标签:pat   ini   span   失败   cat   oid   man   classpath   sys   

原文地址:http://www.cnblogs.com/javaweb2/p/6260725.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!