Spring Boot 2 Testing with PreAuthorize security

I'm having some problems testing a Spgring Boot 2 app using Spring Security 5.1.

Problem: I'm always getting a 403 on the response.

Here are the two approaches I've tried:

1) Disable security for testing by doing:

@Value("${security.enabled:true}")

private boolean securityEnabled;

@Override

protected void configure(HttpSecurity pHttpSecurity) throws Exception

{

if (!securityEnabled)

{

return;

}

And using an application.properties only for testing with this variable set to false. This still leads to 403 since PreAuthorize still wants you to be authorized and I've observed same behaviour when disabling security configuration in the past: I had to also comment out all PreAuthorize annotations to manually...

Read More »

By: StackOverFlow - Tuesday, 6 November

Related Posts