title: My application with Spring Security don't go beyond login page
body: <p>I just started a project with uses Spring Security for authentication which uses Java configuration instead XML. That's my class SecurityConfig.java:</p>
  
  <pre><code>@Configuration
  @EnableWebSecurity
  public class SecurityConfig extends WebSecurityConfigurerAdapter {
  
      @Autowired
      public void configure(AuthenticationManagerBuilder auth) throws Exception {
          auth
              .inMemoryAuthentication()
                  .withUser("kleber")
                  .password("123")
                  .roles("USER");
      }
  
      protected void configure(HttpSecurity http) throws Exception {
          http
              .csrf()
                  .disable()
              .authorizeRequests()
                  .antMatchers("/css/**", "/fonts/**", "/image/**", "/js/**").permitAll()
                  .anyRequest().authenticated()
                  .and()
              .formLogin()
                  .loginPage("/spring/index").permitAll()
                              .loginProcessingUrl("/spring/login").permitAll()
                  .usernameParameter("login")
                  .passwordParameter("senha")
                  .defaultSuccessUrl("/spring/home")
                  .failureUrl("/spring/erro-login")
                  .and()
              .logout()
                  .logoutUrl("/spring/logout")
                  .logoutSuccessUrl("/spring/index").permitAll();
      }
  
  }
  </code></pre>
  
  <p>With this configuration, I can reach the login page, but after I inform my credencials (username and password) the system return to this same login page, despite the username and password informed are correct.</p>
  
  <p>All this URLs informed in the class SecurityConfig are mapped in this controller:</p>
  
  <pre><code>@Controller
  @RequestMapping(value="spring")
  public class SpringController {
  
      @RequestMapping(value="index")
      public ModelAndView index() {
          ModelAndView mav = new ModelAndView();
          mav.setViewName("index");
          return mav;
      }
  
      @RequestMapping(value="home")
      public ModelAndView home() {
          ModelAndView mav = new ModelAndView();
          mav.setViewName("home");
          return mav;
      }
  
      @RequestMapping(value="doLogin", method=RequestMethod.POST)
      public void doLogin(HttpServletRequest request, HttpServletResponse response) {
          //
      }
  
      @RequestMapping(value="logout")
      public void logout(HttpServletRequest request, HttpServletResponse response) throws IOException {
          request.getSession().invalidate();
          response.sendRedirect(request.getContextPath());
      }
  
  }
  </code></pre>
  
  <p>What I am doing wrong?</p>
  
  <p>-->Still related to topic above:</p>
  
  <p>I need implement this 'loginProcessingUrl', which is mapped in my controller this way:</p>
  
  <pre><code>@RequestMapping(value="doLogin", method=RequestMethod.POST)
  public void doLogin(HttpServletRequest request, HttpServletResponse response) {
      //
  }
  </code></pre>
  
  <p>I already have in my application two classes which, according to the articles I read, will be necessary for this process, but I could be wrong and maybe i need  another approach:</p>
  
  <p><strong>SampleAuthenticationManager</strong></p>
  
  <pre><code>public class SampleAuthenticationManager implements AuthenticationManager {
    static final List&lt;GrantedAuthority&gt; AUTHORITIES = new ArrayList&lt;GrantedAuthority&gt;();
  
    static
    {
      AUTHORITIES.add(new SimpleGrantedAuthority("ROLE_USER"));
    }
  
    public Authentication authenticate(Authentication auth) throws AuthenticationException
    {
      if (auth.getName().equals(auth.getCredentials()))
      {
          return new UsernamePasswordAuthenticationToken(auth.getName(), auth.getCredentials(), AUTHORITIES);
      }
      throw new BadCredentialsException("Bad Credentials");
    }
  
  }
  </code></pre>
  
  <p><strong>DefaultAuthenticationProcessingFilter</strong></p>
  
  <pre><code>    public class DefaultAuthenticationProcessingFilter extends AbstractAuthenticationProcessingFilter {
  
      private static final String INTERCEPTOR_PROCESS_URL = "/spring/doLogin";
  
      private static AuthenticationManager am = new SampleAuthenticationManager();
  
      protected DefaultAuthenticationProcessingFilter() {
          super(INTERCEPTOR_PROCESS_URL);
          // TODO Auto-generated constructor stub
      }
  
      @Override
      public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response) throws AuthenticationException, IOException, ServletException {
          // TODO Auto-generated method stub
  
          String login = request.getParameter("login");
          String senha = request.getParameter("senha");
  
          Authentication input = new UsernamePasswordAuthenticationToken(login, senha);
          Authentication output = null;
          try {
              output = am.authenticate(input);
              SecurityContextHolder.getContext().setAuthentication(output);
              getSuccessHandler().onAuthenticationSuccess(request, response, output);
          } catch (AuthenticationException failed) {
              getFailureHandler().onAuthenticationFailure(request, response, failed);
          }
  
          return output;
      }
  
  }
  </code></pre>
  
  <p>In this scenario, how I should implement the method doLogin from my controller? Take in consideration that in this moment I am using inMemory authentication, for later extend my project for use a database.</p>