title: Spring Security and RequestCache with Anonymous User
body: <p>That's my Security Configuration</p>
  
  <pre><code>@Override
  protected void configure(HttpSecurity http) throws Exception {
      http.csrf().disable()
              .requestCache().requestCache(new CustomRequestCache())
              .and().authorizeRequests()
              .antMatchers("/").permitAll()
              .anyRequest().hasAnyAuthority(Role.getAllRoles())
              .and().formLogin().loginPage(LOGIN_URL).permitAll()
                    .loginProcessingUrl(LOGIN_PROCESSING_URL)
              .failureUrl(LOGIN_FAILURE_URL)
              .successHandler(new SavedRequestAwareAuthenticationSuccessHandler())
              .and().logout().logoutSuccessUrl(LOGOUT_SUCCESS_URL);
  }
  </code></pre>
  
  <p>The problem is that the CustomRequestCache is not called when I navigate from / to a protected URL and so the SavedRequestAwareAuthenticationSuccessHandler does not redirect to the requested page after login.</p>
  
  <p>I assume that this is because permitAll creates a anonymous user.</p>
  
  <p>How do I have to configure Spring Security to make SavedRequestAwareAuthenticationSuccessHandler work?</p>