You need to:
- Save SecurityManager upon Shiro initiailzation (look at Shiro docs how to 
customize WebEnvironment)
- Use that in your Spring boot code

sample code (untested)

import org.apache.shiro.web.env.IniWebEnvironment;

/**
 * 
 * @author lprimak
 */
public class WebEnvironment extends IniWebEnvironment
{
    public static SecurityManager staticSecManager;

    @Override
    protected void configure()
    {
        super.configure();
        staticSecManager = getSecurityManager();
    }
}


> On Nov 16, 2015, at 6:56 PM, mgiammarco <[email protected]> wrote:
> 
> I have just tried, in spring boot initialization shiro security manager is
> not ready.
> So I have tried in @PostConstruct of my @Controller bean and also there
> security manager is not yet initialized.
> I have no idea when security manager is ready and so I can get it and put
> in thread context.
> 
> Thanks again,
> Mario
> 
> 2015-11-16 1:47 GMT+01:00 lprimak [via Shiro User] <
> [email protected]>:
> 
>> You need to bind the SecurityManager to thread context before using Shiro.
>>>>> ThreadContext.bind(securityManager);
>> 
>> and you will need get security manager from somewhere via SpringBoot
>> initialization
>> 
>>> On Nov 15, 2015, at 5:23 PM, mgiammarco <[hidden email]
>> <http:///user/SendEmail.jtp?type=node&node=7580850&i=0>> wrote:
>>> 
>>> Hello,
>>> I have a spring-boot web app that provides some jsp pages and uses
>>> websockets.
>>> I have configured shiro correctly for web use.
>>> But now when I use in the spring websocket part:
>>> 
>>> Subject.Builder().sessionId("token").buildSubject();
>>> 
>>> I get:
>>> 
>>> org.apache.shiro.UnavailableSecurityManagerException: No SecurityManager
>>> accessible to the calling code, either bound to the
>>> org.apache.shiro.util.ThreadContext or as a vm static singleton.  This
>> is an
>>> invalid application configuration
>>> 
>>> and SecurityUtils.getSubject() returns null
>>> 
>>> Obviously this happens because I cannot get the web SecurityManager from
>>> non-web thread.
>>> 
>>> But I need badly to access that SecurityManager from all threads.
>>> How can I do it?
>>> 
>>> 
>>> Thanks,
>>> Mario
>>> 
>>> 
>>> 
>>> --
>>> View this message in context:
>> http://shiro-user.582556.n2.nabble.com/Get-SecurityManager-in-a-mixed-web-app-tp7580849.html
>>> Sent from the Shiro User mailing list archive at Nabble.com.
>>> 
>> 
>> 
>> 
>> ------------------------------
>> If you reply to this email, your message will be added to the discussion
>> below:
>> 
>> http://shiro-user.582556.n2.nabble.com/Get-SecurityManager-in-a-mixed-web-app-tp7580849p7580850.html
>> To unsubscribe from Get SecurityManager in a mixed web app, click here
>> <http://shiro-user.582556.n2.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=7580849&code=bWdpYW1tYXJjb0BnbWFpbC5jb218NzU4MDg0OXwtMTIyMTI5ODI4>
>> .
>> NAML
>> <http://shiro-user.582556.n2.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>> 
> 
> 
> 
> 
> --
> View this message in context: 
> http://shiro-user.582556.n2.nabble.com/Get-SecurityManager-in-a-mixed-web-app-tp7580849p7580854.html
> Sent from the Shiro User mailing list archive at Nabble.com.
> 

Reply via email to