An Authentication object was not found in the SecurityContext - Spring 3.2.2

后端 未结 6 1039
灰色年华
灰色年华 2020-12-03 04:26

I\'m trying to invoke a protected method from a class that implements the ApplicationListener interface on successful login (S

6条回答
  •  一整个雨季
    2020-12-03 05:04

    I encountered the same error while using SpringBoot 2.1.4, along with Spring Security 5 (I believe). After one day of trying everything that Google had to offer, I discovered the cause of error in my case. I had a setup of micro-services, with the Auth server being different from the Resource Server. I had the following lines in my application.yml which prevented 'auto-configuration' despite of having included dependencies spring-boot-starter-security, spring-security-oauth2 and spring-security-jwt. I had included the following in the properties (during development) which caused the error.

    spring:
      autoconfigure:
        exclude: org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration
    

    Commenting it out solved it for me.

    #spring:
    #  autoconfigure:
    #    exclude: org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration
    

    Hope, it helps someone.

提交回复
热议问题