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