In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "simple example Analysis of spring security". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "simple example Analysis of spring security".
1 pom. The main file I introduced into thymeleaf-extras-springsecurity5,springboot2.1.6 org.springframework.boot spring-boot-starter-thymeleaf
Org.thymeleaf.extras thymeleaf-extras-springsecurity5 org.springframework.boot spring-boot-starter-web org.springframework.boot spring-boot-starter-security org.springframework.boot spring-boot-starter-test test 2 controller [@ Controller] (https://my.oschina.net/u/1774615)
Public class KungfuController {
Private final String PREFIX = "pages/"; @ RequestMapping ("/") public String index () {System.out.println ("hello word"); return "welcome";} @ RequestMapping ("/ userlogin") public String loginPage () {return PREFIX+ "login1";} @ GetMapping ("/ level1/ {path}") public String level1 (@ PathVariable ("path") String path) {return PREFIX+ "level1/" + path } @ GetMapping ("/ level2/ {path}") public String level2 (@ PathVariable ("path") String path) {return PREFIX+ "level2/" + path;} @ GetMapping ("/ level3/ {path}") public String level3 (@ PathVariable ("path") String path) {return PREFIX+ "level3/" + path;}
}
/ / configure
@ EnableWebSecurity public class mySecurity extends WebSecurityConfigurerAdapter {
/ / Why is this bean introduced, because after securety uses the login template of the system after 5.0, the password is encrypted by default, and this one is written not to encrypt the password.
@ Beanpublic static NoOpPasswordEncoder passwordEncoder () {return (NoOpPasswordEncoder) NoOpPasswordEncoder.getInstance () } protected void configure (HttpSecurity http) throws Exception {/ / Custom request authorization rules http.authorizeRequests (). AntMatchers ("/"). PermitAll () .antMatrices ("/ level1/**"). HasRole ("VIP1") .antMatrices ("/ level2/**"). HasRole ("VIP2") .antMatch ("/ level3/**") .hasRole ("VIP3") / / enable automatic login function http.formLogin (); / / enable automatic configuration logout function http.logout () .logoutSuccessUrl ("/") } public void configure (AuthenticationManagerBuilder auth) throws Exception {auth.inMemoryAuthentication (). WithUser ("mao"). Password ("123"). Roles (" VIP1 "," VIP2 ") .and (). WithUser (" zhang "). Password (" 123"). Roles ("VIP1", "VIP3"). And () .withUser ("li"). Password ("VIP2", "VIP3") }
} / / the templates are all from Shangxue School.
Insert title here
Welcome to Wulin Secret Book Management system
Hello, tourists. If you want to see the secret books of Wulin, please log in.
Hello, your roles are: thank you for reading, the above is the content of "simple example Analysis of spring security". After the study of this article, I believe you have a deeper understanding of the simple example analysis of spring security, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.