title: Spring boot redirect loop
body: <p>This project can be run in two ways to start: first,use the run debug Main.java: debug start, and then redirect loop;Second, debug by spring boot run  commandrun (use the spring-boot-maven-plugin startup),but no redirection loop. The environment is those:spring-boot-starter-parent ：1.2.3.RELEASE. How the whole?</p>
  
  <pre><code> /*--------- FreeMarker Configuration -------**/    
  
  @Bean
  public FreeMarkerConfigurer freeMarkerConfigurer() {
      FreeMarkerConfigurer fmc = new FreeMarkerConfigurer();
      fmc.setPreferFileSystemAccess(false);
      fmc.setTemplateLoaderPath("/WEB-INF/templates");
  
      Map&lt;String, Object&gt; variables = new HashMap&lt;String, Object&gt;();
      variables.put("base", contextPath);
      fmc.setFreemarkerVariables(variables);
  
      Properties settings = new Properties();
      settings.put("defaultEncoding","UTF-8");
      fmc.setFreemarkerSettings(settings);
      return fmc;
  }
  
  @Bean
  public FreeMarkerViewResolver freeMarkerViewResolver() {
      FreeMarkerViewResolver fvr = new FreeMarkerViewResolver();
      fvr.setCache(false);
      fvr.setPrefix("");
      fvr.setSuffix(".ftl");
      fvr.setContentType("text/html;charset=UTF-8");
      return fvr;
  }
  
  /*--------- Shiro  Configuration -------**/
  
  private static Map&lt;String, String&gt; filterChainDefinitionMap = new LinkedHashMap&lt;String, String&gt;();
  
  @Bean(name = "ShiroRealmImpl")
  public ShiroDatabaseRealm getShiroRealm() {
      return new ShiroDatabaseRealm();
  }
  
  @Bean(name = "securityManager")
  public DefaultWebSecurityManager getDefaultWebSecurityManager() {
      DefaultWebSecurityManager dwsm = new DefaultWebSecurityManager();
      dwsm.setRealm(getShiroRealm());
      dwsm.setCacheManager(getEhCacheManager());
      return dwsm;
  }
  
  @Bean(name = "shiroEhcacheManager")
  public EhCacheManager getEhCacheManager() {
      EhCacheManager em = new EhCacheManager();
      em.setCacheManagerConfigFile("classpath:ehcache-shiro.xml");
      return em;
  }
  
  @Bean(name = "lifecycleBeanPostProcessor")
  public LifecycleBeanPostProcessor getLifecycleBeanPostProcessor() {
      return new LifecycleBeanPostProcessor();
  }
  
  /**
   * 
   * @return
   */
  @Bean
  public AuthorizationAttributeSourceAdvisor getAuthorizationAttributeSourceAdvisor() {
      AuthorizationAttributeSourceAdvisor aasa = new AuthorizationAttributeSourceAdvisor();
      aasa.setSecurityManager(getDefaultWebSecurityManager());
      return new AuthorizationAttributeSourceAdvisor();
  }
  
  @Bean(name = "shiroFilter")
  public ShiroFilterFactoryBean shiroFilter() {
      ShiroFilterFactoryBean shiroFilterFactoryBean = new ShiroFilterFactoryBean();
      shiroFilterFactoryBean.setSecurityManager(getDefaultWebSecurityManager());
      shiroFilterFactoryBean.setLoginUrl("/initlogin");
      shiroFilterFactoryBean.setUnauthorizedUrl("/login.jhtml");
      shiroFilterFactoryBean.setSuccessUrl("/admin/common/main");
      filterChainDefinitionMap.put("/admin/**", "authc");
      filterChainDefinitionMap.put("/api/**", "anon");
      shiroFilterFactoryBean.setFilterChainDefinitionMap(filterChainDefinitionMap);
      return shiroFilterFactoryBean;
  }
  
  
  
  /*--------- Mapping Handler -------**/
  
  @RequestMapping(value={"/"})
  private String home(){
          return "redirect:/admin/common/main";
  }
  
  
  @RequestMapping(value={"/admin/common/main"}, method={RequestMethod.GET,RequestMethod.POST})
  private String main(){
      return "/admin/common/main";//main.ftl
  }
  
  @RequestMapping("/initlogin")
  public String login(ModelMap model,HttpServletRequest request) {
      boolean isAuth = SecurityUtils.getSubject().isAuthenticated();
      if(isAuth){
          return "redirect:/admin/common/main.jhtml";
      }
      return "login";
  }
  
  @RequestMapping(value={"/login"}, method={RequestMethod.GET,RequestMethod.POST})
  public String login(String username,String password,ModelMap model){
      boolean isAuth = SecurityUtils.getSubject().isAuthenticated();
      if(!isAuth){//
          String errorMsg = null;
          try{
              if(StringUtils.isEmpty(username) || StringUtils.isEmpty(password)){
                  errorMsg = "admin.login.incorrectCredentials";
                  model.addAttribute("msg", ApplicationSupport.getMessageByEnv(errorMsg));
              }else{
                  UsernamePasswordToken token = new UsernamePasswordToken(username,DigestUtils.md5Hex(password));
                  if (token!=null)
                      SecurityUtils.getSubject().login(token);
              }
          }catch(Exception e){
              return "login";
          }
          return "login";// I want to go redirect to login.ftl
      }
      //redirect to main.ftl  
      return "redirect:/admin/common/main.jhtml";
  }
  </code></pre>