adding filter.active option
diff --git a/README.adoc b/README.adoc
index d4b1f5c..a2839fc 100644
--- a/README.adoc
+++ b/README.adoc
@@ -39,6 +39,7 @@
|geronimo.jwt-auth.jwt.header.alg.default|The default `alg` if specified|RS256
|geronimo.jwt-auth.jwt.header.typ.default|The default `typ` if specified|JWT
|geronimo.jwt-auth.jwt.header.typ.validate|Should the typ value be validated (only `JWT` is supported)|true
+|geronimo.jwt-auth.filter.active|If `true` it forces the filter to be added whatever config (`@LoginConfig` is used or not)|false
|geronimo.jwt-auth.filter.mapping.default|When the JAX-RS `Application` doesn't have an `@ApplicationPath` and no servlet registration are found for the application this defines the path to use to handle JWT|/*
|geronimo.jwt-auth.filter.publicUrls|List of URL to ignore|-
|geronimo.jwt-auth.kids.key.mapping|The mapping between the kid and the public key to use|-
diff --git a/geronimo-jwt-auth-impl/src/main/java/org/apache/geronimo/microprofile/impl/jwtauth/servlet/GeronimoJwtAuthInitializer.java b/geronimo-jwt-auth-impl/src/main/java/org/apache/geronimo/microprofile/impl/jwtauth/servlet/GeronimoJwtAuthInitializer.java
index 023ddcb..43f85be 100644
--- a/geronimo-jwt-auth-impl/src/main/java/org/apache/geronimo/microprofile/impl/jwtauth/servlet/GeronimoJwtAuthInitializer.java
+++ b/geronimo-jwt-auth-impl/src/main/java/org/apache/geronimo/microprofile/impl/jwtauth/servlet/GeronimoJwtAuthInitializer.java
@@ -21,6 +21,7 @@
import java.util.Comparator;
import java.util.EnumSet;
import java.util.Set;
+import java.util.function.Supplier;
import javax.servlet.DispatcherType;
import javax.servlet.FilterRegistration;
@@ -39,12 +40,23 @@
public class GeronimoJwtAuthInitializer implements ServletContainerInitializer {
@Override
public void onStartup(final Set<Class<?>> classes, final ServletContext ctx) throws ServletException {
- ofNullable(classes).filter(c -> !c.isEmpty()).ifPresent(marked -> marked.stream()
- .filter(Application.class::isAssignableFrom) // needed? what's the issue dropping it? nothing normally
- .filter(app -> app.isAnnotationPresent(LoginConfig.class))
- .filter(it -> "MP-JWT".equalsIgnoreCase(it.getAnnotation(LoginConfig.class).authMethod()))
- .sorted(Comparator.comparing(Class::getName)) // to be deterministic
- .findFirst()
+ final Supplier<GeronimoJwtAuthConfig> config = new Supplier<GeronimoJwtAuthConfig>() {
+ private GeronimoJwtAuthConfig config;
+
+ @Override
+ public GeronimoJwtAuthConfig get() {
+ return config == null ? config = GeronimoJwtAuthConfig.create() : config;
+ }
+ };
+ ofNullable(classes).filter(c -> !c.isEmpty()).ifPresent(marked -> // needed? what's the issue dropping it?
+ // nothing normally
+ // to be deterministic
+ marked.stream()
+ .filter(Application.class::isAssignableFrom) // needed? what's the issue dropping it? nothing
+ // normally
+ .filter(app -> "true".equalsIgnoreCase(config.get().read("filter.active", "false")) ||
+ (app.isAnnotationPresent(LoginConfig.class) && "MP-JWT".equalsIgnoreCase(app.getAnnotation(LoginConfig.class).authMethod())))
+ .min(Comparator.comparing(Class::getName))
.ifPresent(app -> {
final FilterRegistration.Dynamic filter = ctx.addFilter("geronimo-microprofile-jwt-auth-filter", GeronimoJwtAuthFilter.class);
filter.setAsyncSupported(true);
@@ -70,7 +82,7 @@
}
// unlikely
- return new String[]{GeronimoJwtAuthConfig.create().read("filter.mapping.default", "/*")};
+ return new String[]{config.get().read("filter.mapping.default", "/*")};
});
filter.addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), false, mappings);
}));