Skip to content
Permalink
Browse files
adding filter.active option
  • Loading branch information
rmannibucau committed May 21, 2018
1 parent 6db5388 commit 83423c4022e007d159238f8026a307c4104e5420
Showing 2 changed files with 20 additions and 7 deletions.
@@ -39,6 +39,7 @@ and if not system properties and `META-INF/geronimo/microprofile/jwt-auth.proper
|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|-
@@ -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 @@ public void onStartup(final Set<Class<?>> classes, final ServletContext ctx) thr
}

// 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);
}));

0 comments on commit 83423c4

Please sign in to comment.