Search in sources :

Example 1 with Archiver

use of com.sun.identity.log.spi.Archiver in project OpenAM by OpenRock.

the class SecureFileHandler method initializeSecurity.

void initializeSecurity() {
    String currentFileName = logName;
    try {
        String logPath = lmanager.getProperty(LogConstants.LOG_LOCATION);
        if (!logPath.endsWith("/"))
            logPath += "/";
        String FileName = currentFileName;
        String loggerFileName = logPath + PREFIX + "log." + FileName;
        String verifierFileName = logPath + PREFIX + "ver." + FileName;
        helper = (SecureLogHelper) getSecureLogHelper(logName);
        if (helper == null) {
            helper = getSecureLogHelperInst();
            setSecureLogHelper(logName, helper);
        }
        helper.initializeSecureLogHelper(loggerFileName, logPassword, verifierFileName, logPassword);
        if (verificationInitialized) {
            helper.initializeVerifier(verifierFileName, logPassword, verPassword);
        }
    } catch (Exception e) {
        Debug.error(logName + ":Logger: exception thrown while initializing secure logger", e);
    //throw custom defined exception
    }
    Archiver archiver = null;
    try {
        if (getArchiver(logName) == null) {
            archiver = (Archiver) Class.forName(archiverClass).newInstance();
            setArchiver(logName, archiver);
        }
    } catch (Exception e) {
        Debug.error(logName + ":SecureFileHandler: Could Not set Archiver", e);
    }
    String Interval = lmanager.getProperty(LogConstants.LOGSIGN_PERIODINSECONDS);
    if ((Interval == null) || (Interval.length() == 0)) {
        signInterval = LogConstants.LOGSIGN_PERIODINSECONDS_DEFAULT * 1000;
    } else {
        signInterval = Long.parseLong(Interval) * 1000;
    }
    startPeriodicLogSigner();
    // Uncomment lines before deploying
    if (verificationInitialized) {
        startVerifierThread();
    }
    Debug.message(logName + ":Done initializeSecurity in Handler");
    // add the non archived files in the current file list.
    VerifierList vl = new VerifierList();
    String path = location;
    if (!path.endsWith("/")) {
        path += "/";
    }
    TreeMap tm = vl.getKeysAndFiles(new File(path), logName);
    Vector logFiles = (Vector) tm.get(PREFIX + "log." + logName);
    for (int j = 1; j < logFiles.size(); j++) {
        // fiels are sorted according to the timestamp so first add all the 
        // files ending with timestamp
        String name = (String) logFiles.elementAt(j);
        name = name.substring(PREFIX.length(), name.length());
        addToCurrentFileList(name, name, logName);
        if (archiver != null) {
            // increment filesPerKeystoreCounter
            archiver.incrementCount();
        }
    }
    // now add the current file (without time stamp)
    String name = (String) logFiles.elementAt(0);
    name = name.substring(PREFIX.length(), name.length());
    addToCurrentFileList(name, name, logName);
}
Also used : VerifierList(com.sun.identity.log.secure.VerifierList) TreeMap(java.util.TreeMap) Archiver(com.sun.identity.log.spi.Archiver) File(java.io.File) Vector(java.util.Vector) NullLocationException(com.iplanet.log.NullLocationException) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 2 with Archiver

use of com.sun.identity.log.spi.Archiver 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();
}
Also used : IOException(java.io.IOException) NullLocationException(com.iplanet.log.NullLocationException) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) LogRecord(java.util.logging.LogRecord) LogSign(com.sun.identity.log.secure.LogSign) Archiver(com.sun.identity.log.spi.Archiver) File(java.io.File)

Aggregations

NullLocationException (com.iplanet.log.NullLocationException)2 Archiver (com.sun.identity.log.spi.Archiver)2 File (java.io.File)2 IOException (java.io.IOException)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 LogSign (com.sun.identity.log.secure.LogSign)1 VerifierList (com.sun.identity.log.secure.VerifierList)1 TreeMap (java.util.TreeMap)1 Vector (java.util.Vector)1 LogRecord (java.util.logging.LogRecord)1