博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Spring boot Security Disable security
阅读量:6220 次
发布时间:2019-06-21

本文共 4892 字,大约阅读时间需要 16 分钟。

When I use security.basic.enabled=false to disable security on a Spring Boot project that has the following dependencies:

org.springframework.boot
spring-boot-starter-web
org.springframework.boot
spring-boot-starter-security
org.springframework.boot
spring-boot-starter-actuator
com.oracle
ojdbc6
org.springframework.boot
spring-boot-starter-tomcat
provided
org.springframework.boot
spring-boot-starter-test
test

I see the following Exception:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.actuate.autoconfigure.ManagementSecurityAutoConfiguration$ManagementWebSecurityConfigurerAdapter': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire method: public void org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter.setObjectPostProcessor(org.springframework.security.config.annotation.ObjectPostProcessor); nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.security.config.annotation.ObjectPostProcessor] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}

In order to fix this exception I had to add the property - management.security.enabled=false . My understanding is that when the actuator is in the classpath, both security.basic.enabled=false and management.security.enabled=false should be set to disable the security.

Could someone please let me know if my understanding is wrong?

 
1  
Why do you need security on your classpath if you just want to disable everything? Anyway, your stack trace is incomplete so there is no way to know what was preventing the app from starting. I would expect it would start, but the actuator endpoints should stay secure until you explicitly open them up. –  May 27 '14 at 17:41
    
@DaveSyer I would like to disable security temporarily and also my application code refers security jars to work. –  Feb 19 '15 at 21:36
    
You still haven't posted enough information to see why the app isn't starting. A full stack trace would be a start. –  Feb 20 '15 at 8:41
1  
@DaveSyer One reason would be a microservice managing spring-sec-oauth2 ClientDetails. You'll have a transitive import of spring-security but maybe don't want basic auth in your service. – Oct 23 '15 at 15:52

4 Answers

33

In case you have spring-boot-actuator in your package, you should add the following

@EnableAutoConfiguration(exclude = {        org.springframework.boot.autoconfigure.security.SecurityAutoConfiguration.class,        org.springframework.boot.actuate.autoconfigure.ManagementWebSecurityAutoConfiguration.class})

With older Spring-boot, the class was called ManagementSecurityAutoConfiguration.

 
3  
In Spring boot 1.3 the name seems to have changed to ManagementWebSecurityAutoConfiguration. –  Nov 25 '15 at 15:12
    
Thanks @James for pointing out, I have mentioned this in the answer now. –  Dec 17 '15 at 9:25
 
19

What also seems to work fine is creating a file application-dev.properties that contains:

security.basic.enabled=falsemanagement.security.enabled=false

If you then start your Spring Boot app with the dev profile, you don't need to log on.

 
18

If you need security as a dependency but don't want Spring Boot to configure it for you, you can use this exclusion:

@EnableAutoConfiguration(exclude = {         org.springframework.boot.autoconfigure.security.SecurityAutoConfiguration.class     })
 
    
Work perfectly for me. FYI - My app depends on security jars but I would like to temporarily disable security –  Feb 19 '15 at 21:42
3

In order to avoid security you can use annotations. Use this annotation on top of configure class:

@EnableWebSecurity

For example:

@EnableWebSecurity@Configurationpublic class AuthFilter{   // configured method }

转载地址:http://sklja.baihongyu.com/

你可能感兴趣的文章
[ARCH] 1、virtualbox中安装archlinux+i3桌面,并做简单美化
查看>>
MVVM模式下关闭窗口的实现
查看>>
程序员晋级CTO之路的8大准则
查看>>
linux curl 命令详解,以及实例
查看>>
CentOS7 下 keepalived 的安装和配置
查看>>
R绘图 第七篇:绘制条形图(ggplot2)
查看>>
Perl输出复杂数据结构:Data::Dumper,Data::Dump,Data::Printer
查看>>
安装Cloudera manager Server步骤详解
查看>>
Windows 10原版ISO下载地址(持续更新)
查看>>
js 日期 相关
查看>>
爬取伯乐在线文章(一)
查看>>
thymeleaf使用详解
查看>>
.hashCode方法的作用
查看>>
高通平台启动log概述(PBL log、sbl1 log、kernel log)【转】
查看>>
高并发处理思路与手段(七):数据库切库(读写分离)、分库、分表
查看>>
python安装教程(Windows系统,python3.7为例)
查看>>
repo总结【转】
查看>>
Git强制拉取覆盖本地
查看>>
WPF通过附加属性控制窗口关闭
查看>>
Elasticsearch Document
查看>>