2017-12-19 15 views
0

私はZuulの後ろにOauth2サーバーを実行しています。 Zuulはユーザーをログインページに転送します。 ZuulもHttpSecurity以下を定義します。FreemarkerテンプレートのSpring CSRFトークンヌル

@Override 
public void configure(HttpSecurity http) throws Exception { 
... 
.and().csrf().csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse()); 
} 

のOAuth2サーバー上のログインFreemarkerのテンプレートは、このようなCSRFトークン解析します。ここまで

<from> 
... 
<input type="hidden" id="csrf_token" name="${_csrf.parameterName}" value="${_csrf.token}"/> 
</form> 

を、すべてが正常に動作します。

次WebMvcConfigurerAdapter構成とともに
<a href="/uaa/reset"><@spring.message "login.forgot"/></a> 

:いいえ、私はパスワードへのリンクFreemarkerのテンプレートをリセットを含め、私はリセットビューに移動すると

@Configuration 
public class OAuthWebFormConfiguration extends WebMvcConfigurerAdapter { 

@Override 
public void addViewControllers(ViewControllerRegistry registry) { 
    registry.addViewController("/login").setViewName("login"); 
    registry.addViewController("/reset").setViewName("reset"); 
} 

私は次のエラーを取得する:

: Servlet.service() for servlet [dispatcherServlet] in context with path 
[/uaa] threw exception [Request processing failed; nested exception is 
freemarker.core.InvalidReferenceException: The following has evaluated to 
null or missing: 
==> _csrf [in template "reset.ftl" at line 21, column 64] 

Tip: If the failing expression is known to legally refer to something 
that's sometimes null or missing, either specify a default value like 
myOptionalVar!myDefault, or use <#if myOptionalVar??>when- 
present<#else>when-missing</#if>. (These only cover the last step of the 
expression; to cover the whole expression, use parenthesis: 
(myOptionalVar.foo)!myDefault, (myOptionalVar.foo)?? 

FTL stack trace ("~" means nesting-related): 
- Failed at: ${_csrf.parameterName} [in template "reset.ftl" at line 21, 
column 62] 
----] with root cause 

freemarker.core.InvalidReferenceException: The following has evaluated to 
null or missing: 
==> _csrf [in template "reset.ftl" at line 21, column 64] 

Tip: If the failing expression is known to legally refer to something that's 
sometimes null or missing, either specify a default value like 
myOptionalVar!myDefault, or use <#if myOptionalVar??>when- 
present<#else>when- 
missing</#if>. (These only cover the last step of the expression; to cover 
the whole expression, use parenthesis: (myOptionalVar.foo)!myDefault, 
(myOptionalVar.foo)?? 

FTL stack trace ("~" means nesting-related): 
- Failed at: ${_csrf.parameterName} [in template "reset.ftl" at line 21, 
column 62] 

助けが必要ですか?

答えて

0

修正はとても似antMatchersのリストにリセットビューを追加することです:

@Override 
    protected void configure(HttpSecurity http) throws Exception { 
     // @formatter:off 
     http 
      .authorizeRequests() 
       .antMatchers("/console/**", "/reset").permitAll() 
      .and() 
       .formLogin() 
       .loginPage("/login") 
       .permitAll() 
      .and() 
       .requestMatchers() 
       .antMatchers("/login", "/oauth/authorize", "/oauth/confirm_access", "/reset") 
      .and() 
       .authorizeRequests() 
       .anyRequest() 
       .authenticated(); 
     // @formatter:on 
    } 

スプリングスCsrfFilterがでキックやと要求属性としてCSRFトークンを追加しますこの方法です。

関連する問題