首页 > 代码库 > shiro的Helloworld

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 }
View Code

 shiro

se4j

shiro的Helloworld