I am trying to refactor my Spring MVC xml based project configurations to Spring Boot java based configurations. While setting up shiro configurations as follows:
@Configuration
public class ShiroConfig {
@Bean
public Realm realm() {
JdbcRealm myRealm = new JdbcRealm();
myRealm.setCredentialsMatcher(sha256Matcher());
myRealm.setPermissionsLookupEnabled(true);
myRealm.setSaltStyle(JdbcRealm.SaltStyle.COLUMN);
return myRealm;
}
@Bean
public HashedCredentialsMatcher sha256Matcher() {
HashedCredentialsMatcher sha256Matcher = new HashedCredentialsMatcher();
sha256Matcher.setHashAlgorithmName("SHA-256");
return sha256Matcher;
}
@Bean
public LifecycleBeanPostProcessor lifecycleBeanPostProcessor() {
return new LifecycleBeanPostProcessor();
}
@Bean
public CacheManager cacheManager() {
return new MemoryConstrainedCacheManager();
}
@Bean
public Filter jwtv() {
return new JWTVerifyingFilter();
}
@Bean
public Filter ljwtv() {
return new LimitedAccessJWTVerifyingFilter();
}
@Bean
public Filter logout() {
LogoutFilter logoutFilter = new LogoutFilter();
logoutFilter.setRedirectUrl("/login.jsp");
return logoutFilter;
}
@Bean
public ShiroFilterChainDefinition shiroFilterChainDefinition() {
DefaultShiroFilterChainDefinition chainDefinition = new DefaultShiroFilterChainDefinition();
chainDefinition.addPathDefinition("/login", "authc");
chainDefinition.addPathDefinition("/logout", "logout");
chainDefinition.addPathDefinition("/my/test/**", "anon");
chainDefinition.addPathDefinition("/my/xyz/**/abc", "ljwtv"); chainDefinition.addPathDefinition("/my/xyz/**/mno", "ljwtv");
chainDefinition.addPathDefinition("/my/**", "jwtv");
return chainDefinition;
}
}
I am encountering the following error:
Error starting Tomcat context. Exception: org.springframework.beans.factory.BeanCreationException. Message: Error creating bean with name 'filterShiroFilterRegistrationBean' defined in class path resource [org/apache/shiro/spring/config/web/autoconfigure/ShiroWebFilterConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.web.servlet.FilterRegistrationBean]: Factory method 'filterShiroFilterRegistrationBean' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'shiroFilterFactoryBean': FactoryBean threw exception on object creation; nested exception is java.lang.IllegalArgumentException: There is no filter with name 'jwtv' to apply to chain [/my/**] in the pool of available Filters. Ensure a filter with that name/path has first been registered with the addFilter method(s).
The custom filer JWTVerifyingFilter is a @Component that extends org.apache.shiro.web.filter.AccessControlFilter. Don't know what I am missing, it all works with the xml configuration. Please Help.