Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
segaura opened this issue Nov 15, 2022 · 0 comments

Comments

@segaura
Copy link

segaura commented Nov 15, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant