Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package org.keycloak.jaxrs;
 
 import java.net.URL;
 
Variant of JaxrsBearerTokenFilter, which can be used to properly use resources from current osgi bundle

Author(s):
Marek Posolda
    private final static Logger log = Logger.getLogger("" + JaxrsBearerTokenFilterImpl.class);
    private BundleContext bundleContext;
    public BundleContext getBundleContext() {
        return ;
    }
    public void setBundleContext(BundleContext bundleContext) {
        this. = bundleContext;
        attemptStart();
    }
    @Override
    protected boolean isInitialized() {
        return super.isInitialized() &&  != null;
    }
    @Override
    protected Class<? extends KeycloakConfigResolverloadResolverClass() {
        String resolverClass = getKeycloakConfigResolverClass();
        try {
            return (Class<? extends KeycloakConfigResolver>) .getBundle().loadClass(resolverClass);
        } catch (ClassNotFoundException cnfe) {
            .warning("Not able to find class from bundleContext. Fallback to current classloader");
            return super.loadResolverClass();
        }
    }
    @Override
    protected InputStream loadKeycloakConfigFile() {
        String keycloakConfigFile = getKeycloakConfigFile();
        if (keycloakConfigFile.startsWith(.)) {
            // Load from classpath of current bundle
            String classPathLocation = keycloakConfigFile.replace(."");
            .fine("Loading config from classpath on location: " + classPathLocation);
            URL cfgUrl = .getBundle().getResource(classPathLocation);
            if (cfgUrl == null) {
                .warning("Not able to find configFile from bundleContext. Fallback to current classloader");
                return super.loadKeycloakConfigFile();
            }
            try {
                return cfgUrl.openStream();
            } catch (IOException ioe) {
                throw new RuntimeException(ioe);
            }
        } else {
            return super.loadKeycloakConfigFile();
        }
    }
New to GrepCode? Check out our FAQ X