I am using the Custom Landing Page hook project (https://github.com/opensourceforlife/CustomLandingPage-Hook) to direct users to the private site of the organization they are associated with. The hook works fine when the actual user logs in.
But I have a requirement to allow admins to impersonate users, which also works fine but can only be configured to open one specific page.
What I need is to have the URL change based on the logic of the custom landing page hook (logic that I can easily implement). The result would be that the admin would end up on the correct page for the user they are impersonating.
I have looked into this, and the URL is generated by the <liferay-security:doAsURL> tag which is implemented in com.liferay.taglib.security.DoAsURLTag.java
I am confident that I would be able to write the code to create the correct URL, however I am not sure how to overwrite the existing code. I have done JSP hooks before, but I have never overwritten a taglib class (nor any class in an OSGI bundle - just JSPs). I have to believe that this is possible, but I have yet to find any guidance for doing this (yes, I did look...).
Instead of changing the tag's implementation, I'd recommend to replace the URL with a custom generated one (generate the right URL from the beginning) and change the JSP where the tag that you found is used.
AFAIK it's a single place where you can choose to impersonate a user, so the effort should be relatively low. As a positive side effect: Changing the tag implementation wouldn't automatically recompile a JSP, so that you might still end up with stale code (depending on the implementation nature of the tag, which I didn't look at).
Replacing the URL with a custom implementation should also be a lot easier and more straightforward than open heart surgery on a taglib.