[keycloak-user] OsgiJaxrsBearerTokenFilterImpl init resolver class on every request

Nhut Thai Le ntle at castortech.com
Mon Jan 28 13:04:58 EST 2019


Hello,

We are using OsgiJaxrsBearerTokenFilterImpl of keycloak 4.6 in our OSGI env
to filter requests to our REST service as follow:

@Component(
service = {
ContainerRequestFilter.class,
ContainerResponseFilter.class
},
scope = ServiceScope.PROTOTYPE,
property = {
"osgi.jaxrs.extension=true",
JAX_RS_NAME + "=DiagramRestFilter",
DiagramConstants.REST_APP_SELECT
}
)
@PreMatching
@Priority(Priorities.AUTHENTICATION)
public final class DiagramRestFilter extends OsgiJaxrsBearerTokenFilterImpl
implements ContainerResponseFilter {
private static final String REFERER_HEADER = "Referer"; //$NON-NLS-1$
private static final String UTF_8_CHARSET = "UTF-8"; //$NON-NLS-1$
private final Logger log = LoggerFactory.getLogger(getClass());

@Reference
private SessionService sessionService;

@Activate
public void activate(BundleContext bundleContext) {
log.trace("Activating {}", getClass()); //$NON-NLS-1$
setKeycloakConfigResolverClass("com.castortech.iris.ba.web.filters.BundleBasedKeycloakConfigResolver");
//$NON-NLS-1$
setBundleContext(bundleContext);
}

As you can see, we set the filter scope to Prototype as recommended by OSGI
compedium (
https://osgi.org/specification/osgi.cmpn/7.0.0/service.jaxrs.html#d0e133685)
but we see a lot of the following line got printed when the server started
INFO: Using
com.castortech.iris.ba.web.filters.BundleBasedKeycloakConfigResolver at 738e48f7
to resolve Keycloak configuration on a per-request basis.

Does that means the config resolver is being instantiate for each request ?
Since the the configuration never change, would it make sense to
instantiate this config resolver only once?

Thai Le


More information about the keycloak-user mailing list