Hi,
I would say that this:
-----
@Component(
immediate=true,
property= {
"osgi.jaxrs.extension=true",
"osgi.jaxrs.extension.select=(authentication.with=keycloak)"
}
)
-----
should be:
-----
@Component(
immediate=true,
property= {
"osgi.jaxrs.extension=true",
"osgi.jaxrs.application.select=(authentication.with=keycloak)"
}
)
-----
note the "extension -> application", otherwise your filter is waiting
for another extension that never arrives.
I would also suggest that you make your component ServiceScope.PROTOTYPE
so every application gets its own instance of the filter.
Let me know if this helps.
Carlos.
El 28/8/18 a las 19:10, Nhut Thai Le escribió:
> Hello,
>
> I'm using aries-jax-rs-whiteboard to host by REST service and I want
> to use a ContainerRequestFilter to check for authentication token.
> However, although the filter is registered as an OSGI service, it is
> not triggered or even instantiated. Here is my REST api and filter code:
>
> =====the application====
> @Component(
> immediate = true,
> service = Application.class,
> property= {
> "osgi.jaxrs.name <http://osgi.jaxrs.name/>=RestApp",
> JAX_RS_APPLICATION_BASE + "=/rest",
> "authentication.with=keycloak"
> }
> )
> public class RestApiApp extends Application{
>
> @Override
> public Set<Object> getSingletons() {
> return Collections.singleton(this);
> }
> }
>
> =====the API==========
> @Component(
> immediate=true,
> service = Api.class,
> property = {
> "osgi.jaxrs.application.select=(osgi.jaxrs.name
> <http://osgi.jaxrs.name/>=RestApp)",
> "osgi.jaxrs.resource=true"
> }
> )
> @Path("/common")
> public final class Api {
> public static final Response EMPTY_RESPONSE =
> Response.noContent().type(MediaType.TEXT_HTML_TYPE).build();
>
> @GET
> @Path("/getObject")
> @Produces(MediaType.APPLICATION_JSON)
> public String getObject() {
> return "Rest call 2"; //$NON-NLS-1$
> }
> }
>
> ======the filter==========
> @Component(
> immediate=true,
> property= {
> "osgi.jaxrs.extension=true",
> "osgi.jaxrs.extension.select=(authentication.with=keycloak)"
> }
> )
> @PreMatching
> @Priority(Priorities.AUTHENTICATION)
> public final class JaxrsAuthenticationFilter extends
> OsgiJaxrsBearerTokenFilterImpl implements ContainerRequestFilter
> {
> public static final int count = 1; //BREAKPOINT NEVER HIT
> @Override
> public void filter(ContainerRequestContext arg0) throws IOException {
> super.filter(arg0); //BREAKPOINT NEVER HIT
> }
> }
>
> Could anyone give a hint what I may miss?
>