Spring SECURITY3-MVC Integration Tutorial

Source: Internet
Author: User
Tags bind documentation xmlns
Below we will implement a series of tutorials on spring Security3.
The ultimate goal is to integrate spring Security + SPRING3MVC
Complete a function similar to Mini-web in SpringSide3.

What is Spring security?

Reference spring Security, a secure framework based on spring AOP and servlet filters. It provides a comprehensive security solution that handles both identity recognition and authorization at the Web request level and at the method call level. Based on the spring framework, spring security takes full advantage of dependency injection (Di,dependency injection) and facet-oriented technology.

Information on spring security learning.
The most important, the most complete Chinese material is of course family168 's Chinese document
Spring Security2 Reference Documentation

Spring Security3 Reference Documentation

The attachment contains a good first-entry PDF tutorial.
It is best to take 30 minutes to follow the tutorials on the PDF step-by-step operation.
Although there is no practical application value, it is very helpful for beginners to know SpringSecurity3.

Our project directory structure is ultimately:




The jar package that needs to be added:




We first implement a controller:

Maincontroller.java

Java code    package org.liukai.tutorial.controller;      import  org.apache.log4j.logger;   import org.springframework.stereotype.controller;   Import  org.springframework.web.bind.annotation.RequestMapping;   import  org.springframework.web.bind.annotation.requestmethod;      @Controller    @ Requestmapping ("/main")    public class maincontroller {        protected static logger logger = logger.getlogger ("Controller");          /**       *  Jump to commonpage page         *        *  @return         */        @RequestMapping (value =  "/common",  method  = requestmethod.get)     &NBsp;  public string getcommonpage ()  {            logger.debug ("Received request to show common page");            return  "Commonpage";       }           /**       *  Skip to Adminpage page        *        *  @return         */        @RequestMapping (value =  "/admin",  Method = requestmethod.get)        public string getaadminpage ()  {           logger.debug ("received request  To show admin page ");           return " Adminpage ","           }     }  

The controller has two mapping mappings:

Reference Main/common
Main/admin

Now we will be able to access the Main/common with the Spring Security3 framework for successful landings.
However, only users with admin privileges can access main/admin.


Let's start with Spring3mvc and SpringSecurity3 in Web. Xml.

Xml

XML code    <?xml version= "1.0"  encoding= "UTF-8"?>   <web-app id= "WebApp _id " 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 ">               <!-- springsecurity Necessary filter -->       <filter>            <filter-name>springsecurityfilterchain</ filter-name>           <filter-class> Org.springframework.web.filter.delegatingfilterproxy</filter-class

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.