package shiro; import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.config.IniSecurityManagerFactory;
import org.apache.shiro.util.Factory;
import org.apache.shiro.mgt.SecurityManager;
import org.apache.shiro.subject.Subject; public class ShiroTest { public static void main(String[] args) {
//初始化工厂
Factory<SecurityManager> factory=new IniSecurityManagerFactory("classpath:shiro/shiro.ini");
SecurityManager securityManager=factory.getInstance();
SecurityUtils.setSecurityManager(securityManager);
Subject subject=SecurityUtils.getSubject();
UsernamePasswordToken token=new UsernamePasswordToken("tom1","123");
try {
subject.login(token);
System.out.println("登陆成功");
} catch (Exception e) {
e.printStackTrace();
System.out.println("登陆失败");
}
subject.logout();
}
}
shiro
se4j