Closed danielkec closed 1 year ago
Workaround
package my.package;
import io.helidon.messaging.connectors.wls.IsolatedContextFactory; import javax.naming.Context; import javax.naming.NamingException; import javax.naming.spi.InitialContextFactory; import java.lang.reflect.*; import java.util.Hashtable;
/**
to switch from WLS Thread-Based Security to Object-Based Security. */ public class Workaround5838 extends IsolatedContextFactory {
static String WLS_INIT_CTX_FACTORY = "weblogic.jms.WLInitialContextFactory";
@Override public Context getInitialContext(Hashtable<?, ?> env) throws NamingException { ClassLoader originalCl = Thread.currentThread().getContextClassLoader(); try { Class<?> clClass = Class.forName("io.helidon.messaging.connectors.wls.ThinClientClassLoader"); Method getInstanceMethod = clClass.getDeclaredMethod("getInstance"); getInstanceMethod.setAccessible(true); ClassLoader thinClientCl = (ClassLoader) getInstanceMethod.invoke(null); Thread.currentThread().setContextClassLoader(thinClientCl); Class<?> wlInitialContextFactory = thinClientCl.loadClass(WLS_INIT_CTX_FACTORY); Constructor<?> contextFactoryConstructor = wlInitialContextFactory.getConstructor(); InitialContextFactory contextFactoryInstance = (InitialContextFactory) contextFactoryConstructor.newInstance(); return contextFactoryInstance.getInitialContext(env); } catch (ClassNotFoundException e) { throw new RuntimeException("Cannot find " + WLS_INIT_CTX_FACTORY, e); } catch (NoSuchMethodException | InvocationTargetException | InstantiationException | IllegalAccessException e) { throw new RuntimeException("Cannot instantiate " + WLS_INIT_CTX_FACTORY, e); } finally { Thread.currentThread().setContextClassLoader(originalCl); } } }
3. Use it as context factory with following setting:
```yaml
mp:
messaging:
connector:
helidon-weblogic-jms:
jndi.env-properties.java.naming.factory.initial: my.package.Workaround5838
New WLS connector initializes InitialContextFactory within different thread than the one which creates destination. This makes WLS Thread-Based Security unusable. We need to switch to Object-Based Security.
PR's