use of org.apache.shiro.web.servlet.AbstractShiroFilter in project dq-easy-cloud by dq-open-cloud.
the class EcAuthorityManager method doUpdateFilterChains.
/**
* <p>
* 执行更新过滤器链
* </p>
*
* @param filterChainDefinitionMap
* @return void
* @author daiqi
* @date 2018/6/27 13:00
*/
private void doUpdateFilterChains(Map<String, String> filterChainDefinitionMap) {
AbstractShiroFilter shiroFilter;
try {
shiroFilter = (AbstractShiroFilter) shiroFilterFactoryBean.getObject();
} catch (Exception e) {
throw new RuntimeException(e.getMessage(), e);
}
PathMatchingFilterChainResolver filterChainResolver = (PathMatchingFilterChainResolver) shiroFilter.getFilterChainResolver();
DefaultFilterChainManager manager = (DefaultFilterChainManager) filterChainResolver.getFilterChainManager();
// 清空老的过滤器链
manager.getFilterChains().clear();
shiroFilterFactoryBean.getFilterChainDefinitionMap().clear();
shiroFilterFactoryBean.setFilterChainDefinitionMap(filterChainDefinitionMap);
// 重新构建生成
Map<String, String> chains = shiroFilterFactoryBean.getFilterChainDefinitionMap();
for (Map.Entry<String, String> entry : chains.entrySet()) {
String url = entry.getKey();
String chainDefinition = entry.getValue().trim().replace(" ", "");
manager.createChain(url, chainDefinition);
}
}
use of org.apache.shiro.web.servlet.AbstractShiroFilter in project dropwizard-shiro by silb.
the class ShiroBundle method createFilter.
/**
* Create the Shiro filter. Overriding this method allows for complete customization of how Shiro is initialized.
*/
protected Filter createFilter(final T configuration) {
ShiroConfiguration shiroConfig = narrow(configuration);
final IniWebEnvironment shiroEnv = new IniWebEnvironment();
shiroEnv.setConfigLocations(shiroConfig.iniConfigs());
shiroEnv.init();
AbstractShiroFilter shiroFilter = new AbstractShiroFilter() {
@Override
public void init() throws Exception {
Collection<Realm> realms = createRealms(configuration);
WebSecurityManager securityManager = realms.isEmpty() ? shiroEnv.getWebSecurityManager() : new DefaultWebSecurityManager(realms);
setSecurityManager(securityManager);
setFilterChainResolver(shiroEnv.getFilterChainResolver());
}
};
return shiroFilter;
}
use of org.apache.shiro.web.servlet.AbstractShiroFilter in project shiro by apache.
the class ShiroFilterFactoryBeanTest method testFilterDefinitionWithInit.
/**
* Verifies fix for <a href="https://issues.apache.org/jira/browse/SHIRO-167">SHIRO-167</a>
*
* @throws Exception if there is any unexpected error
*/
@Test
public void testFilterDefinitionWithInit() throws Exception {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("org/apache/shiro/spring/web/ShiroFilterFactoryBeanTest.xml");
AbstractShiroFilter shiroFilter = (AbstractShiroFilter) context.getBean("shiroFilter");
FilterConfig mockFilterConfig = createNiceMock(FilterConfig.class);
ServletContext mockServletContext = createNiceMock(ServletContext.class);
expect(mockFilterConfig.getServletContext()).andReturn(mockServletContext).anyTimes();
HttpServletRequest mockRequest = createNiceMock(HttpServletRequest.class);
expect(mockRequest.getContextPath()).andReturn("/").anyTimes();
expect(mockRequest.getRequestURI()).andReturn("/").anyTimes();
HttpServletResponse mockResponse = createNiceMock(HttpServletResponse.class);
replay(mockFilterConfig);
replay(mockServletContext);
shiroFilter.init(mockFilterConfig);
verify(mockServletContext);
verify(mockFilterConfig);
FilterChain filterChain = new FilterChain() {
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse) throws IOException, ServletException {
HttpServletRequest request = (HttpServletRequest) servletRequest;
assertNotNull(request.getSession());
// this line asserts the fix for the user-reported issue:
assertNotNull(request.getSession().getServletContext());
}
};
replay(mockRequest);
replay(mockResponse);
shiroFilter.doFilter(mockRequest, mockResponse, filterChain);
verify(mockResponse);
verify(mockRequest);
}
use of org.apache.shiro.web.servlet.AbstractShiroFilter in project shiro by apache.
the class ShiroFilterFactoryBeanTest method testFilterDefinition.
@Test
public void testFilterDefinition() {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("org/apache/shiro/spring/web/ShiroFilterFactoryBeanTest.xml");
AbstractShiroFilter shiroFilter = (AbstractShiroFilter) context.getBean("shiroFilter");
PathMatchingFilterChainResolver resolver = (PathMatchingFilterChainResolver) shiroFilter.getFilterChainResolver();
DefaultFilterChainManager fcManager = (DefaultFilterChainManager) resolver.getFilterChainManager();
NamedFilterList chain = fcManager.getChain("/test");
assertNotNull(chain);
assertEquals(chain.size(), 2);
Filter[] filters = new Filter[chain.size()];
filters = chain.toArray(filters);
assertTrue(filters[0] instanceof DummyFilter);
assertTrue(filters[1] instanceof FormAuthenticationFilter);
}
Aggregations