public class MyTest {
public static void main(String[] args) {
Factory<SecurityManager> factory = new IniSecurityManagerFactory("classpath:shiro.ini");
SecurityManager securityManager = factory.getInstance();
/***/
SecurityUtils.setSecurityManager(securityManager);
Subject subject = SecurityUtils.getSubject();
System.out.println("==================begin===================");
Session session = subject.getSession();
session.setAttribute("name","name");
System.out.println(session.getAttribute("name"));
System.out.println(subject.isAuthenticated()?"have logined":"have not login");
UsernamePasswordToken token = new UsernamePasswordToken("presidentskroob","12345");
subject.login(token);
System.out.println("尝试登陆,验证登陆是否成功");
System.out.println(subject.isAuthenticated()?"have logined":"have not login");
System.out.println(subject.hasRole("president")?"yes,have this role":"have not");
System.out.println(subject.isPermitted("winnebago:drive:eagle5")?"you have this Operation authority":"oh,sorry you have not ");
System.out.println("==================end===================");
}
}