Shiro first step, use the configuration file to verify the login

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.