title: Spring security redirection after login
body: <p>After successfull login, it doesn't redirects to "index.php". It redirects same page which is "login.php". Is there something wrong with my spring-security.xml page?</p>
  
  <p>By the way when I run the application it redirects me to "login.php" which is good. But It doesn't shows primefaces components but html components. After I succesfully login, It redirects the same page but this time It shows Primefaces components instead of html components.</p>
  
  <pre><code>&lt;beans:beans xmlns="http://www.springframework.org/schema/security"
           xmlns:beans="http://www.springframework.org/schema/beans" 
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://www.springframework.org/schema/beans
  http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
  http://www.springframework.org/schema/security
  http://www.springframework.org/schema/security/spring-security-3.1.xsd"&gt;
  
  &lt;http auto-config="true" use-expressions="true"&gt;
      &lt;intercept-url pattern="/pages/login.xhtml*" access="permitAll"/&gt;
      &lt;intercept-url pattern="/**" access="hasRole('admin')" /&gt;
      &lt;form-login login-page='/pages/login.xhtml' default-target-url="/pages/index.xhtml"                    
                  authentication-failure-url="/pages/login.xhtml"/&gt;
      &lt;logout logout-success-url="/pages/logout.xhtml" /&gt;
  
  &lt;/http&gt;
  &lt;!--Authentication Manager Details --&gt;    
  &lt;authentication-manager alias="authenticationManager"&gt;
      &lt;authentication-provider user-service-ref="customUserDetailsService"&gt;
  &lt;!--            &lt;password-encoder hash="md5"/&gt;--&gt;
      &lt;/authentication-provider&gt;
  &lt;/authentication-manager&gt;
  </code></pre>
  
  <p></p>
  
  <p>my web.xml</p>
  
  <pre><code>&lt;welcome-file-list&gt;
      &lt;welcome-file&gt;pages/index.xhtml&lt;/welcome-file&gt;
  &lt;/welcome-file-list&gt;
  </code></pre>
  
  <p>my login page</p>
  
  <pre><code>&lt;p:outputPanel id="loginOutputPanelId" style="border: navy"&gt;
                          &lt;p:panelGrid id="loginInformationPanel" columns="2"&gt;
                              &lt;h:outputText value="Username: "/&gt;
                              &lt;p:inputText value="#{loginController.userName}"/&gt;
                              &lt;h:outputText value="Password: "/&gt;
                              &lt;p:inputText value="#{loginController.password}"/&gt;
                          &lt;/p:panelGrid&gt;
                          &lt;p:commandButton value="Login" actionListener="#{loginController.login()}"/&gt;
                      &lt;/p:outputPanel&gt;
  </code></pre>
  
  <p>my loginController.login() method returns "index" string and my faces.config;</p>
  
  <pre><code>&lt;navigation-rule&gt;
          &lt;from-view-id&gt;/pages/login.xhtml&lt;/from-view-id&gt;
          &lt;navigation-case&gt;
              &lt;from-outcome&gt;index&lt;/from-outcome&gt;
              &lt;to-view-id&gt;/pages/index.xhtml&lt;/to-view-id&gt;
              &lt;redirect /&gt;
          &lt;/navigation-case&gt;
      &lt;/navigation-rule&gt;
  </code></pre>
  
  <p><strong>EDIT:</strong> 
  without  component it runs without any problem. When i add form-login it says "The webpage at <code>http://localhost:8080/myApplication/pages/login.xhtml</code> has resulted in too many redirects".</p>
  
  <pre><code>&lt;http auto-config='true' use-expressions="true"&gt;
  &lt;intercept-url pattern="/**" access="hasRole('admin')" /&gt;
  &lt;logout logout-success-url="/pages/logout.xhtml" /&gt;
  &lt;form-login login-page="/pages/login.xhtml"
                  login-processing-url="/j_spring_security_check"                                                       
                  default-target-url="/pages/index.xhtml"                                                        
                  authentication-failure-url="/pages/login.xhtml"/&gt;
  &lt;/http&gt;
  </code></pre>
  
  <p>My login page </p>
  
  <pre><code>&lt;p:outputPanel id="loginOutputPanelId" style="border: navy"&gt;
                          &lt;p:panelGrid id="loginInformationPanel" columns="2"&gt;
                              &lt;h:outputText value="Kullanıcı Adı: "/&gt;
                              &lt;p:inputText id="j_username" required="true" value="#{loginController.userName}"/&gt;
                              &lt;h:outputText value="Şifre: "/&gt;
                              &lt;p:inputText id="j_password" required="true" value="#{loginController.password}"/&gt;
                          &lt;/p:panelGrid&gt;
                          &lt;p:commandButton id="login" type="submit" ajax="false" value="Login" actionListener="#{loginController.login()}"/&gt;
                      &lt;/p:outputPanel&gt;
  </code></pre>
  
  <p>My new loginController.login() method;</p>
  
  <pre><code>ExternalContext context = FacesContext.getCurrentInstance().getExternalContext();
  
          RequestDispatcher dispatcher = ((ServletRequest) context.getRequest())
           .getRequestDispatcher("/j_spring_security_check");
  
          dispatcher.forward((ServletRequest) context.getRequest(),
           (ServletResponse) context.getResponse());
  
          FacesContext.getCurrentInstance().responseComplete();
  </code></pre>