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

PermitAllSupport should support AuthorizeHttpRequestsConfigurer #10482

Closed
jzheaux opened this issue Nov 10, 2021 · 2 comments · Fixed by #10543
Closed

PermitAllSupport should support AuthorizeHttpRequestsConfigurer #10482

jzheaux opened this issue Nov 10, 2021 · 2 comments · Fixed by #10543
Assignees
Labels
in: config An issue in spring-security-config status: ideal-for-contribution An issue that we actively are looking for someone to help us with type: enhancement A general enhancement

Comments

@jzheaux
Copy link
Contributor

jzheaux commented Nov 10, 2021

When using HttpSecurity#authorizeHttpRequests together with FormLoginConfigurer#permitAll, PermitAllSupport throws the error:

permitAll only works with HttpSecurity.authorizeRequests()

PermitAllSupport should allow for either an ExpressionUrlAuthorizationConfigurer or an AuthorizeHttpRequestsConfigurer.

Having both of these configured will make PermitAllSupport's role ambiguous, and so it should error if neither or both of those configurers are present.

@jzheaux jzheaux added status: waiting-for-triage An issue we've not yet triaged type: enhancement A general enhancement labels Nov 10, 2021
@jzheaux jzheaux added in: config An issue in spring-security-config status: ideal-for-contribution An issue that we actively are looking for someone to help us with and removed status: waiting-for-triage An issue we've not yet triaged labels Nov 10, 2021
@igorpele
Copy link
Contributor

igorpele commented Nov 15, 2021

Hi, i would like to try this. As far as I understood I should additonally try to get an AuthorizeHttpRequestsConfigurer:

AuthorizeHttpRequestsConfigurer<?> httpConfigurer = http.getConfigurer(AuthorizeHttpRequestsConfigurer.class);

and make sure that either a ExpressionUrlAuthorizationConfigurer or an AuthorizeHttpRequestsConfigurer is defined and otherwise throw "permitAll only works with HttpSecurity.authorizeRequests() or HttpSecurity.authorizeHttpRequests()"

Additionally if an AuthorizeHttpRequestsConfigurer is defined all the URLs should be registered:

if (httpConfigurer != null) {
	httpConfigurer.getRegistry().chainRequestMatchers(Arrays.asList(requestMatchers)).permitAll();
}

The only problem with this approach is that the mappings in the AuthorizationManagerRequestMatcherRegistry are stored in a LinkedHashMap and if you add anyRequest (as in PermitAllTests) to it before the permitAll requests, this entry always matches first. One possibility would be introducing a method addMatcherAt and reorder the map accordingly. Any hints on this would be highly appreciated.
Thx.

@jzheaux
Copy link
Contributor Author

jzheaux commented Nov 15, 2021

Hi, @igorpele! It's yours.

Yes, I think adding a package-private addMappingAt would be beneficial. It may mean reworking some of the internals of AuthorizationManagerRequestMatcherRegistry.

igorpele added a commit to igorpele/spring-security that referenced this issue Nov 30, 2021
PermitAllSupport supports either an ExpressionUrlAuthorizationConfigurer or an AuthorizeHttpRequestsConfigurer. If none or both are configured an error message is thrown.

Closes spring-projectsgh-10482
jzheaux pushed a commit that referenced this issue Nov 30, 2021
PermitAllSupport supports either an ExpressionUrlAuthorizationConfigurer or an AuthorizeHttpRequestsConfigurer. If none or both are configured an error message is thrown.

Closes gh-10482
jzheaux added a commit that referenced this issue Nov 30, 2021
jzheaux pushed a commit that referenced this issue Nov 30, 2021
PermitAllSupport supports either an ExpressionUrlAuthorizationConfigurer or an AuthorizeHttpRequestsConfigurer. If none or both are configured an error message is thrown.

Closes gh-10482
jzheaux added a commit that referenced this issue Nov 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: config An issue in spring-security-config status: ideal-for-contribution An issue that we actively are looking for someone to help us with type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants