kapua icon indicating copy to clipboard operation
kapua copied to clipboard

Shiro realms in Kapua Console are initialised twice

Open gbarbon opened this issue 4 years ago • 0 comments

Describe the bug

When booting the console the Shiro realms detailed in the shiro.ini file are initialised twice.

The realm initialisation seems to be managed by the execute() method of the Shiro ReflectionBuilder class. This method has a loop that iterates over a list of 'statements' (6 in our case), and initialises them one by one (see LifecycleUtils.init(bd.getBean()); at line 785 of that class). Among these statements there are our 3 realms UserPassAuthenticatingRealm, KapuaAuthorizingRealm, JwtAuthenticatingRealm and the SecurityManager. So, thanks to this loop, the three realms are initialised.

However, there is a LifecycleUtils.init(objects.values()); at line 264 that initialises some object that are passed as parameters. This initialisation is executed just after the method execute() detailed above. And, among the 17 elements that it initialises, there are also our three realms. That's why they are initialised twice.

It is not clear to me wether this is a Shiro intended behaviour (that would be weird), or we are passing something unnecessary somewhere.

To Reproduce Steps to reproduce the behaviour:

  1. Using a debugger, put a breakpoint at line 395 of the Shiro AuthenticatingRealm (onInit() method call).
  2. Run the console.
  3. The breakpoint will stop the execution at each realm initialisation.
  4. Each realm will be initialised twice.

An alternative can be to put the breakpoint directly on the onInit() override in one of the realm classes (e.g. JwtAuthenticatingRealm), and see that it is called twice.

Expected behavior A realm should be initialised only once.

Screenshots N/A

Version of Kapua [e.g. 1.3.0-SNAPSHOT]

Type of deployment [ ] Local Vagrant deployment [ ] Docker [ ] Openshift (in its variants) [x] Others

Main component affected [x] Console (in case of console please report info on which browser you encountered the problem) [?] REST API [?] Message Broker [x] - Others

Additional context This issue has been detected in the console, however similar issues might impact also other components that use shiro, such as the broker and the REST API.

gbarbon avatar May 22 '20 15:05 gbarbon