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

Provide guide for migrating from FilterSecurityInterceptor to AuthorizationFilter #11337

Closed
9 tasks done
Tracked by #9290
vpavic opened this issue Jun 6, 2022 · 11 comments
Closed
9 tasks done
Tracked by #9290
Assignees
Labels
in: config An issue in spring-security-config type: enhancement A general enhancement
Milestone

Comments

@vpavic
Copy link
Contributor

vpavic commented Jun 6, 2022

After learning about the new authorization configuration support in HttpSecurity::authorizeHttpRequests and seeing the docs stating that AuthorizationFilter is intended to supersede the FilterSecurityInterceptor, I've opened the PR against Spring Boot (with 3.0 being a natural target for such a change) to initiate the migration to the new configuration support:

However, the migration wasn't as trivial as one would expect looking at the docs (for example, no apparent direct replacements for #anonymous or #fullyAuthenticated) and I haven't found any migration guide available either in the reference docs or in the Wiki here on GitHub.

So, IMO it would be a good idea to provide such a migration guide.

Here's a list of use cases that should inform the contents of such a guide:

@vpavic vpavic added status: waiting-for-triage An issue we've not yet triaged type: enhancement A general enhancement labels Jun 6, 2022
@rwinch rwinch removed the status: waiting-for-triage An issue we've not yet triaged label Jun 6, 2022
@rwinch
Copy link
Member

rwinch commented Jun 6, 2022

@vpavic Thanks!

@jzheaux I feel like this might be something we need to enhance so that all the same expressions are available. What are your thoughts?

@jzheaux
Copy link
Contributor

jzheaux commented Jun 10, 2022

@rwinch, I think that most of them should be added to AuthorizeHttpRequestsConfigurer and the corresponding AuthorizationManager.

I'm not sure about hasIpAddress, I think I'd prefer to wait as protection by IP address is quite brittle these days.

I've created #11360 where I have an initial list, we can discuss anything else that needs adding over there.

Also, I realize that authorizeRequests does not expose hasPermission, but I also see some value in introducing something like PermissionAuthorizationManager to give applications a programmatic equivalent to what is available in SecurityExpressionRoot. I've added #11361 for consideration.

@vpavic
Copy link
Contributor Author

vpavic commented Jul 21, 2022

What's the migration path for security configurations that used #filterSecurityInterceptorOncePerRequest?

@jzheaux
Copy link
Contributor

jzheaux commented Jul 21, 2022

Thanks, @vpavic, for asking. I don't believe there is one, yet. Will you please open a ticket to make sure it gets addressed?

@vpavic
Copy link
Contributor Author

vpavic commented Jul 21, 2022

After taking a closer look, I'm not sure that the direct replacement is needed (or possible).

This is based on the observation that FilterSecurityInterceptor is a plain Filter that has observeOncePerRequest flag (and the accompanying logic) whereas the new AuthorizationFilter extends OncePerRequestFilter thus inheriting once per request semantics by default.

Seems to me like the replacement is to use #shouldFilterAllDispatcherTypes on the new configuration DSL.

Can you confirm?

@jzheaux
Copy link
Contributor

jzheaux commented Jul 26, 2022

@vpavic, I just reached out to @marcusdacoregio to confirm and yes, shouldFilterAllDispatcherTypes is the equivalent.

@vpavic
Copy link
Contributor Author

vpavic commented Jul 26, 2022

Thanks for the confirmation. Since my last comment I updated spring-projects/spring-boot#31255 and everything builds cleanly now. In the end, the changes in that PR are quite straightforward thanks to the changes made in Spring Security in response to this issue so thanks for that.

@jzheaux jzheaux moved this to Todo in Spring Security Team Sep 20, 2022
jzheaux added a commit that referenced this issue Oct 28, 2022
@jzheaux jzheaux modified the milestones: 5.8.x, 5.8.0 Oct 28, 2022
jzheaux added a commit that referenced this issue Oct 28, 2022
jzheaux added a commit that referenced this issue Oct 28, 2022
- Added step to declare the 5.8 default in case later preparation steps
cannot be taken yet

Issue gh-11337
jzheaux added a commit that referenced this issue Oct 28, 2022
- Add instruction to declare 5.8 defaults

Issue gh-11337
jzheaux added a commit that referenced this issue Oct 28, 2022
- Revert steps removed since implicitly included in preparation guide

Issue gh-11337
jzheaux added a commit that referenced this issue Oct 28, 2022
jzheaux added a commit that referenced this issue Oct 28, 2022
jzheaux added a commit that referenced this issue Oct 31, 2022
jzheaux added a commit that referenced this issue Oct 31, 2022
Repository owner moved this from Todo to Done in Spring Security Team Oct 31, 2022
@sjohnr
Copy link
Member

sjohnr commented Nov 22, 2022

Hi @JohnZ1385, the guide was restructured after the comment above. See https://docs.spring.io/spring-security/reference/5.8/migration/servlet/authorization.html#_use_authorizationmanager_for_request_security instead.

@filiphr
Copy link
Contributor

filiphr commented Aug 14, 2023

We are in the process of migrating from Spring Boot 2.7 to Spring Boot 3.1 and this was one of the issues that we were hit with. We are using the RunAsManager with a combination of the FilterSecurityInterceptor. The proposed solution in the documentation to use a customized RunAsAuthorizationManagerAdapter is not identical to what was happening before.

The FilterSecurityInteceptor through the AbstractSecurityInterceptor was also changing the SecurityContext with the new authentication. e.g. in

The newly proposed solution is not doing that. This might be linked to #13435 where the default SwitchUserFilter was changed to use sessions by default. However, our Switch user approach is not using sessions, which means that currently there is no way for us to provide this out of the box. It means that we need to have our own filter that is going to perform what was being done in the FilterSecurityInterceptor with the RunAsManager

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 type: enhancement A general enhancement
Projects
Status: Done
Development

No branches or pull requests

6 participants