Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.x] WLS JMS Object-Based Security #5854

Merged
merged 2 commits into from
Jan 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion docs/mp/reactivemessaging/weblogic.adoc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
///////////////////////////////////////////////////////////////////////////////

Copyright (c) 2022 Oracle and/or its affiliates.
Copyright (c) 2022, 2023 Oracle and/or its affiliates.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -43,6 +43,9 @@ WebLogic installation.
WARNING: Avoid placing `wlthint3client.jar` on Helidon classpath, client library location needs to be
configured and loaded by Helidon messaging connector.

WARNING: Don't forget to start your Helidon app with `--add-opens=java.base/java.io=ALL-UNNAMED` to allow
wlthint3client use reflection.

include::{rootdir}/includes/dependencies.adoc[]

[source,xml]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, 2022 Oracle and/or its affiliates.
* Copyright (c) 2020, 2023 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -111,7 +111,7 @@ private Object lookup(String jndi) {
try {
return ctx.lookup(jndi);
} catch (NamingException e) {
LOGGER.log(Level.FINE, e, () -> "JNDI lookup of " + jndi + " failed");
LOGGER.log(Level.WARNING, e, () -> "JNDI lookup of " + jndi + " failed");
return null;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Oracle and/or its affiliates.
* Copyright (c) 2022, 2023 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -18,6 +18,7 @@
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.Hashtable;
import java.util.Optional;

import javax.naming.Context;
import javax.naming.NamingException;
Expand All @@ -28,23 +29,26 @@
*/
public class IsolatedContextFactory implements InitialContextFactory {

private static final String WLS_INIT_CTX_FACTORY = "weblogic.jndi.WLInitialContextFactory";
private static final String WLS_INIT_CTX_FACTORY_DEFAULT = "weblogic.jms.WLInitialContextFactory";

@Override
public Context getInitialContext(Hashtable<?, ?> env) throws NamingException {
return ThinClientClassLoader.executeInIsolation(() -> {
String wlsInitFactoryClass =
Optional.ofNullable((String) env.get("wls-init-ctx-factory"))
.orElse(WLS_INIT_CTX_FACTORY_DEFAULT);
try {
Class<?> wlInitialContextFactory = ThinClientClassLoader.getInstance().loadClass(WLS_INIT_CTX_FACTORY);
Class<?> wlInitialContextFactory = ThinClientClassLoader.getInstance().loadClass(wlsInitFactoryClass);
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);
throw new RuntimeException("Cannot find " + wlsInitFactoryClass, e);
} catch (NoSuchMethodException
| InvocationTargetException
| InstantiationException
| IllegalAccessException e) {
throw new RuntimeException("Cannot instantiate " + WLS_INIT_CTX_FACTORY, e);
throw new RuntimeException("Cannot instantiate " + wlsInitFactoryClass, e);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Oracle and/or its affiliates.
* Copyright (c) 2022, 2023 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -57,7 +57,9 @@ protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundE
try {
return super.loadClass(name, resolve);
} catch (ClassNotFoundException e) {
LOGGER.log(TRACE, "Cannot load class " + name + " from WLS thin client classloader.", e);
LOGGER.log(TRACE, () -> "Cannot load class "
+ name
+ " from WLS thin client classloader, delegating to ctx classloader.", e);
contextClassLoader.loadClass(name);
}
}
Expand Down Expand Up @@ -94,6 +96,11 @@ static <T> T executeInIsolation(IsolationSupplier<T> supplier) {
}

boolean inWlsJar(String name) {
// Load jms exceptions from inside the thin jar to avoid deserialization issues
if (name.startsWith("javax.jms") && name.endsWith("Exception")) {
return true;
}

// Load only javax JMS API from outside, so cast works
return !name.startsWith("javax.jms")
&& !name.equals(IsolatedContextFactory.class.getName());
Expand Down