2016-09-30 9 views
0

私のプロジェクトは、Javaベースのコンフィグレーションに完全に基づいていました。Spring Securityのweb.xmlとJavaベースの設定を正しく定義する方法

うまく動作
public class MyWebAppInitializer implements WebApplicationInitializer { 

    @Override 
    public void onStartup(ServletContext container) throws ServletException { 
     AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext(); 
      rootContext.register(WebAppConfiguration.class); 
      AnnotationConfigWebApplicationContext dispatcherContext = new AnnotationConfigWebApplicationContext(); 

      ServletRegistration.Dynamic dispatcher = container.addServlet("dispatcher", new DispatcherServlet(dispatcherContext)); 
      dispatcher.setLoadOnStartup(1); 
      dispatcher.addMapping("/"); 
    } 

、と私はそのようなThymeleafのテンプレートでCSRFトークンを取得することができました:だからではなく、スタンダールのweb.xmlの私はこれを持っていた

<meta name="_csrf" th:content="${_csrf.token}"/> 
<meta name="_csrf_header" th:content="${_csrf.headerName}"/> 

しかし、今私が展開する必要がありますGoogle App Engineへの私のプロジェクトであり、web.xmlを持っている必要があります。それ以外の場合は起動しません。 私はweb.xmlファイルを追加し、上記のJavaの設定を削除します。

<context-param> 
     <param-name>contextClass</param-name> 
     <param-value> 
     org.springframework.web.context.support.AnnotationConfigWebApplicationContext 
    </param-value> 
    </context-param> 

    <listener> 
     <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 
    </listener> 

    <context-param> 
     <param-name>contextConfigLocation</param-name> 
     <param-value>com.demshin.medpro.configuration.WebAppConfiguration</param-value> 
    </context-param> 

    <servlet> 
     <servlet-name>springServlet</servlet-name> 
     <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
     <init-param> 
      <param-name>contextClass</param-name> 
      <param-value>org.springframework.web.context.support.AnnotationConfigWebApplicationContext</param-value> 
     </init-param> 
     <load-on-startup>1</load-on-startup> 
    </servlet> 
    <servlet-mapping> 
     <servlet-name>springServlet</servlet-name> 
     <url-pattern>/*</url-pattern> 
    </servlet-mapping> 

そして、私は私のアプリのURLを開こうとすると、私は例外を取得:

org.thymeleaf.exceptions.TemplateProcessingException:例外 SpringELの式を評価しています: "_csrf.token"

私が思うに、この問題はフィルターチェーンが壊れています。 しかし、私はweb.xmlに以下を追加した場合:代わりに、このJavaの設定の

<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> 

public class SecurityWebApplicationInitializer extends AbstractSecurityWebApplicationInitializer { 
    public SecurityWebApplicationInitializer() { 
     super(WebSecurityConfiguration.class); 
    } 
} 

トレースは少し異なるが、問題はまだそこにあります。

これはどのように治すことができますか? Google App Engineでweb.xmlを削除する方法がありますか? ありがとうございます。

答えて

0

有用な情報が見つかりましたhere WebApplicationInitializerはServlet 3.0が必要ですが、AppengineはServlet 2.5のみをサポートしているという問題があります。したがって、少なくとも初期化のためには、プレーンなXMLベースの設定を使用する必要があります。 Web.xmlでSpringフィルタ/サーブレットを手動で設定します。 残念ながら、私はspringの設定をxmlに完全に移行させることなく、spring-security.xmlを追加するだけで動作しませんでした。

サーブレット3.0のサポートhereに投票することもできますが、残念ながらGoogleに追加する予定はありません。

0

Javaの設定を保存して空のweb.xmlを作成するとどうなりますか?

<?xml version="1.0" encoding="UTF-8"?> 
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" 
    version="3.1"> 

</web-app> 
+0

このようなものは動作しません。 –

関連する問題