Four bags: Commons-logging.jar
Shiro-core.jar
Slf4j-api.jar
Sljf-simple.jar
Create a user profile under the class Users.ini
Content:
[Users] Zhang=123wang=123
Create Class Testshiro.java
Import org.apache.shiro.securityutils;import org.apache.shiro.authc.usernamepasswordtoken;import org.apache.shiro.config.IniSecurityManagerFactory;import org.apache.shiro.mgt.SecurityManager; import org.apache.shiro.subject.subject;import org.apache.shiro.util.factory;import org.junit.test;public class testshiro {@Testpublic void testshiro001 () { &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;//1, get SecurityManager factory, use INI configuration file to initialize securitymanagerfactory< Org.apache.shiro.mgt.securitymanager> factory = new inisecuritymanagerfactory (" Classpath:shiro.ini ");//2, Get SecurityManager instance and bind to Securityutils securitymanager securitymanager = factory.getinstance (); Securityutils.setsecuritymanager (SecurityManager)//3, get Subject and create username/password Authentication token (i.e. user identity/credentials) Subject Subject = securityutils.getsubject (); Usernamepasswordtoken token = new usernamepasswordtoken ("ZHang ", " 123 "); Try{subject.login (token); System.out.println ("SUCCESS");} catch (exception e) {System.out.println ("ERROR");}}}
End of Test
This article from "I love to Play it" blog, declined reprint!
Shiro first step, use the configuration file to verify the login