spring-boot - 使用 Spring Boot 安全性时未显示初始登录页面
问题描述
我尝试将 Spring Boot 安全依赖项添加到我的博客系统中。在添加 Spring Boot 安全性之前,会像我的代码一样显示初始视图。但是当我像下面添加spring boot security的配置文件时,
@Configuration
@EnableWebSecurity
public class BlogWebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
// TODO Auto-generated method stub
super.configure(auth);
}
@Override
protected void configure(HttpSecurity http) throws Exception {
// TODO Auto-generated method stub
super.configure(http);
}
}
显示了一些有线初始登录视图。
如何删除这个初始登录视图,以便显示我的初始 view.html?是否有任何选项可以删除此登录视图?
解决方案
我相信这是弹簧安全的默认设置。configure
您应该根据需要修改覆盖的方法。
您可以阅读本教程,了解如何使用自定义配置实现 Spring Security。
例如:
@Override
protected void configure(HttpSecurity http) throws Exception {
http.cors().and().csrf().disable()
.authorizeRequests()
// add your resources here. By default, spring security blocks all resources that is not under /resources/**
.antMatchers(HttpMethod.GET, "/", "/js/**", "/css/**", "/images/**").permitAll()
// prevent spring security from blocking some pages that doesn't require authentication to be access here.
.antMatchers("/forgot-password", "/change-password").permitAll()
.anyRequest().authenticated()
.and()
// login configuration
.formLogin()
.loginPage("/login") // can either be mapping or file
.permitAll()
.and()
// logout configuration
.logout()
.logoutUrl("/logout")
.logoutSuccessUrl("/")
.invalidateHttpSession(true)
.deleteCookies("JSESSIONID")
.clearAuthentication(true)
.permitAll();
}
推荐阅读
- flutter - 列小部件内的嵌套 TabView
- php - 使用 Mailjet 在 PHP 中发送电子邮件
- java - 将元素添加到现有的 REST-api
- python - 关于sklearn中的confusion_matrix()
- reactjs - react - 生产中的 webpack sass/scss 模块
- sql - postgres - 可以使用窗口函数来解决此查询吗?
- c++ - C++ 模板函数和定义特殊情况
- vim - fzf.vim 动态更改工作目录
- c# - 当我将 playerprefs save 转换为标准文件 io save 时出现 Unity 问题
- github - GitHub Actions:fastlane match 无法解密 repo