• 博客园logo
  • 会员
  • 周边
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
轶东的程序世界
博客园       新随笔    联系   管理    订阅  订阅

spring-boot-starter-security放行全部请求

Spring Boot项目中加了spring-boot-starter-security默认会把全部请求设置要求登录。

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-security</artifactId>
</dependency>

系统自动建一个user用户,密码随机

如果想不要这个安全保护,不要登录。 方法:加一个SecurityFilterChain,定义为Bean。
package jixin.Config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityCustomizer;
import org.springframework.security.config.annotation.web.configurers.LogoutConfigurer;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.provisioning.InMemoryUserDetailsManager;
import org.springframework.security.web.SecurityFilterChain;

@Configuration
@EnableWebSecurity(debug = false)
public class WebSecurityConfig
{
  @Bean
  public SecurityFilterChain NameDoesnotMatter(HttpSecurity http) throws Exception
  {
    return http.build();
  }

}

加了这个输出中仍然会有安全提示。但是网页已经不需要登录了。

posted @ 2024-12-20 11:37  赵轶东  阅读(161)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3