use of com.sun.identity.log.secure.LogSign in project OpenAM by OpenRock.
the class SecureFileHandler method archive.
/**
* This method does the following in sequence:
* 1: get the signature for the fileName
* 2: create a dummy logrecord with the signature field and the info to lr.
* 3: get the formatted string from the formatter..
* 4: write the signature to the file....
* 5: archive the file(append timestamp and keep it away) n open new file
* 6: write the headers in the new file created and also the previous
* signature...
*/
private void archive() {
Archiver archiver = getArchiver(logName);
String message = "";
String signature = "Signature";
try {
LogSign ls = new LogSign(logName);
signature = ls.sign();
} catch (Exception e) {
Debug.error(logName + ":SecureFileHandler: could not generate signature");
}
/*
* periodic signer is creating log record at Level.SEVERE, so
* do it here, too.
*/
com.sun.identity.log.LogRecord lr = new com.sun.identity.log.LogRecord(Level.SEVERE, "Signature");
lr.setLoggerName(logName);
lr.addLogInfo(LogConstants.SIGNATURE_FIELDNAME, signature);
message = getFormatter().format(lr);
try {
writer.write(message);
} catch (IOException ioe) {
Debug.error(logName + ":SecureLogHelper: could not write signature to file", ioe);
}
flush();
try {
if (writer != null) {
writer.close();
}
} catch (IOException ioe) {
Debug.error(logName + ":SecureFileHandler: Couldnot close writer", ioe);
}
try {
archiver.archive(logName, location);
int fileCount = archiver.checkCount();
if (Debug.messageEnabled()) {
Debug.message(logName + ":Files per keystore=" + filesPerKeyStore + " and current file count = " + fileCount);
}
if (fileCount >= filesPerKeyStore) {
Debug.message(logName + ":Keystore limit reached");
archiver.archiveKeyStore(logName, location);
Debug.message(logName + ":FilesPerKeystore counter = " + archiver.checkCount());
initializeKeyStore();
}
} catch (Exception ioe) {
Debug.error(logName + ":SecureFileHandler: Could not archive file", ioe);
}
try {
open(new File(location + PREFIX + logName), false);
writer.write(getFormatter().getHead(this));
headerWritten = true;
int fileCount = archiver.checkCount();
if (fileCount != 0)
writer.write(message);
} catch (IOException ex) {
Debug.error(logName + ":SecureFileHandler: could not write to file", ex);
}
flush();
}
Aggregations