8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster/**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Copyright (c) 2006 Sun Microsystems Inc. All Rights Reserved
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * The contents of this file are subject to the terms
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * of the Common Development and Distribution License
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * (the License). You may not use this file except in
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * compliance with the License.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * You can obtain a copy of the License at
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * https://opensso.dev.java.net/public/CDDLv1.0.html or
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * opensso/legal/CDDLv1.0.txt
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * See the License for the specific language governing
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * permission and limitations under the License.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * When distributing Covered Code, include this CDDL
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Header Notice in each file and include the License file
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * at opensso/legal/CDDLv1.0.txt.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * If applicable, add the following below the CDDL Header,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * with the fields enclosed by brackets [] replaced by
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * your own identifying information:
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * "Portions Copyrighted [year] [name of copyright owner]"
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * $Id: LogReader.java,v 1.7 2008/10/30 04:11:06 bigfatrat Exp $
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster/*
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Portions Copyrighted [2011] [ForgeRock AS]
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterpackage com.sun.identity.log;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport java.io.File;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport java.io.IOException;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport java.lang.reflect.Array;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport java.util.ArrayList;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport java.util.HashSet;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport java.util.Iterator;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport java.util.Set;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport java.util.StringTokenizer;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.sun.identity.log.spi.Debug;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster/**LogReader class provides mechanism to read a log file to the caller.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * It does the authorization check, reads line from the file, applies the
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * query (if any), collects most recent records, sorts the records, and
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * returns the result in a two dimensional String. Where columns in the
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * the first row, i.e. 0th row, always holds the header info (field names)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * present in the ELF formatted file.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Other rows hold the value present under those columns.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @supported.all.api
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterpublic class LogReader {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /* private attributes */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static int maxReordToReturn = 1;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static final String FILE_SOURCE = "File";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static java.util.logging.LogManager manager;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static String [][] queryResult = null;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static String logFileName = null;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static String logPathName = null;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static String logFields = null;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static String fileHandlerClass = null;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static String maxRecStr = null;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static String dbHandlerClass = null;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static String logStorageType = null;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static String logSecurity = null;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static String securityPrefix = "_secure";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static String loggerName; /* name of the logger object */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static com.sun.identity.log.handlers.LogReadHandler currentHandler
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster = null;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static com.sun.identity.log.handlers.LogReadDBHandler
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster currentDBHandler = null;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static boolean logTypeIsFile = true; /* default "File" */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /* private constructor. Only assigns manager. */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private LogReader() {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster this.manager = LogManagerUtil.getLogManager();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Returns the units (LogConstants.NUM_BYTES or LogConstants.NUM_RECORDS)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * that applies to the value returned by getSize(logName).
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return the units applying to the return value of getSize(logName),
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * LogConstants.NUM_BYTES (in the case of File logging), or
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * LogConstants.NUM_RECORDS (in the case of DB logging).
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws Exception if unrecoverable problem occurs, that is beyond
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * its control.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster **/
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public static int getSizeUnits()
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throws Exception
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster LogReader lr = new LogReader();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster try {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster lr.readConfiguration();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } catch (Exception ex) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Debug.error("LogReader.getSizeUnits:could not read configuration");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throw ex;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster int i = LogConstants.NUM_RECORDS;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (logTypeIsFile) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return (LogConstants.NUM_BYTES);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return (i);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Returns the number of LogRecords in the specified table in the DB.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * In the case where logging is to a file, the number of bytes in
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * the specified file is returned. Use getSizeUnits() to get which
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * units apply.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param logName the name of the Table or File.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return the number of LogRecords (in the DB table), or number of
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * bytes (in the file).
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws IOException if file does not exist.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws Exception if unrecoverable problem occurs, that is beyond
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * its control.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster **/
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public static long getSize(String logName)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throws IOException, Exception
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster LogReader lr = new LogReader();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster try {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster lr.readConfiguration();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } catch (Exception ex) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Debug.error("LogReader.getSize: could not read configuration");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throw ex;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster long li;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (logTypeIsFile) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String file = logPathName + logName;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster File thisFile = new File (file);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (thisFile.exists()) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster li = thisFile.length();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } else {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throw new IOException(logName + " does not exist.");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } else {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster li = currentDBHandler.getNumberOfRows(manager, logName);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return li;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Returns the names of the Log Files or Tables. The Set of names is
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * what is found in the directory or DB, filtered through a default
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * list of names. Thus, log files or tables with custom names will
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * not be included. This does not preclude querying those log files
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * or tables with custom names.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return the Log File/Table names in a Set.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster **/
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public static Set getLogNames() {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster LogReader lr = new LogReader();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Set logNames = new HashSet();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster try {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster lr.readConfiguration();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } catch (Exception ex) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return logNames;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (logTypeIsFile) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster File dir = new File(logPathName);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String [] dirList = dir.list();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (dirList != null) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster int numFiles = Array.getLength(dirList);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster int numDefFiles = Array.getLength(LogConstants.LOGFILENAMES);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (numFiles > 0) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster for (int i = 0; i < numFiles; i++) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster for (int j = 0; j < numDefFiles; j++) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String nmToCompare = LogConstants.LOGFILENAMES[j];
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /*
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * want to keep out the files that start with:
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * _secure.log. and _secure.ver.. just want
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * the _secure.am* files.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (logSecurity.equalsIgnoreCase("ON")) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster nmToCompare = securityPrefix + "." +
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster nmToCompare;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (dirList[i].indexOf(nmToCompare) > -1) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster logNames.add(dirList[i]);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster break;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } else {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster queryResult = currentDBHandler.getTableNames(manager);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster int szOfList = Array.getLength(queryResult);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster int numDefFiles = Array.getLength(LogConstants.LOGFILENAMES);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /*
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * for commonality, make both sides uppercase because
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * oracle makes the tablenames uppercase; mysql doesn't.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster for (int i = 0; i < szOfList; i++) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String tFile = queryResult[i][0].replace('_', '.');
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String thisFile = tFile.toUpperCase();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String thatFile = null;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster for (int j = 0; j < numDefFiles; j++) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster thatFile = LogConstants.LOGFILENAMES[j].toUpperCase();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (thatFile.indexOf(thisFile) > -1) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster logNames.add(queryResult[i][0]); /* real tblname */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster break;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return logNames;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Returns the names of the Log Fields that are selected for logging
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * in the Logging Service template, plus the mandatory "time" and
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * "Data" fields.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return the Field/Column names in an ArrayList.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster **/
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public static ArrayList getLogFields() {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ArrayList lFHS = new ArrayList();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster LogReader lr = new LogReader();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster try {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster lr.readConfiguration();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } catch (Exception ex) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return lFHS;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster lFHS.add("time");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster lFHS.add(LogConstants.DATA);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if ((logFields != null) && (logFields.length() != 0)) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster StringTokenizer stok = new StringTokenizer(logFields, ", ");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster while (stok.hasMoreElements()) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster lFHS.add(stok.nextToken());
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return lFHS;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Reads the specified log file provided the user has the authorization.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * It reads all records and returns them without any modification.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * This query ignores the max record parameter set through configuration.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * This API is present to support log verifier requirement.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param fileName the filename without path to be read.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param userCrdential user credential to check authorization.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return results in a two dimensional String, where columns in the
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * the first row always hold the field names present in the
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * file. Other rows hold the values present under those column.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws IOException if interrupted or failed to do I/O.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws NoSuchFieldException if invalid field has been specified.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws IllegalArgumentException when inappropriate argument specified.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws RuntimeException when it has been caught in any phase.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws Exception if unrecoverable problem occurs, that is beyond
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * its control.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster **/
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public static synchronized String [][] read(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String fileName,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Object userCrdential
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ) throws IOException, NoSuchFieldException,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster IllegalArgumentException,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster RuntimeException, Exception
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /*
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * READ METHOD 1
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * read the configuration from LogManager to use updated info.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster LogReader lr = new LogReader();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster lr.readConfiguration();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (fileName == null) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throw new IllegalArgumentException("filename can't be null");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster lr.setLoggerName(fileName);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /* check whether user is authorized or not */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (lr.isAllowed(userCrdential) != true) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throw new AMLogException(fileName + ":" +
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster AMLogException.LOG_RD_AUTH_FAILED);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /* form the full file name */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String fullFileName = logPathName + fileName;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /* get all the records through file handler */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster LogQuery qry = new LogQuery(LogQuery.ALL_RECORDS);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (logTypeIsFile) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster queryResult = currentHandler.logRecRead(fullFileName,qry,false);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } else {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster queryResult = currentDBHandler.logRecRead(fileName, qry,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster manager, false);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return queryResult;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Retrieves records from a log file provided the user has the required
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * authorization. It identifies the filename using <code>logname</code> and
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * <code>type</code>.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * It reads all records from the file but returns the maximum number
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * of most recent records set through configuration.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param logName an identifier and is a part of file name to be read.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param logType the components of file name that will be read. it could
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * be either of "access", "error" or "system".
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param userCrdential user credential to check authorization.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return results in a two dimensional String, where columns in the
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * the first row always hold the field names present in the
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * file. Other rows hold the values present under those column.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws IOException if interrupted or failed to do I/O.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws NoSuchFieldException if invalid field has been specified.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws IllegalArgumentException when inappropriate argument specified.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws RuntimeException when it has been caught in any phase.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws Exception if unrecoverable problem occurs, that is beyond
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * its control.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster **/
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public static synchronized String [][] read(String logName,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String logType,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Object userCrdential
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ) throws IOException, NoSuchFieldException,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster IllegalArgumentException,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster RuntimeException, Exception
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /*
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * READ METHOD 2
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * pass the call to the CORE logName based read api to collect data
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster queryResult = read(logName, logType, (String)null, (LogQuery)null,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster userCrdential);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return queryResult;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Reads a log file provided the user has the authorization. It reads all
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * records but returns the maximum number of most recent records set
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * through configuration.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param logName an identifier and is a part of file name to be read.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param logType the components of filename to be read, not null.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param timeStamp last component of filename to be read and not null.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param userCrdential user credential for authorization check.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return results in a two dimensional String, where columns in the
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * the first row always hold the field names present in the
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * file. Other rows hold the values present under those column.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws IOException if interrupted or failed to do I/O.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws NoSuchFieldException if invalid field has been specified.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws IllegalArgumentException when inappropriate argument specified.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws RuntimeException when it has been caught in any phase.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws Exception if unrecoverable problem occurs, that is beyond
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * its control.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster **/
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public static synchronized String [][] read(String logName,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String logType,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String timeStamp,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Object userCrdential
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ) throws IOException, NoSuchFieldException,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster IllegalArgumentException,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster RuntimeException,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Exception
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /*
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * READ METHOD 3
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * pass the call to the CORE logName based read api to collect data
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster queryResult = read(logName,logType,timeStamp,null,userCrdential);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return queryResult;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Retrieves records from log file provided it has
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * the required authorization. It reads all records applies query
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * and returns the result as asked by the caller.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param logName an identifier and is a part of file name to be read.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param logType the components of filename to be read.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param logQuery contains search criteria details.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param userCrdential user credential for authorization check.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return results in a two dimensional String, where columns in the
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * the first row always hold the field names present in the
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * file. Other rows hold the values present under those column.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws IOException if interrupted or failed to do I/O.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws NoSuchFieldException if invalid field has been specified.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws IllegalArgumentException when inappropriate argument specified.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws RuntimeException when it has been caught in any phase.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws Exception if unrecoverable problem occurs, that is beyond
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * its control.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public static synchronized String [][] read(String logName,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String logType,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster LogQuery logQuery,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Object userCrdential
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ) throws IOException, NoSuchFieldException,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster IllegalArgumentException,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster RuntimeException, Exception
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /*
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * READ METHOD 4
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * pass the call to the CORE logName based read api to collect data
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster queryResult = read(logName,logType,null,logQuery,userCrdential);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return queryResult;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Reads a log file provided it has the required authorization.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * It reads all records but returns the maximum number of most recent
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * records (if asked) those meet the caller's requirement as specified
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * through query.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param logname an identifier and is a part of file name to be read.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param logtype the components of filename to be read.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param timeStamp is the last component of filename to be read and not
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * null.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param logQuery contains search criteria details.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param userCrdential user credential for authorization check.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return results in a two dimensional String, where columns in the
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * the first row always hold the field names present in the
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * file. Other rows hold the values present under those column.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws IOException if interrupted or failed to do I/O.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws NoSuchFieldException if invalid field has been specified.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws IllegalArgumentException when inappropriate argument specified.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws RuntimeException when it has been caught in any phase.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws Exception if unrecoverable problem occurs, that is beyond
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * its control.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster **/
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public static String [][] read(String logname,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String logtype,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String timeStamp,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster LogQuery logQuery,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Object userCrdential
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ) throws IOException, NoSuchFieldException,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster IllegalArgumentException,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster RuntimeException, Exception
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /*
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * READ METHOD 5
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Create the actual file name out of the components
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String mainFileName = new String();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /* set logger name */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster setLoggerName(logname,logtype);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster mainFileName = loggerName;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (timeStamp != null) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (mainFileName.length() == 0) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /* atleast one of logname or logtype must be present */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return null;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster mainFileName += "." + timeStamp;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster queryResult = read(mainFileName,logQuery,userCrdential);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return queryResult;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Retrieves specific records in a given sorted order on
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * specific field (if user specifies valid sorting by field). The API
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * also needs the user has a successful authorization.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param fileName filename without path that will be read.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param logQuery contains search criteria details.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param userCrdential user credential for authorization check.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return results in a two dimensional String, where columns in the
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * the first row always hold the field names present in the
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * file. Other rows hold the values present under those column.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws IOException if interrupted or failed to do I/O.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws NoSuchFieldException if invalid field has been specified.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws IllegalArgumentException when inappropriate argument specified.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws RuntimeException when it has been caught in any phase.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws Exception if unrecoverable problem occurs, that is beyond
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * its control.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster **/
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public static String [][] read(String fileName,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster LogQuery logQuery,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Object userCrdential
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ) throws IOException, NoSuchFieldException,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster IllegalArgumentException,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster RuntimeException, Exception
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /* READ METHOD 6 */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster LogReader lr = new LogReader();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /* this is the CORE read api, used by all other read apis */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster lr.readConfiguration();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /* pass the request to the file handler & collect all required data */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (fileName == null) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throw new IllegalArgumentException("filename can't be null");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (maxReordToReturn <= 0) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster maxReordToReturn = 1;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (logQuery != null) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (logQuery.getNumRecordsWanted() < LogQuery.ALL_RECORDS) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster logQuery.setMaxRecord(maxReordToReturn);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } else if ((logQuery.getNumRecordsWanted() ==
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster LogQuery.MOST_RECENT_MAX_RECORDS) && (logTypeIsFile))
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /* MOST_RECENT_MAX_RECORDS processed in DB reader */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster logQuery.setMaxRecord(maxReordToReturn);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } else {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster logQuery = new LogQuery(maxReordToReturn);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /* sets logger name */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster setLoggerName(fileName);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /* check whether user is authorized or not */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (lr.isAllowed(userCrdential) != true) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throw new AMLogException(fileName + ":" +
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster AMLogException.LOG_RD_AUTH_FAILED);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (logTypeIsFile) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String fullFileName = logPathName + fileName;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster queryResult = currentHandler.logRecRead(fullFileName,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster logQuery, true);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } else {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster queryResult = currentDBHandler.logRecRead(fileName, logQuery,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster manager, true);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return queryResult;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Retrieves specific records in a given sorted order on
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * specific field (if user specifies valid sorting by field). The API
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * also needs the user has a successful authorization.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param fileNames set of filenames without path that will be read
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param logQuery contains search criteria details
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param userCrdential user credential for authorization check.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return results in a two dimensional String, where columns in the
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * the first row always hold the field names present in the
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * file. Other rows hold the values present under those column.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws IOException if interrupted or failed to do I/O.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws NoSuchFieldException if invalid field has been specified.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws IllegalArgumentException when inappropriate argument specified.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws RuntimeException when it has been caught in any phase.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws Exception if unrecoverable problem occurs, that is beyond
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * its control.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster **/
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public static String [][] read(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Set fileNames,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster LogQuery logQuery,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Object userCrdential
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ) throws IOException, NoSuchFieldException,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster IllegalArgumentException,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster RuntimeException, Exception
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /* READ METHOD 7 */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster LogReader lr = new LogReader();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /* this is the CORE read api, used by all other read apis */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster lr.readConfiguration();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /* pass the request to the file handler & collect all required data */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (fileNames == null) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throw new IllegalArgumentException("filenames can't be null");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (fileNames.isEmpty()) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throw new IllegalArgumentException("filenames can't be empty");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } else {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /* check all filenames in set */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster for (Iterator it = fileNames.iterator(); it.hasNext(); ) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String ss = (String)it.next();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (ss != null) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ss = ss.trim();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if ((ss == null) || (ss.length() == 0)) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throw new IllegalArgumentException(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "filename cannot be null");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (maxReordToReturn <= 0) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster maxReordToReturn = 1;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (logQuery != null) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (logQuery.getNumRecordsWanted() < LogQuery.ALL_RECORDS) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster logQuery.setMaxRecord(maxReordToReturn);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } else if ((logQuery.getNumRecordsWanted() ==
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster LogQuery.MOST_RECENT_MAX_RECORDS) && (logTypeIsFile))
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /* MOST_RECENT_MAX_RECORDS processed in DB reader */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster logQuery.setMaxRecord(maxReordToReturn);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } else {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster logQuery = new LogQuery(maxReordToReturn);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String tmpF = getAllFilenames (fileNames);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /* sets logger name */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster setLoggerName(tmpF);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /* check whether user is authorized or not */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (lr.isAllowed(userCrdential) != true) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throw new AMLogException(tmpF + ":" +
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster AMLogException.LOG_RD_AUTH_FAILED);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (logTypeIsFile) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Set fullFileNames = new HashSet();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster for (Iterator it = fileNames.iterator(); it.hasNext(); ) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String ss = (String)it.next();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ss = logPathName + ss;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster fullFileNames.add(ss);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster queryResult =
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster currentHandler.logRecRead(fullFileNames, logQuery, true);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } else {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster queryResult =
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster currentDBHandler.logRecRead(fileNames, logQuery, manager,true);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return queryResult;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static String getAllFilenames (Set fileNames) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster StringBuilder fsSB = new StringBuilder();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (fileNames == null) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return null;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (fileNames.isEmpty()) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return "";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String ts = null;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster for (Iterator it=fileNames.iterator(); it.hasNext(); ) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ts = (String)it.next();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster fsSB.append(ts);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ts = fsSB.toString();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return (ts);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /*
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * This method collects the current file name used by this Logger.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *@param logName an identifier and is a part of file name to be read.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *@param logType the components of filename to be read.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *@param userCrdential user credential for authorization check.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *@return name of the current logfile associated with this logname.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * returns null, if there is no file or invalid input params.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *@throws IOException if interrupted or failed to do I/O.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *@throws NoSuchFieldException if invalid field has been specified.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *@throws IllegalArgumentException when inappropriate argument specified.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *@throws RuntimeException when it has been caught in any phase.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *@throws Exception if unrecoverable problem occurs, that is beyond
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * its control.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static String getCurrentFile(String logname,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String logtype,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Object userCrdential
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ) throws IOException, NoSuchFieldException,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster IllegalArgumentException,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster RuntimeException, Exception
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // sets loggerName
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster setLoggerName(logname,logtype);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Logger logInstance =
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster (com.sun.identity.log.Logger)Logger.getLogger(loggerName);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster try {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster logFileName = logInstance.getCurrentFile();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } catch ( RuntimeException e) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Debug.error("LogReader:getCurrentFile:" +
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "RuntimeException: ", e);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster logFileName = null;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throw e;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return logFileName;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /*
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *This method checks whether this user/ role does have the required
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *(here reading) permission on the resourse.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *It uses spi based interface to check it. It returns true when allowed
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *else false.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *@param userCredential contains the user/ role details required to check
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * the authorization.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private boolean isAllowed(Object userCredential) throws Exception {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster boolean isAuthorized = false;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster try {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster isAuthorized =
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster com.sun.identity.log.spi.Authorizer.isAuthorized(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster loggerName,"READ",
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster userCredential);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } catch (Exception e) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Debug.error("LogReader:isAllowed:" + "Exception: ", e);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throw e;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return isAuthorized;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /*
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *This method is to read configuration details it needs to perform
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *its task. LogManager always has the updated configuration information.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *So this method goes to read its well defined property from LogManager.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *This method should be called before each read request to ensure the
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *latest configuration has been used.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private void readConfiguration() throws Exception {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster cleanup(); // first cleans up all previous setting
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster try {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster logPathName = manager.getProperty(LogConstants.LOG_LOCATION);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (logPathName == null) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Debug.error("LogReader:readConfiguration:" +
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "unable to get log location");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster logStorageType = manager.getProperty(LogConstants.BACKEND);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster maxRecStr = manager.getProperty(LogConstants.MAX_RECORDS);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if ((maxRecStr == null) || (maxRecStr.length() == 0)) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster maxRecStr = LogConstants.MAX_RECORDS_DEFAULT;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster logFields = manager.getProperty(LogConstants.LOG_FIELDS);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /* depending on whether "File" or "DB" backend... */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster logTypeIsFile = true;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (logStorageType.equals("File")) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster fileHandlerClass =
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster manager.getProperty(LogConstants.FILE_READ_HANDLER);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (!(logPathName.endsWith(File.separator))) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster logPathName = logPathName + File.separator;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster logSecurity =
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster manager.getProperty(LogConstants.SECURITY_STATUS);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } else {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster logTypeIsFile = false;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster dbHandlerClass =
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster manager.getProperty(LogConstants.DB_READ_HANDLER);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } catch (Exception e) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Debug.error("LogReader:readConfiguration:" + "Exception: ", e);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throw e; // rethrow the exception as it is
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster try {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /* check type of log backend and instantiate appropriate object */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (logStorageType.compareToIgnoreCase(FILE_SOURCE) == 0 ) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Class clz = Class.forName(fileHandlerClass);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster currentHandler =(com.sun.identity.log.handlers.LogReadHandler)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster clz.newInstance();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } else if (logStorageType.compareToIgnoreCase("DB") == 0 ) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /* FOR DB Handler */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Class clz = Class.forName(dbHandlerClass);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Following type casting has to be changed for DB support
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster currentDBHandler =
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster (com.sun.identity.log.handlers.LogReadDBHandler)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster clz.newInstance();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } catch (Exception e) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Debug.error("LogReader:readConfiguration:" + "Exception: ", e);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throw e; /* rethrow the exception as it is */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster try {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (maxRecStr != null) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster maxRecStr = maxRecStr.trim();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster maxReordToReturn = Integer.parseInt(maxRecStr);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } catch (Exception ex) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Debug.error("LogReader:readConfiguration:" + "Exception: ", ex);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throw ex; // rethrow the exception as it is
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /*
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *setLoggerName method set the logname i.e. logger name from filename.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *@param filename name of the file to read.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static void setLoggerName(String name) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /* checks for security prefix, if present removes it. */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (name.startsWith(securityPrefix) == true) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster name = name.substring(securityPrefix.length()+1,name.length());
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /* check for time stamp, if present removes it. */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster int datePos = name.lastIndexOf(".");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster int strLen = name.length();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ++datePos;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String dateCheck = name.substring(datePos+1,strLen);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster try {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Long longTm = new Long(dateCheck);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster long dateValue = longTm.longValue();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (dateValue >= 1) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /* valid time present so remove it to get file name */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster name = name.substring(0,datePos-1);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } catch (Exception e) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /*
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * exception suggests the log file name doesn't have time stamp
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * attached so loggerName = name.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * do nothing
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster loggerName = name;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /*
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *setLoggerName method set the logname i.e. logger name from filename.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *@param logname 1st part (if has 2 parts) of the logger name.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *@param logtype 2nd part (if any) of the logger name
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static void setLoggerName(String logname, String logtype) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /* checks for security prefix, if present removes it. */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (logname != null) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster loggerName = logname;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (logtype != null) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (logname != null) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster loggerName += ".";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster loggerName += logtype;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /*This method clears all the stored information and previous result
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *to make sure there is no effect from previous query. It should be
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *be called before reading configuration.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private void cleanup() {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster this.maxReordToReturn = LogQuery.MOST_RECENT_MAX_RECORDS;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster this.queryResult = null;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster this.currentHandler = null;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public static boolean isLogSecure() {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return (logSecurity.equalsIgnoreCase("ON"));
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster}