sqoop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jar...@apache.org
Subject git commit: SQOOP-1143: Sqoop2: Provide server audit log for operations upon metadata structures
Date Wed, 14 Aug 2013 16:02:53 GMT
Updated Branches:
  refs/heads/sqoop2 72f0ff1c7 -> ee4e4c476


SQOOP-1143: Sqoop2: Provide server audit log for operations upon metadata structures

(Mengwei Ding via Jarek Jarcec Cecho)


Project: http://git-wip-us.apache.org/repos/asf/sqoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/sqoop/commit/ee4e4c47
Tree: http://git-wip-us.apache.org/repos/asf/sqoop/tree/ee4e4c47
Diff: http://git-wip-us.apache.org/repos/asf/sqoop/diff/ee4e4c47

Branch: refs/heads/sqoop2
Commit: ee4e4c476fb41c1d3d0b1f23db2db14c9eb52554
Parents: 72f0ff1
Author: Jarek Jarcec Cecho <jarcec@apache.org>
Authored: Wed Aug 14 09:01:59 2013 -0700
Committer: Jarek Jarcec Cecho <jarcec@apache.org>
Committed: Wed Aug 14 09:01:59 2013 -0700

----------------------------------------------------------------------
 .../org/apache/sqoop/audit/AuditLogger.java     |  67 +++++++++
 .../sqoop/audit/AuditLoggerConstants.java       |  37 +++++
 .../apache/sqoop/audit/AuditLoggerError.java    |  50 +++++++
 .../apache/sqoop/audit/AuditLoggerManager.java  | 149 +++++++++++++++++++
 .../org/apache/sqoop/audit/FileAuditLogger.java |  88 +++++++++++
 .../java/org/apache/sqoop/core/SqoopServer.java |   3 +
 dist/src/main/server/conf/sqoop.properties      |  12 ++
 .../sqoop/handler/ConnectionRequestHandler.java |  17 +++
 .../sqoop/handler/ConnectorRequestHandler.java  |   9 ++
 .../sqoop/handler/FrameworkRequestHandler.java  |   5 +
 .../apache/sqoop/handler/JobRequestHandler.java |  17 +++
 .../sqoop/handler/SubmissionRequestHandler.java |  18 +++
 .../sqoop/handler/VersionRequestHandler.java    |   4 +
 13 files changed, 476 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/sqoop/blob/ee4e4c47/core/src/main/java/org/apache/sqoop/audit/AuditLogger.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/sqoop/audit/AuditLogger.java b/core/src/main/java/org/apache/sqoop/audit/AuditLogger.java
new file mode 100644
index 0000000..881532d
--- /dev/null
+++ b/core/src/main/java/org/apache/sqoop/audit/AuditLogger.java
@@ -0,0 +1,67 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sqoop.audit;
+
+import java.util.Map;
+
+import org.apache.sqoop.core.SqoopConfiguration;
+
+/**
+ * Interface to define an audit logger
+ */
+public abstract class AuditLogger {
+
+  /**
+   * The name of this logger
+   */
+  private String loggerName;
+
+  /**
+   * Initialize the logger
+   */
+  abstract void initialize();
+
+  /**
+   * Called to log an audit event
+   *
+   * @param username Name of the user executing the request.
+   * @param ip Remote address of the request.
+   * @param operation The type of the event.
+   * @param objectType The type of the object to be operated upon.
+   * @param objectId The id of the object to be operated upon.
+   */
+  abstract void logAuditEvent(String username, String ip,
+      String operation, String objectType, String objectId);
+
+  public String getLoggerName() {
+    return loggerName;
+  }
+
+  public void setLoggerName(String loggerName) {
+    this.loggerName = loggerName;
+  }
+
+  /**
+   * Parse out all configurations for current logger
+   * @return all configurations
+   */
+  protected Map<String, String> getLoggerConfig() {
+    String prefix = AuditLoggerConstants.PREFIX_AUDITLOGGER_CONFIG + getLoggerName() + ".";
+    return SqoopConfiguration.getInstance().getContext().getNestedProperties(prefix);
+  }
+}

http://git-wip-us.apache.org/repos/asf/sqoop/blob/ee4e4c47/core/src/main/java/org/apache/sqoop/audit/AuditLoggerConstants.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/sqoop/audit/AuditLoggerConstants.java b/core/src/main/java/org/apache/sqoop/audit/AuditLoggerConstants.java
new file mode 100644
index 0000000..d056a34
--- /dev/null
+++ b/core/src/main/java/org/apache/sqoop/audit/AuditLoggerConstants.java
@@ -0,0 +1,37 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sqoop.audit;
+
+import org.apache.sqoop.core.ConfigurationConstants;
+
+public class AuditLoggerConstants {
+
+  /**
+   * All audit logger related configuration is prefixed with this:
+   * <tt>org.apache.sqoop.auditlogger.</tt>
+   */
+  public static final String PREFIX_AUDITLOGGER_CONFIG =
+      ConfigurationConstants.PREFIX_GLOBAL_CONFIG + "auditlogger.";
+
+  /**
+   * To specify an audit logger, the logger class must be given via
+   * [LoggerName].provider.
+   */
+  public static final String SUFFIX_AUDITLOGGER_CLASS =
+      ".class";
+}

http://git-wip-us.apache.org/repos/asf/sqoop/blob/ee4e4c47/core/src/main/java/org/apache/sqoop/audit/AuditLoggerError.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/sqoop/audit/AuditLoggerError.java b/core/src/main/java/org/apache/sqoop/audit/AuditLoggerError.java
new file mode 100644
index 0000000..5999e1c
--- /dev/null
+++ b/core/src/main/java/org/apache/sqoop/audit/AuditLoggerError.java
@@ -0,0 +1,50 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sqoop.audit;
+
+import org.apache.sqoop.common.ErrorCode;
+
+public enum AuditLoggerError implements ErrorCode {
+
+  /** An unknown error has occurred. */
+  AUDIT_0000("An unknown error has occurred"),
+
+  /** The system was unable to find or load the audit logger provider. */
+  AUDIT_0001("The system was unable to find or load audit logger class"),
+
+  /** The audit logger output file is not given. */
+  AUDIT_0002("The output file for FileAuditLogger is not given"),
+
+  ;
+
+  private final String message;
+
+  private AuditLoggerError(String message) {
+    this.message = message;
+  }
+
+  @Override
+  public String getCode() {
+    return name();
+  }
+
+  @Override
+  public String getMessage() {
+    return message;
+  }
+}

http://git-wip-us.apache.org/repos/asf/sqoop/blob/ee4e4c47/core/src/main/java/org/apache/sqoop/audit/AuditLoggerManager.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/sqoop/audit/AuditLoggerManager.java b/core/src/main/java/org/apache/sqoop/audit/AuditLoggerManager.java
new file mode 100644
index 0000000..17a996f
--- /dev/null
+++ b/core/src/main/java/org/apache/sqoop/audit/AuditLoggerManager.java
@@ -0,0 +1,149 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sqoop.audit;
+
+import org.apache.log4j.Logger;
+import org.apache.sqoop.common.MapContext;
+import org.apache.sqoop.common.SqoopException;
+import org.apache.sqoop.core.Reconfigurable;
+import org.apache.sqoop.core.SqoopConfiguration;
+import org.apache.sqoop.core.SqoopConfiguration.CoreConfigurationListener;
+import org.apache.sqoop.utils.ClassUtils;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+public class AuditLoggerManager implements Reconfigurable {
+
+  /**
+   * Logger object for this class
+   */
+  private static final Logger LOG = Logger.getLogger(AuditLoggerManager.class);
+
+  /**
+   * All audit loggers
+   */
+  private List<AuditLogger> loggers;
+
+  /**
+   * Private instance to singleton of this class
+   */
+  private static AuditLoggerManager instance;
+
+  /**
+   * Create default object
+   */
+  static {
+    instance = new AuditLoggerManager();
+  }
+
+  /**
+   * Return current instance
+   *
+   * @return Current instance
+   */
+  public static AuditLoggerManager getInstance() {
+    return instance;
+  }
+
+  /**
+   * Allows to set instance in case that it's need.
+   *
+   * @param newInstance New instance
+   */
+  public void setInstance(AuditLoggerManager newInstance) {
+    instance = newInstance;
+  }
+
+  public AuditLoggerManager() {
+    loggers = new ArrayList<AuditLogger>();
+  }
+
+  public synchronized void initialize() {
+    LOG.info("Begin audit logger manager initialization");
+    initializeLoggers();
+
+    SqoopConfiguration.getInstance().getProvider()
+        .registerListener(new CoreConfigurationListener(this));
+
+    LOG.info("Audit logger manager initialized: OK");
+  }
+
+  private void initializeLoggers() {
+    loggers.clear();
+
+    MapContext context = SqoopConfiguration.getInstance().getContext();
+
+    Map<String, String> auditLoggerProps = context.getNestedProperties(
+        AuditLoggerConstants.PREFIX_AUDITLOGGER_CONFIG);
+
+    // Initialize audit loggers
+    for (String key : auditLoggerProps.keySet()) {
+      if (key.endsWith(AuditLoggerConstants.SUFFIX_AUDITLOGGER_CLASS)) {
+        String loggerName = key.substring(0, key.indexOf("."));
+        String loggerClassName = auditLoggerProps.get(key);
+
+        if (loggerClassName == null || loggerClassName.trim().length() == 0) {
+          throw new SqoopException(AuditLoggerError.AUDIT_0001,
+              "Logger name: " + loggerName);
+        }
+
+        Class<?> loggerClass =
+            ClassUtils.loadClass(loggerClassName);
+
+        if (loggerClass == null) {
+          throw new SqoopException(AuditLoggerError.AUDIT_0001,
+              "Logger Class: " + loggerClassName);
+        }
+
+        AuditLogger newLogger;
+        try {
+          newLogger = (AuditLogger) loggerClass.newInstance();
+        } catch (Exception ex) {
+          throw new SqoopException(AuditLoggerError.AUDIT_0001,
+              "Logger Class: " + loggerClassName, ex);
+        }
+
+        newLogger.setLoggerName(loggerName);
+        newLogger.initialize();
+        loggers.add(newLogger);
+        LOG.info("Audit Logger has been initialized: " + loggerName);
+      }
+    }
+  }
+
+  public synchronized void destroy() {
+    LOG.trace("Begin audit logger manager destroy");
+  }
+
+  public void logAuditEvent(String username,
+      String ip, String operation, String objectType, String objectId) {
+    for (AuditLogger logger : loggers) {
+      logger.logAuditEvent(username, ip, operation, objectType, objectId);
+    }
+  }
+
+  @Override
+  public void configurationChanged() {
+    LOG.info("Begin audit logger manager reconfiguring");
+    initializeLoggers();
+    LOG.info("Audit logger manager reconfigured");
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/sqoop/blob/ee4e4c47/core/src/main/java/org/apache/sqoop/audit/FileAuditLogger.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/sqoop/audit/FileAuditLogger.java b/core/src/main/java/org/apache/sqoop/audit/FileAuditLogger.java
new file mode 100644
index 0000000..ca93266
--- /dev/null
+++ b/core/src/main/java/org/apache/sqoop/audit/FileAuditLogger.java
@@ -0,0 +1,88 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sqoop.audit;
+
+import java.util.Map;
+import java.util.Properties;
+
+import org.apache.log4j.Logger;
+import org.apache.log4j.PropertyConfigurator;
+import org.apache.sqoop.common.SqoopException;
+
+public class FileAuditLogger extends AuditLogger {
+
+  private Logger LOG = Logger.getLogger(FileAuditLogger.class);
+
+  private static final String APPENDER_SURFIX = "Appender";
+
+  /**
+   * The option name for audit log file location
+   */
+  private static final String FILE = "file";
+
+  /**
+   * The logger for output log lines
+   */
+  private Logger logger;
+
+  /**
+   * Configurations for this audit logger
+   */
+  private Map<String, String> config;
+
+  /**
+   * Properties to setup logger
+   */
+  private Properties props;
+
+  public FileAuditLogger() {
+    this.props = new Properties();
+  }
+
+  public void initialize() {
+    config = getLoggerConfig();
+
+    String outputFile = config.get(FILE);
+    if (outputFile == null) {
+      throw new SqoopException(AuditLoggerError.AUDIT_0002);
+    }
+
+    // setup logger
+    String appender = "log4j.appender." + getLoggerName() + APPENDER_SURFIX;
+    LOG.warn("appender: " + appender);
+    props.put(appender, "org.apache.log4j.RollingFileAppender");
+    props.put(appender + ".File", outputFile);
+    props.put(appender + ".layout", "org.apache.log4j.PatternLayout");
+    props.put(appender + ".layout.ConversionPattern", "%d %-5p %c: %m%n");
+    props.put("log4j.logger." + getLoggerName(), "INFO," + getLoggerName() + APPENDER_SURFIX);
+    PropertyConfigurator.configure(props);
+
+    logger = Logger.getLogger(getLoggerName());
+  }
+
+  public void logAuditEvent(String username, String ip, String operation, String objectType,
+          String objectId) {
+    StringBuilder sentence = new StringBuilder();
+    sentence.append("user=").append(username).append("\t");
+    sentence.append("ip=").append(ip).append("\t");
+    sentence.append("op=").append(operation).append("\t");
+    sentence.append("obj=").append(objectType).append("\t");
+    sentence.append("objId=").append(objectId);
+    logger.info(sentence.toString());
+  }
+}

http://git-wip-us.apache.org/repos/asf/sqoop/blob/ee4e4c47/core/src/main/java/org/apache/sqoop/core/SqoopServer.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/sqoop/core/SqoopServer.java b/core/src/main/java/org/apache/sqoop/core/SqoopServer.java
index 90bb327..d4c3b39 100644
--- a/core/src/main/java/org/apache/sqoop/core/SqoopServer.java
+++ b/core/src/main/java/org/apache/sqoop/core/SqoopServer.java
@@ -18,6 +18,7 @@
 package org.apache.sqoop.core;
 
 import org.apache.log4j.Logger;
+import org.apache.sqoop.audit.AuditLoggerManager;
 import org.apache.sqoop.connector.ConnectorManager;
 import org.apache.sqoop.framework.FrameworkManager;
 import org.apache.sqoop.framework.JobManager;
@@ -36,6 +37,7 @@ public class SqoopServer {
     FrameworkManager.getInstance().destroy();
     ConnectorManager.getInstance().destroy();
     RepositoryManager.getInstance().destroy();
+    AuditLoggerManager.getInstance().destroy();
     SqoopConfiguration.getInstance().destroy();
     LOG.info("Sqoop server has been correctly terminated");
   }
@@ -44,6 +46,7 @@ public class SqoopServer {
     try {
       LOG.info("Booting up Sqoop server");
       SqoopConfiguration.getInstance().initialize();
+      AuditLoggerManager.getInstance().initialize();
       RepositoryManager.getInstance().initialize();
       ConnectorManager.getInstance().initialize();
       FrameworkManager.getInstance().initialize();

http://git-wip-us.apache.org/repos/asf/sqoop/blob/ee4e4c47/dist/src/main/server/conf/sqoop.properties
----------------------------------------------------------------------
diff --git a/dist/src/main/server/conf/sqoop.properties b/dist/src/main/server/conf/sqoop.properties
index 76596b4..bb01016 100755
--- a/dist/src/main/server/conf/sqoop.properties
+++ b/dist/src/main/server/conf/sqoop.properties
@@ -57,6 +57,18 @@ org.apache.sqoop.log4j.category.org.apache.sqoop=DEBUG
 org.apache.sqoop.log4j.category.org.apache.derby=INFO
 
 #
+# Audit Loggers Configuration
+# Multiple audit loggers could be given here. To specify an
+# audit logger, you should at least add org.apache.sqoop.
+# auditlogger.[LoggerName].class. You could also provide
+# more configuration options by using org.apache.sqoop.
+# auditlogger.[LoggerName] prefix, then all these options
+# are parsed to the logger class.
+#
+org.apache.sqoop.auditlogger.default.class=org.apache.sqoop.audit.FileAuditLogger
+org.apache.sqoop.auditlogger.default.file=@LOGDIR@/default.audit
+
+#
 # Repository configuration
 # The Repository subsystem provides the special prefix which
 # is "org.apache.sqoop.repository.sysprop". Any property that

http://git-wip-us.apache.org/repos/asf/sqoop/blob/ee4e4c47/server/src/main/java/org/apache/sqoop/handler/ConnectionRequestHandler.java
----------------------------------------------------------------------
diff --git a/server/src/main/java/org/apache/sqoop/handler/ConnectionRequestHandler.java b/server/src/main/java/org/apache/sqoop/handler/ConnectionRequestHandler.java
index 62be8f4..875729f 100644
--- a/server/src/main/java/org/apache/sqoop/handler/ConnectionRequestHandler.java
+++ b/server/src/main/java/org/apache/sqoop/handler/ConnectionRequestHandler.java
@@ -18,6 +18,7 @@
 package org.apache.sqoop.handler;
 
 import org.apache.log4j.Logger;
+import org.apache.sqoop.audit.AuditLoggerManager;
 import org.apache.sqoop.common.SqoopException;
 import org.apache.sqoop.connector.ConnectorManager;
 import org.apache.sqoop.connector.spi.SqoopConnector;
@@ -116,6 +117,10 @@ public class ConnectionRequestHandler implements RequestHandler {
     String sxid = ctx.getLastURLElement();
     long xid = Long.valueOf(sxid);
 
+    AuditLoggerManager.getInstance()
+        .logAuditEvent(ctx.getUserName(), ctx.getRequest().getRemoteAddr(),
+        "delete", "connection", sxid);
+
     Repository repository = RepositoryManager.getInstance().getRepository();
     repository.deleteConnection(xid);
 
@@ -202,10 +207,18 @@ public class ConnectionRequestHandler implements RequestHandler {
     // If we're good enough let's perform the action
     if(finalStatus.canProceed()) {
       if(update) {
+        AuditLoggerManager.getInstance()
+            .logAuditEvent(ctx.getUserName(), ctx.getRequest().getRemoteAddr(),
+            "update", "connection", String.valueOf(connection.getPersistenceId()));
+
         RepositoryManager.getInstance().getRepository().updateConnection(connection);
       } else {
         RepositoryManager.getInstance().getRepository().createConnection(connection);
         outputBean.setId(connection.getPersistenceId());
+
+        AuditLoggerManager.getInstance()
+            .logAuditEvent(ctx.getUserName(), ctx.getRequest().getRemoteAddr(),
+            "create", "connection", String.valueOf(connection.getPersistenceId()));
       }
     }
 
@@ -216,6 +229,10 @@ public class ConnectionRequestHandler implements RequestHandler {
     String sxid = ctx.getLastURLElement();
     ConnectionBean bean;
 
+    AuditLoggerManager.getInstance()
+        .logAuditEvent(ctx.getUserName(), ctx.getRequest().getRemoteAddr(),
+        "get", "connection", sxid);
+
     Locale locale = ctx.getAcceptLanguageHeader();
     Repository repository = RepositoryManager.getInstance().getRepository();
 

http://git-wip-us.apache.org/repos/asf/sqoop/blob/ee4e4c47/server/src/main/java/org/apache/sqoop/handler/ConnectorRequestHandler.java
----------------------------------------------------------------------
diff --git a/server/src/main/java/org/apache/sqoop/handler/ConnectorRequestHandler.java b/server/src/main/java/org/apache/sqoop/handler/ConnectorRequestHandler.java
index 4c389cc..d1b6b9a 100644
--- a/server/src/main/java/org/apache/sqoop/handler/ConnectorRequestHandler.java
+++ b/server/src/main/java/org/apache/sqoop/handler/ConnectorRequestHandler.java
@@ -20,6 +20,7 @@ package org.apache.sqoop.handler;
 import org.apache.log4j.Logger;
 import org.apache.sqoop.common.SqoopException;
 import org.apache.sqoop.connector.ConnectorManager;
+import org.apache.sqoop.audit.AuditLoggerManager;
 import org.apache.sqoop.json.JsonBean;
 import org.apache.sqoop.json.ConnectorBean;
 import org.apache.sqoop.model.MConnector;
@@ -71,6 +72,10 @@ public class ConnectorRequestHandler implements RequestHandler {
       // display all connectors
       connectors = ConnectorManager.getInstance().getConnectorsMetadata();
       bundles = ConnectorManager.getInstance().getResourceBundles(locale);
+
+      AuditLoggerManager.getInstance()
+          .logAuditEvent(ctx.getUserName(), ctx.getRequest().getRemoteAddr(),
+          "get", "connector", "all");
     } else {
       Long id = Long.parseLong(cid);
 
@@ -84,6 +89,10 @@ public class ConnectorRequestHandler implements RequestHandler {
 
       connectors.add(ConnectorManager.getInstance().getConnectorMetadata(id));
       bundles.put(id, ConnectorManager.getInstance().getResourceBundle(id, locale));
+
+      AuditLoggerManager.getInstance()
+          .logAuditEvent(ctx.getUserName(), ctx.getRequest().getRemoteAddr(),
+          "get", "connector", String.valueOf(id));
     }
 
     return new ConnectorBean(connectors, bundles);

http://git-wip-us.apache.org/repos/asf/sqoop/blob/ee4e4c47/server/src/main/java/org/apache/sqoop/handler/FrameworkRequestHandler.java
----------------------------------------------------------------------
diff --git a/server/src/main/java/org/apache/sqoop/handler/FrameworkRequestHandler.java b/server/src/main/java/org/apache/sqoop/handler/FrameworkRequestHandler.java
index 04ffc3c..616e974 100644
--- a/server/src/main/java/org/apache/sqoop/handler/FrameworkRequestHandler.java
+++ b/server/src/main/java/org/apache/sqoop/handler/FrameworkRequestHandler.java
@@ -19,6 +19,7 @@ package org.apache.sqoop.handler;
 
 import org.apache.log4j.Logger;
 
+import org.apache.sqoop.audit.AuditLoggerManager;
 import org.apache.sqoop.framework.FrameworkManager;
 import org.apache.sqoop.json.FrameworkBean;
 import org.apache.sqoop.json.JsonBean;
@@ -42,6 +43,10 @@ public class FrameworkRequestHandler  implements RequestHandler {
 
   @Override
   public JsonBean handleEvent(RequestContext ctx) {
+    AuditLoggerManager.getInstance()
+        .logAuditEvent(ctx.getUserName(), ctx.getRequest().getRemoteAddr(),
+        "get", "framework", "");
+
     return new FrameworkBean(FrameworkManager.getInstance().getFramework(),
       FrameworkManager.getInstance().getBundle(ctx.getAcceptLanguageHeader()));
   }

http://git-wip-us.apache.org/repos/asf/sqoop/blob/ee4e4c47/server/src/main/java/org/apache/sqoop/handler/JobRequestHandler.java
----------------------------------------------------------------------
diff --git a/server/src/main/java/org/apache/sqoop/handler/JobRequestHandler.java b/server/src/main/java/org/apache/sqoop/handler/JobRequestHandler.java
index 0d15329..59a4511 100644
--- a/server/src/main/java/org/apache/sqoop/handler/JobRequestHandler.java
+++ b/server/src/main/java/org/apache/sqoop/handler/JobRequestHandler.java
@@ -18,6 +18,7 @@
 package org.apache.sqoop.handler;
 
 import org.apache.log4j.Logger;
+import org.apache.sqoop.audit.AuditLoggerManager;
 import org.apache.sqoop.common.SqoopException;
 import org.apache.sqoop.connector.ConnectorManager;
 import org.apache.sqoop.connector.spi.SqoopConnector;
@@ -116,6 +117,10 @@ public class JobRequestHandler implements RequestHandler {
     String sxid = ctx.getLastURLElement();
     long jid = Long.valueOf(sxid);
 
+    AuditLoggerManager.getInstance()
+        .logAuditEvent(ctx.getUserName(), ctx.getRequest().getRemoteAddr(),
+        "delete", "job", sxid);
+
     Repository repository = RepositoryManager.getInstance().getRepository();
     repository.deleteJob(jid);
 
@@ -201,10 +206,18 @@ public class JobRequestHandler implements RequestHandler {
     // If we're good enough let's perform the action
     if(finalStatus.canProceed()) {
       if(update) {
+        AuditLoggerManager.getInstance()
+            .logAuditEvent(ctx.getUserName(), ctx.getRequest().getRemoteAddr(),
+            "update", "job", String.valueOf(job.getPersistenceId()));
+
         RepositoryManager.getInstance().getRepository().updateJob(job);
       } else {
         RepositoryManager.getInstance().getRepository().createJob(job);
         outputBean.setId(job.getPersistenceId());
+
+        AuditLoggerManager.getInstance()
+            .logAuditEvent(ctx.getUserName(), ctx.getRequest().getRemoteAddr(),
+            "create", "job", String.valueOf(job.getPersistenceId()));
       }
 
     }
@@ -216,6 +229,10 @@ public class JobRequestHandler implements RequestHandler {
     String sjid = ctx.getLastURLElement();
     JobBean bean;
 
+    AuditLoggerManager.getInstance()
+        .logAuditEvent(ctx.getUserName(), ctx.getRequest().getRemoteAddr(),
+        "get", "job", sjid);
+
     Locale locale = ctx.getAcceptLanguageHeader();
     Repository repository = RepositoryManager.getInstance().getRepository();
 

http://git-wip-us.apache.org/repos/asf/sqoop/blob/ee4e4c47/server/src/main/java/org/apache/sqoop/handler/SubmissionRequestHandler.java
----------------------------------------------------------------------
diff --git a/server/src/main/java/org/apache/sqoop/handler/SubmissionRequestHandler.java b/server/src/main/java/org/apache/sqoop/handler/SubmissionRequestHandler.java
index 65686a8..6d9777a 100644
--- a/server/src/main/java/org/apache/sqoop/handler/SubmissionRequestHandler.java
+++ b/server/src/main/java/org/apache/sqoop/handler/SubmissionRequestHandler.java
@@ -20,6 +20,7 @@ package org.apache.sqoop.handler;
 import java.util.List;
 
 import org.apache.log4j.Logger;
+import org.apache.sqoop.audit.AuditLoggerManager;
 import org.apache.sqoop.common.SqoopException;
 import org.apache.sqoop.framework.FrameworkManager;
 import org.apache.sqoop.framework.JobManager;
@@ -96,6 +97,10 @@ public class SubmissionRequestHandler implements RequestHandler {
 
     switch (ctx.getMethod()) {
       case GET:
+        AuditLoggerManager.getInstance()
+            .logAuditEvent(ctx.getUserName(), ctx.getRequest().getRemoteAddr(),
+            "status", "submission", String.valueOf(jid));
+
         return submissionStatus(jid);
       case POST:
         // TODO: This should be outsourced somewhere more suitable than here
@@ -104,8 +109,17 @@ public class SubmissionRequestHandler implements RequestHandler {
           JobManager.getInstance().setNotificationBaseUrl(
             url.split("v1")[0] + "/v1/submission/notification/");
         }
+
+        AuditLoggerManager.getInstance()
+            .logAuditEvent(ctx.getUserName(), ctx.getRequest().getRemoteAddr(),
+            "submit", "submission", String.valueOf(jid));
+
         return submissionSubmit(jid);
       case DELETE:
+        AuditLoggerManager.getInstance()
+            .logAuditEvent(ctx.getUserName(), ctx.getRequest().getRemoteAddr(),
+            "stop", "submission", String.valueOf(jid));
+
         return submissionStop(jid);
     }
 
@@ -113,6 +127,10 @@ public class SubmissionRequestHandler implements RequestHandler {
   }
 
   private JsonBean handleHistoryEvent(RequestContext ctx, String sjid) {
+    AuditLoggerManager.getInstance()
+        .logAuditEvent(ctx.getUserName(), ctx.getRequest().getRemoteAddr(),
+        "get", "submission", sjid);
+
     if (sjid.equals("all")) {
       return getSubmissions();
     } else {

http://git-wip-us.apache.org/repos/asf/sqoop/blob/ee4e4c47/server/src/main/java/org/apache/sqoop/handler/VersionRequestHandler.java
----------------------------------------------------------------------
diff --git a/server/src/main/java/org/apache/sqoop/handler/VersionRequestHandler.java b/server/src/main/java/org/apache/sqoop/handler/VersionRequestHandler.java
index f92d107..64c4536 100644
--- a/server/src/main/java/org/apache/sqoop/handler/VersionRequestHandler.java
+++ b/server/src/main/java/org/apache/sqoop/handler/VersionRequestHandler.java
@@ -19,6 +19,7 @@ package org.apache.sqoop.handler;
 
 import org.apache.log4j.Logger;
 import org.apache.sqoop.common.VersionInfo;
+import org.apache.sqoop.audit.AuditLoggerManager;
 import org.apache.sqoop.json.JsonBean;
 import org.apache.sqoop.json.VersionBean;
 import org.apache.sqoop.server.RequestContext;
@@ -53,6 +54,9 @@ public class VersionRequestHandler implements RequestHandler {
 
   @Override
   public JsonBean handleEvent(RequestContext ctx) {
+    AuditLoggerManager.getInstance()
+        .logAuditEvent(ctx.getUserName(), ctx.getRequest().getRemoteAddr(),
+        "show", "version", "");
     return versionBean;
   }
 }


Mime
View raw message