Apache Shiro Identity Authentication Example

Source: Internet
Author: User


In this example, Apache Shiro is used to implement identity authentication in a Web application, integrating Shiro with spring and storing user information using an embedded Derby database.

The persistent layer is hibernate, and the database connection pool is Alibaba druid. 2. Preparation

Create an inline Derby database, this example uses db-derby-10.10.1.1. 2.1 Build Table

Create Table Users (

Id int PRIMARY KEY,

Name varchar (20),

PASSWD varchar (20)

); 2.2 Initializing Data

Insert into users values (1, ' admin ', ' admin ');

Insert into users values (2, ' Peter ', ' Peter '); 3. Configuring 3.1 web. XML

[HTML]   View plain  copy   <!-- Apache Shiro -->    <filter>   <filter-name>shiroFilter</filter-name>   <filter-class >org.springframework.web.filter.DelegatingFilterProxy</filter-class>   <init-param>    <param-name>targetFilterLifecycle</param-name>   <param-value>true</ param-value>   </init-param>   </filter>   <filter-mapping>    <filter-name>shiroFilter</filter-name>   <url-pattern>/*</ url-pattern>   </filter-mapping>  

3.2 applicationcontext.xml [HTML]   View plain  copy   <! --  Safety Authentication Filter  -->       <bean id= "Shirofilter"  class= " Org.apache.shiro.spring.web.ShiroFilterFactoryBean ">            <property name= "SecurityManager"  ref= "SecurityManager"  />            <property name= "loginurl"  value= "/index.do"  />                        <property name= "Filterchaindefinitions";

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.