0

Explanation of the problem.

I am using a library that is essentially a web server. This web server has a user login manager class and in that class there is a onUserLogin(User user) method that is triggered every time a user is logged in. I do not have access to the source code and I don't want to change it even if I had.

I want to know if it is possible to somehow register an event that is triggered every time this method is called and get the argument that it was called with on my code.

For more context, my code is a library that this webserver will use in return but the only thing that the webserver is blindly registering all plugins from a single entry point without offering any other API.

Nick Chapsas
  • 6,872
  • 1
  • 20
  • 29
  • Did you already read this question about intercepting method calls? https://stackoverflow.com/questions/12372165/intercepting-method-calls – Jens Dibbern Jan 26 '19 at 18:02
  • Yes I did, but the problem is that I am using Kotlin. The reason why I added the java tag was just in case there is a java solution that can be used in Kotlin too. – Nick Chapsas Jan 26 '19 at 18:05
  • Can you use a proxy similar to this question: https://stackoverflow.com/q/52082041/3755692 – msrd0 Jan 26 '19 at 19:53
  • @msrd0 don't proxies require to be called as proxies in the first place? I don't have access to the code that is calling the `onUserLogin`. – Nick Chapsas Jan 26 '19 at 20:34
  • I've never used it myself, but I wouldn't be supprised if that was some java reflection magic that you could use to intercept that call - https://docs.oracle.com/javase/8/docs/api/java/lang/reflect/Proxy.html – msrd0 Jan 26 '19 at 20:37
  • Could you elaborate on what webserver do you use? – Alexey Soshin Jan 26 '19 at 20:43
  • @AlexeySoshin It doesn't matter. It's not even a webserver, its a private emulator's loginserver, but I wanted to make the issue relatable to what most people know. It doesn't affect the answer. – Nick Chapsas Jan 26 '19 at 20:45
  • It does matter, actually. If you control how this "server" is started, you could use instrumentation to change the class, as described here: http://armoredbarista.blogspot.com/2012/01/patching-java-at-runtime.html . I could produce you an example, if you're really interested. – Alexey Soshin Jan 26 '19 at 21:19
  • @AlexeySoshin No it doesn't. I am not looking for runtime patching but rather compile time or runtime interception interception. I don't wanna change the class. I wanna add "after" behaviour. – Nick Chapsas Jan 26 '19 at 21:36

0 Answers0