Shiro 放行静态资源,以及失效的一些解决方法

Shiro 放行静态资源,以及失效的一些解决方法

通常我们习惯将静态资源放在resource的static文件夹下面。

在配置文件中,如果把static放行了还是行不通,可以尝试将其他静态文件添加进去。

可是!!尽管这样,还是有一些资源还是被拦截。我就因为这个问题耽误了太多时间了(心碎)。

后面查询资料发现原因在于hashmap是无序的,故这里最好用有序的——

LinkedHashMap

(如图所示)

 //1. Create shiroFilter , Responsible for intercepting all requests
    @Bean
    public ShiroFilterFactoryBean getShiroFilterFactoryBean(DefaultWebSecurityManager defaultWebSecurityManager){
        ShiroFilterFactoryBean shiroFilterFactoryBean = new ShiroFilterFactoryBean();

        //Set a security manager for the filter
        shiroFilterFactoryBean.setSecurityManager(defaultWebSecurityManager);

        //Configure system limited resources , Configure system public resources
        Map<String,String> map = new LinkedHashMap<>();

        map.put("/static/**","anon");
        map.put("/js/**","anon");   // anon  Set as a public resource
        map.put("/css/**","anon");   // anon  Set as a public resource
        map.put("/bootstrap/**/**","anon");   // anon  Set as a public resource
        map.put("/images/**","anon");   // anon  Set as a public resource
        map.put("/layui/**","anon");   // anon  Set as a public resource
        map.put("/index.html","anon");   // anon  Set as a public resource
        map.put("/login.html","anon");   // anon  Set as a public resource
        map.put("/user/index","anon");    // anon  Set as a public resource
        map.put("/user/login","anon");      // anon  Set as a public resource  // anon  Set as a public resource
        map.put("/user/getImage","anon");   // anon  Set as a public resource
        map.put("/**","authc"); // authc Indicates that the request for this resource requires authentication and authorization

        //Default authentication interface path
        shiroFilterFactoryBean.setLoginUrl("/user/loginview");

        shiroFilterFactoryBean.setFilterChainDefinitionMap(map);

        return shiroFilterFactoryBean;
    }

那前端应该怎么写静态资源的路径嘞,这边贴出一部分代码,仅供参考(有时候前端接收访问不到资源可能就是一个“ / ”没写,害)

    <script src="/js/jquery-3.0.0.min.js"></script>
    <script src="/bootstrap/js/bootstrap.js"></script>

你可能感兴趣的:(后端,java,shiro,后端)