org.apache.shiro.web.filter.mgt.PathMatchingFilterChainResolver Java Examples

The following examples show how to use org.apache.shiro.web.filter.mgt.PathMatchingFilterChainResolver. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MyShiroFilterFactoryBean.java    From springboot-shiro-cas-mybatis with MIT License 6 votes vote down vote up
@Override
protected AbstractShiroFilter createInstance() throws Exception {
	SecurityManager securityManager = getSecurityManager();
	if (securityManager == null){
		throw new BeanInitializationException("SecurityManager property must be set.");
	}

	if (!(securityManager instanceof WebSecurityManager)){
		throw new BeanInitializationException("The security manager does not implement the WebSecurityManager interface.");
	}

	PathMatchingFilterChainResolver chainResolver = new PathMatchingFilterChainResolver();
	FilterChainManager chainManager = createFilterChainManager();
	chainResolver.setFilterChainManager(chainManager);
	return new MySpringShiroFilter((WebSecurityManager)securityManager, chainResolver);
}
 
Example #2
Source File: WebSecurityModule.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected void configureShiroWeb() {
  bindRealm().to(EmptyRealm.class); // not used in practice, just here to keep Shiro module happy

  bindSingleton(SessionFactory.class, NexusSessionFactory.class);
  bindSingleton(SessionStorageEvaluator.class, NexusSessionStorageEvaluator.class);
  bindSingleton(SubjectDAO.class, NexusSubjectDAO.class);

  // configure our preferred security components
  bindSingleton(SessionDAO.class, NexusSessionDAO.class);
  bindSingleton(Authenticator.class, FirstSuccessfulModularRealmAuthenticator.class);
  bindSingleton(Authorizer.class, ExceptionCatchingModularRealmAuthorizer.class);
  bindSingleton(FilterChainManager.class, DynamicFilterChainManager.class);

  // path matching resolver has several constructors so we need to point Guice to the appropriate one
  bind(FilterChainResolver.class).toConstructor(ctor(PathMatchingFilterChainResolver.class)).asEagerSingleton();

  // bindings used by external modules
  expose(FilterChainResolver.class);
  expose(FilterChainManager.class);
}
 
Example #3
Source File: MyShiroFilterFactoryBean.java    From springboot-shiro-cas-mybatis with MIT License 5 votes vote down vote up
public MySpringShiroFilter(
		WebSecurityManager securityManager, PathMatchingFilterChainResolver chainResolver) {
	super();
	if (securityManager == null){
		throw new IllegalArgumentException("WebSecurityManager property cannot be null.");
	}
	setSecurityManager(securityManager);
	if (chainResolver != null){
		setFilterChainResolver(chainResolver);
	}
}
 
Example #4
Source File: ShiroConfigService.java    From layui-admin with MIT License 5 votes vote down vote up
/**
 * 更新权限,解决需要重启tomcat才能生效权限的问题
 */
public void updatePermission() {
    try {
        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
        ServletContext servletContext = request.getSession().getServletContext();
        AbstractShiroFilter shiroFilter = (AbstractShiroFilter) WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext).getBean("myShiroFilter");

        synchronized (shiroFilter) {
            // 获取过滤管理器
            PathMatchingFilterChainResolver filterChainResolver = (PathMatchingFilterChainResolver) shiroFilter.getFilterChainResolver();
            DefaultFilterChainManager manager = (DefaultFilterChainManager) filterChainResolver.getFilterChainManager();
            // 清空初始权限配置
            manager.getFilterChains().clear();
            // 重新获取资源
            Map<String, String> chains = loadFilterChainDefinitions();

            for (Map.Entry<String, String> entry : chains.entrySet()) {
                String url = entry.getKey();
                String chainDefinition = entry.getValue().trim().replace(" ", "");

                manager.createChain(url, chainDefinition);
            }
            log.info("更新权限成功!!");
        }
    } catch (Exception e) {
        log.error("更新权限到shiro异常", e);
    }
}