How to integrate Spring Security and GWT?

前端 未结 7 1147
面向向阳花
面向向阳花 2021-02-07 07:24

I\'m trying to integrate Spring Security and GWT. I\'m also using gwt-incubator-security. I configured everything as it was described on their wiki pages. I managed to get secur

7条回答
  •  梦如初夏
    2021-02-07 08:03

    I'am using GWT+Spring security. I find in your configuration, there is some misunderstanding. In fact, there is a very simple way that can let spring security work with your gwt regardless the gwt-incubator-security. You just need to declare your application context in you web.xml.

      
        contextConfigLocation
        /WEB-INF/applicationContext-security.xml
      
    
      
        springSecurityFilterChain
        org.springframework.web.filter.DelegatingFilterProxy
      
    
      
        springSecurityFilterChain
        /*
      
    
      
            org.springframework.web.context.ContextLoaderListener
       
    

    You don't declare here your MVC dispatcherServlet ! Then everything works because of the Spring Security framework mechanism.

    But This way of configuration doesn't declare DispatcherServlet, it is simple, but in case that you need some security funcionality that need DispatcherServlet, is is a "piege". So as i've met.

    Then if you insist to use gwt-incubator-security. I've read a very good solution in french, but it rest uncheck. http://hugo.developpez.com/tutoriels/java/gwt/utilisation-gwt-avec-spring-et-hibernate/

    1. Integrate Spring in the application with GWT-SL: In fact, for the integration of Spring and hibernate, the problem is how to configure correctly the servlet. One should be aware that the Spring has its own servlet “DispatcherServlet” so as the gwt with its “gwt servlet”. Normally, in the tutorial for the GWT RPC, the gwt-servlet is declared in the web-xml, like
     
        appService
        com.google.gwt.app.example.server.AppServiceImpl
      
      
         appService
         /app/appService
       
    

    If you like very much Spring, and you want to use DispatcherServlet to dispatch the request, then GWT-handler can help you to get rid of the problem. Firstly, you load application context in the web.xml as below:

    
     contextConfigLocation 
         classpath:applicationContext_GWT.xml 
    
    
        org.springframework.web.context.ContextLoaderListener
    
    
    

    Then you can declare your rpc service in Spring context: applicationContext_GWT.xml

    
    
    

    But you should not forget to add the GWTHandler declaration in the application context file applicationContext_GWT.xml
    The last thing is to declare the spring servlet: DispatcherServlet in the web.xml. Pay attention to the fact that this is the spring’s proper servlet not the GWT-SL’s. web.xml

      
        handler
         org.springframework.web.servlet.DispatcherServlet 
           1
      
    
    handler
    *.rpc
    
    

    Servlet name is important because DispatcherServlet will search for the spring context file named by “*-servlet.xml”. As the servlet name is handler, it will search for the spring context “handler-servlet.xml”. So here we will solve the problem like this, we put the application context which is independent with the DispatcherServlet in the “applicationContext_GWT.xml”, then the one that is dependent with the DispatcherServlet in the “-servlet.xml”, as the servlet name is “handler”, then we should have “handler-servlet.xml”, then put the following configuration of GWT_SL from applicationContext_GWT.xml into handler-servlet.xml Handler-servlet.xml

    
            
            
                 
        
        
                 
             
     
    

    Then add the following configuration in the web.xml dans la declaration de servlet.

    
                   contextConfigLocation
         /WEB-INF/handler-servlet.xml 
    
    

    The filter pattern concerns just the RPC call with a suffix .rpc (I didn’t use the GWT-SL, so the method above for integration has not been checked.)

    After you have all the above configuration, then you create your filtreprocessentrypoint in your applicationi context file.

    Hope this can help you!

提交回复
热议问题