Spring security2 learning notes 1 (minimum configuration)

Source: Internet
Author: User

1. Create a web project:

Jar package:

Ii. Configure the filter:

<Filter>
<Filter-Name> springsecurityfilterchain </filter-Name>
<Filter-class> org. springframework. Web. Filter. delegatingfilterproxy </filter-class>
</Filter>
<Filter-mapping>
<Filter-Name> springsecurityfilterchain </filter-Name>
<URL-pattern>/* </url-pattern>
</Filter-mapping>

 

3. basic configuration of applicationcontext. xml:

<? XML version = "1.0" encoding = "UTF-8"?>

<! -- ① Namespace configuration -->
<Beans: Beans xmlns = "http://www.springframework.org/schema/security"
Xmlns: Beans = "http://www.springframework.org/schema/beans"
Xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance"
Xsi: schemalocation = "http://www.springframework.org/schema/beans
Http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
Http://www.springframework.org/schema/security
Http://www.springframework.org/schema/security/spring-security-2.0.4.xsd>

<! -- ② How to intercept user requests in the HTTP section. Auto-Config = 'true' automatically configures several common permission control mechanisms -->

<Http auto-Config = 'true'>

<! -- ③ Intercept-URL to determine the permissions required by the user to access the corresponding URL resources -->
<Intercept-URL pattern = "/admin. jsp" Access = "role_admin"/>
<Intercept-URL pattern = "/**" Access = "role_user"/>
</HTTP>

<! -- ④ Authorities: defines the permissions that the user will have after login. It is one-to-one with the permissions defined in intercept-URL above -->

<Authentication-provider>
<User-service>
<User name = "admin" Password = "admin" authorities = "role_user, role_admin"/>
<User name = "user" Password = "user" authorities = "role_user"/>
</User-service>
</Authentication-provider>

</Beans: Beans>

 

Iv. Web. xml configuration:

<? XML version = "1.0" encoding = "UTF-8"?>
<Web-app version = "2.4" xmlns = "http://java.sun.com/xml/ns/j2ee"
Xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance"
Xsi: schemalocation = "http://java.sun.com/xml/ns/j2ee
Http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd>

<Filter>
<Filter-Name> springsecurityfilterchain </filter-Name>
<Filter-class>
Org. springframework. Web. Filter. delegatingfilterproxy
</Filter-class>
</Filter>
<Filter-mapping>
<Filter-Name> springsecurityfilterchain </filter-Name>
<URL-pattern>/* </url-pattern>
</Filter-mapping>
<Context-param>
<Param-Name> contextconfiglocation </param-Name>
<Param-value>/WEB-INF/applicationcontext. xml </param-value>
</Context-param>
<Listener>
<Listener-class>
Org. springframework. Web. Context. contextloaderlistener
</Listener-class>
</Listener>

</Web-app>

 

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.