2017-12-19 3 views
0

저는 Zuul 뒤에 Oauth2 서버를 실행하고 있습니다. Zuul은 사용자를 로그인 페이지로 전달합니다.Freemarker 템플릿의 CSRF 토큰이 null입니다.

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

OAuth2를 서버에 로그인 프리 마커 템플릿이 같은 CSRF 토큰을 구문 분석 :

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

여기까지, 모든 것이 잘 작동 Zuul은 또한 다음과 같은 HttpSecurity을 정의합니다. 다음 WebMvcConfigurerAdapter 구성과 함께

<a href="/uaa/reset"><@spring.message "login.forgot"/></a> 

: 아니, 난 암호에 대한 링크 프리 마커 템플릿을 다시 포함

@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 토큰을 추가 할 것입니다 이런 식으로.

관련 문제