Skip to content

Commit

Permalink
Sort FileSystemAccess methods, improve error handling and refactor in…
Browse files Browse the repository at this point in the history
… JavaAspectConfiguration
  • Loading branch information
sarpsahinalp committed Aug 8, 2024
1 parent 7bfdfd5 commit cf9d98f
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class JavaAspectConfiguration implements AspectConfiguration {

private final JavaSupportedAspectConfiguration javaSupportedAspectConfiguration;
private final SecurityPolicy securityPolicy;
// TODO: this is currently not used
private final Path withinPath;

/**
Expand Down Expand Up @@ -90,6 +91,7 @@ public String createAspectConfigurationFileContent() {
.collect(Collectors.joining(",\n")));
content.append("\n);\n");
}
default -> throw new UnsupportedOperationException("Unsupported configuration: " + javaSupportedAspectConfiguration);
}
return content.toString();
}
Expand All @@ -103,26 +105,19 @@ public void runAspectConfiguration() {
deactivateAspectJConfig();
return;
}
// TODO: This is definitely a code smell. Why do we change static stuff from a non-static method take a look at java:S2696
switch (javaSupportedAspectConfiguration) {
case FILESYSTEM_INTERACTION -> {
JavaAspectConfigurationLists.allowedFileSystemInteractions = securityPolicy.iAllowTheFollowingFileSystemInteractionsForTheStudents();
}
case NETWORK_CONNECTION -> {
JavaAspectConfigurationLists.allowedNetworkConnections = securityPolicy.iAllowTheFollowingNetworkConnectionsForTheStudents();
}
case COMMAND_EXECUTION -> {
JavaAspectConfigurationLists.allowedCommandExecutions = securityPolicy.iAllowTheFollowingCommandExecutionsForTheStudents();
}
case THREAD_CREATION -> {
JavaAspectConfigurationLists.allowedThreadCreations = securityPolicy.iAllowTheFollowingThreadCreationsForTheStudents();
}
case PACKAGE_IMPORT -> {
JavaAspectConfigurationLists.allowedPackageImports = securityPolicy.iAllowTheFollowingPackageImportForTheStudents();
}
case FILESYSTEM_INTERACTION -> JavaAspectConfigurationLists.allowedFileSystemInteractions = securityPolicy.iAllowTheFollowingFileSystemInteractionsForTheStudents();
case NETWORK_CONNECTION -> JavaAspectConfigurationLists.allowedNetworkConnections = securityPolicy.iAllowTheFollowingNetworkConnectionsForTheStudents();
case COMMAND_EXECUTION -> JavaAspectConfigurationLists.allowedCommandExecutions = securityPolicy.iAllowTheFollowingCommandExecutionsForTheStudents();
case THREAD_CREATION -> JavaAspectConfigurationLists.allowedThreadCreations = securityPolicy.iAllowTheFollowingThreadCreationsForTheStudents();
case PACKAGE_IMPORT -> JavaAspectConfigurationLists.allowedPackageImports = securityPolicy.iAllowTheFollowingPackageImportForTheStudents();
default -> throw new UnsupportedOperationException("Unsupported configuration: " + javaSupportedAspectConfiguration);
}
}

public void deactivateAspectJConfig () {
// TODO: Why do we even need this??? This should be handled more elegantly.
public static void deactivateAspectJConfig () {
JavaAspectConfigurationLists.allowedFileSystemInteractions = null;
JavaAspectConfigurationLists.allowedNetworkConnections = null;
JavaAspectConfigurationLists.allowedCommandExecutions = null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,68 +1,77 @@
java.io.File.length()
java.io.File.isFile()
java.io.File.lastModified()
java.io.File.isDirectory()
java.io.File.isHidden()
java.awt.Desktop.browse(java.net.URI)
java.awt.Desktop.browseFileDirectory(java.io.File)
java.awt.Desktop.edit(java.io.File)
java.awt.Desktop.mail()
java.awt.Desktop.mail(java.net.URI)
java.awt.Desktop.moveToTrash(java.io.File)
java.awt.Desktop.open(java.io.File)
java.awt.Desktop.openHelpViewer()
java.awt.Desktop.print(java.io.File)
java.awt.Desktop.setOpenFileHandler(java.awt.desktop.OpenFilesHandler)
java.awt.Desktop.setOpenFileHandler(java.awt.desktop.OpenFilesHandler)
java.awt.Desktop.setOpenURIHandler(java.awt.desktop.OpenURIHandler)
java.io.File.canExecute()
java.io.File.canRead()
java.io.File.canWrite()
java.io.File.createNewFile()
java.io.File.createTempFile(java.lang.String, java.lang.String, java.io.File)
java.io.File.delete()
java.io.File.deleteOnExit()
java.io.File.exists()
java.io.File.getUsableSpace()
java.io.File.getTotalSpace()
java.io.File.normalizedList()
java.io.File.getFreeSpace()
java.io.FileInputStream.<init>(java.io.File)
java.io.RandomAccessFile.<init>(java.io.File, java.lang.String, boolean)
sun.nio.fs.WindowsPath.checkRead()
sun.nio.fs.WindowsPath.register(java.nio.file.WatchService, [Ljava.nio.file.WatchEvent$Kind;, [Ljava.nio.file.WatchEvent$Modifier;)
sun.nio.fs.WindowsFileSystem.getRootDirectories()
sun.nio.fs.WindowsChannelFactory.open(java.lang.String, java.lang.String, sun.nio.fs.WindowsChannelFactory$Flags, long)
sun.nio.fs.WindowsAclFileAttributeView.checkAccess(sun.nio.fs.WindowsPath, boolean, boolean)
sun.nio.fs.AbstractUserDefinedFileAttributeView.checkAccess(java.lang.String, boolean, boolean)
sun.net.www.protocol.jar.JarFileFactory.getCachedJarFile(java.net.URL)
sun.net.httpserver.simpleserver.FileServerHandler.<init>(java.nio.file.Path, java.util.function.UnaryOperator)
sun.awt.shell.Win32ShellFolderManager2.checkFile(java.io.File, java.lang.SecurityManager)
sun.awt.shell.Win32ShellFolder2.getFileSystemPath(int)
sun.awt.shell.Win32ShellFolder2.listFiles(boolean)
sun.awt.shell.ShellFolderManager.checkFile(java.io.File, java.lang.SecurityManager)
sun.awt.image.FileImageSource.<init>(java.lang.String)
java.util.zip.ZipFile.<init>(java.io.File, int, java.nio.charset.Charset)
java.io.WinNTFileSystem.access(java.lang.String)
java.io.WinNTFileSystem.resolve(java.io.File)
sun.nio.fs.WindowsFileSystemProvider.checkAccess(java.nio.file.Path, [Ljava.nio.file.AccessMode;)
java.io.File.canExecute()
java.io.File.setReadOnly()
java.io.File.getTotalSpace()
java.io.File.getUsableSpace()
java.io.File.isDirectory()
java.io.File.isFile()
java.io.File.isHidden()
java.io.File.lastModified()
java.io.File.length()
java.io.File.mkdir()
java.io.File.setWritable(boolean, boolean)
java.io.File.setReadable(boolean, boolean)
java.io.File.createTempFile(java.lang.String, java.lang.String, java.io.File)
java.io.File.canWrite()
java.io.File.setLastModified(long)
java.io.File.createNewFile()
java.io.File.normalizedList()
java.io.File.renameTo(java.io.File)
java.io.File.renameTo(java.io.File)
java.io.File.setExecutable(boolean, boolean)
java.io.File.setLastModified(long)
java.io.File.setReadOnly()
java.io.File.setReadable(boolean, boolean)
java.io.File.setWritable(boolean, boolean)
java.io.FileInputStream.<init>(java.io.File)
java.io.FileOutputStream.<init>(java.io.File, boolean)
java.io.RandomAccessFile.<init>(java.io.File, java.lang.String, boolean)
java.io.RandomAccessFile.<init>(java.io.File, java.lang.String, boolean)
java.io.UnixFileSystem.checkAccess(java.io.File, int)
java.io.UnixFileSystem.resolve(java.io.File)
java.io.WinNTFileSystem.access(java.lang.String)
java.io.WinNTFileSystem.resolve(java.io.File)
java.lang.ProcessImpl.newFileOutputStream(java.io.File, boolean)
java.util.zip.ZipFile.<init>(java.io.File, int, java.nio.charset.Charset)
java.util.zip.ZipFile.<init>(java.io.File, int, java.nio.charset.Charset)
sun.awt.image.FileImageSource.<init>(java.lang.String)
sun.awt.shell.DefaultShellFolder.getFileSystemPath(int)
sun.awt.shell.DefaultShellFolder.listFiles(boolean)
sun.awt.shell.ShellFolderManager.checkFile(java.io.File, java.lang.SecurityManager)
sun.awt.shell.Win32ShellFolder2.getFileSystemPath(int)
sun.awt.shell.Win32ShellFolder2.listFiles(boolean)
sun.awt.shell.Win32ShellFolderManager2.checkFile(java.io.File, java.lang.SecurityManager)
sun.net.httpserver.simpleserver.FileServerHandler.<init>(java.nio.file.Path, java.util.function.UnaryOperator)
sun.net.www.protocol.jar.JarFileFactory.getCachedJarFile(java.net.URL)
sun.nio.fs.AbstractUserDefinedFileAttributeView.checkAccess(java.lang.String, boolean, boolean)
sun.nio.fs.AbstractUserDefinedFileAttributeView.checkAccess(java.lang.String, boolean, boolean)
sun.nio.fs.UnixChannelFactory.open(int, sun.nio.fs.UnixPath, java.lang.String, sun.nio.fs.UnixChannelFactory$Flags, int)
sun.nio.fs.UnixFileSystem.getRootDirectories()
sun.nio.fs.UnixFileSystemProvider.readSymbolicLink(java.nio.file.Path)
sun.nio.fs.UnixPath.checkDelete()
sun.nio.fs.UnixPath.checkRead()
sun.nio.fs.UnixPath.checkWrite()
sun.nio.fs.UnixPath.register(java.nio.file.WatchService, [Ljava.nio.file.WatchEvent$Kind;, [Ljava.nio.file.WatchEvent$Modifier;)
sun.nio.fs.WindowsAclFileAttributeView.checkAccess(sun.nio.fs.WindowsPath, boolean, boolean)
sun.nio.fs.WindowsChannelFactory.open(java.lang.String, java.lang.String, sun.nio.fs.WindowsChannelFactory$Flags, long)
sun.nio.fs.WindowsPath.checkWrite()
sun.print.Win32PrintJob.getAttributeValues(javax.print.DocFlavor)
java.awt.Desktop.moveToTrash(java.io.File)
java.io.File.delete()
java.io.File.deleteOnExit()
java.util.zip.ZipFile.<init>(java.io.File, int, java.nio.charset.Charset)
sun.nio.fs.WindowsChannelFactory.open(java.lang.String, java.lang.String, sun.nio.fs.WindowsChannelFactory$Flags, long)
sun.nio.fs.WindowsFileSystem.getRootDirectories()
sun.nio.fs.WindowsFileSystemProvider.checkAccess(java.nio.file.Path, [Ljava.nio.file.AccessMode;)
sun.nio.fs.WindowsFileSystemProvider.readSymbolicLink(java.nio.file.Path)
sun.nio.fs.WindowsPath.checkDelete()
java.awt.Desktop.edit(java.io.File)
java.awt.Desktop.browseFileDirectory(java.io.File)
java.awt.Desktop.print(java.io.File)
java.awt.Desktop.mail(java.net.URI)
java.awt.Desktop.openHelpViewer()
java.awt.Desktop.setOpenFileHandler(java.awt.desktop.OpenFilesHandler)
java.awt.Desktop.open(java.io.File)
java.awt.Desktop.setOpenURIHandler(java.awt.desktop.OpenURIHandler)
java.awt.Desktop.mail()
java.awt.Desktop.browse(java.net.URI)
java.awt.Desktop.setOpenFileHandler(java.awt.desktop.OpenFilesHandler)
sun.nio.fs.WindowsFileSystemProvider.readSymbolicLink(java.nio.file.Path)
sun.nio.fs.WindowsPath.checkRead()
sun.nio.fs.WindowsPath.checkWrite()
sun.nio.fs.WindowsPath.register(java.nio.file.WatchService, [Ljava.nio.file.WatchEvent$Kind;, [Ljava.nio.file.WatchEvent$Modifier;)
sun.print.UnixPrintJob.getAttributeValues(javax.print.DocFlavor)
sun.print.Win32PrintJob.getAttributeValues(javax.print.DocFlavor)

0 comments on commit cf9d98f

Please sign in to comment.