title: Why the "/index" redirect to the UnauthorizedUrl in shiro?
body: <p>I test the shiro with springboot,but no matter what urls like 127.0.0.1:8080/index are redirected to the the UnauthorizedUrl("/error");</p>
  
  <p>Here is my ShiroConfig:</p>
  
  <pre><code>@Configuration
  public class ShiroConfig {
  
      @Bean(name = "lifecycleBeanPostProcessor")
      public LifecycleBeanPostProcessor lifecycleBeanPostProcessor() {
          return new LifecycleBeanPostProcessor();
      }
  
      @Bean
      @DependsOn("lifecycleBeanPostProcessor")
      public MyShiroRealm myShiroRealm(){
          MyShiroRealm myShiroRealm = new MyShiroRealm();
          myShiroRealm.setCredentialsMatcher(hashedCredentialsMatcher());
          return myShiroRealm;
      }
  
      @Bean
      public HashedCredentialsMatcher hashedCredentialsMatcher(){
          HashedCredentialsMatcher hashedCredentialsMatcher = new HashedCredentialsMatcher();
          hashedCredentialsMatcher.setHashAlgorithmName("MD5");
          hashedCredentialsMatcher.setHashIterations(2);
          return hashedCredentialsMatcher;
      }
  
      @Bean
      public DefaultWebSecurityManager securityManager() {
          DefaultWebSecurityManager securityManager = new DefaultWebSecurityManager();
          securityManager.setRealm(myShiroRealm());
          //securityManager.setCacheManager(ehCacheManager());
          return securityManager;
      }
  
      @Bean
      public ShiroFilterFactoryBean shiroFilter() {
          ShiroFilterFactoryBean shiroFilterFactoryBean = new ShiroFilterFactoryBean();
          shiroFilterFactoryBean.setSecurityManager(securityManager());
  
          Map&lt;String,String&gt; filterChainDefinitionMap = new LinkedHashMap&lt;String,String&gt;();
          filterChainDefinitionMap.put("/index", "anon");
  
          filterChainDefinitionMap.put("/logout", "logout");
  
          filterChainDefinitionMap.put("/**", "authc");
  
          shiroFilterFactoryBean.setLoginUrl("/login");
  
          shiroFilterFactoryBean.setSuccessUrl("/welcome");
          //Unauthorized;
          shiroFilterFactoryBean.setUnauthorizedUrl("/error");        
          shiroFilterFactoryBean.setFilterChainDefinitionMap(filterChainDefinitionMap);       
          return shiroFilterFactoryBean;
      } 
  
      @Bean
      public AuthorizationAttributeSourceAdvisor authorizationAttributeSourceAdvisor(){
          AuthorizationAttributeSourceAdvisor authorizationAttributeSourceAdvisor = new AuthorizationAttributeSourceAdvisor();
          authorizationAttributeSourceAdvisor.setSecurityManager(securityManager());
          return authorizationAttributeSourceAdvisor;
      }
  
      @Bean
      @ConditionalOnMissingBean
      public DefaultAdvisorAutoProxyCreator defaultAdvisorAutoProxyCreator() {
          DefaultAdvisorAutoProxyCreator defaultAAP = new DefaultAdvisorAutoProxyCreator();
          defaultAAP.setProxyTargetClass(true);
          return defaultAAP;
      }
  
      @Bean
      public PassThruAuthenticationFilter passThruAuthenticationFilter(){
          return new PassThruAuthenticationFilter();
      }
  }
  </code></pre>
  
  <p>And  the Realm</p>
  
  <pre><code>public class MyShiroRealm extends AuthorizingRealm {
      private static final  Logger LOGGER = Logger.getLogger(MyShiroRealm.class);
      @Resource 
      UserService userService;
  
      @Override
      protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection) {
          LOGGER.info("AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection) : "+principalCollection);
          String principal=(String) principalCollection.getPrimaryPrincipal();
          LOGGER.info(principal);
          User user=(User) userService.findUserByName(principal);
          SimpleAuthorizationInfo info = new SimpleAuthorizationInfo();
          for(Role role:user.getRoles()){
              info.addRole(role.getName());
              for(Permission permission:role.getPermissions()){
                  info.addStringPermission(permission.getName());
              }
          }
          return info;
      }
  
      @Override
      protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken) throws AuthenticationException {
          LOGGER.info("AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken) : "+authenticationToken);
          String name=((UsernamePasswordToken)authenticationToken).getUsername();
          User user=userService.findUserByName(name);
          if (user != null) {
            Session session = SecurityUtils.getSubject().getSession();
            session.setAttribute("user", user);
            return new SimpleAuthenticationInfo(name,user.getPassword(),getName());
        } else {
            return null;
        }
      }
  }
  </code></pre>
  
  <p>Properties in application.properties</p>
  
  <pre><code>#thymeleaf
  spring.thymeleaf.cache=false
  
  #hibernate
  spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect
  
  spring.jpa.show-sql= true
  #html
  
  spring.mvc.view.prefix=/
  
  spring.mvc.view.suffix=.html
  </code></pre>
  
  <p>DB properties are not given. Tomcat's server port is 8080.</p>
  
  <p>The recources dir:
  <a href="https://i.stack.imgur.com/s6OY5.png" rel="nofollow noreferrer">dir of resource</a></p>
  
  <p>When I access the "127.0.0.1:8080/index" ,it redirects to the "error" page setted by </p>
  
  <pre><code>  shiroFilterFactoryBean.setUnauthorizedUrl("/error");.
  </code></pre>
  
  <p>when the "/login" Controller method is given it redirects to login page.</p>
  
  <p>I am so confused and cannot find a way to solve it.</p>
  
  <p>UPDATE </p>
  
  <p>After moving the index.html to templates dir and make a @RequestMapping("/index") method,I get the index in browser.(If the index.html is in the static dir, A @RequestMapping("/index") method don't work.)
  How could I get the static html ?</p>