在配置类中实现相关的配置

    @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权限方案_用户认证_自定义用户登录页面相关推荐

  1. [SpringSecurity]web权限方案_用户认证_查询数据库完成认证

    #mysql 数据库连接 spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver spring.datasource.url=jdbc ...

  2. [SpringSecurity]web权限方案_用户授权_基于权限访问控制_基于角色访问控制_hasAuthority和hasAnyAuthority_hasRole和hasAnyRole

    基于角色或权限进行访问控制 hasAuthority 方法 如果当前的主体具有指定的权限,则返回 true,否则返回 false 在配置类设置当前访问地址有哪些 @Overrideprotected ...

  3. [SpringSecurity]web权限方案_用户认证_设置用户名密码

    设置登陆的用户名和密码 第一种方式:通过配置文件 spring.security.user.name=atguigu spring.security.user.password=atguigu 第二种 ...

  4. [SpringSecurity]web权限方案_用户授权_注解使用

    注解使用 @Secured 判断用户是否具有角色,可以访问方法,另外需要注意的是这里匹配的字符串需要添加前缀"ROLE_". 使用注解先要开启注解功能! 启动类(配置类)开启注解 ...

  5. [SpringSecurity]web权限方案_用户授权_自定义403页面

    自定义403页面 unauth.html <!DOCTYPE html> <html lang="en"> <head><meta cha ...

  6. [SpringSecurity]web权限方案_自动登陆_原理分析和具体实现

    自动登陆 1.cookie技术 2.安全框架机制实现自动登陆 这里我们使用安全框架机制实现自动登陆技术 实现原理 具体实现 第一步 创建数据库 CREATE TABLE `persistent_log ...

  7. [SpringSecurity]web权限方案_用户注销

    用户注销 在配置类中添加退出映射地址 //退出http.logout().logoutUrl("/logout").logoutSuccessUrl("/test/hel ...

  8. [SpringSecurity]web权限方案_CSRF功能

    CSRF CSRF功能默认是已经打开了! 具体过程可以阅读CsrfFilter这个过滤器的源码 CSRF 理解 在登录页面添加一个隐藏域 <input type="hidden&quo ...

  9. SpringSecurity(Web权限方案)

    SpringSecurity 一.基本概要 1.认证和授权 1.认证:用户是否登录 2.授权:用户是否有权利去做别的东西 2.特点 全面的权限控制 为web开发设计 旧版本不能脱离Web环境 新版本对 ...

最新文章

  1. vs发布免安装文件_戒掉PC,免pc开发,cloud ide and debug设想
  2. 如果中国要做自己的GPT-3,一定离不开这家公司的算力
  3. Linux常用命令速查备忘(包括我)
  4. JavaScript 学习(2) - JS的内建对象
  5. 16线激光雷达配置教程
  6. oracle中lock和latch的用途
  7. Madplay移植到mini2440开发板【转】
  8. php如何逐条读取数据库,php从数据库中读取特定的行(实例)
  9. 信捷伺服刚性调整_信捷電氣(603416):伺服與PLC增長將加速,口罩機解決方案帶來新增量...
  10. java防止上传恶意文件_从补丁分析到在野利用:揭秘CVE20201464 Windows文件签名验证绕过漏洞疑云...
  11. android导航栏高度开启,如何在Android中真正获得导航栏高度
  12. 13.C#的函数练习
  13. aspen吸收塔气液比优化_Aspen吸收塔的设计
  14. jlabel 不能连续两次set_关于JLabel的setText在监听器中不刷新有关问题(2)
  15. iphone查看删除的短信_手机里的短信不小心删除了怎么才能恢复?此文为你解答...
  16. kindle 3 webbrowser破解,
  17. 实变函数与泛函数分析学习笔记(三):有界线性算子
  18. Notion笔记软件简介
  19. MacOS High Sierra(10.13.6)上安装xcode10.2.1
  20. 单点登录系统的设计与实现方案

热门文章

  1. oracle 修改sgamaxsize_oracle初始化内存配置参数(sga,pga,sharepool)
  2. [转]maven与java命名规则
  3. ArcGIS实验教程——实验三十五:ArcGIS Model Builder与空间建模原理、案例详解
  4. 最新Modis影像数据下载完整流程---以MOD13Q1 NDVI数据下载为例(2020年12月2日更新)
  5. C语言试题六十八之请编写函数实现亲密数
  6. Android之使用AIDL时的跨进程回调—Server回调Client
  7. Android之6.0 权限申请封装
  8. Android之Lollipop DevicePolicyManager学习(下)
  9. 【C语言简单说】十六:do...while循环
  10. 嵌入式开发linux工具,嵌入式Linux开发入门之MfgTool工具的使用