首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >在春季启动时无法禁用安全性。

在春季启动时无法禁用安全性。
EN

Stack Overflow用户
提问于 2016-04-05 09:49:52
回答 2查看 3.2K关注 0票数 0

我希望在我的应用程序中禁用spring安全性,并在security.basic.enable=false文件中设置属性application.yml。

代码语言:javascript
代码运行次数:0
运行
复制
security:
  basic:
    enabled: false

我使用弹簧引导驱动器检查了/env,并发现它已正确加载:(在第2行)

代码语言:javascript
代码运行次数:0
运行
复制
[classpath:/application.yml]":{"spring.datasource.url":"jdbc:mysql://localhost:3306/toe?useUnicode=true&characterEncoding=utf8&allowMultiQueries=true","spring.datasource.username":"root","spring.datasource.password":"******",
"security.basic.enabled":false,
"server.port":7777,"flyway.enabled":false}}

但是,安全配置仍然有效,我无法访问需要身份验证的配置,但我可以访问那些是permitAll。

这是应用程序类:

代码语言:javascript
代码运行次数:0
运行
复制
@SpringBootApplication
@MapperScan("team.xuli.toe.dao")
public class ToeServerApplication {
    public static void main(String[] args) {
        SpringApplication.run(ToeServerApplication.class, args);}
}

这是securityConfigutaion:

代码语言:javascript
代码运行次数:0
运行
复制
@Configuration
@Order(SecurityProperties.ACCESS_OVERRIDE_ORDER)
public class SecurityConfig extends WebSecurityConfigurerAdapter{

  @Override
  protected void configure(HttpSecurity http) throws Exception {
      http.csrf().disable();
      http.httpBasic();
      http.
             authorizeRequests()
             .antMatchers("/hello").permitAll()
             .anyRequest().authenticated();
  }
  @Autowired
  public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
      System.out.println("user added in mem!");
      auth
          .inMemoryAuthentication()
              .withUser("xqf").password("123").roles("ADMIN");
  }
}
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2016-04-05 15:14:44

如果您在应用程序中的任何位置使用@Configuration定义@EnableWebSecurity,它将在Spring中关闭默认的webapp安全设置。

票数 0
EN

Stack Overflow用户

发布于 2016-04-05 09:56:05

如果您需要将安全性作为依赖项,但不希望Spring为您配置安全性,则可以使用此排除:

代码语言:javascript
代码运行次数:0
运行
复制
@EnableAutoConfiguration(exclude = { 
        org.springframework.boot.autoconfigure.security.SecurityAutoConfiguration.class

    })
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36422837

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档