Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SHIRO-892 Ensure ShiroWebModules works with explicit bindings in with Guice #519

Merged
merged 1 commit into from
Nov 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
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;
Expand Down Expand Up @@ -135,6 +136,7 @@ protected final void configureShiro() {
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);
Expand Down Expand Up @@ -246,6 +248,17 @@ protected void bindWebSecurityManager(AnnotatedBindingBuilder<? super WebSecurit
}
}

/**
* 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/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import org.apache.shiro.web.filter.mgt.FilterChainResolver;
import org.apache.shiro.web.mgt.WebSecurityManager;

import javax.inject.Named;
import com.google.inject.name.Named;
import javax.servlet.ServletContext;

@Singleton
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.name.Named;
import com.google.inject.Provides;
import com.google.inject.binder.AnnotatedBindingBuilder;
import com.google.inject.name.Names;
Expand All @@ -47,7 +49,6 @@
import org.junit.Assume;
import org.junit.Test;

import javax.inject.Named;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
Expand Down Expand Up @@ -432,7 +433,7 @@ public void testChangeInvalidFilterConfig() {
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() {

Expand Down