List of usage examples for java.lang SecurityException getMessage
public String getMessage()
From source file:org.openremote.modeler.cache.LocalFileCache.java
/** * TODO : See Javadoc on interface definition. This exists to support earlier API patterns. */// ww w.j a va 2s .com @Override public void markInUseImages(Set<File> markedImageFiles) { for (File file : markedImageFiles) { try { // TODO : // // There are still bugs in the implementation and/or previous designer serialized state // that cause the domain model to reference images that are not present in the cache. // // This is a workaround to prevent later errors occuring due to missing cache // resources -- if the image being marked as 'in-use' does not exist, do not include it, // instead log an error. // [JPL] File cacheResource = new File(cacheFolder, file.getName()); if (!cacheResource.exists()) { cacheLog.error( "BUG: domain model references image {0} ({1}) which was not found in cache folder.", file, cacheResource); } else { imageFiles.add(file); } } catch (SecurityException e) { cacheLog.error("Security manager denied read access to ''{0}'' : {1}", new File(cacheFolder, file.getName()).getAbsolutePath(), e.getMessage()); } } }
From source file:org.openremote.modeler.cache.LocalFileCache.java
/** * Checks for the existence of local cache folder this cache implementation uses for its * operations.// w ww. ja v a2 s .c o m * * @return true if cache directory already exists, false otherwise * * @throws ConfigurationException * if read access to file system has been denied */ private boolean hasCacheFolder() throws ConfigurationException { try { return cacheFolder.exists(); } catch (SecurityException e) { throw new ConfigurationException( "Security manager has denied read access to local user cache in ''{0}'' : {1}", e, cacheFolder.getAbsolutePath(), e.getMessage()); } }
From source file:org.openremote.modeler.cache.LocalFileCache.java
/** * TODO : http://jira.openremote.org/browse/MODELER-285 * * Checks for the existence of cache *backup* folder. * * @return true if cache backup directory already exists, false otherwise * * @throws ConfigurationException//from w w w. j ava2 s. c o m * if read access to file system has been denied */ private boolean hasBackupFolder() throws ConfigurationException { File backupFolder = getBackupFolder(); try { return backupFolder.exists(); } catch (SecurityException e) { throw new ConfigurationException( "Security manager has denied read access to local user cache in ''{0}'' : {1}", e, backupFolder.getAbsolutePath(), e.getMessage()); } }
From source file:org.openremote.modeler.cache.LocalFileCache.java
/** * Removes the local filesystem directory structure to store a cached * Beehive archive associated with a given account. <p> * * @see #createCacheFolder//from ww w.j av a2s . c o m * @see #hasCacheFolder * * @throws ConfigurationException * if the deletion of the directories fail for any reason */ private void removeCacheFolder() throws ConfigurationException { try { FileUtils.deleteDirectory(cacheFolder); cacheLog.info("Deleted account {0} cache folder (User: {1}).", currentUserAccount.getAccount().getOid(), currentUserAccount.getUsernamePassword().getUsername()); } catch (SecurityException e) { throw new ConfigurationException( "Security manager has denied read/write access to local user cache in ''{0}'' : {1}", e, cacheFolder.getAbsolutePath(), e.getMessage()); } catch (IOException e) { throw new ConfigurationException("Unable to delete cache directory for ''{0}''.", cacheFolder.getAbsolutePath()); } }
From source file:org.openremote.modeler.cache.LocalFileCache.java
/** * TODO : http://jira.openremote.org/browse/MODELER-285 * * Constructs the local filesystem backup directory for Beehive archives. * * @throws ConfigurationException/*from w w w. j av a2s .co m*/ * if the creation of the directory fail for any reason */ private void createBackupFolder() throws ConfigurationException { File backupFolder = getBackupFolder(); try { boolean success = backupFolder.mkdirs(); if (!success) { throw new ConfigurationException("Unable to create required directories for ''{0}''.", backupFolder.getAbsolutePath()); } else { cacheLog.debug("Created cache backup folder for account {0} (User: {1}).", currentUserAccount.getAccount().getOid(), currentUserAccount.getUsernamePassword().getUsername()); } } catch (SecurityException e) { throw new ConfigurationException( "Security manager has denied read/write access to local user cache in ''{0}'' : {1}", e, backupFolder.getAbsolutePath(), e.getMessage()); } }
From source file:org.openremote.modeler.cache.LocalFileCache.java
/** * Constructs the local filesystem directory structure to store a cached * Beehive archive associated with a given account. <p> * * Both the local cache directory and common subdirectories are created. * * @see #hasCacheFolder/*ww w .j a va 2 s . co m*/ * * @throws ConfigurationException * if the creation of the directories fail for any reason */ private void createCacheFolder() throws ConfigurationException { try { boolean success = cacheFolder.mkdirs(); if (!success) { throw new ConfigurationException("Unable to create required directories for ''{0}''.", cacheFolder.getAbsolutePath()); } else { cacheLog.info("Created account {0} cache folder (User: {1}).", currentUserAccount.getAccount().getOid(), currentUserAccount.getUsernamePassword().getUsername()); } } catch (SecurityException e) { throw new ConfigurationException( "Security manager has denied read/write access to local user cache in ''{0}'' : {1}", e, cacheFolder.getAbsolutePath(), e.getMessage()); } if (!hasBackupFolder()) // TODO : See MODELER-285 { createBackupFolder(); } }
From source file:org.openremote.modeler.cache.LocalFileCache.java
/** * TODO : MODELER-285 -- this implementation should migrate to Beehive side. * * Creates a backup of the downloaded Beehive archive in the given account's cache folder. * Backups are created at most once per day. Number of daily backups can be limited. Daily * backups may optionally be rolled to weekly or monthly backups. * * @throws ConfigurationException//w w w . ja va 2 s.c o m * if read/write access to cache folder or cache backup folder has not been granted, * or creation of the required files fails for any other reason * * @throws CacheOperationException * if any runtime or I/O errors occur during the normal file operations required * to create backups, or if there's any indication that backup operation is not * working as expected and admin should be notified */ private void backup() throws ConfigurationException, CacheOperationException { // See if we should run... if (haltAccountBackups.contains(currentUserAccount.getAccount().getOid())) { cacheLog.warn("Backups for account {0} have been stopped!", currentUserAccount.getAccount().getOid()); return; } // Sanity check... if (!hasCachedArchive() && hasNewestDailyBackup()) { // It looks like the originally cached BEEHIVE_ARCHIVE_NAME has disappeared, but some // cache backup is still in place. // // This is odd, so bail out and notify. throw new CacheOperationException( "The Beehive archive was not found in cache but some backups were created earlier. " + "Should investigate the issue."); } // If no BEEHIVE_ARCHIVE_NAME file is found in cache directory, (and there are no backups) // it means this is the first time the Beehive archive will be downloaded (hopefully, // otherwise we got some deeper issues). There's nothing to back up yet. if (!hasCachedArchive()) { cacheLog.info("No existing Beehive archive found. Backup skipped."); return; } // If it looks like this is the first backup being made (hopefully not due to cache // backups getting wiped due to some other errors)... if (!hasBackupFolder()) { createBackupFolder(); } try { // If there are no existing backups, just make a blanket copy... if (!hasNewestDailyBackup()) { makeDailyBackup(); } else { // If previous backups exist, check the timestamps and create a new one if the // newest is older than 24 hours... long timestamp = getCachedArchive().lastModified(); long backuptime = getNewestDailyBackupFile().lastModified(); if (timestamp - backuptime > DAY) { cacheLog.info("Current daily backup is {0} days old. Creating a new backup...", new DecimalFormat("######0.00").format((float) (timestamp - backuptime) / DAY)); makeDailyBackup(); } else { cacheLog.info("Current archive was created only {0} hours ago. Skipping daily backup...", new DecimalFormat("######0.00").format(((float) (timestamp - backuptime)) / HOUR)); } } } catch (SecurityException e) { throw new ConfigurationException("Security manager has denied read access to ''{0}'' : {1}", e, getCachedArchive().getAbsolutePath(), e.getMessage()); } }
From source file:org.openremote.modeler.cache.LocalFileCache.java
/** * TODO : MODELER-289/*from w w w . j a va 2 s.c o m*/ * * - This method should not be public. Once the faulty export implementation in * Designer is corrected (see Modeler-288), should become private * * * * Creates an exportable zip file archive on the local file system in the configured * account's cache directory. <p> * * The archive is created based on the files as currently existing in the cache. * It is up to the caller of the method to ensure the cache is in the desired state * before creating the export file. * * This archive is used to send user design and configuration changes, added resource * files, etc. as a single HTTP POST payload to Beehive server. <p> * * This implementation is based on the current object model used in Designer which is * not (yet) versioned. The list of artifacts included in the export archive therefore * include : <p> * * <ul> * <li>panel.xml</li> * <li>controller.xml</li> * <li>panels.obj</li> * <li>ui_state.xml</li> * <li>building_modeler.xml</li> // EBR this is not yet part of this branch * <li>lircd.conf</li> * <li>rules</li> * <li>image resources</li> * </ul> * * * @return reference to the export archive file in the account's cache directory * * @throws CacheOperationException * if any of the file operations fail * * @throws ConfigurationException * if there are any security restrictions on file access * */ public File createExportArchive() throws CacheOperationException, ConfigurationException { File panelXMLFile = new File("panel.xml"); File controllerXMLFile = new File("controller.xml"); File panelsObjFile = new File("panels.obj"); File lircdFile = new File("lircd.conf"); File rulesFile = new File("rules", "modeler_rules.drl"); File uiXMLFile = new File("ui_state.xml"); File buildingXMLFile = new File("building_modeler.xml"); // Collect all the files going into the archive... Set<File> exportFiles = new HashSet<File>(); exportFiles.addAll(this.imageFiles); exportFiles.add(uiXMLFile); exportFiles.add(buildingXMLFile); exportFiles.add(panelXMLFile); exportFiles.add(controllerXMLFile); try { if (new File(cacheFolder, panelsObjFile.getPath()).exists()) { exportFiles.add(panelsObjFile); } } catch (SecurityException e) { throw new ConfigurationException( "Security manager denied read access to file ''{0}'' (Account : {1}) : {2}", e, panelsObjFile.getAbsolutePath(), currentUserAccount.getAccount().getOid(), e.getMessage()); } try { if (new File(cacheFolder, rulesFile.getPath()).exists()) { exportFiles.add(rulesFile); } } catch (SecurityException e) { throw new ConfigurationException( "Security manager denied read access to file ''{0}'' (Account : {1}) : {2}", e, rulesFile.getAbsolutePath(), currentUserAccount.getAccount().getOid(), e.getMessage()); } try { if (new File(cacheFolder, lircdFile.getPath()).exists()) { exportFiles.add(lircdFile); } } catch (SecurityException e) { throw new ConfigurationException( "Security manager denied read access to file ''{0}'' (Account : {1}) : {2}", e, lircdFile, currentUserAccount.getAccount().getOid(), e.getMessage()); } // Create export archive file (do not overwrite the existing beehive archive)... File exportDir = new File(cacheFolder, "export"); File targetFile = new File(exportDir, BEEHIVE_ARCHIVE_NAME); try { if (!exportDir.exists()) { boolean success = exportDir.mkdirs(); if (!success) { throw new CacheOperationException( "Cannot complete export archive operation. Unable to create required " + "file directory ''{0}'' for cache (Account ID = {1}).", exportDir.getAbsolutePath(), currentUserAccount.getAccount().getOid()); } } if (targetFile.exists()) { boolean success = targetFile.delete(); if (!success) { throw new CacheOperationException( "Cannot complete export archive operation. Unable to delete pre-existing " + "file ''{0}'' (Account ID = {1})", targetFile.getAbsolutePath(), currentUserAccount.getAccount().getOid()); } } } catch (SecurityException e) { throw new ConfigurationException( "Security manager denied access to temporary export archive file ''{0}'' for " + "account ID = {1} : {2}", e, targetFile.getAbsolutePath(), currentUserAccount.getAccount().getOid(), e.getMessage()); } // Zip it up... compress(targetFile, exportFiles); // Done. return targetFile; }
From source file:org.openremote.modeler.cache.LocalFileCache.java
/** * TODO : MODELER-285 -- migrate this implementation to Beehive side * * Creates a daily backup copy of the downloaded (and cached) Beehive archive for the associated * account. The backup is only created if the existing (if any) backup is older than one day * (based on file timestamps). The copy is created via a temp file in case I/O errors occur. * * @see #hasCachedArchive/*from w ww . ja va2 s. c o m*/ * @see #getCachedArchive * @see #hasBackupFolder * @see #getBackupFolder * * @throws CacheOperationException * if any runtime or I/O errors occur while making backups * * @throws ConfigurationException * if read/write access to cache backup directory has been denied */ private void makeDailyBackup() throws CacheOperationException, ConfigurationException { /** * The Maximum number of daily backups we'll create. */ final int MAX_DAILY_BACKUPS = 5; File cacheFolder = getBackupFolder(); cacheLog.debug("Making a daily backup of current Beehive archive..."); try { File oldestDaily = new File(DAILY_BACKUP_PREFIX + "." + MAX_DAILY_BACKUPS); // If we've reached the maximum number of copies already, see if any of them // are more than a week old (and could be stored to weekly backups). if (oldestDaily.exists()) { moveToWeeklyBackup(oldestDaily); } // Shuffle older backup copies out of the way (down by one index) to make space // for the latest to be saved in DAILY_BACKUP_PREFIX.1 for (int index = MAX_DAILY_BACKUPS - 1; index > 0; index--) { File daily = new File(cacheFolder, DAILY_BACKUP_PREFIX + "." + index); File target = new File(cacheFolder, DAILY_BACKUP_PREFIX + "." + (index + 1)); if (!daily.exists()) { cacheLog.debug("Daily backup file ''{0}'' was not present. Skipping...", daily.getAbsolutePath()); continue; } if (!daily.renameTo(target)) { sortBackups(); throw new CacheOperationException("There was an error moving ''{0}'' to ''{1}''.", daily.getAbsolutePath(), target.getAbsolutePath()); } else { cacheLog.debug("Moved " + daily.getAbsolutePath() + " to " + target.getAbsolutePath()); } } } catch (SecurityException e) { throw new ConfigurationException( "Security Manager has denied read/write access to daily backup files in ''{0}'' : {1}" + e, cacheFolder.getAbsolutePath(), e.getMessage()); } // Now make the actual copy of existing Beehive archive into cache backups. Copy to a // temp file first in case of errors (such as out-of-disk-space) might occur. File beehiveArchive = getCachedArchive(); File tempBackupArchive = new File(cacheFolder, BEEHIVE_ARCHIVE_NAME + ".tmp"); BufferedInputStream archiveReader = null; BufferedOutputStream tempBackupWriter = null; try { archiveReader = new BufferedInputStream(new FileInputStream(beehiveArchive)); tempBackupWriter = new BufferedOutputStream(new FileOutputStream(tempBackupArchive)); int len, bytecount = 0; final int BUFFER_SIZE = 4096; byte[] buffer = new byte[BUFFER_SIZE]; while ((len = archiveReader.read(buffer, 0, BUFFER_SIZE)) != -1) { tempBackupWriter.write(buffer, 0, len); bytecount += len; } tempBackupWriter.flush(); long originalFileSize = beehiveArchive.length(); // Just a sanity check -- we should get the same amount of bytes on both sides on copy... if (originalFileSize != bytecount) { throw new CacheOperationException("Original archive size was {0} bytes but only {1} were copied.", originalFileSize, bytecount); } cacheLog.debug("Finished copying ''{0}'' to ''{1}''.", beehiveArchive.getAbsolutePath(), tempBackupArchive.getAbsolutePath()); } catch (FileNotFoundException e) { throw new CacheOperationException( "Files required for copying a backup of Beehive archive could not be found, opened " + "or created : {1}", e, e.getMessage()); } catch (IOException e) { throw new CacheOperationException("Error while making a copy of the Beehive archive : {0}", e, e.getMessage()); } finally { if (archiveReader != null) { try { archiveReader.close(); } catch (Throwable t) { cacheLog.warn("Failed to close stream to ''{0}'' : {1}", t, beehiveArchive.getAbsolutePath(), t.getMessage()); } } if (tempBackupWriter != null) { try { tempBackupWriter.close(); } catch (Throwable t) { cacheLog.warn("Failed to close stream to ''{0}'' : {1}", t, tempBackupArchive.getAbsolutePath(), t.getMessage()); } } } validateArchive(tempBackupArchive); // Copy was ok, now move from temp to actual location... File newestDaily = getNewestDailyBackupFile(); try { if (!tempBackupArchive.renameTo(newestDaily)) { throw new CacheOperationException("Error moving ''{0}'' to ''{1}''.", tempBackupArchive.getAbsolutePath(), newestDaily.getAbsolutePath()); } else { cacheLog.info("Backup complete. Saved in ''{0}''", newestDaily.getAbsolutePath()); } } catch (SecurityException e) { throw new ConfigurationException("Security Manager has denied write access to ''{0}'' : {1}", e, newestDaily.getAbsolutePath(), e.getMessage()); } }