标签:nts auto generate iot com name 错误 dmi http
shiro.ini
1 ##填写用户信息 2 [users] 3 admin=123456,role_admin,role_user 4 5 [roles] 6 role_admin=user:to_edit,user:to_add,user:add 7 role_user = modular:add
测试代码:
1 package cn.lqp.shrio.test; 2 3 import org.apache.shiro.SecurityUtils; 4 import org.apache.shiro.authc.AuthenticationException; 5 import org.apache.shiro.authc.UsernamePasswordToken; 6 import org.apache.shiro.config.IniSecurityManagerFactory; 7 import org.apache.shiro.mgt.SecurityManager; 8 import org.apache.shiro.subject.Subject; 9 10 public class ShrioTest { 11 12 public static void main(String[] args) { 13 14 //读取配置文件 15 IniSecurityManagerFactory factory = new IniSecurityManagerFactory("classpath:shiro.ini"); 16 SecurityManager securityManager = factory.createInstance(); 17 18 //第二步 L构建验证信息Token 19 UsernamePasswordToken token = new UsernamePasswordToken("admin","1234567"); 20 21 //第三步:获得一个没有权限信息的身份对象 22 SecurityUtils.setSecurityManager(securityManager); 23 Subject subject = SecurityUtils.getSubject(); 24 25 //第四步 : 校验 26 try { 27 Subject resultSubject = securityManager.login(subject, token); 28 System.out.println("获得校验后的用户名:"+resultSubject.getPrincipal()); 29 System.out.println("判断校验是否通过:"+resultSubject.isAuthenticated()); 30 31 32 } catch (AuthenticationException e) { 33 // TODO Auto-generated catch block 34 e.printStackTrace(); 35 } 36 42 } 43 44 }
标签:nts auto generate iot com name 错误 dmi http
原文地址:https://www.cnblogs.com/meizhoulqp/p/11140620.html