00 - spring security框架使用

spring security框架使用

环境

  1. jdk版本:jdk 17

依赖





<dependency>
    <groupId>org.springframework.bootgroupId>
    <artifactId>spring-boot-starter-webartifactId>
dependency>
<dependency>
    <groupId>org.springframework.bootgroupId>
    <artifactId>spring-boot-starter-securityartifactId>
dependency>
<dependency>
    <groupId>org.springframework.bootgroupId>
    <artifactId>spring-boot-starter-thymeleafartifactId>
dependency>

登录认证

  1. 依赖spring-boot-starter-security后,服务启动时,控制台日志会输出自动生成的密码

    1. 日志信息如下

      Using generated security password: 2d9c8697-8ebd-4be7-afea-a6bc922a7d5b
      
      This generated password is for development use only. Your security configuration must be updated before running your application in production.
      
    2. 默认的用户名为:user

  2. 依赖spring-boot-starter-security后,调用接口时就会进行登录认证,会跳转到默认的登录页面:/login,该页面是框架自带的

    1. 页面加载较慢,样式加载不成功,但不影响功能使用。原因:会加载一些无法访问的css数据
    2. 输入默认的用户名和密码,进行登录认证,登录认证成功即可访问接口数据
    3. 该页面可自定义
  3. 默认的登出页面:/logout,该页面是框架自带的

    1. 页面加载较慢,样式加载不成功
    2. 该页面有一个确认登出按钮,点击后即可退出登录,调用接口时会重新进行登录认证
    3. 该页面可自定义

你可能感兴趣的:(spring,security,spring,java,后端)