diff --git a/src/main/java/org/wildfly/transaction/client/provider/jboss/FileSystemXAResourceRegistry.java b/src/main/java/org/wildfly/transaction/client/provider/jboss/FileSystemXAResourceRegistry.java index 68ea6c7..27d48fd 100644 --- a/src/main/java/org/wildfly/transaction/client/provider/jboss/FileSystemXAResourceRegistry.java +++ b/src/main/java/org/wildfly/transaction/client/provider/jboss/FileSystemXAResourceRegistry.java @@ -17,6 +17,8 @@ */ package org.wildfly.transaction.client.provider.jboss; +import static java.security.AccessController.doPrivileged; + import org.wildfly.common.annotation.NotNull; import org.wildfly.transaction.client.LocalTransaction; import org.wildfly.transaction.client.SimpleXid; @@ -39,6 +41,9 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.StandardOpenOption; +import java.security.PrivilegedAction; +import java.security.PrivilegedActionException; +import java.security.PrivilegedExceptionAction; import java.util.Collections; import java.util.HashSet; import java.util.List; @@ -204,14 +209,20 @@ private final class XAResourceRegistryFile extends XAResourceRegistry { * @throws SystemException if the there was a problem when creating the recovery file in file system */ XAResourceRegistryFile(Xid xid) throws SystemException { - xaRecoveryPath.toFile().mkdir(); // create dir if non existent + final String xidString = SimpleXid.of(xid).toHexString('_'); this.filePath = xaRecoveryPath.resolve(xidString); - openFilePaths.add(xidString); + try { - fileChannel = FileChannel.open(filePath, StandardOpenOption.APPEND, StandardOpenOption.CREATE_NEW); + fileChannel = doPrivileged((PrivilegedExceptionAction) () -> { + xaRecoveryPath.toFile().mkdir(); // create dir if non existent + return FileChannel.open(filePath, StandardOpenOption.APPEND, StandardOpenOption.CREATE_NEW); + }); + openFilePaths.add(xidString); fileChannel.lock(); Log.log.xaResourceRecoveryFileCreated(filePath); + } catch (PrivilegedActionException e) { + throw Log.log.createXAResourceRecoveryFileFailed(filePath, (IOException)e.getCause()); } catch (IOException e) { throw Log.log.createXAResourceRecoveryFileFailed(filePath, e); }