Skip to content

Commit

Permalink
8296718: Refactor bootstrap Test Common Functionalities to test/lib/U…
Browse files Browse the repository at this point in the history
…tils

Reviewed-by: sspitsyn, kevinw
  • Loading branch information
Bill Huang committed Nov 9, 2022
1 parent 17e3412 commit cc8bf95
Show file tree
Hide file tree
Showing 4 changed files with 239 additions and 237 deletions.
Expand Up @@ -21,6 +21,8 @@
* questions.
*/

import jdk.test.lib.Utils;

import sun.management.jmxremote.ConnectorBootstrap;

import java.io.File;
Expand Down
47 changes: 5 additions & 42 deletions test/jdk/sun/management/jmxremote/bootstrap/RmiTestBase.java
Expand Up @@ -26,6 +26,7 @@
* */

import jdk.test.lib.Platform;
import jdk.test.lib.Utils;

import java.io.File;
import java.io.FilenameFilter;
Expand Down Expand Up @@ -144,55 +145,17 @@ static List<Path> prepareTestFiles(String filenamePattern) throws IOException {
return Collections.unmodifiableList(propertyFiles);
}

/**
* Grant file access.
*
* @param file file to grant access
* @param access user access or full access
* @throws IOException if error occurs
*/
static void grantAccess(Path file, AccessControl access) throws IOException {
Set<String> attr = file.getFileSystem().supportedFileAttributeViews();
if (attr.contains("posix")) {
String perms = access == AccessControl.OWNER ? "rw-------" : "rwxrwxrwx";
Files.setPosixFilePermissions(file, PosixFilePermissions.fromString(perms));
} else if (attr.contains("acl")) {
AclFileAttributeView view = Files.getFileAttributeView(file, AclFileAttributeView.class);
List<AclEntry> acl = new ArrayList<>();
for (AclEntry thisEntry : view.getAcl()) {
if (access == AccessControl.OWNER) {
if (thisEntry.principal().getName().equals(view.getOwner().getName())) {
acl.add(Utils.allowAccess(thisEntry));
} else if (thisEntry.type() == AclEntryType.ALLOW) {
acl.add(Utils.revokeAccess(thisEntry));
} else {
acl.add(thisEntry);
}
} else {
if (!thisEntry.principal().getName().contains("NULL SID")
&& thisEntry.type() != AclEntryType.ALLOW) {
acl.add(Utils.allowAccess(thisEntry));
} else {
acl.add(thisEntry);
}
}
}
view.setAcl(acl);
} else {
throw new RuntimeException("Unsupported file attributes: " + attr);
}
}

/**
* Grant files' access.
*
* @param files files to grant access
* @param access user access or full access
* @throws IOException if error occurs
*/
static void grantFilesAccess(List<Path> files, AccessControl access) throws IOException {
static void grantFilesAccess(List<Path> files, AccessControl access)
throws IOException {
for (Path thisFile : files) {
grantAccess(thisFile, access);
Utils.grantFileAccess(thisFile, access == AccessControl.OWNER);
}
}

Expand All @@ -209,7 +172,7 @@ static void copySsl() throws IOException {
Utils.copyFiles(files, sslTarget, StandardCopyOption.REPLACE_EXISTING);

for (Path file : files) {
grantAccess(sslTarget.resolve(file.getFileName()), AccessControl.EVERYONE);
Utils.fullAccess(sslTarget.resolve(file.getFileName()));
}
}

Expand Down
195 changes: 0 additions & 195 deletions test/jdk/sun/management/jmxremote/bootstrap/Utils.java

This file was deleted.

1 comment on commit cc8bf95

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.