0

I have two OSGi bundles deployed in Apache Karaf. A and B. My A OSGi bundle works as basic authentication handler. I have set up my security handler it works fine:

<bean id="securityHandler" class="org.eclipse.jetty.security.ConstraintSecurityHandler">
    <property name="authenticator">
        <bean class="org.eclipse.jetty.security.authentication.BasicAuthenticator"/>
    </property>
    <property name="constraintMappings">
        <list>
            <ref bean="constraintMapping"/>
        </list>
    </property>
    <property name="loginService" ref="loginService"/>
    <property name="strict" value="false"/>
    <property name="identityService" ref="identityService"/>
</bean>

This handler is in bundle A. What I need to do is to make this handler as an OSGi service to be used by other bundles, in this case, by bundle B. I can not implement any interface to ConstraintSecurityHandler class because it is from org.eclipse.jetty.security package.

I have tried to create my own Handler class then extend ConstraintSecurityHandler and implement my interface. So OSGi service looked like this:

<osgi:service ref="securityHandler" interface="my.company.MyInterface"  />

This does not work, I get the exception:

org.apache.camel.RuntimeCamelException: org.apache.camel.FailedToCreateRouteException: Failed to create route route1: Route[[From[jetty:http://0.0.0.0:8019/TARGETjobs/Indeed?hand... because of Failed to resolve endpoint: jetty://http://0.0.0.0:8019/TARGETjobs/Indeed?handlers=securityHandler&matchOnUriPrefix=true due to: null

So the question is how can I make this securityHandler bean as an OSGi service available to other OSGi bundles?

Paulius Matulionis
  • 23,085
  • 22
  • 103
  • 143

1 Answers1

1

I have found the solution my self. I the A bundle I have created:

public class BasicAuthSecurityHandler implements Handler {

    private ConstraintSecurityHandler securityHandler;

    @Override
    public ConstraintSecurityHandler getSecurityHandler() {
        return securityHandler;
    }

    public void setSecurityHandler(ConstraintSecurityHandler securityHandler) {
        this.securityHandler = securityHandler;
    }        

}

And an interface:

public interface Handler {

    ConstraintSecurityHandler getSecurityHandler();

}

In my A bundle Spring context I set the security handler to this bean and made OSGi service from this bean:

<bean id="basicAuthSecurityHandler" class="com.groupgti.handler.authentication.basic.BasicAuthSecurityHandler">
    <property name="securityHandler" ref="securityHandler"/>
</bean>

<osgi:service ref="basicAuthSecurityHandler" interface="com.groupgti.handler.authentication.basic.Handler"/>

Now in my bundle B I can easily retrieve my security handler like this:

<osgi:reference id="basicAuthSecurityHandler" interface="com.groupgti.handler.authentication.basic.Handler"/>
<bean id="securityHandler" factory-bean="basicAuthSecurityHandler" factory-method="getSecurityHandler"/>

And everything works fine.

Paulius Matulionis
  • 23,085
  • 22
  • 103
  • 143