spring-projects / spring-projects/spring-security-samples

Reactive OAuth2 Resource Server: Correct way to bypass authentication for a path

Open
#105 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
1.8k
Forks
797
Avg merge
3m
Merged PRs (30d)
5

Description

In non-reactive spring-security I am able to bypass authorization and authentication using "ignoring()" in a WebSecurityCustomizer

https://docs.spring.io/spring-security/site/docs/current/api/org/springframework/security/config/annotation/web/configuration/WebSecurityCustomizer.html

,which is amazing, however I am not able to exploit this behaviour along a "spring-security-powered-oauth2-reactive-resource-server" because the @EnableWebFluxSecurity does not allow using WebSecurityCustomizer.

I thought the correct way to do this is using .permitAll() in my SecurityWebFilterChain bean, for instance adding before row 43 in the example something like

.pathMatchers(HttpMethod.GET, "/free-path/**").permitAll()

this works, meaning I can GET any /free-path/something without providing any JWT, but have the problematic behaviour that, if I provide a JWT, this token is evaluated and if it's not valid, e.g. expired, I get a 401 response.

Which is the correct way to add a "free" path?
Can you kindly consider adding a "free" resource to the reactive sample project to make things clearer?

EDIT: actually I am able to mimic ingnoring() approach using this SO suggestion

.securityMatcher(new NegatedServerWebExchangeMatcher(ServerWebExchangeMatchers.pathMatchers("/free-path/**")))

but I am not sure this is the preferred solution and I know from the documentation that ignoring() is more for static content than for dynamic one

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with reactive/webflux/java/oauth2/resource-server/src/main/java/example/SecurityConfiguration.java around row 43, then compare the described permitAll and securityMatcher approaches with the linked WebFlux guidance. Confirm the preferred way to expose a free path and update the reactive resource-server sample so the behavior is clear.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring
Domain
backend, security
Issue type
Documentation
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.