org.eclipse.microprofile.auth.LoginConfig Java Examples

The following examples show how to use org.eclipse.microprofile.auth.LoginConfig. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SmallRyeJWTAuthJaxRsFeature.java    From smallrye-jwt with Apache License 2.0 5 votes vote down vote up
boolean mpJwtEnabled() {
    boolean enabled = false;

    if (restApplication != null) {
        Class<?> applicationClass = restApplication.getClass();

        if (applicationClass.isAnnotationPresent(LoginConfig.class)) {
            LoginConfig config = applicationClass.getAnnotation(LoginConfig.class);
            enabled = "MP-JWT".equals(config.authMethod());
        }
    }

    return enabled;
}
 
Example #2
Source File: MPJWTInitializer.java    From tomee with Apache License 2.0 5 votes vote down vote up
@Override
public void onStartup(final Set<Class<?>> classes, final ServletContext ctx) throws ServletException {

    if (classes == null || classes.isEmpty()) {
        return; // no class having @LoginConfig on it
    }

    for (Class<?> clazz : classes) {
        final LoginConfig loginConfig = clazz.getAnnotation(LoginConfig.class);

        if (loginConfig.authMethod() == null && !"MP-JWT".equals(loginConfig.authMethod())) {
            continue;
        }

        if (!Application.class.isAssignableFrom(clazz)) {
            continue;
            // do we really want Application?
            // See https://github.com/eclipse/microprofile-jwt-auth/issues/70 to clarify this point
        }

        final FilterRegistration.Dynamic mpJwtFilter = ctx.addFilter("mp-jwt-filter", MPJWTFilter.class);
        mpJwtFilter.setAsyncSupported(true);
        mpJwtFilter.addMappingForUrlPatterns(null, false, "/*");

        break; // no need to add it more than once
    }

}