public static void openFile() { try { output = new Formatter("clients.txt"); // open the file } catch (SecurityException securityException) { System.err.println("Write permission denied. Terminating."); System.exit(1); // terminate the program } catch (FileNotFoundException fileNotFoundException) { System.err.println("Error opening file. Terminating."); System.exit(1); // terminate the program } }
private synchronized String privGetCanonicalPath(final StorageFile file) { actionCode = STORAGE_FILE_GET_CANONICALPATH_ACTION; actionStorageFile = file; try { return (String) AccessController.doPrivileged( this); } catch( PrivilegedActionException pae) { return null; } // does not throw an exception catch(SecurityException se) { // there are no permission to get canonical path // just return null. return null; } finally { actionStorageFile = null; } }
private synchronized String privGetCanonicalPath(final File file) { actionCode = REGULAR_FILE_GET_CANONICALPATH_ACTION; actionRegularFile = file; try { return (String) AccessController.doPrivileged( this); } catch( PrivilegedActionException pae) { return null; } // does not throw an exception catch(SecurityException se) { // there are no permission to get canonical path // just return null. return null; } finally { actionRegularFile = null; } }
public void openFile() { try { output = new Formatter( "clients.txt" ); } // end try catch ( SecurityException securityException ) { System.err.println( "You do not have write access to this file." ); System.exit( 1 ); } // end catch catch ( FileNotFoundException filesNotFoundException ) { System.err.println( "Error creating file." ); System.exit( 1 ); } // end catch }
/** * Runs the test using the specified harness. * * @param harness the test harness (<code>null</code> not permitted). */ public void test(TestHarness harness) { SecurityException object1 = new SecurityException(); harness.check(object1 != null); harness.check(object1.toString(), "java.lang.SecurityException"); SecurityException object2 = new SecurityException("nothing happens"); harness.check(object2 != null); harness.check(object2.toString(), "java.lang.SecurityException: nothing happens"); SecurityException object3 = new SecurityException((String)null); harness.check(object3 != null); harness.check(object3.toString(), "java.lang.SecurityException"); }
public static String generateMnemonicCode(byte[] entropy) throws SecurityException{ try { String[] words = MnemonicCode.INSTANCE.toMnemonic(entropy).toArray(new String[0]); return String.join(" ", words); } catch (Exception ex){ throw new SecurityException("generate mnemonic code failed", ex); } }
public static void main(String[] args) throws Exception { // get location of run class. CodeSource cs = null; try { cs = com.pivotal.gemfirexd.internal.iapi.tools.run.class.getProtectionDomain().getCodeSource(); } catch (SecurityException se) { System.out.println("Security exception: " + se.getMessage()); } URL result = cs.getLocation(); jvm jvm = null; String derbyrunloc = null; if (result.toString().endsWith(".jar")) { derbyrunloc = result.toString().substring(5); if (System.getProperty("os.name").startsWith("Windows")) derbyrunloc = derbyrunloc.substring(1); jvm = jvm.getJvm("currentjvm"); // ensure compatibility } String[][] testCommands = new String[][] { {"ij", "--help"}, {"sysinfo", "-cp", "help"}, {"dblook"}, {"server"}, }; for (int i = 0; i < testCommands.length; i++) { runtool(jvm, derbyrunloc, testCommands[i]); } }
private static String getPathName(String route) throws IOException { if (route == null) { route = TARGET_DIRECTORY; } File file = new File(route); if (file.exists() && !file.isDirectory()) { throw new IOException("File " + route + " exists but it is not a directory"); } else if (!file.exists()) { // path does not yet exist try { if (!file.mkdir()) { throw new IOException("Error creating directory " + route); } } catch (SecurityException se) { throw new IOException("Security Exception creating " + route); } } StringBuilder path = new StringBuilder().append(route).append(File.separator).append(J2PUML); SimpleDateFormat instant = new SimpleDateFormat("ddMMyyyy_HM_mm", Locale.getDefault()); Date now = new Date(); StringBuilder fileName = new StringBuilder(instant.format(now)); path.append(fileName).append("." + FILE_EXTENSION); return path.toString(); }
public static String getPropSigned(final String key) { try { return System.getProperty(key); } catch (final SecurityException se) { se.printStackTrace(); return "SECURITY EXCEPTION"; } }
public static String getPropUnsigned(final String key) { try { return System.getProperty(key); } catch (final SecurityException se) { se.printStackTrace(); return "SECURITY EXCEPTION"; } }
private void writeSimpleFiles(String path, String ext, int numOfFiles) { // Create folder File folder = new File(path); if (!folder.exists()) { try { folder.mkdir(); } catch (SecurityException se) { fail("Failed creating directory:" + path + se); } } // Write files for (int i = 1; i <= numOfFiles; i++) { String fn = null; if (ext != null) { fn = Integer.toString(i) + "." + ext; } else { fn = Integer.toString(i); } try { FileWriter fwr = new FileWriter(new File(path, fn)); fwr.write(Integer.toString(i)); fwr.close(); } catch (IOException ioe) { fail("Fail writing to input file: " + fn + " in directory: " + path + ioe.getMessage()); } } }
/** * Runs the test using the specified harness. * * @param harness the test harness (<code>null</code> not permitted). */ public void test(TestHarness harness) { // flag that is set when exception is caught boolean caught = false; try { throw new SecurityException("SecurityException"); } catch (SecurityException e) { // correct exception was caught caught = true; } harness.check(caught); }
private void writeSimpleFiles(String path, String ext, int numOfFiles) { // Create folder File folder = new File(path); if (!folder.exists()) { try{ folder.mkdir(); } catch(SecurityException se){ fail("Failed creating directory:"+path+se); } } // Write files for (int i=1; i<=numOfFiles; i++) { String fn = null; if (ext != null) { fn = Integer.toString(i) + "."+ ext; } else { fn = Integer.toString(i); } try { FileWriter fwr = new FileWriter(new File(path,fn)); fwr.write(Integer.toString(i)); fwr.close(); } catch (IOException ioe) { fail("Fail writing to input file: "+ fn + " in directory: " + path + ioe.getMessage()); } } }
private void crawl( File curDir, StringBuilder className) { if( verbose) System.out.println( "Searching directory " + curDir.getPath()); try { if( ! curDir.isDirectory()) { System.err.println( "*** " + curDir.getPath() + " is not a directory."); System.exit(1); } } catch( SecurityException se) { System.err.println( "Cannot access " + curDir.getPath()); System.exit(1); } String[] filenames = curDir.list( ); if( className.length() != 0) className.append( "."); int classNameLength = className.length(); for( int fileIdx = 0; fileIdx < filenames.length; fileIdx++) { if( filenames[fileIdx].endsWith( ".class")) { // Strip off the ".class" suffix String s = filenames[fileIdx].substring( 0, filenames[fileIdx].length() - 6); className.append( s); Class targetClass = null; String targetClassName = className.toString(); try { targetClass = Class.forName( targetClassName); if( !targetClass.isInterface()) { for( int interfaceIdx = 0; interfaceIdx < interfaceCount; interfaceIdx++) { if( interfaceList[interfaceIdx].isAssignableFrom( targetClass)) addClass( targetClass); } } } catch( ClassNotFoundException cnfe) { System.err.println( "Could not find class " + targetClassName); System.exit(1); } catch( Throwable t){} className.setLength( classNameLength); } else { File nextDir = new File( curDir, filenames[fileIdx]); if( nextDir.isDirectory()) { className.append( filenames[fileIdx]); crawl( nextDir, className); className.setLength( classNameLength); } } } }
public List getEntities(EntityReference ref, Search search){ Vector results = new Vector(); String siteId = null; Restriction[] restrictions = search.getRestrictions(); String userId = null; for(int r=0;r<restrictions.length;r++){ if(restrictions[r].property.equalsIgnoreCase("siteId")){ siteId = (String) restrictions[r].value; } if(restrictions[r].property.equalsIgnoreCase("userId")){ userId = (String) restrictions[r].value; } if(restrictions[r].property.equalsIgnoreCase("context")){ siteId = (String) restrictions[r].value; } } if(userId==null){ userId = developerHelperService.getCurrentUserId(); } if (userId == null) { throw new SecurityException("No user is currently logged in so no data can be retrieved"); } if(userId==null)return results; if(siteId==null) return results; String orderBy = "title"; List assessments = null; boolean canPublish = false; Date currentDate = new Date(); // Check what the user can do if (securityService.unlock(CAN_PUBLISH, "/site/"+siteId)) { publishedAssessmentFacadeQueries. getBasicInfoOfAllActivePublishedAssessments(orderBy, siteId, true); assessments = publishedAssessmentFacadeQueries .getBasicInfoOfAllInActivePublishedAssessments(orderBy, siteId, true); assessments.addAll(publishedAssessmentFacadeQueries .getBasicInfoOfAllActivePublishedAssessments(orderBy, siteId, true)); canPublish = true; } else if (securityService.unlock(CAN_TAKE, "/site/"+siteId)) { assessments = publishedAssessmentFacadeQueries .getBasicInfoOfAllActivePublishedAssessments(orderBy, siteId, true); } if (assessments != null) { Iterator assessmentIterator = assessments.iterator(); while(assessmentIterator.hasNext()){ PublishedAssessmentFacade pub = (PublishedAssessmentFacade) assessmentIterator.next(); results.add(pub); } } return results; }
/** Get the keystore associated with the security domain */ public KeyStore getKeyStore() throws SecurityException;
/** Get the KeyManagerFactory associated with the security domain */ public KeyManagerFactory getKeyManagerFactory() throws SecurityException;
/** Get the TrustManagerFactory associated with the security domain */ public TrustManagerFactory getTrustManagerFactory() throws SecurityException;
/** Get the truststore associated with the security domain. This may be the same as the keystore. */ public KeyStore getTrustStore() throws SecurityException;
/** * Get the keystore associated with the security domain * * @return the keystore */ public KeyStore getKeyStore() throws SecurityException;
/** * Get the KeyManagers created by the configured KeyManagerFactory * * @return the initialized KeyManagers */ public KeyManager[] getKeyManagers() throws SecurityException;
/** * Get the truststore associated with the security domain. This may be the same as the keystore * * @return the truststore */ public KeyStore getTrustStore() throws SecurityException;
/** * Get the TrustManagers created by the configured TrustManagerFactory * * @return the initialized TrustManagers */ public TrustManager[] getTrustManagers() throws SecurityException;