Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/security/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Spring引导:禁用安全自动配置_Java_Security_Web_Spring Security_Spring Boot - Fatal编程技术网

Java Spring引导:禁用安全自动配置

Java Spring引导:禁用安全自动配置,java,security,web,spring-security,spring-boot,Java,Security,Web,Spring Security,Spring Boot,我有一个多部分的网络项目Web管理员部分包含: compile('org.springframework.boot:spring-boot-starter-web') compile("org.springframework.boot:spring-boot-starter-thymeleaf") compile("org.springframework.boot:spring-boot-starter-jetty") compile("org.springframework.boot:spri

我有一个多部分的网络项目<代码>Web管理员部分包含:

compile('org.springframework.boot:spring-boot-starter-web')
compile("org.springframework.boot:spring-boot-starter-thymeleaf")
compile("org.springframework.boot:spring-boot-starter-jetty")
compile("org.springframework.boot:spring-boot-starter-actuator")
主项目生成文件包含:

compile group: 'org.springframework', name: "spring-webmvc", version: springVersion
compile(group: 'org.springframework.security', name: "spring-security-web", version: springSecurityVersion) { exclude(module: 'spring-jdbc') }
Spring启动应用程序文件:

@SpringBootApplication(exclude = {SecurityAutoConfiguration.class})
public class WebAdminApplication {

    public static void main(String[] args) {
        SpringApplication.run(WebAdminApplication.class, args);
    }
}
但是,当我对我的管理部分执行http请求时,我会在我的
AuthenticationProvider
中获取用户和密码:

auth.getPrincipal() -> user
auth.getCredentials() -> caeebd3a-307b-4edf-8f2f-833fad9ebc00
如何禁用自动安全性

如果您查看(撰写本文时为1.3.5版),您会发现安全性有4个自动配置类:

org.springframework.boot.autoconfigure.security.SecurityAutoConfiguration,\
org.springframework.boot.autoconfigure.security.SecurityFilterAutoConfiguration,\
org.springframework.boot.autoconfigure.security.FallbackWebSecurityAutoConfiguration,\
org.springframework.boot.autoconfigure.security.oauth2.OAuth2AutoConfiguration,\

您可能还想禁用SecurityFilterAutoConfiguration(或全部4个)

即使我面临同样的问题。所以,我添加了下面的代码

  • 案例1:如果您未激活“执行器”:
    @springbootplication(exclude={SecurityAutoConfiguration.class})

  • 案例2:如果您已激活“执行器”:
    @springbootplication(exclude={org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration.class,org.springframework.boot.actuate.autoconfigure.security.servlet.ManagementWebSecurityAutoConfiguration.class})


您到底想禁用什么?如果您不将spring安全性作为依赖项,spring boot将不会为您自动配置它。如果你想要一个不同的配置,你需要自己配置。我想完全禁用默认用户/密码的创建