Skip to content

Make AuthorizationProxyFactory.proxy generic #16996

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

big-cir
Copy link
Contributor

@big-cir big-cir commented Apr 25, 2025

Overview

This pull request updates the AuthorizationProxyFactory interface to make its proxy method generic, ensuring that it returns the same type as the input object.

The following changes are included:

  • Refactored AuthorizationProxyFactory.proxy to use generics ( T proxy(T object)).
  • Removed redundant casts from production and test code that are no longer necessary due to the type-safe proxy method.

Related

ISSUE: #16706


Note

I’m aware that the issue is currently labeled with status: waiting-for-triage, which indicates that the final design direction may not be settled yet. This PR reflects my current understanding of the issue and is intended as a starting point for further discussion.

If this approach does not align with the intended direction, please feel free to close the PR or provide feedback. I am happy to revise or take a different direction as needed. Thank you!

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Apr 25, 2025
@jzheaux jzheaux added this to the 7.0.x milestone May 1, 2025
Copy link
Contributor

@jzheaux jzheaux left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @big-cir! I've left some feedback inline.

@@ -335,7 +335,7 @@ public void setTargetVisitorThenUses() {
@Test
public void setTargetVisitorIgnoreValueTypesThenIgnores() {
AuthorizationAdvisorProxyFactory factory = AuthorizationAdvisorProxyFactory.withDefaults();
assertThatExceptionOfType(ClassCastException.class).isThrownBy(() -> ((Integer) factory.proxy(35)).intValue());
assertThatExceptionOfType(ClassCastException.class).isThrownBy(() -> (factory.proxy(35)).intValue());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like the parentheses are no longer needed around factory.proxy(35). Can you remove them please?

@@ -20,6 +20,7 @@
* A factory for wrapping arbitrary objects in authorization-related advice
*
* @author Josh Cummings
* @author daewon kim
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will you please update the copyright year in this file and any other file you modify to 2025?

@jzheaux jzheaux modified the milestones: 7.0.x, 7.0.0-M1 May 1, 2025
@jzheaux jzheaux added in: core An issue in spring-security-core type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged labels May 1, 2025
@big-cir big-cir force-pushed the refactor/generic-proxy-method branch from 70bab2b to 7b8ba13 Compare May 2, 2025 02:09
@big-cir
Copy link
Contributor Author

big-cir commented May 2, 2025

Thanks, @big-cir! I've left some feedback inline.

@jzheaux Thank you for your valuable feedback.
I've updated the code according to your comments.
Please review the changes and let me know if any further modifications are needed. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core An issue in spring-security-core type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants