Auto-configure RequestAttributeSecurityContextRepository for OAuth2 resource server
See original GitHub issueThis appears to have broken in 2.6.X
as older versions (I tried 2.5.X
) do not exhibit the behavior described below.
Step 1: provide a WebSecurityConfigurerAdapter
and configure it with the STATELESS
session creation policy:
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
.and().authorizeRequests()
.antMatchers("/test-user").hasRole("USER")
.antMatchers("/test-admin").hasRole("ADMIN")
.antMatchers("/error").authenticated()
.and().httpBasic();
}
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.inMemoryAuthentication()
.withUser("user").password("{noop}password").roles("USER").and()
.withUser("admin").password("{noop}password").roles("ADMIN", "USER");
}
}
Step 2: setup a simple controller
@Controller
public class ExampleController {
@GetMapping(path = {"test-user", "test-admin"})
public void test(HttpServletResponse response) {
response.setStatus(HttpServletResponse.SC_OK);
}
}
Step 3: run the application and send a request to a resource the user is not authorized to view
curl -v -u user:password http://localhost:8080/test-admin
Expected Behavior: the user receives a HTTP 403 Forbidden
response status code and a response body (such as the below):
{
"timestamp":"2022-02-04T23:42:41.621+00:00",
"status":403,
"error":"Forbidden",
"path":"/test-admin"
}
Actual Behavior: the user receives a HTTP 403 Forbidden
response status code with no response body
Note: if the STATELESS
session creation policy is removed from the above configuration, it works as expected.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:4
- Comments:16 (9 by maintainers)
Top Results From Across the Web
OAuth2 Autoconfig - Spring
Creating a Resource Server is easy, just add @EnableResourceServer and provide some configuration to allow the server to decode access tokens. If your ......
Read more >oauth2 is it okay to have user send password to backend
Authentication: An identify provider like Google is only a partial solution. ... RequestAttributeSecurityContextRepository for OAuth2 resource server#29655.
Read more >Spring boot 2.0.3 + Security + Oauth2 autoconfigure
I tried to replicate your use case: I develop an AuthServer with spring cloud security and an ResourceServer. The problem that I see...
Read more >Index (spring-security-oauth2-autoconfigure 2.5.5 API)
Configuration properties for Authorization Server Jwt configuration ... Auto-configure a Spring Security OAuth2 resource server.
Read more >A Quick Guide to OAuth 2.0 with Spring Security
Create an OAuth 2.0 Server · Build Your Client App · Test the Resource Server · Create an OpenID Connect Application · Create...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@datagitlies Spring Boot 2.6.x uses Spring security 5.6.x, so yes it won’t be using spring security 5.7.x
I updated our
WebSecurityConfigurerAdapter
by removing some cruft and the issue is no longer reproducible. Thank you.