java version b2b2c social electricity supplier spring cloud distributed micro-services (13) Security Control using Spring Security

Preparations
First, build a simple Web projects to add security controls for follow-up, how to use Spring Boot when building Web applications.

Web layer implements mapping request

@Controller
public class HelloController {
 
    @RequestMapping("/")
    public String index() {
        return "index";
    }
 
    @RequestMapping("/hello")
    public String hello() {
        return "hello";
    }
 
}

/: Is mapped to index.html
/ the Hello: hello.html map to
achieve the mapping page
src / main / resources / templates / index.html

<! DOCTYPE HTML> 
<HTML xmlns = "http://www.w3.org/1999/xhtml" xmlns: TH = "http://www.thymeleaf.org" xmlns: sec = "HTTP: // the WWW. thymeleaf.org/thymeleaf-extras-springsecurity3 "> 
    <head> 
        <title> Getting the Spring Security </ title> 
    </ head> 
    <body> 
        <h1> Security Welcome to the Spring! </ h1> 
        <the p-> click <a th : href = "@ {/ hello }"> here </a> hello </ P> 
    </ body> 
</ HTML>

src/main/resources/templates/hello.html

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3">
    <head>
        <title>Hello World!</title>
    </head>
    <body>
        <h1>Hello world!</h1>
    </body>
</html>

Can be seen to provide a link / hello in index.html, it is clear where no security control, so click on the link after the jump directly to hello.html page.
JAVASpring Cloud needs of large enterprises distributed micro cloud services built B2B2C e-commerce platform source code, please add penguin beg: 3536247259

Guess you like

Origin www.cnblogs.com/itcode-code/p/11161763.html