Hi,
thank to all for replies.
I need to to use the same security manager in the web part and in websocket.
I paste here the main class:

package org.kurento.tutorial.one2onecalladv;

import java.util.EnumSet;

import javax.servlet.DispatcherType;
import javax.servlet.Servlet;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.config.IniSecurityManagerFactory;
import org.apache.shiro.mgt.SecurityManager;
import org.apache.shiro.util.Factory;
import org.apache.shiro.web.env.EnvironmentLoaderListener;
import org.kurento.client.KurentoClient;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import
org.springframework.boot.autoconfigure.web.DispatcherServletAutoConfiguration;
import org.springframework.boot.context.embedded.FilterRegistrationBean;
import
org.springframework.boot.context.embedded.ServletListenerRegistrationBean;
import org.springframework.boot.context.embedded.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.DispatcherServlet;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import
org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;


@Configuration
@EnableWebSocket
@EnableAutoConfiguration
@ComponentScan
public class One2OneCallAdvApp implements WebSocketConfigurer {

    final static String DEFAULT_KMS_WS_URI = "ws://localhost:8888/kurento";
    // final static String DEFAULT_APP_SERVER_URL = "http://localhost:8080";;

    @Bean
    public CallHandler callHandler() {
        return new CallHandler();
    }

    @Bean
    public UserRegistry registry() {
        return new UserRegistry();
    }

    @Bean
    public KurentoClient kurentoClient() {
        return KurentoClient.create(System.getProperty("kms.ws.uri",
DEFAULT_KMS_WS_URI));
    }

    @Bean
    public FilterRegistrationBean shiroFilter() {
        FilterRegistrationBean registration = new FilterRegistrationBean();
        registration.setFilter(new
org.apache.shiro.web.servlet.ShiroFilter());

registration.setDispatcherTypes(EnumSet.allOf(DispatcherType.class));

        registration.setOrder(0);
        registration.addUrlPatterns("/*");
        return registration;
    }

    @Bean
    public ServletListenerRegistrationBean
shiroServletListenerRegistrationBean() {
        ServletListenerRegistrationBean registrationBean = new
ServletListenerRegistrationBean();
        EnvironmentLoaderListener environmentLoaderListener = new
EnvironmentLoaderListener();
        registrationBean.setListener(environmentLoaderListener);
        registrationBean.setOrder(0);
        return registrationBean;
    }

//    @Bean
//    public DispatcherServlet dispatcherServlet() {
//        return new DispatcherServlet();
//    }

//    @Bean
//    public Servlet operator() {
//        return new AuthInjectServlet();
//    }
    /**
     * Register dispatcherServlet programmatically
     *
     * @return ServletRegistrationBean
     */
//    @Bean
//    public ServletRegistrationBean dispatcherServletRegistration() {
//
//        ServletRegistrationBean registration = new
ServletRegistrationBean(
//                dispatcherServlet(), "/callme/*");
//
//        registration
//
.setName(DispatcherServletAutoConfiguration.DEFAULT_DISPATCHER_SERVLET_REGISTRATION_BEAN_NAME);
//
//        return registration;
//    }
//    @Bean
//    public ServletRegistrationBean
dispatcherRegistration(DispatcherServlet dispatcherServlet) {
//        ServletRegistrationBean registration = new
ServletRegistrationBean(dispatcherServlet);
//        registration.addUrlMappings("/callme/*");
//        return registration;
//    }

    public void registerWebSocketHandlers(WebSocketHandlerRegistry
registry) {
        registry.addHandler(callHandler(), "/call");
    }

    public static void main(String[] args) throws Exception {
//        //1. Load the INI configuration
//        Factory<SecurityManager> factory =
//        new IniSecurityManagerFactory("classpath:shiro.ini");
//
//        //2. Create the SecurityManager
//        SecurityManager securityManager = factory.getInstance();
//
//        //3. Make it accessible
//        SecurityUtils.setSecurityManager(securityManager);
        new SpringApplication(One2OneCallAdvApp.class).run(args);
    }

}


2015-11-16 13:48 GMT+01:00 Jared Bunting <[email protected]>:

> Depending on where these other threads are coming from, Shiro provides
> some utilities that might be useful here. Can you provide a bit more
> context?
> On Nov 15, 2015 6:47 PM, "Lenny Primak" <[email protected]> wrote:
>
>> 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 <[email protected]> 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.
>> >
>>
>>

Reply via email to