0

i want to use apache-shiro to protect my URLs. so, i did this config

@Configuration
public class ApplicationConfigShiro {

    @Bean
    public ShiroFilterFactoryBean shiroFilter() {
        ShiroFilterFactoryBean factoryBean = new ShiroFilterFactoryBean();
        factoryBean.setSecurityManager(securityManager());
        return factoryBean;
    }

    // blah blah ...

    @Bean(name = "realm")
    @DependsOn("lifecycleBeanPostProcessor")
    public PropertiesRealm realm() {
        // blah blah
    }

    @Bean
    public LifecycleBeanPostProcessor lifecycleBeanPostProcessor() {
        return new LifecycleBeanPostProcessor();
    }

    @Bean
    @DependsOn("lifecycleBeanPostProcessor")
    public DefaultAdvisorAutoProxyCreator defaultAdvisorAutoProxyCreator() {
        return new DefaultAdvisorAutoProxyCreator();
    }

    @Bean
    public AuthorizationAttributeSourceAdvisor authorizationAttributeSourceAdvisor() {
        AuthorizationAttributeSourceAdvisor advisor = new AuthorizationAttributeSourceAdvisor();
        advisor.setSecurityManager(securityManager());
        return advisor;
    }
}

and here is my mvc-request-method

@Controller
@RequestMapping("/html")
public class HtmlController {

    @Resource
    private UserService userService;

    @RequestMapping(value = "/users", method = RequestMethod.GET)
    public ModelAndView listUsers() {
        List<User> users = userService.findAllUsers();
        ModelAndView modelAndView = new ModelAndView("users");
        modelAndView.addObject("users", users);
        return modelAndView;
    }

}

very thing is OK. and i start my project by mvn spring-boot:run. and check out http://localhost:8080/mappings the json result can tell me mapping /html/users is ready to use. i did check out the http://localhost:8080/html/users, it was fine.

BUT once i add shiro's annotations like @RequiresAuthentication to my request-mapping-method like this:

@RequiresAuthentication    // **I ADD THIS LINE**
@RequestMapping(value = "/users", method = RequestMethod.GET)
public ModelAndView listUsers() {
    List<User> users = userService.findAllUsers();
    ModelAndView modelAndView = new ModelAndView("users");
    modelAndView.addObject("users", users);
    return modelAndView;
}

re-run this project, re-check http://localhost:8080/mappings, the mapping /html/users is just GONE. try to access http://localhost:8080/html/users i got a 404 of course.

Did i miss something? Or this is a bug of spring?

Help me please. Sorry to give you a trouble.

git clone git@github.com:yingzhuo/spring-playground.git
cd spring-playground
mvn clean spring-boot:run
Zhuo YING
  • 972
  • 3
  • 11
  • 19
  • FYI you might want to make the lifecycleBeanPostProcessor method static as discussed http://stackoverflow.com/a/31412419/618087 – Rob Winch Jul 15 '15 at 03:38
  • Thank you. `static` make sure is lifecycleBeanPostProcessor is the first bean what to be created. – Zhuo YING Jul 15 '15 at 05:06

1 Answers1

1

OK, i found the answer by myslef.

@Bean
    @DependsOn("lifecycleBeanPostProcessor")
    public DefaultAdvisorAutoProxyCreator defaultAdvisorAutoProxyCreator() {
        DefaultAdvisorAutoProxyCreator proxyCreator = new DefaultAdvisorAutoProxyCreator();
        proxyCreator.setProxyTargetClass(true); // this SETTING
        return proxyCreator;
    }
Zhuo YING
  • 972
  • 3
  • 11
  • 19