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 // reads the configuration file 15 IniSecurityManagerFactory Factory = new new IniSecurityManagerFactory ( "CLASSPATH: shiro.ini" ); 16 the SecurityManager securityManager = factory.createInstance (); . 17 18 is // Step L constructing authentication information the Token . 19 UsernamePasswordToken token = new new UsernamePasswordToken ( " ADMIN-ERROR ", "1234567" ); 20 21 // third step: get a no identity object authority information 22 SecurityUtils.setSecurityManager (securityManager); 23 subject subject = SecurityUtils.getSubject (); 24- 25 @ fourth step: the check 26 is the try { 27 the Subject resultSubject = securityManager.login (Subject, token); 28 System.out.println ( "check after obtaining the user name:" + resultSubject.getPrincipal ()); 29 System.out.println ( "verify determined by:" + resultSubject.isAuthenticated ()); 30 31 is 32 } the catch (of AuthenticationException E) { 33 is // the TODO Auto-Generated Block the catch 34 is e.printStackTrace (); 35 } 36 37 [ } 38 is 39 }
shiro frame --- bug debugging (account number error)
Guess you like
Origin www.cnblogs.com/meizhoulqp/p/11140642.html
Recommended
Ranking