Java Spring引导:禁用安全自动配置
我有一个多部分的网络项目<代码>Web管理员部分包含: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
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})