Class SecureFileHandler


  • public class SecureFileHandler
    extends Handler
    This SecureFileHandler is very much similar to the java.util.logging.FileHandler .

    The FileHandler can either write to a specified file, or it can write to a rotating set of files.

    For a archiving set of files, as each file reaches the limit ( LogConstants.MAX_FILE_SIZE), it is closed, archived, and a new file opened. Successively older files and named by adding a ".ddMMyyyyHHmmss" to the base filename. The Locking mechanism is much more relaxed(in JDK's FileHandler an exclusive lock is created on the file till the handler is closed which makes reading impossible)

    Version:
    6.0
    Author:
    rk133022
    • Constructor Detail

      • SecureFileHandler

        public SecureFileHandler​(String fileName)
        Creates a new SecureFileHandler. It takes a string parameter which represents file name. When this constructor is called a new file to be created. Assuming that the fileName logger provides is the timestamped fileName.
        Parameters:
        fileName - The filename associate with file handler.
    • Method Detail

      • setEncoding

        public void setEncoding​(String encoding)
                         throws SecurityException,
                                UnsupportedEncodingException
        Set (or change) the character encoding used by this Handler. The encoding should be set before any LogRecords are written to the Handler.
        Overrides:
        setEncoding in class Handler
        Parameters:
        encoding - The name of a supported character encoding. May be null, to indicate the default platform encoding.
        Throws:
        SecurityException - if a security manager exists and if the caller does not have LoggingPermission("control") .
        UnsupportedEncodingException - if the named encoding is not supported.
      • flush

        public void flush()
        Flush any buffered messages.
        Specified by:
        flush in class Handler
      • close

        public void close()
        Flush any buffered messages and Close all the files.
        Specified by:
        close in class Handler
      • publish

        public void publish​(LogRecord lrecord)
        Format and publish a LogRecord.

        This FileHandler is associated with a Formatter, which has to format the LogRecord according to ELF and return back the string formatted as per ELF. This method first checks if the header is already written to the file, if not, gets the header from the Formatter and writes it at the beginning of the file.

        Specified by:
        publish in class Handler
        Parameters:
        lrecord - the log record to be published.
      • getArchiver

        public static Archiver getArchiver​(String logName)
        This method takes in a logger name and returns a archiver object corresponding to that logger name. This can also be implemented by keeping the archiver a private instance variable and a getter and setter methods to get/set that private variable.
        Parameters:
        logName - a logger name associate with archiver object
        Returns:
        a archiver object corresponding to that logger name
      • setArchiver

        public static void setArchiver​(String logName,
                                       Archiver archiver)
        This method is to set the archiver corresponding to a loggerName
        Parameters:
        logName - the loggerName corresponding to a archiver
        archiver - the archiver corresponding to a loggerName
      • setLogPassword

        public static void setLogPassword​(AMPassword logPass,
                                          Object token)
        Set logger password
        Parameters:
        logPass - the logger password
        token - AM token
      • setVerPassword

        public static void setVerPassword​(AMPassword verPass,
                                          Object token)
        Sets verifier password.
        Parameters:
        verPass - the verifier password.
        token - AM token
      • getSecureLogHelperInst

        public static SecureLogHelper getSecureLogHelperInst()
        Returns SecureLogHelper instance
        Returns:
        SecureLogHelper instance
      • getSecureLogHelper

        public static SecureLogHelper getSecureLogHelper​(String logName)
        This method takes in a logger name and returns a helper object corresponding to that logger name. This can also be implemented by keeping the helper a private instance variable and a getter and setter methods to get/set that private variable.
        Parameters:
        logName - the logger name associate with helper object.
        Returns:
        a helper object corresponding to that logger name.
      • initializeVerifier

        public static void initializeVerifier​(AMPassword verPass,
                                              Object token)
        Initialize SecureLog verifier
        Parameters:
        verPass - verifier password
        token - AM token
      • addToCurrentFileList

        public static void addToCurrentFileList​(String oldFileName,
                                                String newFileName,
                                                String logName)
        Add new file name to the file list
        Parameters:
        oldFileName - old file name already exist.
        newFileName - new file name needs to be added to file list.
        logName - logger name for this file list.
      • getCurrentFileList

        public static ArrayList getCurrentFileList​(String logName)
        Return the current file list for the logger.
        Parameters:
        logName - Associated logger name for this file list.
        Returns:
        the current file list for the logger.
      • resetCurrentFileList

        public static void resetCurrentFileList​(String logName)
        Reset the current file list for the logger.
        Parameters:
        logName - logName Associated logger name for this file list.
      • initializeKeyStore

        public void initializeKeyStore()
        Initialize logger key store
      • setTokenName

        public static void setTokenName​(String tokenName)
        Sets the token name to be used to initialize the SecureLogHelper object.
        Parameters:
        tokenName - the token name associate with logger key store
      • getTokenName

        public static String getTokenName()
        Returns the token name used in the SecureLogHelper object.
      • setLoggerKeyName

        public static void setLoggerKeyName​(String name)
        Set logger key name in associated keystore
        Parameters:
        name - the name of key in the key store
      • getLoggerKeyName

        public static String getLoggerKeyName()
        Return logger key name in associated key store
        Returns:
        logger key name in associated key store
      • getSecureLogHelper

        public SecureLogHelper getSecureLogHelper()
        Return secure logger helper instance
        Returns:
        secure logger helper instance