List of usage examples for java.lang SecurityManager checkRead
public void checkRead(String file)
SecurityException
if the calling thread is not allowed to read the file specified by the string argument. From source file:Main.java
public static void main(String[] args) { System.setProperty("java.security.policy", "file:/C:/java.policy"); SecurityManager sm = new Main(); System.setSecurityManager(sm); sm.checkRead("test.txt"); System.out.println("Allowed!"); }
From source file:Main.java
public static void main(String[] args) { System.setProperty("java.security.policy", "file:/C:/java.policy"); SecurityManager sm = new Main(); System.setSecurityManager(sm); FileDescriptor fd = new FileDescriptor(); sm.checkRead(fd); System.out.println("Allowed!"); }
From source file:CustomSecurityManager.java
public static void main() { System.setSecurityManager(new CustomSecurityManager()); SecurityManager secMgr = System.getSecurityManager(); if (secMgr != null) { secMgr.checkRead("fileName"); }/* w w w. j av a 2s . c o m*/ }
From source file:org.codice.ddf.configuration.migration.ImportMigrationContextImpl.java
@SuppressWarnings("PMD.DefaultPackage" /* designed to be called from ImportMigrationEntryImpl within this package */) @VisibleForTesting// w w w .jav a 2s .c o m InputStream getInputStreamFor(ImportMigrationEntryImpl entry, boolean checkAccess) throws IOException { if (checkAccess && files.contains(entry.getName())) { // we were asked to check if the migratable that is requesting this stream has read access // and the content was exported by the framework and not by the migratable directly, as // such we need to check with the security manager if one was installed final SecurityManager sm = System.getSecurityManager(); if (sm != null) { sm.checkRead(entry.getFile().getPath()); } } final InputStream is = zip.getInputStream(entry.getZipEntry()); inputStreams.add(is); return is; }