question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Spring Security Autoconfiguration isn't stateless anymore

See original GitHub issue

This is a follow up of https://twitter.com/rotnroll666/status/904998421618196481

The attached two projects are identical apart from being BUILD-SNAPSHOT vs M3. demo-sec-build-snapshot.zip demo-sec-m3.zip

There’s a simple REST controller in both projects:

@RestController
@RequestMapping("/api")
public class ApiController {

	@GetMapping("/greeting")
	public String getGreeting(
		final Principal principal)
	{
		return String.format(
			"Hello, %s.",
			Optional.ofNullable(principal)
				.map(Principal::getName)
				.orElse("Anonymous"));
	}
}

Spring Security generates a password in both cases and logs it to console as expected.

Basic auth does work with both projects.

But the build snapshot generates a session and a corresponding cookie / session id and offers a form login (which works)

curl -v http://localhost:8080/api/greeting
*   Trying ::1...
* TCP_NODELAY set
* Connected to localhost (::1) port 8080 (#0)
> GET /api/greeting HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.51.0
> Accept: */*
> 
< HTTP/1.1 302 
< X-Content-Type-Options: nosniff
< X-XSS-Protection: 1; mode=block
< Cache-Control: no-cache, no-store, max-age=0, must-revalidate
< Pragma: no-cache
< Expires: 0
< X-Frame-Options: DENY
< Set-Cookie: JSESSIONID=81C71E0637FAA72F423FFBC4139BFA46; Path=/; HttpOnly
< Location: http://localhost:8080/login
< Content-Length: 0
< Date: Tue, 05 Sep 2017 09:18:52 GMT

Basic-Auth still works, though.

The session creation policy that was set to SessionCreationPolicy.STATELESS before disappeared through @mbhave’s change https://github.com/spring-projects/spring-boot/commit/e08ddbf838a54e589c07e2be36153a3f330f9550

If it stays that way it should be documented in the reference.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
mbhavecommented, Sep 5, 2017

I think @snicoll and I replied simultaneously! I’ll go ahead and close the issue in favor of #7958

1reaction
mbhavecommented, Sep 5, 2017

@michael-simons thanks for pointing out the documentation gap. We are still ironing out a few things and will update the docs shortly. I’ve kept the original issue open for doc updates.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Spring Security without the WebSecurityConfigurerAdapter
In Spring Security 5.7.0-M2 we deprecated the WebSecurityConfigurerAdapter , as we encourage users to move towards a component-based security ...
Read more >
Rework security auto-configuration · Issue #7958 - GitHub
1.x's solution to this problem was for Boot to auto-configure multiple, ordered WebSecurityConfigurerAdapter beans. This required users to slot ...
Read more >
Stateless Sessions with Spring Boot | InSource Software
First, let's use pre-authentication similar to what we explored in the article Stateless API Security with Spring Boot, Part 2.
Read more >
Spring security auto configuration not working in spring boot ...
I have included spring security dependency in pom.xml but the endpoints are not getting secured by default .This is happening in spring boot ......
Read more >
WebSecurityConfigurerAdapter is Deprecated. (Solved!)
Starting from Spring Security version 5.7.0-M2 the WebSecurityConfigurerAdapter is deprecated. In this blog post you will find a complete ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found