spring-security

目录结构为

 

 

pom.xml文件

 

添加spring夹包,spring-security的夹包

 

spring-security.xml

 


<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:security="http://www.springframework.org/schema/security"
    xsi:schemaLocation="http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.2.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd">

    <security:http auto-config="true">
        <security:intercept-url pattern="/admin"
            access="ROLE_USER" />
        <security:form-login login-page="/login"
            default-target-url="/welcome" authentication-failure-url="/login?error"
            password-parameter="password" username-parameter="username" />
        <security:http-basic />
    </security:http>

    <security:authentication-manager>
        <security:authentication-provider>
            <!-- <security:user-service> -->
            <!-- <security:user name="tom" password="123" authorities="ROLE_USER"/> -->
            <!-- </security:user-service> -->
            <security:jdbc-user-service
                data-source-ref="dataSource"
                users-by-username-query="select username,password,enabled from user where username=?"
                authorities-by-username-query="select username ,rolename role from role where username=?" />
        </security:authentication-provider>
    </security:authentication-manager>
</beans>

 


web.xml

 

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 3     xmlns="http://xmlns.jcp.org/xml/ns/javaee"
 4     xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
 5     id="WebApp_ID" version="3.1">
 6     <display-name>spring-securtiy</display-name>
 7 
 8     <context-param>
 9         <param-name>contextConfigLocation</param-name>
10         <param-value>classpath:spring-security.xml,classpath:spring-databases.xml</param-value>
11     </context-param>
12     
13     <listener>
14         <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
15     </listener>
16 
17     <servlet>
18         <servlet-name>spring</servlet-name>
19         <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
20     </servlet>
21 
22     <servlet-mapping>
23         <servlet-name>spring</servlet-name>
24         <url-pattern>/</url-pattern>
25     </servlet-mapping>
26 
27     <filter>
28         <filter-name>springSecurityFilterChain</filter-name>
29         <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
30     </filter>
31 
32     <filter-mapping>
33         <filter-name>springSecurityFilterChain</filter-name>
34         <url-pattern>/*</url-pattern>
35     </filter-mapping>
36 </web-app>

 

posted on 2016-12-27 14:18  老邱2  阅读(124)  评论(0编辑  收藏  举报

导航