You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@shiro.apache.org by bd...@apache.org on 2022/10/28 20:57:55 UTC
[shiro] 01/01: SHIRO-892 Ensure ShiroWebModules works with explicit bindings in with Guice
This is an automated email from the ASF dual-hosted git repository.
bdemers pushed a commit to branch SHIRO-892-110x
in repository https://gitbox.apache.org/repos/asf/shiro.git
commit af2dd8515c08643f0a095a3e55835bdfb6d1ad90
Author: Brian Demers <bd...@apache.org>
AuthorDate: Fri Oct 28 22:57:46 2022 +0200
SHIRO-892 Ensure ShiroWebModules works with explicit bindings in with Guice
GuiceShiroFilter uses com.google.inject.Inject to conform with other usages
---
.../java/org/apache/shiro/guice/web/GuiceShiroFilter.java | 2 +-
.../java/org/apache/shiro/guice/web/ShiroWebModule.java | 13 +++++++++++++
.../java/org/apache/shiro/guice/web/ShiroWebModuleTest.java | 4 +++-
3 files changed, 17 insertions(+), 2 deletions(-)
diff --git a/support/guice/src/main/java/org/apache/shiro/guice/web/GuiceShiroFilter.java b/support/guice/src/main/java/org/apache/shiro/guice/web/GuiceShiroFilter.java
index ae99b2e3..88f9098f 100644
--- a/support/guice/src/main/java/org/apache/shiro/guice/web/GuiceShiroFilter.java
+++ b/support/guice/src/main/java/org/apache/shiro/guice/web/GuiceShiroFilter.java
@@ -23,7 +23,7 @@ import org.apache.shiro.web.filter.mgt.FilterChainResolver;
import org.apache.shiro.web.mgt.WebSecurityManager;
import org.apache.shiro.web.servlet.AbstractShiroFilter;
-import javax.inject.Inject;
+import com.google.inject.Inject;
/**
* Shiro filter that is managed by and receives its filter chain configurations from Guice. The convenience method to
diff --git a/support/guice/src/main/java/org/apache/shiro/guice/web/ShiroWebModule.java b/support/guice/src/main/java/org/apache/shiro/guice/web/ShiroWebModule.java
index 73ffc7b2..a7faf5d7 100644
--- a/support/guice/src/main/java/org/apache/shiro/guice/web/ShiroWebModule.java
+++ b/support/guice/src/main/java/org/apache/shiro/guice/web/ShiroWebModule.java
@@ -29,6 +29,7 @@ import org.apache.shiro.guice.ShiroModule;
import org.apache.shiro.mgt.SecurityManager;
import org.apache.shiro.session.mgt.SessionManager;
import org.apache.shiro.util.StringUtils;
+import org.apache.shiro.web.config.ShiroFilterConfiguration;
import org.apache.shiro.web.env.WebEnvironment;
import org.apache.shiro.web.filter.InvalidRequestFilter;
import org.apache.shiro.web.filter.PathMatchingFilter;
@@ -135,6 +136,7 @@ public abstract class ShiroWebModule extends ShiroModule {
bindBeanType(TypeLiteral.get(ServletContext.class), Key.get(ServletContext.class, Names.named(NAME)));
bind(Key.get(ServletContext.class, Names.named(NAME))).toInstance(this.servletContext);
bindWebSecurityManager(bind(WebSecurityManager.class));
+ bindShiroFilterConfiguration(bind(ShiroFilterConfiguration.class));
bindWebEnvironment(bind(WebEnvironment.class));
bind(GuiceShiroFilter.class).asEagerSingleton();
expose(GuiceShiroFilter.class);
@@ -246,6 +248,17 @@ public abstract class ShiroWebModule extends ShiroModule {
}
}
+ /**
+ * Binds the Shiro Filter Configuration. Override this method in order to provide your own Shiro Filter Configuration binding.
+ * <p/>
+ * By default, a {@link ShiroFilterConfiguration} is bound as an eager singleton.
+ *
+ * @param bind
+ */
+ protected void bindShiroFilterConfiguration(AnnotatedBindingBuilder<? super ShiroFilterConfiguration> bind) {
+ bind.asEagerSingleton();
+ }
+
/**
* Binds the session manager. Override this method in order to provide your own session manager binding.
* <p/>
diff --git a/support/guice/src/test/java/org/apache/shiro/guice/web/ShiroWebModuleTest.java b/support/guice/src/test/java/org/apache/shiro/guice/web/ShiroWebModuleTest.java
index c24359a4..097497d5 100644
--- a/support/guice/src/test/java/org/apache/shiro/guice/web/ShiroWebModuleTest.java
+++ b/support/guice/src/test/java/org/apache/shiro/guice/web/ShiroWebModuleTest.java
@@ -18,10 +18,12 @@
*/
package org.apache.shiro.guice.web;
+import com.google.inject.Binder;
import com.google.inject.Guice;
import com.google.inject.Inject;
import com.google.inject.Injector;
import com.google.inject.Key;
+import com.google.inject.Module;
import com.google.inject.Provides;
import com.google.inject.binder.AnnotatedBindingBuilder;
import com.google.inject.name.Names;
@@ -432,7 +434,7 @@ public class ShiroWebModuleTest {
expect(request.getAttribute("javax.servlet.include.servlet_path")).andReturn("/test/foobar");
replay(servletContext, request);
- Injector injector = Guice.createInjector(new ShiroWebModule(servletContext) {
+ Injector injector = Guice.createInjector(Binder::requireExplicitBindings, new ShiroWebModule(servletContext) {
@Override
protected void configureShiroWeb() {