This is an automated email from the ASF dual-hosted git repository.
struberg pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/openjpa.git
The following commit(s) were added to refs/heads/master by this push:
new b3d1ef867 OPENJPA-2922 disable JNDI lookup of EMF by default
b3d1ef867 is described below
commit b3d1ef8671751d47617eaf4ac259b43eae45e53b
Author: Mark Struberg <[email protected]>
AuthorDate: Mon May 27 19:00:40 2024 +0200
OPENJPA-2922 disable JNDI lookup of EMF by default
To use this feature please set the following
system.property to true: emf_via_jndi_enabled
---
.../resources/org/apache/openjpa/kernel/localizer.properties | 3 +++
.../org/apache/openjpa/persistence/OpenJPAPersistence.java | 10 ++++++++++
2 files changed, 13 insertions(+)
diff --git
a/openjpa-kernel/src/main/resources/org/apache/openjpa/kernel/localizer.properties
b/openjpa-kernel/src/main/resources/org/apache/openjpa/kernel/localizer.properties
index 35271cca8..f5069ead5 100644
---
a/openjpa-kernel/src/main/resources/org/apache/openjpa/kernel/localizer.properties
+++
b/openjpa-kernel/src/main/resources/org/apache/openjpa/kernel/localizer.properties
@@ -137,6 +137,9 @@ end-trans-error: An exception occurred while ending the
transaction. This \
not-bound: The file named "{0}" could not be found.
naming-exception: A NamingException was thrown while obtaining the \
factory at "{0}" from JNDI.
+jndi-disabled-exception: Accessing the EntityManagerFactory via JNDI has been \
+ disabled. Set the system property {0} to 'true' if you want to use this \
+ feature.
attach-deleted: The object "{0}" with id "{1}" has been deleted and \
cannot be attached.
not-detachable: The class "{0}" does not declare the "detachable" metadata \
diff --git
a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/OpenJPAPersistence.java
b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/OpenJPAPersistence.java
index cc7059dcf..3db497389 100644
---
a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/OpenJPAPersistence.java
+++
b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/OpenJPAPersistence.java
@@ -34,6 +34,7 @@ import org.apache.openjpa.kernel.Broker;
import org.apache.openjpa.lib.conf.ConfigurationProvider;
import org.apache.openjpa.lib.util.Localizer;
import org.apache.openjpa.util.ImplHelper;
+import org.apache.openjpa.util.UserException;
/**
* Static helper methods for JPA users.
@@ -44,6 +45,11 @@ import org.apache.openjpa.util.ImplHelper;
*/
public class OpenJPAPersistence {
+ /**
+ * Set this System property to 'true' if you want to enable the
EntityManager via JNDI
+ */
+ private static final String EMF_VIA_JNDI_ENABLED = "emf_via_jndi_enabled";
+
private static final Localizer _loc =
Localizer.forPackage(OpenJPAPersistence.class);
@@ -137,6 +143,10 @@ public class OpenJPAPersistence {
*/
public static OpenJPAEntityManagerFactory createEntityManagerFactory
(String jndiLocation, Context context) {
+ if
(!"true".equalsIgnoreCase(System.getProperty(EMF_VIA_JNDI_ENABLED))) {
+ throw new UserException(_loc.get("jndi-disabled-exception",
EMF_VIA_JNDI_ENABLED));
+ }
+
if (jndiLocation == null)
throw new NullPointerException("jndiLocation == null");