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";