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

[SHIRO-829]: beanPostProcessor and FactoryBean cause spring aop to fail … #316

Merged
merged 1 commit into from Feb 8, 2022

Conversation

xczs666
Copy link

@xczs666 xczs666 commented Aug 4, 2021

When LifecycleBeanPostProcessor and ShiroFilterFactoryBean are defined in the same configuration
class, Realm's dependency aop (@transactional and cache) is invalidated.

BREAKING CHANGE:
module:shiro-spring class:ShiroFilterFactoryBean

ISSUES CLOSED: #SHIRO-829

Following this checklist to help us incorporate your contribution quickly and easily:

  • Make sure there is a JIRA issue filed
    for the change (usually before you start working on it). Trivial changes like typos do not
    require a JIRA issue. Your pull request should address just this issue, without pulling in other changes.
  • Each commit in the pull request should have a meaningful subject line and body.
  • Format the pull request title like [SHIRO-XXX] - Fixes bug in SessionManager,
    where you replace SHIRO-XXX with the appropriate JIRA issue. Best practice
    is to use the JIRA issue title in the pull request title and in the first line of the commit message.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Run mvn clean install apache-rat:check to make sure basic checks pass. A more thorough check will be performed on your pull request automatically.
  • If you have a group of commits related to the same change, please squash your commits into one and force push your branch using git rebase -i.

Trivial changes like typos do not require a JIRA issue (javadoc, comments...).
In this case, just format the pull request title like (DOC) - Add javadoc in SessionManager.

If this is your first contribution, you have to read the Contribution Guidelines

If your pull request is about ~20 lines of code you don't need to sign an Individual Contributor License Agreement
if you are unsure please ask on the developers list.

To make clear that you license your contribution under the Apache License Version 2.0, January 2004
you have to acknowledge this by using the following check-box.

…in the same Configuration

When LifecycleBeanPostProcessor and ShiroFilterFactoryBean are defined in the same configuration
class, Realm's dependency aop (@transactional and cache) is invalidated.

BREAKING CHANGE:
module:shiro-spring class:ShiroFilterFactoryBean

ISSUES CLOSED: #SHIRO-829
@xczs666 xczs666 changed the title [bugfix]: beanPostProcessor and FactoryBean cause spring aop to fail … [SHIRO-829]: beanPostProcessor and FactoryBean cause spring aop to fail … Aug 4, 2021
@fpapon
Copy link
Member

fpapon commented Aug 4, 2021

@xczs666 it's better to propose this PR on main and we will cherry-pick on the other branches

@xczs666
Copy link
Author

xczs666 commented Aug 5, 2021

@xczs666 it's better to propose this PR on main and we will cherry-pick on the other branches

@fpapon Do I need to resubmit a PR based on the main branch?

@fpapon
Copy link
Member

fpapon commented Aug 5, 2021

@xczs666 it's better to propose this PR on main and we will cherry-pick on the other branches

@fpapon Do I need to resubmit a PR based on the main branch?

No it's ok for now ;)

@xczs666
Copy link
Author

xczs666 commented Aug 5, 2021

@xczs666 it's better to propose this PR on main and we will cherry-pick on the other branches

@fpapon Do I need to resubmit a PR based on the main branch?

No it's ok for now ;)

OK :)

@@ -354,7 +354,7 @@ public void setGlobalFilters(List<String> globalFilters) {
* @return the application's Shiro Filter instance used to filter incoming web requests.
* @throws Exception if there is a problem creating the {@code Filter} instance.
*/
public Object getObject() throws Exception {
public AbstractShiroFilter getObject() throws Exception {
Copy link
Member

Choose a reason for hiding this comment

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

I like this change, but this is API breaking.

@xczs666 any ideas on how to work around this as you were digging into the problem originally?

Copy link
Member

Choose a reason for hiding this comment

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

@xczs666 Thinking about this again, for the 1.x line of Shiro. could we revert lines 357 and 120. I'm guessing that line 370 is all that's needed?

That said, I wasn't able to reproduce the original issue to test it out either way. Do you have a simple example project that demos the problem? From there we should be able write a quick test around the problem.

@bmarwell
Copy link
Contributor

We could pull this into 1.9.0 if you like

@xczs666
Copy link
Author

xczs666 commented Sep 27, 2021

We could pull this into 1.9.0 if you like

Please proceed

@bmarwell
Copy link
Contributor

Hi @xczs666 we would like to integrate your patch.
However, there is one pending review comment (https://github.com/apache/shiro/pull/316/files#r691462174) and your patch is based on an old version (1.7.0).

Could you kindly rebase your patch and apply Brians suggestion?

Thanks.

@xczs666
Copy link
Author

xczs666 commented Jan 24, 2022

Hi @xczs666 we would like to integrate your patch. However, there is one pending review comment (https://github.com/apache/shiro/pull/316/files#r691462174) and your patch is based on an old version (1.7.0).

Could you kindly rebase your patch and apply Brians suggestion?

Thanks.

Hi @bmarwell, I can rebase my patch based on the latest version. But I can't solve the problem of returning the signature change. Because the signature of T getObject() is declared in the org.springframework.beans.factory.FactoryBean interface, to solve this problem need to give T a specific type

@bmarwell
Copy link
Contributor

@xczs666 I think you missed the idea from Brian. If you revert EVERYTHING except line 370, then it should work.

@bdemers
Copy link
Member

bdemers commented Jan 24, 2022

I didn't have push access to the original repo, but I've reverted the API breaking changes here: https://github.com/xuchenzhi/shiro/pull/1/files
@xczs666 please confirm this will work for you

@xczs666
Copy link
Author

xczs666 commented Jan 25, 2022

@bdemers oh no, in spring 4.X (springboot 1.X) the T in the class signature of FactoryBean is parsed to get the type instead of calling getObject(). In spring5.X (springboot 2.X), getObject() was used instead.
I have a project that simulates this problem: https://github.com/xczs666/shiro-829. You try to modify https://github.com/xczs666/shiro-829/blob/main/simple-factory-bean-solution-3/src/main/java/simple/factorybean/support/ShiroFilterFactoryBean.java, then execute https://github.com/xczs666/shiro-829/blob/main/simple-factory-bean-solution-3/src/test/java/simple/factorybean/aspect/ServiceAopTest.java. You will find that springboot1.X resolves the class signature instead of calling getObject().
I have been busy these two days. Later, I will point out the location of the spring source code for you, as well as the verification demo of different spring versions.

@bdemers
Copy link
Member

bdemers commented Jan 25, 2022

@xczs666 thanks for the info! that really helps!

Can you rebase this onto 1.9.x or main (that should fix the CI issues), and then we can get it merged!

@fpapon
Copy link
Member

fpapon commented Jan 27, 2022

@xczs666 yes, rebase on main please, I will cherry-pick on 1.9.x

@xczs666
Copy link
Author

xczs666 commented Jan 27, 2022

@bdemers I tried to fix it rebase on main. After modification, a circular dependency error occurs: ShiroFilterFactoryBean --create--> AbstractShiroFilter --implements--> Filter, ShiroFilterFactoryBean --depends--> Filter(Map<String, Filter> filters).Means ShiroFilterFactoryBean both creates and depends on Filter.

Running ShiroWebConfigurationTest#testMinimalConfiguration produces exception:

UnsatisfiedDependencyException: Error creating bean with name 'shiroWebFilterConfiguration': Unsatisfied dependency expressed through field 'filterMap'; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'shiroFilterFactoryBean': Requested bean is currently in creation: Is there an unresolvable circular reference?

Please clone https://github.com/xczs666/shiro/tree/bugfix/shiro-829 and run ShiroWebConfigurationTest.testMinimalConfiguration to reproduce the above error

So I locally removed filterFactoryBean.setFilters(filterMap)(line:71) in org.apache.shiro.spring.web.config.AbstractShiroWebFilterConfiguration, because ShiroFilterFactoryBean will automatically inject Filter Beans through the postProcessBeforeInitialization(Object, String) method.
Although injecting Spring Filter Beans is redundant, accepting this modification will bring about changes in the use of the ShiroFilterFactoryBean#setFilter method, which may cause errors in the user's stock code, and you need your help in evaluating the impact and solutions.
Actually in my opinion, in Spring, the setFilters(Map<String, Filter>) method should not be provided.

@fpapon fpapon requested a review from bdemers February 7, 2022 20:15
@bdemers
Copy link
Member

bdemers commented Feb 7, 2022

@xczs666 We can merge this into 1.x as is, and I created this issue for v2: SHIRO-859 to track this

@xczs666
Copy link
Author

xczs666 commented Feb 8, 2022

@xczs666 We can merge this into 1.x as is, and I created this issue for v2: SHIRO-859 to track this

@bdemers ok then i resubmit a PR based on the 1.9.x branch?

@bdemers bdemers changed the base branch from 1.7.x to 1.9.x February 8, 2022 16:51
@bdemers
Copy link
Member

bdemers commented Feb 8, 2022

@xczs666 Thanks! I just switched the target branch to 1.9

@fpapon fpapon self-requested a review February 8, 2022 16:51
Copy link
Member

@fpapon fpapon left a comment

Choose a reason for hiding this comment

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

@xczs666 it's ok, @bdemers did the change for the target branch.
Thank you very much for your contribution!

@fpapon fpapon merged commit b8de57f into apache:1.9.x Feb 8, 2022
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

Successfully merging this pull request may close these issues.

None yet

4 participants