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>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值