*/ public class PermissionTest1 { public static void main(String[] args) { //1.创建安全工厂管理器 IniSecurityManagerFactory iniSecurityManagerFactory = new IniSecurityManagerFactory("classpath:shiro_permission.ini"); //2.通过工厂获取安全管理器 SecurityManager instance = iniSecurityManagerFactory.getInstance(); //3.将安全管理器放入到安全工厂工具类当中 SecurityUtils.setSecurityManager(instance); //4.获取到主体 Subject subject = SecurityUtils.getSubject(); //5.调用主体当中的方法完成认证 subject.login(new UsernamePasswordToken("zhangsan","123456")); //判断认证是否成功 System.out.println(subject.isAuthenticated()?"认证成功":"认证失败"); //7.权限操作 System.out.println(subject.hasRole("role1")?"有sole1角色":"没有sole1角色"); System.out.println(subject.hasRole("role2")?"有sole2角色":"没有sole2角色"); //8.查询员工信息 if (subject.hasRole("role1")){ System.out.println("有查询员工权限"); }else{ System.out.println("没有查询员工的权限"); } //9.判断权限 subject.isPermitted("user:create"); subject.isPermitted("user:show"); if (subject.isPermitted("user:create")){ System.out.println("有创建新的员工的功能-----------"); }else{ System.out.println("没有创建员工的功能"); } } }