本文整理汇总了Java中org.apache.shiro.web.servlet.AbstractShiroFilter类的典型用法代码示例。如果您正苦于以下问题:Java AbstractShiroFilter类的具体用法?Java AbstractShiroFilter怎么用?Java AbstractShiroFilter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AbstractShiroFilter类属于org.apache.shiro.web.servlet包,在下文中一共展示了AbstractShiroFilter类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createInstance
import org.apache.shiro.web.servlet.AbstractShiroFilter; //导入依赖的package包/类
@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);
}
示例2: setUp
import org.apache.shiro.web.servlet.AbstractShiroFilter; //导入依赖的package包/类
@Before
public void setUp() throws ServletException {
TokenFilter tokenFilter = (TokenFilter) wac.getBean("tokenFilter");
mockMvc = MockMvcBuilders.webAppContextSetup(wac).alwaysDo(print()) // 默认每次执行请求后都做的动作
// 这里不加shiro过滤器的话testAuth最后获取用户信息不会被过滤,尽管配置文件中有配置
// 但是如果是添加
// AbstractShiroFilter shiroFilter = (AbstractShiroFilter)
// wac.getBean("shiroFilter");这个过滤器的话
// 控制器里的@RequiresPermissions注解要去掉,否则抛异常.貌似ShiroTestUtils没起作用,运行过程中的DelegatingSubject和模拟的不是一个
// http://stackoverflow.com/questions/22152530/spring-end-to-end-test-including-filters-and-controller-method-using-mockhttpser
.addFilter(tokenFilter, "/users/1").build();
User user = new User();
user.setUsername("root");
user.setLocked(false);
ShiroTestUtils.mockCurrentUser(user, true);
// 没有没有下面这几句,tokenfilter也不会工作
AbstractShiroFilter shiroFilter = (AbstractShiroFilter) wac.getBean("shiroFilter");
FilterConfig mockFilterConfig = mock(FilterConfig.class);
shiroFilter.init(mockFilterConfig);
}
示例3: createFilter
import org.apache.shiro.web.servlet.AbstractShiroFilter; //导入依赖的package包/类
/**
* 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;
}
示例4: testFilter
import org.apache.shiro.web.servlet.AbstractShiroFilter; //导入依赖的package包/类
@Test
public void testFilter() {
AbstractShiroFilter shiroFilter = (AbstractShiroFilter) wac.getBean("shiroFilter");
PathMatchingFilterChainResolver resolver = (PathMatchingFilterChainResolver) shiroFilter
.getFilterChainResolver();
DefaultFilterChainManager fcManager = (DefaultFilterChainManager) resolver.getFilterChainManager();
NamedFilterList chain = fcManager.getChain("/users/**");
assertNotNull(chain);
assertEquals(chain.size(), 2);
Filter[] filters = new Filter[chain.size()];
filters = chain.toArray(filters);
assertTrue(filters[1] instanceof TokenFilter);
}
示例5: disableRegistrationShiroFilter
import org.apache.shiro.web.servlet.AbstractShiroFilter; //导入依赖的package包/类
/**
* 取消 Shiro Filter 的/*自动注册行为
* @param filter
* @return
*/
@Bean
public FilterRegistrationBean disableRegistrationShiroFilter(AbstractShiroFilter filter) {
FilterRegistrationBean registration = new FilterRegistrationBean(filter);
registration.setEnabled(false);
return registration;
}
示例6: createDelegateFilter
import org.apache.shiro.web.servlet.AbstractShiroFilter; //导入依赖的package包/类
protected Filter createDelegateFilter() {
return (Filter) applicationContext.getBean(AbstractShiroFilter.class);
}
示例7: setUp
import org.apache.shiro.web.servlet.AbstractShiroFilter; //导入依赖的package包/类
@Before
public void setUp() throws ServletException {
AbstractShiroFilter shiroFilter = (AbstractShiroFilter) wac.getBean("shiroFilter");
mockMvc = MockMvcBuilders.webAppContextSetup(wac).alwaysDo(print()) // 默认每次执行请求后都做的动作
.addFilter(shiroFilter, "/*").build();
}