[Jboss-cvs] JBossAS SVN: r56155 - in trunk/security/src/main/org/jboss/security: . audit audit/providers
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Aug 22 16:12:45 EDT 2006
Author: anil.saldhana at jboss.com
Date: 2006-08-22 16:12:44 -0400 (Tue, 22 Aug 2006)
New Revision: 56155
Added:
trunk/security/src/main/org/jboss/security/audit/
trunk/security/src/main/org/jboss/security/audit/AbstractAuditProvider.java
trunk/security/src/main/org/jboss/security/audit/AuditContext.java
trunk/security/src/main/org/jboss/security/audit/AuditEvent.java
trunk/security/src/main/org/jboss/security/audit/AuditLevel.java
trunk/security/src/main/org/jboss/security/audit/AuditManager.java
trunk/security/src/main/org/jboss/security/audit/AuditProvider.java
trunk/security/src/main/org/jboss/security/audit/providers/
trunk/security/src/main/org/jboss/security/audit/providers/LogAuditProvider.java
Log:
JBAS-2738: Audit framework
Added: trunk/security/src/main/org/jboss/security/audit/AbstractAuditProvider.java
===================================================================
--- trunk/security/src/main/org/jboss/security/audit/AbstractAuditProvider.java 2006-08-22 19:26:58 UTC (rev 56154)
+++ trunk/security/src/main/org/jboss/security/audit/AbstractAuditProvider.java 2006-08-22 20:12:44 UTC (rev 56155)
@@ -0,0 +1,23 @@
+/*
+ * JBoss, the OpenSource J2EE webOS
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.security.audit;
+
+/**
+ * Abstract class of Audit Providers.
+ * <p>An audit provider is one that can be used to log audit events in
+ * a file, a database or any external sink of choice</p>
+ * @author <a href="mailto:Anil.Saldhana at jboss.org">Anil Saldhana</a>
+ * @version $Revision$
+ * @since Aug 21, 2006
+ */
+public abstract class AbstractAuditProvider implements AuditProvider
+{
+ /**
+ * @see AuditProvider#audit(AuditEvent)
+ */
+ public abstract void audit(AuditEvent auditEvent);
+}
Added: trunk/security/src/main/org/jboss/security/audit/AuditContext.java
===================================================================
--- trunk/security/src/main/org/jboss/security/audit/AuditContext.java 2006-08-22 19:26:58 UTC (rev 56154)
+++ trunk/security/src/main/org/jboss/security/audit/AuditContext.java 2006-08-22 20:12:44 UTC (rev 56155)
@@ -0,0 +1,60 @@
+/*
+ * JBoss, the OpenSource J2EE webOS
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.security.audit;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jboss.security.audit.providers.LogAuditProvider;
+
+
+/**
+ * Context for Audit Purposes that manages a set of providers
+ * @see AuditProvider
+ * @author <a href="mailto:Anil.Saldhana at jboss.org">Anil Saldhana</a>
+ * @version $Revision$
+ * @since Aug 21, 2006
+ */
+public class AuditContext
+{
+ private String securityDomain = null;
+
+ private List providerList = new ArrayList();
+
+ public AuditContext(String securityDomainName)
+ {
+ this.securityDomain = securityDomainName;
+ providerList.add(new LogAuditProvider());
+ }
+
+ public void audit(AuditEvent ae)
+ {
+ int len = this.providerList.size();
+
+ for(int i = 0; i < len; i++)
+ {
+ AuditProvider ap = (AuditProvider)this.providerList.get(i);
+ ap.audit(ae);
+ }
+ }
+
+ public void addProvider(AuditProvider ap)
+ {
+ providerList.add(ap);
+ }
+
+ public void addProviders(List list)
+ {
+ providerList.addAll(list);
+ }
+
+ public void replaceProviders(List list)
+ {
+ providerList.clear();
+ providerList = list;
+ }
+}
Added: trunk/security/src/main/org/jboss/security/audit/AuditEvent.java
===================================================================
--- trunk/security/src/main/org/jboss/security/audit/AuditEvent.java 2006-08-22 19:26:58 UTC (rev 56154)
+++ trunk/security/src/main/org/jboss/security/audit/AuditEvent.java 2006-08-22 20:12:44 UTC (rev 56155)
@@ -0,0 +1,63 @@
+/*
+ * JBoss, the OpenSource J2EE webOS
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.security.audit;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Holder of audit information
+ * @author <a href="mailto:Anil.Saldhana at jboss.org">Anil Saldhana</a>
+ * @version $Revision$
+ * @since Aug 21, 2006
+ */
+public class AuditEvent
+{
+ private String auditLevel = AuditLevel.INFO;
+
+ private Map contextMap = new HashMap();
+
+ private Exception underlyingException = null;
+
+ public AuditEvent(String level)
+ {
+ this.auditLevel = level;
+ }
+
+ public String getAuditLevel()
+ {
+ return this.auditLevel;
+ }
+
+ public Map getContextMap()
+ {
+ return contextMap;
+ }
+
+ public void setContextMap(final Map cmap)
+ {
+ this.contextMap = cmap;
+ }
+
+ public Exception getUnderlyingException()
+ {
+ return underlyingException;
+ }
+
+ public void setUnderlyingException(Exception underlyingException)
+ {
+ this.underlyingException = underlyingException;
+ }
+
+ public String toString()
+ {
+ StringBuilder sbu = new StringBuilder();
+ sbu.append("[").append(auditLevel).append("]");
+ sbu.append(contextMap);
+ return sbu.toString();
+ }
+}
Added: trunk/security/src/main/org/jboss/security/audit/AuditLevel.java
===================================================================
--- trunk/security/src/main/org/jboss/security/audit/AuditLevel.java 2006-08-22 19:26:58 UTC (rev 56154)
+++ trunk/security/src/main/org/jboss/security/audit/AuditLevel.java 2006-08-22 20:12:44 UTC (rev 56155)
@@ -0,0 +1,27 @@
+/*
+ * JBoss, the OpenSource J2EE webOS
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.security.audit;
+
+/**
+ * Define the Audit Levels of Severity
+ * @author <a href="mailto:Anil.Saldhana at jboss.org">Anil Saldhana</a>
+ * @version $Revision$
+ * @since Aug 21, 2006
+ */
+public interface AuditLevel
+{
+ /** Denotes situations where there has been a server exception */
+ String ERROR = "Error";
+
+ /** Denotes situations when there has been a failed attempt */
+ String FAILURE = "Failure";
+
+ String SUCCESS = "Success";
+
+ /** Just some info being passed into the audit logs */
+ String INFO = "Info";
+}
Added: trunk/security/src/main/org/jboss/security/audit/AuditManager.java
===================================================================
--- trunk/security/src/main/org/jboss/security/audit/AuditManager.java 2006-08-22 19:26:58 UTC (rev 56154)
+++ trunk/security/src/main/org/jboss/security/audit/AuditManager.java 2006-08-22 20:12:44 UTC (rev 56155)
@@ -0,0 +1,43 @@
+/*
+ * JBoss, the OpenSource J2EE webOS
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.security.audit;
+
+import org.jboss.security.audit.providers.LogAuditProvider;
+
+import EDU.oswego.cs.dl.util.concurrent.ConcurrentHashMap;
+
+/**
+ * Manages a set of AuditContext
+ * @author <a href="mailto:Anil.Saldhana at jboss.org">Anil Saldhana</a>
+ * @version $Revision$
+ * @since Aug 22, 2006
+ */
+public class AuditManager
+{
+ private static ConcurrentHashMap contexts = new ConcurrentHashMap();
+
+ private static AuditContext defaultContext = null;
+
+ static
+ {
+ defaultContext = new AuditContext("Default_Context");
+ defaultContext.addProvider(new LogAuditProvider());
+ }
+
+ public static AuditContext getAuditContext(String securityDomain)
+ {
+ AuditContext ac = (AuditContext)contexts.get(securityDomain);
+ if(ac == null)
+ ac = defaultContext;
+ return ac;
+ }
+
+ public static void addAuditContext(String securityDomain, AuditContext ac)
+ {
+ contexts.put(securityDomain, ac);
+ }
+}
Added: trunk/security/src/main/org/jboss/security/audit/AuditProvider.java
===================================================================
--- trunk/security/src/main/org/jboss/security/audit/AuditProvider.java 2006-08-22 19:26:58 UTC (rev 56154)
+++ trunk/security/src/main/org/jboss/security/audit/AuditProvider.java 2006-08-22 20:12:44 UTC (rev 56155)
@@ -0,0 +1,24 @@
+/*
+ * JBoss, the OpenSource J2EE webOS
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.security.audit;
+
+/**
+ * Audit Provider that can log audit events to an external
+ * sink
+ * @author <a href="mailto:Anil.Saldhana at jboss.org">Anil Saldhana</a>
+ * @version $Revision$
+ * @since Aug 21, 2006
+ */
+public interface AuditProvider
+{
+ /**
+ * Perform an audit of the event passed
+ * A provider can log the audit as per needs.
+ * @param ae audit event that holds information on the audit
+ */
+ public void audit(AuditEvent ae);
+}
Added: trunk/security/src/main/org/jboss/security/audit/providers/LogAuditProvider.java
===================================================================
--- trunk/security/src/main/org/jboss/security/audit/providers/LogAuditProvider.java 2006-08-22 19:26:58 UTC (rev 56154)
+++ trunk/security/src/main/org/jboss/security/audit/providers/LogAuditProvider.java 2006-08-22 20:12:44 UTC (rev 56155)
@@ -0,0 +1,39 @@
+/*
+ * JBoss, the OpenSource J2EE webOS
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.security.audit.providers;
+
+import org.jboss.logging.Logger;
+import org.jboss.security.audit.AbstractAuditProvider;
+import org.jboss.security.audit.AuditEvent;
+
+/**
+ * Audit Provider that just logs the audit event using a Logger.
+ * The flexibility of passing the audit log entries to a different
+ * sink (database, jms queue, file etc) can be controlled in the
+ * logging configuration (Eg: log4j.xml in log4j)
+ * <p>
+ * Ensure that the appender is configured properly in the
+ * global log4j.xml for log entries to go to a log, separate
+ * from the regular server logs.
+ * </p>
+ * @author <a href="mailto:Anil.Saldhana at jboss.org">Anil Saldhana</a>
+ * @version $Revision$
+ * @since Aug 21, 2006
+ */
+public class LogAuditProvider extends AbstractAuditProvider
+{
+ private static final Logger log = Logger.getLogger(LogAuditProvider.class);
+
+ public void audit(AuditEvent auditEvent)
+ {
+ Exception e = auditEvent.getUnderlyingException();
+ if(e != null)
+ log.trace(auditEvent, e);
+ else
+ log.trace(auditEvent);
+ }
+}
More information about the jboss-cvs-commits
mailing list