日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > javascript >内容正文

javascript

[SpringSecurity]web权限方案_用户认证_自定义用户登录页面

發布時間:2023/12/4 javascript 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 [SpringSecurity]web权限方案_用户认证_自定义用户登录页面 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

在配置類中實現相關的配置

@Overrideprotected void configure(HttpSecurity http) throws Exception {http.formLogin() //自定義自己編寫的登陸頁面.loginPage("/login.html") //登陸頁面設置.loginProcessingUrl("/user/login") //登陸訪問路徑.defaultSuccessUrl("/test/index").permitAll() //登陸成功之后,跳轉路徑.and().authorizeRequests().antMatchers("/","/test/hello","/user/login").permitAll() //設置哪些路徑可以直接訪問,不需要認證.anyRequest().authenticated().and().csrf().disable(); //關閉csrf防護}

創建出相關頁面,controller

  • login.html
<!DOCTYPE html> <html lang="en"> <head><meta charset="UTF-8"><title>Title</title> </head> <body><form action="/user/login" method="post">用戶名:<input type = "text" name = "username"><br/>密碼:<input type = "text" name = "password"><br/><input type = "submit" value = "login"></form></body> </html>

特別注意,表單那兩個value必須是username和password,閱讀UsernamePasswordAuthenticationFilter的源碼就知道為什么了!

  • controller
package com.atguigu.securitydemo1.controller;import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController;@RestController @RequestMapping("/test") public class TestController {@GetMapping("hello")public String hello(){return "hello security";}@GetMapping("index")public String index(){return "hello index";}}

測試


創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎

總結

以上是生活随笔為你收集整理的[SpringSecurity]web权限方案_用户认证_自定义用户登录页面的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。