You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by jb...@apache.org on 2016/03/29 23:45:10 UTC
karaf git commit: KARAF-4414 - Add LogAuditLoginModule and disable
FileAuditLoginModule by default
Repository: karaf
Updated Branches:
refs/heads/master 276fc039e -> b71686bf2
KARAF-4414 - Add LogAuditLoginModule and disable FileAuditLoginModule by default
Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/b71686bf
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/b71686bf
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/b71686bf
Branch: refs/heads/master
Commit: b71686bf2034d0612705c393114e8ce1d0cea439
Parents: 276fc03
Author: Jean-Baptiste Onofré <jb...@apache.org>
Authored: Tue Mar 29 08:25:00 2016 +0200
Committer: Jean-Baptiste Onofré <jb...@apache.org>
Committed: Tue Mar 29 23:44:48 2016 +0200
----------------------------------------------------------------------
.../resources/etc/org.ops4j.pax.logging.cfg | 28 ++++++++-
.../jaas/modules/audit/LogAuditLoginModule.java | 61 ++++++++++++++++++++
.../karaf/jaas/modules/impl/Activator.java | 5 +-
.../karaf/jaas/modules/impl/KarafRealm.java | 11 ++++
4 files changed, 101 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/karaf/blob/b71686bf/assemblies/features/base/src/main/resources/resources/etc/org.ops4j.pax.logging.cfg
----------------------------------------------------------------------
diff --git a/assemblies/features/base/src/main/resources/resources/etc/org.ops4j.pax.logging.cfg b/assemblies/features/base/src/main/resources/resources/etc/org.ops4j.pax.logging.cfg
index 48e1069..d066e7f 100644
--- a/assemblies/features/base/src/main/resources/resources/etc/org.ops4j.pax.logging.cfg
+++ b/assemblies/features/base/src/main/resources/resources/etc/org.ops4j.pax.logging.cfg
@@ -30,16 +30,26 @@ log4j2.rootLogger.appenderRef.RollingFile.ref = RollingFile
log4j2.rootLogger.appenderRef.PaxOsgi.ref = PaxOsgi
log4j2.rootLogger.appenderRef.Console.ref = Console
+# Loggers configuration
+log4j2.loggers = audit
+
+# Security audit logger
+log4j2.logger.audit.name = org.apache.karaf.jaas.modules.audit
+log4j2.logger.audit.level = INFO
+log4j2.logger.audit.additivity = false
+log4j2.logger.audit.appenderRefs = AuditRollingFile
+log4j2.logger.audit.appenderRef.AuditRollingFile.ref = AuditRollingFile
+
# Appenders configuration
-log4j2.appenders = console, rolling, osgi
+log4j2.appenders = console, rolling, audit, osgi
-# CONSOLE appender not used by default
+# Console appender not used by default (see log4j2.rootLogger.appenderRefs)
log4j2.appender.console.type = Console
log4j2.appender.console.name = Console
log4j2.appender.console.layout.type = PatternLayout
log4j2.appender.console.layout.pattern = ${log4j2.pattern}
-# File appender
+# Rolling file appender
log4j2.appender.rolling.type = RollingRandomAccessFile
log4j2.appender.rolling.name = RollingFile
log4j2.appender.rolling.fileName = ${karaf.data}/log/karaf.log
@@ -53,6 +63,18 @@ log4j2.appender.rolling.policies.type = Policies
log4j2.appender.rolling.policies.size.type = SizeBasedTriggeringPolicy
log4j2.appender.rolling.policies.size.size = 16MB
+# Audit file appender
+log4j2.appender.audit.type = RollingRandomAccessFile
+log4j2.appender.audit.name = AuditRollingFile
+log4j2.appender.audit.fileName = ${karaf.data}/security/audit.log
+log4j2.appender.audit.filePattern = ${karaf.data}/security/audit.log.%i
+log4j2.appender.audit.append = false
+log4j2.appender.audit.layout.type = PatternLayout
+log4j2.appender.audit.layout.pattern = ${log4j2.pattern}
+log4j2.appender.audit.policies.type = Policies
+log4j2.appender.audit.policies.size.type = SizeBasedTriggeringPolicy
+log4j2.appender.audit.policies.size.size = 8MB
+
# OSGi appender
log4j2.appender.osgi.type = PaxOsgi
log4j2.appender.osgi.name = PaxOsgi
http://git-wip-us.apache.org/repos/asf/karaf/blob/b71686bf/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/audit/LogAuditLoginModule.java
----------------------------------------------------------------------
diff --git a/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/audit/LogAuditLoginModule.java b/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/audit/LogAuditLoginModule.java
new file mode 100644
index 0000000..f9e6915
--- /dev/null
+++ b/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/audit/LogAuditLoginModule.java
@@ -0,0 +1,61 @@
+/*
+ * Licensed 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.
+ * under the License.
+ */
+package org.apache.karaf.jaas.modules.audit;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.security.auth.Subject;
+import javax.security.auth.callback.CallbackHandler;
+import java.util.Map;
+
+public class LogAuditLoginModule extends AbstractAuditLoginModule {
+
+ public static final String LOG_LEVEL_OPTION = "level";
+ public static final String LOG_LOGGER_OPTION = "logger";
+
+ private String level = "INFO";
+ private Logger logger;
+
+ public void initialize(Subject subject, CallbackHandler callbackHandler,
+ Map sharedState, Map options) {
+ super.initialize(subject, callbackHandler, sharedState, options);
+ level = (String) options.get(LOG_LEVEL_OPTION);
+ logger = LoggerFactory.getLogger((String) options.get(LOG_LOGGER_OPTION));
+ }
+
+ protected synchronized void audit(Action action, String username) {
+ String actionStr;
+ switch (action) {
+ case ATTEMPT: actionStr = "Authentication attempt"; break;
+ case SUCCESS: actionStr = "Authentication succeeded"; break;
+ case FAILURE: actionStr = "Authentication failed"; break;
+ case LOGOUT: actionStr = "Explicit logout"; break;
+ default: actionStr = action.toString(); break;
+ }
+ if (level.equalsIgnoreCase("debug")) {
+ logger.debug("{} - {}", actionStr, username);
+ } else if (level.equalsIgnoreCase("trace")) {
+ logger.trace("{} - {}", actionStr, username);
+ } else if (level.equalsIgnoreCase("warn")) {
+ logger.warn("{} - {}", actionStr, username);
+ } else if (level.equalsIgnoreCase("error")) {
+ logger.error("{} - {}", actionStr, username);
+ } else {
+ logger.info("{} - {}", actionStr, username);
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/karaf/blob/b71686bf/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/impl/Activator.java
----------------------------------------------------------------------
diff --git a/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/impl/Activator.java b/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/impl/Activator.java
index ae53396..8e37aea 100644
--- a/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/impl/Activator.java
+++ b/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/impl/Activator.java
@@ -110,8 +110,11 @@ public class Activator extends BaseActivator implements ManagedService {
populate(config, ENCRYPTION_ALGORITHM, "MD5");
populate(config, ENCRYPTION_ENCODING, "hexadecimal");
populate(config, EVENTADMIN_ENABLED, "true");
- populate(config, "audit.file.enabled", "true");
+ populate(config, "audit.file.enabled", "false");
populate(config, "audit.file.file", System.getProperty("karaf.data") + "/security/audit.log");
+ populate(config, "audit.log.enabled", "true");
+ populate(config, "audit.log.logger", "org.apache.karaf.jaas.modules.audit.LogAuditLoginModule");
+ populate(config, "audit.log.level", "info");
populate(config, "audit.eventadmin.enabled", "true");
populate(config, "audit.eventadmin.topic", "org/apache/karaf/login");
config.put(BundleContext.class.getName(), bundleContext);
http://git-wip-us.apache.org/repos/asf/karaf/blob/b71686bf/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/impl/KarafRealm.java
----------------------------------------------------------------------
diff --git a/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/impl/KarafRealm.java b/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/impl/KarafRealm.java
index 2ec6445..7998dc3 100644
--- a/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/impl/KarafRealm.java
+++ b/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/impl/KarafRealm.java
@@ -22,6 +22,7 @@ import javax.security.auth.login.AppConfigurationEntry;
import org.apache.karaf.jaas.boot.ProxyLoginModule;
import org.apache.karaf.jaas.config.JaasRealm;
+import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
public class KarafRealm implements JaasRealm {
@@ -31,6 +32,7 @@ public class KarafRealm implements JaasRealm {
private static final String PROPERTIES_MODULE = "org.apache.karaf.jaas.modules.properties.PropertiesLoginModule";
private static final String PUBLIC_KEY_MODULE = "org.apache.karaf.jaas.modules.publickey.PublickeyLoginModule";
private static final String FILE_AUDIT_MODULE = "org.apache.karaf.jaas.modules.audit.FileAuditLoginModule";
+ private static final String LOG_AUDIT_MODULE = "org.apache.karaf.jaas.modules.audit.LogAuditLoginModule";
private static final String EVENTADMIN_AUDIT_MODULE = "org.apache.karaf.jaas.modules.audit.EventAdminAuditLoginModule";
private static final String MODULE = "org.apache.karaf.jaas.module";
@@ -86,6 +88,14 @@ public class KarafRealm implements JaasRealm {
fileOptions.put("enabled", properties.get("audit.file.enabled"));
fileOptions.put("file", properties.get("audit.file.file"));
+ Map<String, Object> logOptions = new HashMap<>();
+ logOptions.put(BundleContext.class.getName(), bundleContext);
+ logOptions.put(ProxyLoginModule.PROPERTY_MODULE, LOG_AUDIT_MODULE);
+ logOptions.put(ProxyLoginModule.PROPERTY_BUNDLE, Long.toString(bundleContext.getBundle().getBundleId()));
+ logOptions.put("enabled", properties.get("audit.log.enabled"));
+ logOptions.put("logger", properties.get("audit.log.logger"));
+ logOptions.put("level", properties.get("audit.log.level"));
+
Map<String, Object> eventadminOptions = new HashMap<>();
eventadminOptions.putAll(properties);
eventadminOptions.put(BundleContext.class.getName(), bundleContext);
@@ -98,6 +108,7 @@ public class KarafRealm implements JaasRealm {
new AppConfigurationEntry(ProxyLoginModule.class.getName(), AppConfigurationEntry.LoginModuleControlFlag.OPTIONAL, propertiesOptions),
new AppConfigurationEntry(ProxyLoginModule.class.getName(), AppConfigurationEntry.LoginModuleControlFlag.OPTIONAL, publicKeyOptions),
new AppConfigurationEntry(ProxyLoginModule.class.getName(), AppConfigurationEntry.LoginModuleControlFlag.OPTIONAL, fileOptions),
+ new AppConfigurationEntry(ProxyLoginModule.class.getName(), AppConfigurationEntry.LoginModuleControlFlag.OPTIONAL, logOptions),
new AppConfigurationEntry(ProxyLoginModule.class.getName(), AppConfigurationEntry.LoginModuleControlFlag.OPTIONAL, eventadminOptions)
};
}