Here my ShiroConfig.java file:
@Configuration
public class ShiroConfig {
@Bean
public PasswordService passwordService() {
return new HmacSha1PasswordService();
}
@Bean
public PasswordMatcher passwordMatcher(PasswordService passwordService) {
PasswordMatcher passwordMatcher = new PasswordMatcher();
passwordMatcher.setPasswordService(passwordService);
return passwordMatcher;
}
@Bean
@Qualifier("countly")
@Primary
public Realm countlyRealm(PasswordMatcher passwordMatcher) {
CountlyRealm realm = new CountlyRealm();
realm.setCredentialsMatcher(passwordMatcher);
return realm;
}
@Bean
@Qualifier("mock")
public Realm mockRealm() {
return new MockRealm();
}
@Bean
public DefaultWebSecurityManager securityManager(Realm realm) {
DefaultWebSecurityManager securityManager = new
DefaultWebSecurityManager();
securityManager.setRealm(realm);
return securityManager;
}
@Bean(name = "test")
public TestFilter testFilter() {
return new TestFilter();
}
@Bean
public ShiroFilterChainDefinition shiroFilterChainDefinition() {
DefaultShiroFilterChainDefinition
shiroFilterChainDefinition =
new DefaultShiroFilterChainDefinition();
shiroFilterChainDefinition.addPathDefinition("/api/**", "test");
return shiroFilterChainDefinition;
}
}
When starting using `mvn spring-boot:run` I get the following exception:
Caused by: java.lang.IllegalArgumentException: There is no filter with name
'test' to apply to chain [/api/**] in the pool of available Filters.
Ensure a filter with that name/path has first been registered with the
addFilter method(s).
On Thu, Apr 27, 2017 at 12:45 AM Brian Demers <[email protected]>
wrote:
> Any filter you create should be available by name.
>
> https://shiro.apache.org/static/current/apidocs/org/apache/shiro/spring/web/ShiroFilterFactoryBean.html
>
> something like this should work:
>
> @Bean
> public Filter test() {
> return new MyFilter();
> }
>
> On Wed, Apr 26, 2017 at 12:00 PM, Rui Tang <[email protected]> wrote:
>
> > I'm using shiro-spring-boot package, and I want to use my own filter
> > instead of the default filters.
> >
> > For example, I have a TestFilter which extends from AccessControlFilter,
> > and I want to register this filter as name "test" and use the "test" name
> > when defining filter chain.
> >
> > But I've tried a lot of ways to register this filter but without
> accessed,
> > please give me some tips.
> >
> > Thank you!
> >
>