This is an automated email from the ASF dual-hosted git repository.
rzo1 pushed a commit to branch tomee-10.x
in repository https://gitbox.apache.org/repos/asf/tomee.git
The following commit(s) were added to refs/heads/tomee-10.x by this push:
new 4c00b09b4e Passivate managed beans to a private directory by default
(#3092)
4c00b09b4e is described below
commit 4c00b09b4e7707067e567245ac857aa7f79ed371
Author: Markus Jung <[email protected]>
AuthorDate: Sun Oct 18 14:49:19 2026 +0200
Passivate managed beans to a private directory by default (#3092)
Follow-up to #3077: core/managed/SimplePassivater, used by the managed
container, still fell back to the shared java.io.tmpdir.
(cherry picked from commit b4e5578b540aaa5d662731d6151d55cac229d0ee)
---
.../openejb/core/managed/SimplePassivater.java | 3 +-
.../openejb/core/stateful/SimplePassivater.java | 21 ++++--
.../openejb/core/managed/SimplePassivaterTest.java | 79 ++++++++++++++++++++++
3 files changed, 96 insertions(+), 7 deletions(-)
diff --git
a/container/openejb-core/src/main/java/org/apache/openejb/core/managed/SimplePassivater.java
b/container/openejb-core/src/main/java/org/apache/openejb/core/managed/SimplePassivater.java
index 784c17bb87..59dbffd9ba 100644
---
a/container/openejb-core/src/main/java/org/apache/openejb/core/managed/SimplePassivater.java
+++
b/container/openejb-core/src/main/java/org/apache/openejb/core/managed/SimplePassivater.java
@@ -22,7 +22,6 @@ import org.apache.openejb.core.EnvProps;
import org.apache.openejb.core.ObjectInputStreamFiltered;
import org.apache.openejb.loader.IO;
import org.apache.openejb.loader.SystemInstance;
-import org.apache.openejb.util.JavaSecurityManagers;
import org.apache.openejb.util.LogCategory;
import org.apache.openejb.util.Logger;
@@ -57,7 +56,7 @@ public class SimplePassivater implements PassivationStrategy {
if (dir != null) {
sessionDirectory =
SystemInstance.get().getBase().getDirectory(dir).getAbsoluteFile();
} else {
- sessionDirectory = new
File(JavaSecurityManagers.getSystemProperty("java.io.tmpdir", File.separator +
"tmp")).getAbsoluteFile();
+ sessionDirectory =
org.apache.openejb.core.stateful.SimplePassivater.defaultSessionDirectory().getAbsoluteFile();
}
if (!sessionDirectory.exists() && !sessionDirectory.mkdirs()) {
diff --git
a/container/openejb-core/src/main/java/org/apache/openejb/core/stateful/SimplePassivater.java
b/container/openejb-core/src/main/java/org/apache/openejb/core/stateful/SimplePassivater.java
index 02855da1f6..930d554777 100644
---
a/container/openejb-core/src/main/java/org/apache/openejb/core/stateful/SimplePassivater.java
+++
b/container/openejb-core/src/main/java/org/apache/openejb/core/stateful/SimplePassivater.java
@@ -64,12 +64,8 @@ public class SimplePassivater implements PassivationStrategy
{
try {
if (dir != null) {
sessionDirectory =
SystemInstance.get().getBase().getDirectory(dir);
- } else if (SystemInstance.get().getOptions().get(SHARED_TMPDIR,
false)) {
- sessionDirectory = new
File(JavaSecurityManagers.getSystemProperty("java.io.tmpdir", File.separator +
"tmp"));
} else {
- // created atomically and owner-only, other local users can't
read passivated state
- sessionDirectory =
Files.createTempDirectory("openejb-passivation-").toFile();
- sessionDirectory.deleteOnExit();
+ sessionDirectory = defaultSessionDirectory();
}
if (!sessionDirectory.exists() && !sessionDirectory.mkdirs()) {
@@ -143,6 +139,21 @@ public class SimplePassivater implements
PassivationStrategy {
}
}
+ /**
+ * Passivation directory used when none is configured: a private,
owner-only
+ * temporary directory, or java.io.tmpdir itself with {@link
#SHARED_TMPDIR}.
+ */
+ public static File defaultSessionDirectory() throws IOException {
+ if (SystemInstance.get().getOptions().get(SHARED_TMPDIR, false)) {
+ return new
File(JavaSecurityManagers.getSystemProperty("java.io.tmpdir", File.separator +
"tmp"));
+ }
+
+ // created atomically and owner-only, other local users can't read
passivated state
+ final File directory =
Files.createTempDirectory("openejb-passivation-").toFile();
+ directory.deleteOnExit();
+ return directory;
+ }
+
private File sessionFile(final Object primaryKey) throws IOException {
final String filename = primaryKey.toString().replace(':', '=');
diff --git
a/container/openejb-core/src/test/java/org/apache/openejb/core/managed/SimplePassivaterTest.java
b/container/openejb-core/src/test/java/org/apache/openejb/core/managed/SimplePassivaterTest.java
new file mode 100644
index 0000000000..b5d9304712
--- /dev/null
+++
b/container/openejb-core/src/test/java/org/apache/openejb/core/managed/SimplePassivaterTest.java
@@ -0,0 +1,79 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.openejb.core.managed;
+
+import org.apache.openejb.loader.SystemInstance;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.io.File;
+import java.nio.file.Files;
+import java.nio.file.attribute.PosixFileAttributeView;
+import java.nio.file.attribute.PosixFilePermission;
+import java.util.EnumSet;
+import java.util.UUID;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+public class SimplePassivaterTest {
+
+ @Before
+ @After
+ public void reset() {
+ SystemInstance.reset();
+ }
+
+ @Test
+ public void passivatesToPrivateDirectoryByDefault() throws Exception {
+ final String key = "managed-" + UUID.randomUUID();
+ final SimplePassivater passivater = new SimplePassivater();
+ passivater.passivate(key, "state");
+ try {
+ assertFalse(new File(tmpdir(), key).exists());
+
+ final File[] dirs = tmpdir().listFiles((d, name) ->
name.startsWith("openejb-passivation-") && new File(d, name + File.separator +
key).isFile());
+ assertEquals(1, dirs.length);
+ if
(Files.getFileStore(dirs[0].toPath()).supportsFileAttributeView(PosixFileAttributeView.class))
{
+ assertEquals(EnumSet.of(PosixFilePermission.OWNER_READ,
PosixFilePermission.OWNER_WRITE, PosixFilePermission.OWNER_EXECUTE),
+ Files.getPosixFilePermissions(dirs[0].toPath()));
+ }
+ } finally {
+ assertEquals("state", passivater.activate(key));
+ }
+ }
+
+ @Test
+ public void sharedTmpdirOptOut() throws Exception {
+
SystemInstance.get().setProperty(org.apache.openejb.core.stateful.SimplePassivater.SHARED_TMPDIR,
"true");
+
+ final String key = "managed-" + UUID.randomUUID();
+ final SimplePassivater passivater = new SimplePassivater();
+ passivater.passivate(key, "state");
+ try {
+ assertTrue(new File(tmpdir(), key).isFile());
+ } finally {
+ assertEquals("state", passivater.activate(key));
+ }
+ }
+
+ private static File tmpdir() throws Exception {
+ return new
File(System.getProperty("java.io.tmpdir")).getCanonicalFile();
+ }
+}