shiro01-HelloWorld

[users]
zhangsan=123456
lisi=123456

public class Test01 {
    public static void main(String[] args) throws Exception{
        Factory<SecurityManager> factory = new IniSecurityManagerFactory("classpath:shiro01.ini");
    
        SecurityManager securityManager = factory.getInstance();
        
        SecurityUtils.setSecurityManager(securityManager);
        
        Subject subject = SecurityUtils.getSubject();
        
        UsernamePasswordToken token = new UsernamePasswordToken("zhangsan", "123456");
        
        subject.login(token);
        
        boolean b = subject.isAuthenticated();
        System.out.println(b);
        subject.logout();
        b = subject.isAuthenticated();
        System.out.println(b);
    }
}

 

posted @ 2018-01-17 08:53  yoyo198212  阅读(117)  评论(0编辑  收藏  举报