Implement spring security on google app engine

后端 未结 1 670
我寻月下人不归
我寻月下人不归 2021-01-20 03:16

I\'m trying to integrate the spring security on google app engine. But it doesn\'t work properly. I wang to authenticate user when they try to access index page

相关标签:
1条回答
  • 2021-01-20 03:24

    WebApplicationInitializer requires Servlet 3.0, but Appengine supports only Servlet 2.5. So you have to use plain XML based config, at least for initialization. And configure Spring filter/servlet in web.xml manually.

    You need to put into web.xml:

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/spring-security.xml</param-value>
    </context-param>
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    
    <filter>
        <filter-name>springSecurityFilterChain</filter-name>
        <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>springSecurityFilterChain</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    
    <servlet>
        <servlet-name>spring-dispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
        <init-param>
            <param-name>contextClass</param-name>
            <param-value>org.springframework.web.context.support.AnnotationConfigWebApplicationContext</param-value>
        </init-param>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>path.to.AppConfig</param-value>
        </init-param>
    </servlet>
    <servlet-mapping>
        <servlet-name>spring-dispatcher</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>
    

    and into spring-security.xml:

    <context:annotation-config/>
    <beans:bean class="path.to.SecurityConfig"/>
    

    Basically it's all standard stuff from pre-servlet 3.0 time, and you could use any tutorial (or old docs) based on servlet 2.4 or 2.5, it will work on Appengine.

    PS also you could vote for Servlet 3.0 support at https://code.google.com/p/googleappengine/issues/detail?id=3091

    0 讨论(0)
提交回复
热议问题