简体   繁体   English

Spring Boot 2.2.4 - 禁用安全性

[英]Spring Boot 2.2.4 - disable security

I found a massive amount of blog posts and questions on stackoverflow on how to disable security in spring boot - but none of it seems to work with spring boot 2.2.4.我在 stackoverflow 上发现了大量关于如何在 spring boot 中禁用安全性的博客文章和问题 - 但似乎都不适用于 spring boot 2.2.4。

I'm asking because I want to configuratively disable security for my dev and test profile so that we can deploy without generating jwt tokens all the time.我问是因为我想以配置方式禁用我的开发和测试配置文件的安全性,以便我们可以在不生成 jwt 令牌的情况下进行部署。

The most promising approach from my perspective is to exclude the SecurityAutoConfiguration class via the properties file but as said the exclusion has no effect.从我的角度来看,最有希望的方法是通过属性文件排除SecurityAutoConfiguration类,但正如所说的排除没有任何影响。

spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.security.SecurityAutoConfiguration

The other properties such as management.security.enabled seem to be deprecated.其他属性如management.security.enabled似乎已弃用。

I found a working solution in the spring boot github issues.我在 spring boot github问题中找到了一个可行的解决方案。

Disable security for the entire application:禁用整个应用程序的安全性:

@SpringBootApplication ( exclude = {SecurityAutoConfiguration.class} )
@Import(MySecurityConfiguration.class)
public class MyApplication{
 }

... and enable via parameter in the security configuration: ...并通过安全配置中的参数启用:

@Configuration
@ConditionalOnProperty (  "my.security.enabled" )
@Import ( SecurityAutoConfiguration.class 
public class MySecurityConfiguration extends WebSecurityConfigurerAdapter {

}

Source: https://github.com/spring-projects/spring-boot/issues/12323#issuecomment-370519882来源: https : //github.com/spring-projects/spring-boot/issues/12323#issuecomment-370519882

You could create a WebSecurityConfigurerAdapter Bean for your profile containing following overriden method implementation, to exclude all endpoints from spring security:您可以为包含以下覆盖方法实现的配置文件创建一个 WebSecurityConfigurerAdapter Bean,以从 Spring Security 中排除所有端点:

    @Override
    public void configure(WebSecurity web) {
        web.ignoring().antMatchers(
                "/**"
        );
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM