diff options
author | Endi S. Dewata <edewata@redhat.com> | 2013-10-07 11:48:54 -0400 |
---|---|---|
committer | Endi S. Dewata <edewata@redhat.com> | 2013-10-25 17:17:39 -0400 |
commit | 2119f1b218e9d68b13496e7042785d9c68753966 (patch) | |
tree | b8c7cf5692723340d8d56e5d8c401acdee059ca5 /base/server/cmscore/src/com/netscape/cmscore/logging | |
parent | 7ca5adf1bd5bc4f9a7c5f2035426b9158007bb28 (diff) | |
download | pki-2119f1b218e9d68b13496e7042785d9c68753966.tar.gz pki-2119f1b218e9d68b13496e7042785d9c68753966.tar.xz pki-2119f1b218e9d68b13496e7042785d9c68753966.zip |
Reorganized server packages.
The tomcat, cms, and cmscore packages have been moved from base/common
into separate folders in base/server so that they can be built separately.
Diffstat (limited to 'base/server/cmscore/src/com/netscape/cmscore/logging')
10 files changed, 1636 insertions, 0 deletions
diff --git a/base/server/cmscore/src/com/netscape/cmscore/logging/AuditEventFactory.java b/base/server/cmscore/src/com/netscape/cmscore/logging/AuditEventFactory.java new file mode 100644 index 000000000..fea638eb6 --- /dev/null +++ b/base/server/cmscore/src/com/netscape/cmscore/logging/AuditEventFactory.java @@ -0,0 +1,99 @@ +// --- BEGIN COPYRIGHT BLOCK --- +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +// (C) 2007 Red Hat, Inc. +// All rights reserved. +// --- END COPYRIGHT BLOCK --- +package com.netscape.cmscore.logging; + +import java.util.Properties; + +import com.netscape.certsrv.logging.AuditEvent; +import com.netscape.certsrv.logging.IBundleLogEvent; +import com.netscape.certsrv.logging.ILogEvent; +import com.netscape.certsrv.logging.ILogEventFactory; +import com.netscape.certsrv.logging.ILogger; + +/** + * A log event object for handling audit messages + * <P> + * + * @author mikep + * @author mzhao + * @version $Revision$, $Date$ + */ +public class AuditEventFactory implements ILogEventFactory { + + /** + * List of supported properties. + */ + public static final String PROP_BUNDLE = "bundleName"; + + /** + * Constructs a audit event factory. + */ + public AuditEventFactory() { + } + + /** + * Creates an log event. + * + * @param evtClass the event type + * @param prop the resource bundle + * @param source the subsystem ID who creates the log event + * @param level the severity of the log event + * @param multiline the log message has more than one line or not + * @param msg the detail message of the log + * @param params the parameters in the detail log message + */ + public ILogEvent create(int evtClass, Properties prop, int source, + int level, boolean multiline, String msg, Object params[]) { + if (evtClass != ILogger.EV_AUDIT) + return null; + AuditEvent event = new AuditEvent(msg, params); + + event.setLevel(level); + event.setSource(source); + event.setMultiline(multiline); + setProperties(prop, event); + return event; + } + + /** + * Set the resource bundle of the log event. + * + * @param prop the properties + * @param event the log event + */ + protected void setProperties(Properties prop, IBundleLogEvent event) { + if (prop == null) { + event.setBundleName(null); + } else { + String bundleName = (String) prop.get(PROP_BUNDLE); + + if (bundleName != null) { + event.setBundleName(bundleName); + } + } + } + + /** + * Releases an log event. + * + * @param e the log event + */ + public void release(ILogEvent e) { + // do nothing + } +} diff --git a/base/server/cmscore/src/com/netscape/cmscore/logging/AuditFormat.java b/base/server/cmscore/src/com/netscape/cmscore/logging/AuditFormat.java new file mode 100644 index 000000000..42c3b0d6f --- /dev/null +++ b/base/server/cmscore/src/com/netscape/cmscore/logging/AuditFormat.java @@ -0,0 +1,116 @@ +// --- BEGIN COPYRIGHT BLOCK --- +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +// (C) 2007 Red Hat, Inc. +// All rights reserved. +// --- END COPYRIGHT BLOCK --- +package com.netscape.cmscore.logging; + +import com.netscape.certsrv.logging.ILogger; +import com.netscape.certsrv.request.IRequest; + +/** + * Define audit log message format + * + * @author mzhao + * @version $Revision$, $Date$ + */ +public class AuditFormat { + + /** + * default log level for writing audit log + */ + public static final int LEVEL = ILogger.LL_INFO; + + /** + * initiative: the event is from EE + */ + public static final String FROMUSER = "fromUser"; + + /** + * initiative: the event is from agent + */ + public static final String FROMAGENT = "fromAgent"; + + /** + * initiative: the event is from router + */ + public static final String FROMROUTER = "fromRouter"; + + /** + * initiative: the event is from remote authority + */ + public static final String FROMRA = "fromRemoteAuthority"; + + /** + * authentication module: no Authentication manager + */ + public static final String NOAUTH = "noAuthManager"; + + // for ProcessCertReq.java ,kra + /* 0: request type + 1: request ID + 2: initiative + 3: auth module + 4: status + 5: cert dn + 6: other info. eg cert serial number, violation policies + */ + public static final String FORMAT = + "{0} reqID {1} {2} authenticated by {3} is {4} DN requested: {5} {6}"; + public static final String NODNFORMAT = + "{0} reqID {1} {2} authenticated by {3} is {4}"; + + public static final String ENROLLMENTFORMAT = + IRequest.ENROLLMENT_REQUEST + " reqID {0} {1} authenticated by {2} is {3}. DN requested: {4} {5}"; + public static final String RENEWALFORMAT = + IRequest.RENEWAL_REQUEST + + " reqID {0} {1} authenticated by {2} is {3}. DN requested: {4} old serial number: 0x{5} {6}"; + public static final String REVOCATIONFORMAT = + IRequest.REVOCATION_REQUEST + + " reqID {0} {1} authenticated by {2} is {3}. DN requested: {4} serial number: 0x{5} revocation reason: {6} {7}"; + + // 1: fromAgent AgentID: xxx authenticated by xxx + public static final String DOREVOKEFORMAT = + IRequest.REVOCATION_REQUEST + + " reqID {0} {1} is {2}. DN requested: {3} serial number: 0x{4} revocation reason: {5}"; + // 1: fromAgent AgentID: xxx authenticated by xxx + public static final String DOUNREVOKEFORMAT = + IRequest.UNREVOCATION_REQUEST + " reqID {0} {1} is {2}. DN requested: {3} serial number: 0x{4}"; + + // 0:initiative + public static final String CRLUPDATEFORMAT = + "CRLUpdate request {0} authenticated by {1} is {2}. Id: {3}\ncrl Number: {4} last update time: {5} next update time: {6} number of entries in the CRL: {7}"; + + // audit user/group + public static final String ADDUSERFORMAT = + "Admin UID: {0} added User UID: {1}"; + public static final String REMOVEUSERFORMAT = + "Admin UID: {0} removed User UID: {1} "; + public static final String MODIFYUSERFORMAT = + "Admin UID: {0} modified User UID: {1}"; + public static final String ADDUSERCERTFORMAT = + "Admin UID: {0} added cert for User UID: {1}. cert DN: {2} serial number: 0x{3}"; + public static final String REMOVEUSERCERTFORMAT = + "Admin UID: {0} removed cert of User UID: {1}. cert DN: {2} serial number: 0x{3}"; + public static final String ADDUSERGROUPFORMAT = + "Admin UID: {0} added User UID: {1} to group: {2}"; + public static final String REMOVEUSERGROUPFORMAT = + "Admin UID: {0} removed User UID: {1} from group: {2}"; + public static final String ADDCERTSUBJECTDNFORMAT = + "Admin UID: {0} added cert subject DN for User UID: {1}. cert DN: {2}"; + public static final String REMOVECERTSUBJECTDNFORMAT = + "Admin UID: {0} removed cert subject DN for User UID: {1}. cert DN: {2}"; + +} diff --git a/base/server/cmscore/src/com/netscape/cmscore/logging/AuditService.java b/base/server/cmscore/src/com/netscape/cmscore/logging/AuditService.java new file mode 100644 index 000000000..89ac6263e --- /dev/null +++ b/base/server/cmscore/src/com/netscape/cmscore/logging/AuditService.java @@ -0,0 +1,177 @@ +// --- BEGIN COPYRIGHT BLOCK --- +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +// (C) 2013 Red Hat, Inc. +// All rights reserved. +// --- END COPYRIGHT BLOCK --- + +package com.netscape.cmscore.logging; + +import java.io.UnsupportedEncodingException; +import java.net.URI; +import java.util.Collection; +import java.util.LinkedHashSet; + +import javax.servlet.http.HttpServletRequest; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.HttpHeaders; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Request; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.UriInfo; + +import org.apache.commons.lang.StringUtils; +import org.jboss.resteasy.plugins.providers.atom.Link; + +import com.netscape.certsrv.apps.CMS; +import com.netscape.certsrv.base.EBaseException; +import com.netscape.certsrv.base.IConfigStore; +import com.netscape.certsrv.base.PKIException; +import com.netscape.certsrv.logging.AuditConfig; +import com.netscape.certsrv.logging.AuditResource; +import com.netscape.cms.servlet.base.PKIService; + +/** + * @author Endi S. Dewata + */ +public class AuditService extends PKIService implements AuditResource { + + @Context + private UriInfo uriInfo; + + @Context + private HttpHeaders headers; + + @Context + private Request request; + + @Context + private HttpServletRequest servletRequest; + + public final static int DEFAULT_SIZE = 20; + + public AuditService() { + CMS.debug("AuditService.<init>()"); + } + + public AuditConfig createAuditConfig() throws UnsupportedEncodingException, EBaseException { + + IConfigStore cs = CMS.getConfigStore(); + + AuditConfig auditConfig = new AuditConfig(); + auditConfig.setEnabled(cs.getBoolean("log.instance.SignedAudit.enable", false)); + auditConfig.setSigned(cs.getBoolean("log.instance.SignedAudit.logSigning", false)); + auditConfig.setInterval(cs.getInteger("log.instance.SignedAudit.flushInterval", 5)); + auditConfig.setBufferSize(cs.getInteger("log.instance.SignedAudit.bufferSize", 512)); + + // unselected events + for (String event : StringUtils.split(cs.getString("log.instance.SignedAudit.unselected.events", ""), ", ")) { + auditConfig.setOptionalEvent(event.trim(), false); + } + + // in case of duplicates, selected events override unselected events + for (String event : StringUtils.split(cs.getString("log.instance.SignedAudit.events", ""), ", ")) { + auditConfig.setOptionalEvent(event.trim(), true); + } + + // mandatory events + for (String event : StringUtils.split(cs.getString("log.instance.SignedAudit.mandatory.events", ""), ", ")) { + auditConfig.addMandatoryEvent(event.trim()); + } + + URI uri = uriInfo.getBaseUriBuilder().path(AuditResource.class).build(); + auditConfig.setLink(new Link("self", uri)); + + return auditConfig; + } + + @Override + public AuditConfig getAuditConfig() { + + CMS.debug("AuditService.getAuditConfig()"); + + try { + return createAuditConfig(); + + } catch (PKIException e) { + throw e; + + } catch (Exception e) { + e.printStackTrace(); + throw new PKIException(e.getMessage()); + } + } + + @Override + public Response updateAuditConfig(AuditConfig auditConfig) { + + CMS.debug("AuditService.updateAuditConfig()"); + + try { + IConfigStore cs = CMS.getConfigStore(); + + if (auditConfig.getEnabled() != null) { + cs.putBoolean("log.instance.SignedAudit.enable", auditConfig.getEnabled()); + } + + if (auditConfig.getSigned() != null) { + cs.putBoolean("log.instance.SignedAudit.logSigning", auditConfig.getSigned()); + } + + if (auditConfig.getInterval() != null) { + cs.putInteger("log.instance.SignedAudit.flushInterval", auditConfig.getInterval()); + } + + if (auditConfig.getBufferSize() != null) { + cs.putInteger("log.instance.SignedAudit.bufferSize", auditConfig.getBufferSize()); + } + + // update events selection + Collection<String> selected = new LinkedHashSet<String>(); + Collection<String> unselected = new LinkedHashSet<String>(); + + for (String name : auditConfig.getOptionalEvents().keySet()) { + Boolean value = auditConfig.getOptionalEvent(name); + + if (value) { + selected.add(name); + + } else { + unselected.add(name); + } + } + + cs.putString("log.instance.SignedAudit.events", StringUtils.join(selected, ",")); + cs.putString("log.instance.SignedAudit.unselected.events", StringUtils.join(unselected, ",")); + + // mandatory events cannot be updated + + cs.commit(true); + + auditConfig = createAuditConfig(); + + return Response + .ok(auditConfig) + .type(MediaType.APPLICATION_XML) + .build(); + + } catch (PKIException e) { + throw e; + + } catch (Exception e) { + e.printStackTrace(); + throw new PKIException(e.getMessage()); + } + } +} diff --git a/base/server/cmscore/src/com/netscape/cmscore/logging/Auditor.java b/base/server/cmscore/src/com/netscape/cmscore/logging/Auditor.java new file mode 100644 index 000000000..f0bcb5bee --- /dev/null +++ b/base/server/cmscore/src/com/netscape/cmscore/logging/Auditor.java @@ -0,0 +1,210 @@ +// --- BEGIN COPYRIGHT BLOCK --- +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +// (C) 2012 Red Hat, Inc. +// All rights reserved. +// --- END COPYRIGHT BLOCK --- + +package com.netscape.cmscore.logging; + +import java.util.Enumeration; +import java.util.Map; + +import com.netscape.certsrv.apps.CMS; +import com.netscape.certsrv.base.SessionContext; +import com.netscape.certsrv.common.Constants; +import com.netscape.certsrv.logging.IAuditor; +import com.netscape.certsrv.logging.ILogger; +import com.netscape.certsrv.usrgrp.IGroup; +import com.netscape.certsrv.usrgrp.IUGSubsystem; + +/** + * @author Endi S. Dewata + */ +public class Auditor implements IAuditor { + + public final static Auditor auditor = new Auditor(); + + public ILogger signedAuditLogger = CMS.getSignedAuditLogger(); + + public static IAuditor getAuditor() { + return auditor; + } + + @Override + public String getSubjectID() { + // if no signed audit object exists, bail + if (signedAuditLogger == null) return null; + + SessionContext context = SessionContext.getExistingContext(); + if (context == null) return ILogger.UNIDENTIFIED; + + // Initialize subject ID + String subjectID = (String)context.get(SessionContext.USER_ID); + if (subjectID == null) return ILogger.NONROLEUSER; + + return subjectID.trim(); + } + + @Override + public String getGroups(String subjectID) { + // if no signed audit object exists, bail + if (signedAuditLogger == null) return null; + + if (subjectID == null || subjectID.equals(ILogger.UNIDENTIFIED)) + return ILogger.SIGNED_AUDIT_EMPTY_VALUE; + + Enumeration<IGroup> groups; + + try { + IUGSubsystem userGroupSubsystem = (IUGSubsystem) CMS.getSubsystem(CMS.SUBSYSTEM_UG); + groups = userGroupSubsystem.findGroups("*"); + + } catch (Exception e) { + return ILogger.SIGNED_AUDIT_EMPTY_VALUE; + } + + StringBuilder sb = new StringBuilder(); + + while (groups.hasMoreElements()) { + IGroup group = groups.nextElement(); + + if (group.isMember(subjectID) == true) { + if (sb.length() != 0) sb.append(", "); + sb.append(group.getGroupID()); + } + } + + if (sb.length() == 0) return ILogger.SIGNED_AUDIT_EMPTY_VALUE; + + return sb.toString(); + } + + @Override + public String getParamString(String scope, String type, String id, Map<String, String> params) { + + // if no signed audit object exists, bail + if (signedAuditLogger == null) return null; + StringBuilder parameters = new StringBuilder(); + + // always identify the scope of the request + if (scope != null) { + parameters.append(SIGNED_AUDIT_SCOPE + + SIGNED_AUDIT_NAME_VALUE_DELIMITER + + scope); + } else { + parameters.append(SIGNED_AUDIT_EMPTY_NAME_VALUE_PAIR); + } + + // identify the operation type of the request + if (type != null) { + parameters.append(SIGNED_AUDIT_NAME_VALUE_PAIRS_DELIMITER); + + parameters.append(SIGNED_AUDIT_OPERATION + + SIGNED_AUDIT_NAME_VALUE_DELIMITER + + type); + } + + // identify the resource type of the request + if (id != null) { + parameters.append(SIGNED_AUDIT_NAME_VALUE_PAIRS_DELIMITER); + + parameters.append(SIGNED_AUDIT_RESOURCE + + SIGNED_AUDIT_NAME_VALUE_DELIMITER + + id); + } + + if (params == null) return parameters.toString(); + + // identify any remaining request parameters + + for (Map.Entry<String,String> entry : params.entrySet() ) { + String name = entry.getKey(); + + // skip "RULENAME" parameter + if (name.equals(SIGNED_AUDIT_RULENAME)) continue; + + parameters.append(SIGNED_AUDIT_NAME_VALUE_PAIRS_DELIMITER); + + String value = entry.getValue(); + + if (value == null) { + parameters.append(name + + SIGNED_AUDIT_NAME_VALUE_DELIMITER + + ILogger.SIGNED_AUDIT_EMPTY_VALUE); + continue; + } + + value = value.trim(); + + if (value.equals("")) { + parameters.append(name + + SIGNED_AUDIT_NAME_VALUE_DELIMITER + + ILogger.SIGNED_AUDIT_EMPTY_VALUE); + continue; + } + + // + // To fix Blackflag Bug # 613800: + // + // Check "com.netscape.certsrv.common.Constants" for + // case-insensitive "password", "pwd", and "passwd" + // name fields, and hide any password values: + // + if (name.equals(Constants.PASSWORDTYPE) || /* "password" */ + name.equals(Constants.TYPE_PASSWORD) || + name.equals(Constants.PR_USER_PASSWORD) || + name.equals(Constants.PT_OLD_PASSWORD) || + name.equals(Constants.PT_NEW_PASSWORD) || + name.equals(Constants.PT_DIST_STORE) || + name.equals(Constants.PT_DIST_EMAIL) || + /* "pwd" */name.equals(Constants.PR_AUTH_ADMIN_PWD) || + // ignore this one name.equals( Constants.PR_BINDPWD_PROMPT ) || + name.equals(Constants.PR_DIRECTORY_MANAGER_PWD) || + name.equals(Constants.PR_OLD_AGENT_PWD) || + name.equals(Constants.PR_AGENT_PWD) || + name.equals(Constants.PT_PUBLISH_PWD) || + /* "passwd" */name.equals(Constants.PR_BIND_PASSWD) || + name.equals(Constants.PR_BIND_PASSWD_AGAIN) || + name.equals(Constants.PR_TOKEN_PASSWD)) { + + // hide password value + parameters.append(name + + SIGNED_AUDIT_NAME_VALUE_DELIMITER + + SIGNED_AUDIT_PASSWORD_VALUE); + + } else { + // process normally + parameters.append(name + + SIGNED_AUDIT_NAME_VALUE_DELIMITER + + value); + } + } + + return parameters.toString(); + } + + @Override + public void log(String message) { + + if (signedAuditLogger == null) return; + + signedAuditLogger.log( + ILogger.EV_SIGNED_AUDIT, + null, + ILogger.S_SIGNED_AUDIT, + ILogger.LL_SECURITY, + message); + } +} diff --git a/base/server/cmscore/src/com/netscape/cmscore/logging/LogQueue.java b/base/server/cmscore/src/com/netscape/cmscore/logging/LogQueue.java new file mode 100644 index 000000000..32af1bf2c --- /dev/null +++ b/base/server/cmscore/src/com/netscape/cmscore/logging/LogQueue.java @@ -0,0 +1,122 @@ +// --- BEGIN COPYRIGHT BLOCK --- +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +// (C) 2007 Red Hat, Inc. +// All rights reserved. +// --- END COPYRIGHT BLOCK --- +package com.netscape.cmscore.logging; + +import java.util.Vector; + +import com.netscape.certsrv.logging.ELogException; +import com.netscape.certsrv.logging.ILogEvent; +import com.netscape.certsrv.logging.ILogEventListener; +import com.netscape.certsrv.logging.ILogQueue; + +/** + * A class represents a log queue. + * <P> + * + * @author mzhao + * @version $Revision$, $Date$ + */ +public class LogQueue implements ILogQueue { + + private static LogQueue mLogQueue = new LogQueue(); + protected Vector<ILogEventListener> mListeners = null; + + /** + * Constructs a log queue. + */ + public LogQueue() { + } + + public static ILogQueue getLogQueue() { + return mLogQueue; + } + + /** + * Initializes the log queue. + * <P> + * + */ + public void init() { + mListeners = new Vector<ILogEventListener>(); + + } + + /** + * Stops this log queue: shuts down all registered listeners + * <P> + */ + public void shutdown() { + if (mListeners == null) + return; + for (int i = 0; i < mListeners.size(); i++) { + mListeners.elementAt(i).shutdown(); + } + } + + /** + * Adds an event listener. + * + * @param listener the log event listener + */ + public void addLogEventListener(ILogEventListener listener) { + //Make sure we don't have duplicated listener + if (!mListeners.contains(listener)) + mListeners.addElement(listener); + } + + /** + * Removes an event listener. + * + * @param listener the log event listener + */ + public void removeLogEventListener(ILogEventListener listener) { + mListeners.removeElement(listener); + } + + /** + * Logs an event, and notifies logger to reuse the event. + * + * @param event the log event + */ + public void log(ILogEvent event) { + if (mListeners == null) + return; + for (int i = 0; i < mListeners.size(); i++) { + try { + mListeners.elementAt(i).log(event); + } catch (ELogException e) { + // Raidzilla Bug #57592: Don't display potentially + // incorrect log message. + // ConsoleError.send(new SystemEvent(CMS.getUserMessage("CMS_LOG_EVENT_FAILED", + // event.getEventType(), e.toString()))); + + // Don't do this again. + removeLogEventListener(mListeners.elementAt(i)); + } + } + } + + /** + * Flushes the log buffers (if any) + */ + public void flush() { + for (int i = 0; i < mListeners.size(); i++) { + mListeners.elementAt(i).flush(); + } + } +} diff --git a/base/server/cmscore/src/com/netscape/cmscore/logging/LogSubsystem.java b/base/server/cmscore/src/com/netscape/cmscore/logging/LogSubsystem.java new file mode 100644 index 000000000..aa5714668 --- /dev/null +++ b/base/server/cmscore/src/com/netscape/cmscore/logging/LogSubsystem.java @@ -0,0 +1,271 @@ +// --- BEGIN COPYRIGHT BLOCK --- +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +// (C) 2007 Red Hat, Inc. +// All rights reserved. +// --- END COPYRIGHT BLOCK --- +package com.netscape.cmscore.logging; + +import java.util.Enumeration; +import java.util.Hashtable; +import java.util.Vector; + +import com.netscape.certsrv.apps.CMS; +import com.netscape.certsrv.base.EBaseException; +import com.netscape.certsrv.base.IConfigStore; +import com.netscape.certsrv.base.ISubsystem; +import com.netscape.certsrv.logging.ELogException; +import com.netscape.certsrv.logging.ILogEventListener; +import com.netscape.certsrv.logging.ILogQueue; +import com.netscape.certsrv.logging.ILogSubsystem; +import com.netscape.certsrv.logging.LogPlugin; +import com.netscape.cmscore.util.Debug; + +/** + * A class represents a log subsystem. + * <P> + * + * @author thomask + * @author mzhao + * @version $Revision$, $Date$ + */ +public class LogSubsystem implements ILogSubsystem { + + private static LogSubsystem mInstance = new LogSubsystem(); + private static ILogQueue mLogQueue = LogQueue.getLogQueue(); + private IConfigStore mConfig = null; + + public static final String PROP_LOGGING = "log"; + + public static final String ID = "log"; + + public static final String PROP_CLASS = "class"; + public static final String PROP_IMPL = "impl"; + public static final String PROP_PLUGIN = "pluginName"; + public static final String PROP_INSTANCE = "instance"; + + public Hashtable<String, LogPlugin> mLogPlugins = new Hashtable<String, LogPlugin>(); + public Hashtable<String, ILogEventListener> mLogInsts = new Hashtable<String, ILogEventListener>(); + + /** + * Constructs a log subsystem. + */ + private LogSubsystem() { + } + + public String getId() { + return ID; + } + + public void setId(String id) throws EBaseException { + throw new EBaseException(CMS.getUserMessage("CMS_BASE_INVALID_OPERATION")); + } + + /** + * Initializes the log subsystem. + * <P> + * + * @param owner owner of this subsystem + * @param config configuration store + */ + public void init(ISubsystem owner, IConfigStore config) + throws EBaseException { + mConfig = config; + mLogQueue.init(); + + // load log plugin implementation + IConfigStore c = config.getSubStore(PROP_IMPL); + Enumeration<String> mImpls = c.getSubStoreNames(); + + while (mImpls.hasMoreElements()) { + String id = mImpls.nextElement(); + String pluginPath = c.getString(id + "." + PROP_CLASS); + LogPlugin plugin = new LogPlugin(id, pluginPath); + + mLogPlugins.put(id, plugin); + } + if (Debug.ON) + Debug.trace("loaded logger plugins"); + + // load log instances + c = config.getSubStore(PROP_INSTANCE); + Enumeration<String> instances = c.getSubStoreNames(); + + while (instances.hasMoreElements()) { + String insName = instances.nextElement(); + String implName = c.getString(insName + "." + + PROP_PLUGIN); + LogPlugin plugin = + mLogPlugins.get(implName); + + if (plugin == null) { + throw new EBaseException(implName); + } + String className = plugin.getClassPath(); + // Instantiate and init the log listener. + ILogEventListener logInst = null; + + try { + logInst = (ILogEventListener) + Class.forName(className).newInstance(); + IConfigStore pConfig = + c.getSubStore(insName); + + logInst.init(this, pConfig); + // for view from console + + } catch (ClassNotFoundException e) { + throw new EBaseException(insName + ":Failed to instantiate class " + className); + + } catch (IllegalAccessException e) { + throw new EBaseException(insName + ":Failed to instantiate class " + className); + + } catch (InstantiationException e) { + throw new EBaseException(insName + ":Failed to instantiate class " + className); + + } catch (Throwable e) { + e.printStackTrace(); + throw new EBaseException(insName + + ":Failed to instantiate class " + className + " error: " + e.getMessage()); + } + + if (insName == null) { + throw new EBaseException("Failed to instantiate class " + insName); + } + + // add log instance to list. + mLogInsts.put(insName, logInst); + if (Debug.ON) + Debug.trace("loaded log instance " + insName + " impl " + implName); + } + + } + + public void startup() throws EBaseException { + Debug.trace("entering LogSubsystem.startup()"); + Enumeration<String> enum1 = mLogInsts.keys(); + + while (enum1.hasMoreElements()) { + String instName = enum1.nextElement(); + + Debug.trace("about to call inst=" + instName + " in LogSubsystem.startup()"); + ILogEventListener inst = mLogInsts.get(instName); + + inst.startup(); + } + } + + /** + * Stops this subsystem. + * <P> + */ + public void shutdown() { + mLogQueue.shutdown(); + } + + /** + * Returns the root configuration storage of this system. + * <P> + * + * @return configuration store of this subsystem + */ + public IConfigStore getConfigStore() { + return mConfig; + } + + /** + * Retrieves singleton: the LogSubsystem. + */ + public static LogSubsystem getInstance() { + return mInstance; + } + + /** + * Retrieves LogQueue. + */ + public static ILogQueue getLogQueue() { + return mLogQueue; + } + + public String getLogPluginName(ILogEventListener log) { + IConfigStore cs = log.getConfigStore(); + if (cs == null) { + return ""; + } + try { + return cs.getString("pluginName", ""); + } catch (EBaseException e) { + e.printStackTrace(); + return ""; + } + } + + /** + * Retrieve log instance by it's name + */ + public ILogEventListener getLogInstance(String insName) { + return mLogInsts.get(insName); + } + + public Hashtable<String, LogPlugin> getLogPlugins() { + return mLogPlugins; + } + + public Hashtable<String, ILogEventListener> getLogInsts() { + return mLogInsts; + } + + public Vector<String> getLogDefaultParams(String implName) throws + ELogException { + // is this a registered implname? + LogPlugin plugin = mLogPlugins.get(implName); + + if (plugin == null) { + throw new ELogException(implName); + } + + // a temporary instance + ILogEventListener LogInst = null; + String className = plugin.getClassPath(); + + try { + LogInst = (ILogEventListener) + Class.forName(className).newInstance(); + Vector<String> v = LogInst.getDefaultParams(); + + return v; + } catch (InstantiationException e) { + throw new ELogException( + CMS.getUserMessage("CMS_LOG_LOAD_CLASS_FAIL", className)); + } catch (ClassNotFoundException e) { + throw new ELogException( + CMS.getUserMessage("CMS_LOG_LOAD_CLASS_FAIL", className)); + } catch (IllegalAccessException e) { + throw new ELogException( + CMS.getUserMessage("CMS_LOG_LOAD_CLASS_FAIL", className)); + } + } + + public Vector<String> getLogInstanceParams(String insName) throws + ELogException { + ILogEventListener logInst = getLogInstance(insName); + + if (logInst == null) { + return null; + } + Vector<String> v = logInst.getInstanceParams(); + + return v; + } +} diff --git a/base/server/cmscore/src/com/netscape/cmscore/logging/Logger.java b/base/server/cmscore/src/com/netscape/cmscore/logging/Logger.java new file mode 100644 index 000000000..aec4caec7 --- /dev/null +++ b/base/server/cmscore/src/com/netscape/cmscore/logging/Logger.java @@ -0,0 +1,378 @@ +// --- BEGIN COPYRIGHT BLOCK --- +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +// (C) 2007 Red Hat, Inc. +// All rights reserved. +// --- END COPYRIGHT BLOCK --- +package com.netscape.cmscore.logging; + +import java.util.Hashtable; +import java.util.Properties; + +import com.netscape.certsrv.logging.ILogEvent; +import com.netscape.certsrv.logging.ILogEventFactory; +import com.netscape.certsrv.logging.ILogQueue; +import com.netscape.certsrv.logging.ILogger; + +/** + * A class represents certificate server logger + * implementation. + * <P> + * + * @author thomask + * @author mzhao + * @version $Revision$, $Date$ + */ +public class Logger implements ILogger { + + protected static Logger mLogger = new Logger(); + protected ILogQueue mLogQueue = null; + protected Hashtable<Integer, ILogEventFactory> mFactories = new Hashtable<Integer, ILogEventFactory>(); + + /** + * Constructs a generic logger, and registers a list + * of resident event factories. + */ + public Logger() { + mLogQueue = LogSubsystem.getLogQueue(); + + // register standard event factories + register(EV_AUDIT, new AuditEventFactory()); + register(EV_SYSTEM, new SystemEventFactory()); + register(EV_SIGNED_AUDIT, new SignedAuditEventFactory()); + } + + /** + * get default single global logger + */ + static public Logger getLogger() { + return mLogger; + } + + /** + * Retrieves the associated log queue. + */ + public ILogQueue getLogQueue() { + return mLogQueue; + } + + /** + * Registers log factory. + * + * @param evtClass the event class name: ILogger.EV_SYSTEM or ILogger.EV_AUDIT + * @param f the event factory name + */ + public void register(int evtClass, ILogEventFactory f) { + mFactories.put(evtClass, f); + } + + //************** default level **************** + /** + * Logs an event using default log level: ILogger.LL_INFO + * + * @param evtClass What kind of event it is: EV_AUDIT or EV_SYSTEM. + * @param source the source of the log event + * @param msg the one line detail message to be logged + */ + public void log(int evtClass, int source, String msg) { + log(evtClass, null, source, ILogger.LL_INFO, msg, null); + } + + /** + * Logs an event using default log level: ILogger.LL_INFO + * + * @param evtClass What kind of event it is: EV_AUDIT or EV_SYSTEM. + * @param props the resource bundle used for the detailed message + * @param source the source of the log event + * @param msg the one line detail message to be logged + */ + public void log(int evtClass, Properties props, int source, String msg) { + log(evtClass, props, source, ILogger.LL_INFO, msg, null); + } + + //************** no param **************** + + /** + * Logs an event to the log queue. + * + * @param evtClass What kind of event it is: EV_AUDIT or EV_SYSTEM. + * @param source the source of the log event + * @param level the level of the log event + * @param msg the one line detail message to be logged + */ + public void log(int evtClass, int source, int level, String msg) { + log(evtClass, null, source, level, msg, null); + } + + /** + * Logs an event to the log queue. + * + * @param evtClass What kind of event it is: EV_AUDIT or EV_SYSTEM. + * @param props the resource bundle used for the detailed message + * @param source the source of the log event + * @param level the level of the log event + * @param msg the one line detail message to be logged + */ + public void log(int evtClass, Properties props, int source, int level, String msg) { + log(evtClass, props, source, level, msg, null); + } + + //********************* one param ********************** + + /** + * Logs an event to the log queue. + * + * @param evtClass What kind of event it is: EV_AUDIT or EV_SYSTEM. + * @param props the resource bundle used for the detailed message + * @param source the source of the log event + * @param msg the one line detail message to be logged + * @param param the parameter in the detail message + */ + public void log(int evtClass, int source, int level, String msg, Object param) { + log(evtClass, null, source, level, msg, param); + } + + /** + * Logs an event using default log level: ILogger.LL_INFO + * + * @param evtClass What kind of event it is: EV_AUDIT or EV_SYSTEM. + * @param props the resource bundle used for the detailed message + * @param source the source of the log event + * @param msg the one line detail message to be logged + * @param param the parameter in the detail message + */ + public void log(int evtClass, Properties props, int source, String msg, Object param) { + log(evtClass, props, source, ILogger.LL_INFO, msg, param); + } + + /** + * Logs an event to the log queue. + * + * @param evtClass What kind of event it is: EV_AUDIT or EV_SYSTEM. + * @param props the resource bundle used for the detailed message + * @param source the source of the log event + * @param level the level of the log event + * @param msg the one line detail message to be logged + * @param param the parameter in the detail message + */ + public void log(int evtClass, Properties props, int source, int level, String msg, + Object param) { + Object o[] = new Object[1]; + + o[0] = param; + log(evtClass, props, source, level, msg, o); + } + + //******************* multiple param ************************** + + /** + * Logs an event to the log queue. + * + * @param evtClass What kind of event it is: EV_AUDIT or EV_SYSTEM. + * @param source the source of the log event + * @param level the level of the log event + * @param msg the one line detail message to be logged + * @param params the parameters in the detail message + */ + public void log(int evtClass, int source, int level, String msg, + Object params[]) { + log(evtClass, null, source, level, msg, params); + } + + //*************** the real implementation ***************** + /** + * Logs an event to the log queue. + * + * @param evtClass What kind of event it is: EV_AUDIT or EV_SYSTEM. + * @param props the resource bundle used for the detailed message + * @param source the source of the log event + * @param level the level of the log event + * @param msg the one line detail message to be logged + * @param params the parameters in the detail message + */ + public void log(int evtClass, Properties prop, int source, int level, String msg, + Object params[]) { + ILogEvent iLEvent = create(evtClass, prop, source, level, msg, params, ILogger.L_SINGLELINE); + if (iLEvent != null) + mLogQueue.log(iLEvent); + } + + //******************** multiline log ************************* + //************** default level **************** + /** + * Logs an event using default log level: ILogger.LL_INFO + * + * @param evtClass What kind of event it is: EV_AUDIT or EV_SYSTEM. + * @param source the source of the log event + * @param msg the one line detail message to be logged + * @param multiline true if the message has more than one line, otherwise false + */ + public void log(int evtClass, int source, String msg, boolean multiline) { + log(evtClass, null, source, ILogger.LL_INFO, msg, null, multiline); + } + + /** + * Logs an event using default log level: ILogger.LL_INFO + * + * @param evtClass What kind of event it is: EV_AUDIT or EV_SYSTEM. + * @param props the resource bundle used for the detailed message + * @param source the source of the log event + * @param msg the one line detail message to be logged + * @param multiline true if the message has more than one line, otherwise false + */ + public void log(int evtClass, Properties props, int source, String msg, boolean multiline) { + log(evtClass, props, source, ILogger.LL_INFO, msg, null, multiline); + } + + //************** no param **************** + + /** + * Logs an event to the log queue. + * + * @param evtClass What kind of event it is: EV_AUDIT or EV_SYSTEM. + * @param source the source of the log event + * @param level the level of the log event + * @param msg the one line detail message to be logged + * @param multiline true if the message has more than one line, otherwise false + */ + public void log(int evtClass, int source, int level, String msg, boolean multiline) { + log(evtClass, null, source, level, msg, null, multiline); + } + + /** + * Logs an event to the log queue. + * + * @param evtClass What kind of event it is: EV_AUDIT or EV_SYSTEM. + * @param props the resource bundle used for the detailed message + * @param source the source of the log event + * @param level the level of the log event + * @param msg the one line detail message to be logged + * @param multiline true if the message has more than one line, otherwise false + */ + public void log(int evtClass, Properties props, int source, int level, String msg, boolean multiline) { + log(evtClass, props, source, level, msg, null, multiline); + } + + //********************* one param ********************** + + /** + * Logs an event to the log queue. + * + * @param evtClass What kind of event it is: EV_AUDIT or EV_SYSTEM. + * @param props the resource bundle used for the detailed message + * @param source the source of the log event + * @param msg the one line detail message to be logged + * @param param the parameter in the detail message + * @param multiline true if the message has more than one line, otherwise false + */ + public void log(int evtClass, int source, int level, String msg, Object param, boolean multiline) { + log(evtClass, null, source, level, msg, param, multiline); + } + + /** + * Logs an event using default log level: ILogger.LL_INFO + * + * @param evtClass What kind of event it is: EV_AUDIT or EV_SYSTEM. + * @param props the resource bundle used for the detailed message + * @param source the source of the log event + * @param msg the one line detail message to be logged + * @param param the parameter in the detail message + * @param multiline true if the message has more than one line, otherwise false + */ + public void log(int evtClass, Properties props, int source, String msg, Object param, boolean multiline) { + log(evtClass, props, source, ILogger.LL_INFO, msg, param, multiline); + } + + /** + * Logs an event to the log queue. + * + * @param evtClass What kind of event it is: EV_AUDIT or EV_SYSTEM. + * @param props the resource bundle used for the detailed message + * @param source the source of the log event + * @param level the level of the log event + * @param msg the one line detail message to be logged + * @param param the parameter in the detail message + * @param multiline true if the message has more than one line, otherwise false + */ + public void log(int evtClass, Properties props, int source, int level, String msg, + Object param, boolean multiline) { + Object o[] = new Object[1]; + + o[0] = param; + log(evtClass, props, source, level, msg, o, multiline); + } + + //******************* multiple param ************************** + + /** + * Logs an event to the log queue. + * + * @param evtClass What kind of event it is: EV_AUDIT or EV_SYSTEM. + * @param source the source of the log event + * @param level the level of the log event + * @param msg the one line detail message to be logged + * @param params the parameters in the detail message + * @param multiline true if the message has more than one line, otherwise false + */ + public void log(int evtClass, int source, int level, String msg, + Object params[], boolean multiline) { + log(evtClass, null, source, level, msg, params, multiline); + } + + //*************** the real implementation ***************** + /** + * Logs an event to the log queue. + * + * @param evtClass What kind of event it is: EV_AUDIT or EV_SYSTEM. + * @param props the resource bundle used for the detailed message + * @param source the source of the log event + * @param level the level of the log event + * @param msg the one line detail message to be logged + * @param params the parameters in the detail message + * @param multiline true if the message has more than one line, otherwise false + */ + public void log(int evtClass, Properties prop, int source, int level, String msg, + Object params[], boolean multiline) { + ILogEvent iLEvent = create(evtClass, prop, source, level, msg, params, multiline); + if (iLEvent != null) + mLogQueue.log(iLEvent); + } + + //******************** end multiline log ************************* + + /** + * Creates generic log event. If required, we can recycle + * events here. + */ + //XXXXXXXXXXX prop is out dated!!!! XXXXXXXXXXXXXXX + public ILogEvent create(int evtClass, Properties prop, int source, int level, + String msg, Object params[], boolean multiline) { + ILogEventFactory f = mFactories.get(evtClass); + + if (f == null) + return null; + return f.create(evtClass, prop, source, level, multiline, msg, params); + } + + /** + * Notifies logger to reuse the event. This framework + * opens up possibility to reuse event. + * + * @param event a log event + */ + public void release(ILogEvent event) { + // do nothing for now. + } + +} diff --git a/base/server/cmscore/src/com/netscape/cmscore/logging/SignedAuditEventFactory.java b/base/server/cmscore/src/com/netscape/cmscore/logging/SignedAuditEventFactory.java new file mode 100644 index 000000000..6ba492dc3 --- /dev/null +++ b/base/server/cmscore/src/com/netscape/cmscore/logging/SignedAuditEventFactory.java @@ -0,0 +1,125 @@ +// --- BEGIN COPYRIGHT BLOCK --- +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +// (C) 2007 Red Hat, Inc. +// All rights reserved. +// --- END COPYRIGHT BLOCK --- +package com.netscape.cmscore.logging; + +import java.util.Properties; + +import com.netscape.certsrv.logging.IBundleLogEvent; +import com.netscape.certsrv.logging.ILogEvent; +import com.netscape.certsrv.logging.ILogEventFactory; +import com.netscape.certsrv.logging.ILogger; +import com.netscape.certsrv.logging.SignedAuditEvent; +import com.netscape.cmscore.util.Debug; + +/** + * A log event object for handling system messages + * <P> + * + * @author mikep + * @author mzhao + * @author cfu + * @version $Revision$, $Date$ + */ +public class SignedAuditEventFactory implements ILogEventFactory { + + /** + * List of supported properties. + */ + public static final String PROP_BUNDLE = "bundleName"; + + /** + * Constructs a system event factory. + */ + public SignedAuditEventFactory() { + } + + /** + * Creates an log event. + * + * @param evtClass the event type + * @param prop the resource bundle + * @param source the subsystem ID who creates the log event + * @param level the severity of the log event + * @param multiline the log message has more than one line or not + * @param msg the detail message of the log + * @param params the parameters in the detail log message + */ + public ILogEvent create(int evtClass, Properties prop, int source, + int level, boolean multiline, String msg, Object params[]) { + if (evtClass != ILogger.EV_SIGNED_AUDIT) + return null; + + String message = null; + // assume msg format <type=...>:message + String typeMessage = msg.trim(); + String eventType = null; + int typeBegin = typeMessage.indexOf("<type="); + + if (typeBegin != -1) { + // type is specified + int colon = typeMessage.indexOf(">:"); + + eventType = typeMessage.substring(typeBegin + 6, colon); + message = typeMessage.substring(colon + 2); + Debug.trace("SignedAuditEventFactory: create() message=" + message + "\n"); + + } else { + // no type specified + message = msg; + } + + SignedAuditEvent event = new SignedAuditEvent(message.trim(), params); + + if (eventType != null) + event.setEventType(eventType.trim()); + + event.setLevel(level); + event.setSource(source); + event.setMultiline(multiline); + setProperties(prop, event); + + return event; + } + + /** + * Set the resource bundle of the log event. + * + * @param prop the properties + * @param event the log event + */ + protected void setProperties(Properties prop, IBundleLogEvent event) { + if (prop == null) { + event.setBundleName(null); + } else { + String bundleName = (String) prop.get(PROP_BUNDLE); + + if (bundleName != null) { + event.setBundleName(bundleName); + } + } + } + + /** + * Releases an log event. + * + * @param e the log event + */ + public void release(ILogEvent e) { + // do nothing + } +} diff --git a/base/server/cmscore/src/com/netscape/cmscore/logging/SignedAuditLogger.java b/base/server/cmscore/src/com/netscape/cmscore/logging/SignedAuditLogger.java new file mode 100644 index 000000000..4b6fd55a2 --- /dev/null +++ b/base/server/cmscore/src/com/netscape/cmscore/logging/SignedAuditLogger.java @@ -0,0 +1,39 @@ +// --- BEGIN COPYRIGHT BLOCK --- +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +// (C) 2007 Red Hat, Inc. +// All rights reserved. +// --- END COPYRIGHT BLOCK --- +package com.netscape.cmscore.logging; + +/** + * A class represents certificate server logger + * implementation. + * <P> + * + * @author thomask + * @author mzhao + * @version $Revision$, $Date$ + */ +public class SignedAuditLogger extends Logger { + + /** + * Constructs a generic logger, and registers a list + * of resident event factories. + */ + public SignedAuditLogger() { + super(); + register(EV_SIGNED_AUDIT, new SignedAuditEventFactory()); + } +} diff --git a/base/server/cmscore/src/com/netscape/cmscore/logging/SystemEventFactory.java b/base/server/cmscore/src/com/netscape/cmscore/logging/SystemEventFactory.java new file mode 100644 index 000000000..6821fac6f --- /dev/null +++ b/base/server/cmscore/src/com/netscape/cmscore/logging/SystemEventFactory.java @@ -0,0 +1,99 @@ +// --- BEGIN COPYRIGHT BLOCK --- +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +// (C) 2007 Red Hat, Inc. +// All rights reserved. +// --- END COPYRIGHT BLOCK --- +package com.netscape.cmscore.logging; + +import java.util.Properties; + +import com.netscape.certsrv.logging.IBundleLogEvent; +import com.netscape.certsrv.logging.ILogEvent; +import com.netscape.certsrv.logging.ILogEventFactory; +import com.netscape.certsrv.logging.ILogger; +import com.netscape.certsrv.logging.SystemEvent; + +/** + * A log event object for handling system messages + * <P> + * + * @author mikep + * @author mzhao + * @version $Revision$, $Date$ + */ +public class SystemEventFactory implements ILogEventFactory { + + /** + * List of supported properties. + */ + public static final String PROP_BUNDLE = "bundleName"; + + /** + * Constructs a system event factory. + */ + public SystemEventFactory() { + } + + /** + * Creates an log event. + * + * @param evtClass the event type + * @param prop the resource bundle + * @param source the subsystem ID who creates the log event + * @param level the severity of the log event + * @param multiline the log message has more than one line or not + * @param msg the detail message of the log + * @param params the parameters in the detail log message + */ + public ILogEvent create(int evtClass, Properties prop, int source, + int level, boolean multiline, String msg, Object params[]) { + if (evtClass != ILogger.EV_SYSTEM) + return null; + SystemEvent event = new SystemEvent(msg, params); + + event.setLevel(level); + event.setSource(source); + event.setMultiline(multiline); + setProperties(prop, event); + return event; + } + + /** + * Set the resource bundle of the log event. + * + * @param prop the properties + * @param event the log event + */ + protected void setProperties(Properties prop, IBundleLogEvent event) { + if (prop == null) { + event.setBundleName(null); + } else { + String bundleName = (String) prop.get(PROP_BUNDLE); + + if (bundleName != null) { + event.setBundleName(bundleName); + } + } + } + + /** + * Releases an log event. + * + * @param e the log event + */ + public void release(ILogEvent e) { + // do nothing + } +} |