开发者社区> 问答> 正文

shiro 动态更新权限配置:报错

求教,代码执行了,配置也写进去了,但是拦截没生效,


public void updatePermission() {
		synchronized (shiroFilterFactoryBean) {
			AbstractShiroFilter shiroFilter = null;
			try {
				shiroFilter = (AbstractShiroFilter) shiroFilterFactoryBean.getObject();

				// 获取过滤管理器
				PathMatchingFilterChainResolver filterChainResolver = (PathMatchingFilterChainResolver) shiroFilter.getFilterChainResolver();
				DefaultFilterChainManager manager = (DefaultFilterChainManager) filterChainResolver.getFilterChainManager();

				// 清空初始权限配置
				manager.getFilterChains().clear();
				shiroFilterFactoryBean.getFilterChainDefinitionMap().clear();

				// 重新构建生成
				shiroFilterFactoryBean.setFilterChainDefinitionMap(obtainPermission());

				Map<String, String> chains = shiroFilterFactoryBean.getFilterChainDefinitionMap();
				for (Map.Entry<String, String> entry : chains.entrySet()) {
					manager.createChain(entry.getKey(), entry.getValue().trim().replace(" ", ""));
					System.err.println(entry.toString());
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}



展开
收起
kun坤 2020-06-20 13:29:05 1074 0
1 条回答
写回答
取消 提交回答
  •  manager.getFilterChains().clear(); 
     shiroFilterFactoryBean.getFilterChainDefinitionMap().clear();   // 重新构建生成 // 
     shiroFilterFactoryBean.setFilterChainDefinitions(definitions);  
    shiroFilterFactoryBean.setFilterChainDefinitionMap(initOtherPermission()); 
     Map<String, String> chains = shiroFilterFactoryBean.getFilterChainDefinitionMap(); 

    重构的时候已经清空了初始化的权限配置所以需要加载一下初始化权限

    shiroFilterFactoryBean.setFilterChainDefinitionMap(initOtherPermission()); 

    2020-06-20 13:29:12
    赞同 展开评论 打赏
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载