gpt4 book ai didi

java - 将 apache Shiro 与 Spring MVC 非 xml 项目一起使用

转载 作者:行者123 更新时间:2023-12-03 07:55:45 24 4
gpt4 key购买 nike

我有一个项目,我在其中使用 Spring mvc 4,我需要在其中包含 apache shiro 安全性。我试图在网上搜索我的问题的解决方案,但没有找到任何东西。虽然在 Shiro 的网站上有一个指南,但是这个例子只针对 xml 配置的 Spring 项目,而我的项目根本不包含任何 xml,当我试图用注释配置 Shiro 时它失败了。当我运行这个项目时,我可以访问我所有的端点,并且没有一个受到 Shiro 的限制。我想我的配置是错误的,但我无法弄清楚它的哪一部分是错误的。我不允许使用 Spring boot(我知道有这样的例子)。这是我的配置类:

@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;
}
}

提前致谢!

最佳答案

查看 1.4.0 (RC2) 版本。更新了 Spring 和 Spring-Boot 支持。

以及源代码树中的示例: https://github.com/apache/shiro/tree/master/samples/spring-mvc

关于java - 将 apache Shiro 与 Spring MVC 非 xml 项目一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42976582/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com