mattshma/bigdata

springboot 自动跳到 security basic 验证

mattshma opened this issue · 0 comments

在使用 cas 的过程中,页面一直跳到 security 的验证页:Login with Username and Password。想要关闭自动加载 security 认证,不过去掉 security 会报错。查了下,在springboot 1.x 版本中,通过配置 spring.basic.enabled: false 可禁用,不过在 2.x 的版本中该方法不可用了。

看了下springboot 源码,在开启 EnableAutoConfiguration 时,其会导入 AutoConfigurationImportSelector,而这个类读取 EnableAutoConfiguration
spring.boot.enableautoconfiguration 属性,对应的配置文件会调用 getCandidateConfigurations 方法获取,查看该方法内的 loadFactoryNames ,会读取 META-INF/spring.factories 。于是在 spring-boot-autoconfigure-2.0.5.RELEASE.jar 下查看该文件,看到EnableAutoConfiguration 加载下,其中确实有SecurityAutoConfiguration等相关配置,于是在开启 EnableAutoConfiguration 时排除该类,即:

@EnableAutoConfiguration(exclude = {SecurityAutoConfiguration.class})

问题解决。