title: spring security activate remember me feature always
body: <p>I'm implementing an example of <strong>spring security</strong> with the <strong>remember-me</strong> feature based on <strong>Persistent Token Approach</strong>. Actually i'm using a <strong>custom authentication manager</strong> how can i activate forever the option remember-me without adding the checkbox remember me on login form(i don't want also to put the checkbox input hidden and activate by default). How can i achieve that?
  here the spring security java configuration that i made:</p>
  
  <pre><code>  @Override
    protected void configure(HttpSecurity http) throws Exception {
  
      RequestMatcher matcher = new RequestHeaderRequestMatcher("X-Requested-With");
  
      LOGGER.debug("Creating Security Context ...");
      http.
      sessionManagement()
      .sessionCreationPolicy(SessionCreationPolicy.STATELESS).and().
      csrf().requireCsrfProtectionMatcher(createCSRFMathers()).and();
  
      //Add autologin filter
      http.addFilter(autoLoginFilter)
              .addFilterBefore(new TransactionIdRequestFilter(), AutoLoginFilter.class)
              .exceptionHandling().defaultAuthenticationEntryPointFor(new Http401TimeoutEntryPoint(), matcher)
              .and();
  
      //Add form login
      http.formLogin()
              .successHandler(savedRequestAwareAuthenticationSuccessHandler())
              .loginPage("/page/login")
              .loginProcessingUrl("/page/login/authenticate")
              .failureUrl("/page/login?loginError=true")
              .and();
  
      // Configures the logout function
      http.logout()
              .deleteCookies("JSESSIONID")
              .logoutUrl("/logout")
              .logoutSuccessUrl("/page/login?loginError=false")
              .and();
  
      // Configures url based authorization
      // Anyone can access the following urls
      http.authorizeRequests()
              .antMatchers("posc://**",
                      "/connectedUser/mobileInfos",
                      "/dashboard/config/**",
                      "/page/checklogintoken/**",
                      "/page/httpError",
                      "/page/login/**",
                      "/page/manifest",
                      "/page/token/**",
                      "/service-scripting/**",
                      "/script/**")
              .permitAll()
              .antMatchers("/**")
              .hasRole("USER").and().rememberMe().rememberMeServices(rememberMeServices());
  
    }
  
  @Bean   
    public AbstractRememberMeServices rememberMeServices() {
  
        PersistentTokenBasedRememberMeServices rememberMeServices =
            new PersistentTokenBasedRememberMeServices("AppKey",customUserDetailsService,persistentTokenRepository());
        rememberMeServices.setAlwaysRemember(true);
        return rememberMeServices;
    }
  @Bean
      public PersistentTokenRepository persistentTokenRepository() {
          CassandraTokenRepository db = new CassandraTokenRepository(persistanceTokenDao);
          return db;
      }
  
      @Bean
      public SavedRequestAwareAuthenticationSuccessHandler savedRequestAwareAuthenticationSuccessHandler() {
          SavedRequestAwareAuthenticationSuccessHandler auth = new SavedRequestAwareAuthenticationSuccessHandler();
          auth.setTargetUrlParameter("targetUrl");
          return auth;
      }   
  </code></pre>
  
  <p>I have an AbstractPreAuthenticatedProcessingFilter with a custom authentication manager used to make custom features before authenticating user. how can i use this filter to set the remember me option to true ?</p>
  
  <pre><code>@Component
  public class AutoLoginFilter extends AbstractPreAuthenticatedProcessingFilter {
  
   @Override
    public void doFilter(final ServletRequest request,
                         final ServletResponse response,
                         final FilterChain chain) throws IOException, ServletException {
  ...
  }
  
  }
  </code></pre>
  
  <p><strong><em>Thanks.</em></strong></p>