我有一个Spring Boot web应用程序,配置了spring security.我想暂时禁用身份验证(直到需要).
我把它添加到application.properties:
security.basic.enable: false
management.security.enabled: false
Run Code Online (Sandbox Code Playgroud)
这是我的一部分
但我仍然有一个基本的安全性:启动时生成一个默认的安全密码,我仍然收到HTTP身份验证提示框.
我的pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>fr.test.sample</groupId>
<artifactId>navigo</artifactId>
<version>1.0.0-SNAPSHOT</version>
<!-- Inherit defaults from Spring Boot -->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.1.RELEASE</version>
</parent>
<properties>
<java.version>1.7</java.version>
<jsoup.version>1.8.3</jsoup.version>
<guava.version>18.0</guava.version>
<postgresql.version>9.3-1103-jdbc41</postgresql.version>
</properties>
<!-- Add typical dependencies for a web application -->
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
</dependency>
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency> …Run Code Online (Sandbox Code Playgroud) 我想使用Spring Security进行JWT身份验证.但它带有默认身份验证.我试图禁用它,但是这样做的旧方法 - 禁用它application.properties- 在2.0中已弃用.
这是我试过的:
@Configuration
public class StackWebSecurityConfigurerAdapter extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.httpBasic().disable();
// http.authorizeRequests().anyRequest().permitAll(); // Also doesn't work.
}
}
Run Code Online (Sandbox Code Playgroud)
我怎样才能简单地禁用基本安全性?
更新
可能很高兴知道我不使用web mvc而是web flux.
spring-security spring-boot spring-security-rest spring-webflux
我已经使用Spring Security在Spring Boot Application中实现了身份验证.
控制身份验证的主类应该是websecurityconfig:
@Configuration
@EnableWebSecurity
@PropertySource(value = { "classpath:/config/application.properties" })
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
private RestAuthenticationSuccessHandler authenticationSuccessHandler;
@Autowired
private RestAuthenticationEntryPoint restAuthenticationEntryPoint;
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.httpBasic()
.and()
.csrf().disable()
.sessionManagement().sessionCreationPolicy(
SessionCreationPolicy.STATELESS)
.and()
.exceptionHandling()
.authenticationEntryPoint(restAuthenticationEntryPoint)
.and()
.authorizeRequests()
.antMatchers("/").permitAll()
.antMatchers("/login").permitAll()
.antMatchers("/logout").permitAll()
.antMatchers("/ristore/**").authenticated()
.anyRequest().authenticated()
.and()
.formLogin()
.successHandler(authenticationSuccessHandler)
.failureHandler(new SimpleUrlAuthenticationFailureHandler());
}
Run Code Online (Sandbox Code Playgroud)
因为我做的OAuth,我有AuthServerConfig和ResourceServerConfig也.我的主要应用程序类如下所示:
@SpringBootApplication
@EnableSpringDataWebSupport
@EntityScan({"org.mdacc.ristore.fm.models"})
public class RistoreWebApplication extends SpringBootServletInitializer
{
@Bean
public WebMvcConfigurer corsConfigurer() {
return new WebMvcConfigurerAdapter() {
@Override …Run Code Online (Sandbox Code Playgroud) 我想在某些单元测试期间禁用端点上的安全性。我正在使用 webflux 功能端点,因此以下配置不起作用。
@AutoConfigureMockMvc(secure = false)
我通过使用配置文件停用它,但这意味着我无法再使用测试配置文件测试安全性。还有另一种方法可以用 webflux 做到这一点吗?
预先感谢您的帮助