From 95d5061b43a723efb37d101a81098b40997edb3b Mon Sep 17 00:00:00 2001 From: EvanLiu Date: Sat, 22 Jun 2024 02:50:14 +0800 Subject: [PATCH] solve shiro warning in springboot (#67) Co-authored-by: LiuYe <215159994@qq.com> --- .../src/main/java/org/apache/shiro/samples/WebApp.java | 2 ++ .../ShiroAnnotationProcessorAutoConfiguration.java | 1 + .../config/web/autoconfigure/ShiroWebFilterConfiguration.java | 4 ++++ 3 files changed, 7 insertions(+) diff --git a/samples/spring-boot-3-web/src/main/java/org/apache/shiro/samples/WebApp.java b/samples/spring-boot-3-web/src/main/java/org/apache/shiro/samples/WebApp.java index 6513efdcef..c42a6e59a7 100644 --- a/samples/spring-boot-3-web/src/main/java/org/apache/shiro/samples/WebApp.java +++ b/samples/spring-boot-3-web/src/main/java/org/apache/shiro/samples/WebApp.java @@ -73,6 +73,7 @@ public String handleException(AuthorizationException e, Model model) { } @Bean + @Role(BeanDefinition.ROLE_INFRASTRUCTURE) public Realm realm() { TextConfigurationRealm realm = new TextConfigurationRealm(); realm.setUserDefinitions("joe.coder=password,user\n" + "jill.coder=password,admin"); @@ -83,6 +84,7 @@ public Realm realm() { } @Bean + @Role(BeanDefinition.ROLE_INFRASTRUCTURE) public ShiroFilterChainDefinition shiroFilterChainDefinition() { DefaultShiroFilterChainDefinition chainDefinition = new DefaultShiroFilterChainDefinition(); // need to accept POSTs from the login form diff --git a/support/spring-boot/spring-boot-starter/src/main/java/org/apache/shiro/spring/boot/autoconfigure/ShiroAnnotationProcessorAutoConfiguration.java b/support/spring-boot/spring-boot-starter/src/main/java/org/apache/shiro/spring/boot/autoconfigure/ShiroAnnotationProcessorAutoConfiguration.java index 6c13a4b5ce..f7f7aa12b0 100644 --- a/support/spring-boot/spring-boot-starter/src/main/java/org/apache/shiro/spring/boot/autoconfigure/ShiroAnnotationProcessorAutoConfiguration.java +++ b/support/spring-boot/spring-boot-starter/src/main/java/org/apache/shiro/spring/boot/autoconfigure/ShiroAnnotationProcessorAutoConfiguration.java @@ -52,6 +52,7 @@ public DefaultAdvisorAutoProxyCreator defaultAdvisorAutoProxyCreator() { @Bean @ConditionalOnMissingBean + @Role(BeanDefinition.ROLE_INFRASTRUCTURE) @Override public AuthorizationAttributeSourceAdvisor authorizationAttributeSourceAdvisor(SecurityManager securityManager) { return super.authorizationAttributeSourceAdvisor(securityManager); diff --git a/support/spring-boot/spring-boot-starter/src/main/java/org/apache/shiro/spring/config/web/autoconfigure/ShiroWebFilterConfiguration.java b/support/spring-boot/spring-boot-starter/src/main/java/org/apache/shiro/spring/config/web/autoconfigure/ShiroWebFilterConfiguration.java index 9a103a280c..606c276e34 100644 --- a/support/spring-boot/spring-boot-starter/src/main/java/org/apache/shiro/spring/config/web/autoconfigure/ShiroWebFilterConfiguration.java +++ b/support/spring-boot/spring-boot-starter/src/main/java/org/apache/shiro/spring/config/web/autoconfigure/ShiroWebFilterConfiguration.java @@ -21,12 +21,14 @@ import org.apache.shiro.spring.web.ShiroFilterFactoryBean; import org.apache.shiro.spring.web.config.AbstractShiroWebFilterConfiguration; import org.apache.shiro.web.servlet.AbstractShiroFilter; +import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; import org.springframework.boot.web.servlet.FilterRegistrationBean; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Role; import javax.servlet.DispatcherType; import java.util.List; @@ -37,6 +39,7 @@ @Configuration @ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.SERVLET) @ConditionalOnProperty(name = "shiro.web.enabled", matchIfMissing = true) +@Role(BeanDefinition.ROLE_INFRASTRUCTURE) public class ShiroWebFilterConfiguration extends AbstractShiroWebFilterConfiguration { /** @@ -70,6 +73,7 @@ protected FilterRegistrationBean filterShiroFilterRegistrat } @Bean(name = "globalFilters") + @Role(BeanDefinition.ROLE_INFRASTRUCTURE) @ConditionalOnMissingBean protected List globalFilters() { return super.globalFilters();