LogConfigReader.java revision 5f4d6070f856d0de82c1d16459b89233e2e81ff2
/**
* 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: LogConfigReader.java,v 1.19 2009/11/04 22:33:10 bigfatrat Exp $
*
*/
/*
* Portions Copyrighted 2010-2014 ForgeRock AS
* Portions Copyrighted 2014 Nomura Research Institute, Ltd
*/
/**
* <tt>LogConfigReader</TT> is used to load the configuration from the
* Directory Server and store the configuration as Properties of
* <tt>LogManager</tt>. <p>
* <tt>LogConfigReader</TT> is very Speicific to DSAME. <p>
* java.util.logging.config.class System property should point to this class,
* since LogManager uses this property instantiates this class to load
* the configuration.
*/
public class LogConfigReader implements ServiceListener{
private boolean useOldLogFormat = false;
/**
* Local Log service identifier
*/
private static boolean isRegisteredForDSEvents = false;
private LogManager manager;
/**
* The constructor loads the configuration from the DS using
* DSAME SDK. Constructs a String as "key=value CRLF" for each
* AttributeSchema in the amLogging.xml. In case the AttributeSchema
* has multiple values or a List, it gets converted to a "," seperated
* String.
* <p> Example1: iplanet-am-logging-backend=FILE \r\n
* <p> Example2: iplanet-am-logging-logfields=TIME, DOMAIN, IPADDR,
* HOSTNAME, DATA, LEVEL, LOGINID \r\n
* <p> The input stream hence constructed is converted into a
* ByteArrayInputStream and is loaded into LogManager.
* @throws IOException
*/
public LogConfigReader() throws IOException {
try {
ssoToken = getSSOToken();
} catch (SSOException ssoe) {
return;
}
if (debug.messageEnabled()) {
}
try {
} catch (SMSException smse) {
"get defaultAttributes", smse);
return;
} catch (SSOException ssoe) {
"get defaultAttributes", ssoe);
return;
}
try { inputStream =
} catch (UnsupportedEncodingException unse) {
}
manager =
try {
} catch (IOException ioe) {
}
setLocalFlag();
}
/**
* LogManager needs inputStream in the form of " Key = Value \r\n ".
* so to get that we need to get the keys of the default attributs append
* a "=", get the value for that key and append a CRLF. This input stream
* will then be loaded into the logmanager via properties API.
*/
private String constructInputStream() {
boolean fileBackend = false;
// processing logging attributes.
try {
/*
* generate %BASE_DIR% and %SERVER_URI% values, in case
* they're not set up yet (e.g., during configuration
*/
}
}
} else {
}
} catch (Exception e) {
}
// Database Driver
try {
} else {
}
} catch (Exception e) {
}
// Database Password
try {
} else {
}
} catch (Exception e) {
}
// Database USER
try {
} else {
}
} catch (Exception e) {
}
// all Fields
try {
if (!useOldLogFormat) {
} else {
}
}
}
}
}
// Selected Log Fields
try {
tempBuffer = new StringBuilder();
}
}
} catch (Exception e) {
}
// Enable log rotation
try {
} else {
}
} catch (Exception e) {
}
// Max file size
try {
} else {
}
} catch (Exception e) {
}
// log filename prefix
try {
} else {
}
} catch (Exception e) {
}
// log filename suffix
try {
} else {
}
} catch (Exception e) {
}
// log filename rotation interval
try {
} else {
}
} catch (Exception e) {
}
// number of history files
try {
} else {
}
} catch (Exception e) {
}
// archiver class
try {
} else {
}
} catch (Exception e) {
}
// file handler class
try {
"LogConfigReader: FileHandler class string is null");
} else {
}
} catch (Exception e) {
}
// secure File handler class
try {
} else {
}
} catch (Exception e) {
}
// db handler class
try {
} else {
}
} catch (Exception e) {
}
// remote handler class
try {
} else {
}
} catch (Exception e) {
}
// elf formatter class
try {
} else {
}
} catch (Exception e) {
}
// secure elf formatter class
try {
"ELFFormatter string is null");
} else {
}
} catch (Exception e) {
}
// db formatter class
try {
} catch (Exception e) {
}
// db formatter class
try {
} catch (Exception e) {
}
// authz class
try {
} else {
}
} catch (Exception e) {
}
// security status (on or off)
try {
"LogConfigReader: Security status string is null");
} else {
}
} catch (Exception e) {
}
// secure log signing algorithm name
// MD2withRSA, MD5withRSA, SHA1withDSA, SHA1withRSA
try {
} catch (Exception e) {
"log signing alogorithm ", e);
}
// secure log helper class name
// com.sun.identity.log.secure.impl.SecureLogHelperJSSImpl or
// com.sun.identity.log.secure.impl.SecureLogHelperJCEImpl
try {
} catch (Exception e) {
"log helper class name ", e);
}
// secure logger certificate store
try {
"certificate store is null");
} else {
{
}
}
} catch (Exception e) {
"logger certificate store ", e);
}
// log verification period in seconds
try {
} else {
}
} catch (Exception e) {
}
// log signing period in seconds
try {
} else {
}
} catch (Exception e) {
}
// file read handler class
try {
"string is null");
} else {
}
} catch (Exception e) {
}
// DB read handler class
try {
} else {
}
} catch (Exception e) {
}
// MAX_RECORDS
try {
} else {
}
} catch (Exception e) {
}
// FILES_PER_KEYSTORE
try {
"keystore string is null");
} else {
}
} catch (Exception e) {
}
// Token Generating Class
try {
} else {
}
} catch(Exception e) {
"Generation Class name");
}
// Secure Timestamp generator class
try {
"generator string is null");
} else {
}
} catch(Exception e) {
"Generation Class name");
}
// Verifier Action Output Class
try {
"actionclass string is null");
} else {
}
} catch(Exception e) {
"output Class name");
}
// filter class name
try {
"name string is null");
} else {
}
} catch(Exception e) {
}
// debug Implementation Class
try {
} else {
}
} catch(Exception e) {
}
// Buffer size
try {
} else {
}
} catch(Exception e) {
}
// Max DB Mem Buffer size
try {
"LogConfigReader: Max DB mem buffer size string is null");
} else {
}
} catch(Exception e) {
}
// Buffer Time
try {
} else {
}
} catch(Exception e) {
}
// Time Buffering Status
try {
"buffering status string is null");
} else {
}
} catch(Exception e) {
"buffering status ");
}
// Oracle DB data type for DATA field
try {
} catch(Exception e) {
}
// MySQL DB data type for DATA field
try {
} catch(Exception e) {
}
try {
} catch(Exception e) {
}
try {
} catch(Exception e) {
}
// Log status from the logging config
try {
// try to read from AMConfig.properties
if (debug.messageEnabled()) {
value);
}
value = "ACTIVE";
}
}
// "value" will have a value
} catch(Exception e) {
}
// Logging Level attribute
try {
} catch(Exception e) {
}
// processing platform attributes
try {
} else {
}
} catch (Exception e) {
}
// processing naming attributes
try {
"service url string is null");
} else {
}
} catch (Exception e) {
}
// hostname resolution
try {
"Log Resolve Hostname attribute is null");
// try to read from AMConfig.properties
value =
if (debug.messageEnabled()) {
"####### SystemProperties resolveHostName is: " +
value);
}
value = "false";
}
}
// "value" will have a value
} catch (Exception e) {
}
}
class LogHeaderComparator implements Comparator {
/**
* Compares two strings from the Log headers. Names should either be
* in the form ##:HeaderName or HeaderName, where ## is a two digit
* number. Instances with ##: preceding will go first, in ascending
* order according to the two digit number. If two of the same number
* appear they will be ordered according to the order of in which they
* were compared.
*
* @param o1 First object in comparison
* @param o2 Second object in comparison
* @return Returns positive if prefix for o2 is gt o1, otherwise negative
*/
return 1;
} else {
return -1;
}
return 1;
return -1;
}
return -1;
}
return obj instanceof LogHeaderComparator;
}
}
private void getLoggingDirectory(
boolean fileBackend,
) {
logDir += "/";
return;
}
/*
* log location subdirectory
* is specified in AMConfig.properties. read it here and append
* to log location, so only have to deal with it here.
*/
if (fileBackend) {
{
locSubdir += "/";
}
}
} else {
{
}
value += "/";
}
// locSubdir already ensured trailing slash, above
}
}
}
/**
* This method is used to get the global schemas of Logging, Platform
* and Naming Services. Platform service schema is used to determine the
* platform locale, naming service is used to get the logging service url.
*/
throws SMSException, SSOException {
if (!isRegisteredForDSEvents) {
schemaManager.addListener(this);
}
if (!isRegisteredForDSEvents) {
schemaManager.addListener(this);
}
if (!isRegisteredForDSEvents) {
schemaManager.addListener(this);
isRegisteredForDSEvents = true;
}
// get the default attributes of each service(Logging, Platform and
// Naming).
}
/**
* This method is used for gettting the SSOToken from the
* TokenManager using Principal and defaultOrg. Need to
* whether the existing method is good enough.
* This method of obtaining token has problems in DSAME5.2 alpha(hanging)
* Written on 25/4/2002 for DSAME6.0
* @throws SMSException
* @throws SSOException
*/
}
/**
* This method checks whether the logging service url is explicitly
* mentioned in the naming service. If yes then validates the URL against
* the platform server list of trusted servers. if the logging service
* url is not mentioned explicitly it sets the local flag to true.
*/
private void setLocalFlag() {
if (debug.messageEnabled()) {
}
try{
// can't do this here because NamingService is not
// dynamically updated.
// URL url = WebtopNaming.getServiceURL(LOGGING_SERVICE,
// protocol, host, port);
} else {
}
{
LogManager.isLocal = true;
}
else {
LogManager.isLocal = false;
}
}
} catch (Exception e) {
}
}
// following methods
// to implement ServiceListener
public void globalConfigChanged(
int type
) {
}
public void organizationConfigChanged(
int type
) {
}
if (debug.messageEnabled()) {
}
/*
* if logging config has been read before (i.e., eliminating
* the case where logging status is inactive on startup),
* then if logging status goes from active to inactive,
* force a write of a record (to each active log file)
* indicating the change. can't really do it in LogManager,
* as the java.util.LogManager (below) has already set
* the logging status to inactive, and no more records will
* get written out.
*/
manager =
if (manager.getDidFirstReadConfig() &&
{
}
//shifting to LogManager according to review.
try{
} catch (Exception e) {
}
}
private boolean newStatusIsInactive() {
try {
ssoToken = getSSOToken();
} catch (SSOException ssoe) {
"Could not get proper SSOToken", ssoe);
return false;
}
try {
value = "ACTIVE";
}
} catch(Exception e) {
"error reading Log Status attribute: " + e.getMessage());
}
return false;
}
}