I. Introductory case spring Security Custom Login interface
With the previous section 01-spring Security framework Learning-a simple demonstration of getting Started (i), Spring security uses the login interface that comes with the framework, and the following case will use the login page of your own definition.
Basic steps
- Add the following page:
- Login interface
src/main/webapp/login.html
<!DOCTYPE html>
- Login Results Page
src/main/webapp/login_error.html
<!DOCTYPE html>
- Modify Spring-security.xml configuration
src/main/resources/spring/spring-security.xml
<?xml version= "1.0" encoding= "UTF-8"?> <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.xsd http://www.springframework.org/schema/security Http://www.springframework.org/schema/securi Ty/spring-security.xsd "> <!--settings no need to login rules (Note: The path before the '/' symbol must not be omitted)--
Run effectOperational issues
- The following error:
HTTP Status 403 - Invalid CSRF Token ‘null‘ was found on the request parameter ‘_csrf‘ or header ‘X-CSRF-TOKEN‘.
This is because spring security is enabled by default to prevent CSRF attacks, and the demo demo is now closed.
Ii. Summary of Spring Security
Through the simple configuration on the road, Spring Security will do us a lot of things:
- Authentication is required for each URL in your app
- To create a landing form for you
- Allow users to submit Username user names in the form and Password password to Password for authentication
- Allow user to log off
- Guard against CSRF attacks
- Prevent session Fixation
- Integrated Security Header
Basic principles of Spring security
Spring intercepts HTTP requests via the Servlet interceptor, which is user authentication and authorization under the action of this filter chain.
If you want to learn more about the principle process, please go.
01-spring Security Framework Learning--Getting Started (ii)