Using apache Shiro with Spring MVC non xml project

I have a project where I am using Spring mvc 4 and I need to enable apache siro security there. I tried to search online for a solution for my problem, but I was unable to pay anything. Although the Shiro website has a manual, but this example is only for a Spring project configured for xml, and my project does not contain any xml at all, and when I try to configure Shiro with annotation, it only fails. When I run this project, I have access to all my endpoints and they are not restricted by Shiro. I am assuming my configuration is wrong, but I cannot figure out which part is wrong. I am not allowed to use Spring boot (I know there are examples for this). here is my config class:

@Configuration
@EnableWebMvc
@ComponentScan(basePackages = "com.myproject.menu")
public class AppConfiguration extends WebMvcConfigurerAdapter{


@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
    registry.addResourceHandler("/**").addResourceLocations("/");
}

@Bean(name="shiroFilter")
public ShiroFilterFactoryBean shiroFilter (){
    ShiroFilterFactoryBean shiroFilter = new ShiroFilterFactoryBean();
    shiroFilter.setLoginUrl("/MenuTest/login");
    shiroFilter.setFilterChainDefinitions("/MenuTest/init=anon");
    shiroFilter.setFilterChainDefinitions("/MenuTest/**=authc");
    shiroFilter.setSecurityManager(realm());
    return shiroFilter;
}

private DefaultWebSecurityManager realm(){
    DefaultWebSecurityManager realm = new DefaultWebSecurityManager();
    return realm;
}
}

      

thanks in advance!

+3


source to share


1 answer


Take a look at version 1.4.0 (RC2). Updated support for Spring and Spring-Boot.



And examples in the source tree: https://github.com/apache/shiro/tree/master/samples/spring-mvc

0


source







All Articles