If you're performing a JUnit test in a Bootique Shiro app and encounter an Unavailable Security Manager Exception, this might be a solution for you. Before walking through the issue I should mention that this is specifically a Shiro issue but we're working in Bootique and Guice so we'll be seeing those in the mix, too.
Key Phrases: UnavailableSecurityManagerException, No SecurityManager accessible to the calling code, SecurityUtils Error
Here's the exception runtime.
Here's the simple Bootique Module Test we're running.
If we walk back through the runtime stack we'll see the source of our exception in line 182 of our WebUI class where we're calling Shiro SecurityUtils.
The clue is in the exception description, "No SecurityManager…bound to the Thread Context." Our fix then is to create a Default Security Manager class, set it as Shiro's SecurityUtils Security Manager and bind it to the Thread Context.
There we go!
Source Code Notes for this Post
Source code discussed in this post is found in NixMash Microservices on GitHub.