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

[WFLY-11357] add priv block to FileSystemXAResourceRegistry #62

Merged
merged 1 commit into from Jun 17, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -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;
Expand All @@ -29,6 +31,7 @@
import javax.transaction.xa.XAResource;
import javax.transaction.xa.Xid;
import java.io.File;
import java.io.FilePermission;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
Expand All @@ -39,6 +42,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;
Expand All @@ -56,6 +62,7 @@
*/
final class FileSystemXAResourceRegistry {

private static final FilePermission FILE_PERMISSION = new FilePermission("<<ALL FILES>>", "read,write");
/**
* Name of recovery dir. Location of this dir can be defined at constructor.
*/
Expand Down Expand Up @@ -204,14 +211,24 @@ 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<FileChannel>) () -> {
final SecurityManager sm = System.getSecurityManager();
if(sm != null) {
sm.checkPermission(FILE_PERMISSION);
}
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);
}
Expand Down