|
@@ -22,6 +22,9 @@
|
|
|
|
|
|
package password.pwm.svc.event;
|
|
package password.pwm.svc.event;
|
|
|
|
|
|
|
|
+import lombok.AccessLevel;
|
|
|
|
+import lombok.AllArgsConstructor;
|
|
|
|
+import lombok.Getter;
|
|
import org.graylog2.syslog4j.SyslogIF;
|
|
import org.graylog2.syslog4j.SyslogIF;
|
|
import org.graylog2.syslog4j.impl.AbstractSyslogConfigIF;
|
|
import org.graylog2.syslog4j.impl.AbstractSyslogConfigIF;
|
|
import org.graylog2.syslog4j.impl.AbstractSyslogWriter;
|
|
import org.graylog2.syslog4j.impl.AbstractSyslogWriter;
|
|
@@ -39,6 +42,7 @@ import password.pwm.PwmApplication;
|
|
import password.pwm.PwmConstants;
|
|
import password.pwm.PwmConstants;
|
|
import password.pwm.config.Configuration;
|
|
import password.pwm.config.Configuration;
|
|
import password.pwm.config.PwmSetting;
|
|
import password.pwm.config.PwmSetting;
|
|
|
|
+import password.pwm.config.option.SyslogOutputFormat;
|
|
import password.pwm.error.ErrorInformation;
|
|
import password.pwm.error.ErrorInformation;
|
|
import password.pwm.error.PwmError;
|
|
import password.pwm.error.PwmError;
|
|
import password.pwm.error.PwmOperationalException;
|
|
import password.pwm.error.PwmOperationalException;
|
|
@@ -47,6 +51,7 @@ import password.pwm.health.HealthStatus;
|
|
import password.pwm.health.HealthTopic;
|
|
import password.pwm.health.HealthTopic;
|
|
import password.pwm.svc.stats.Statistic;
|
|
import password.pwm.svc.stats.Statistic;
|
|
import password.pwm.svc.stats.StatisticsManager;
|
|
import password.pwm.svc.stats.StatisticsManager;
|
|
|
|
+import password.pwm.util.java.JavaHelper;
|
|
import password.pwm.util.java.JsonUtil;
|
|
import password.pwm.util.java.JsonUtil;
|
|
import password.pwm.util.java.TimeDuration;
|
|
import password.pwm.util.java.TimeDuration;
|
|
import password.pwm.util.localdb.LocalDB;
|
|
import password.pwm.util.localdb.LocalDB;
|
|
@@ -85,12 +90,12 @@ public class SyslogAuditService {
|
|
|
|
|
|
private final Configuration configuration;
|
|
private final Configuration configuration;
|
|
private final PwmApplication pwmApplication;
|
|
private final PwmApplication pwmApplication;
|
|
- private boolean cefEnabled = true;
|
|
|
|
|
|
+ private final SyslogOutputFormat syslogOutputFormat;
|
|
|
|
|
|
public SyslogAuditService(final PwmApplication pwmApplication)
|
|
public SyslogAuditService(final PwmApplication pwmApplication)
|
|
throws LocalDBException
|
|
throws LocalDBException
|
|
{
|
|
{
|
|
- cefEnabled = pwmApplication.getConfig().readSettingAsBoolean(PwmSetting.AUDIT_COMMONEVENTFORMAT_ENABLE);
|
|
|
|
|
|
+ syslogOutputFormat = pwmApplication.getConfig().readSettingAsEnum(PwmSetting.AUDIT_SYSLOG_OUTPUT_FORMAT, SyslogOutputFormat.class);
|
|
this.pwmApplication = pwmApplication;
|
|
this.pwmApplication = pwmApplication;
|
|
this.configuration = pwmApplication.getConfig();
|
|
this.configuration = pwmApplication.getConfig();
|
|
this.certificates = configuration.readSettingAsCertificate(PwmSetting.AUDIT_SYSLOG_CERTIFICATES);
|
|
this.certificates = configuration.readSettingAsCertificate(PwmSetting.AUDIT_SYSLOG_CERTIFICATES);
|
|
@@ -176,20 +181,26 @@ public class SyslogAuditService {
|
|
|
|
|
|
public void add(final AuditRecord event) throws PwmOperationalException {
|
|
public void add(final AuditRecord event) throws PwmOperationalException {
|
|
|
|
|
|
- if (cefEnabled) {
|
|
|
|
- try {
|
|
|
|
- final String CEFMsg = convertAuditRecordToCEFMessage(event, configuration);
|
|
|
|
- workQueueProcessor.submit(CEFMsg);
|
|
|
|
- } catch (PwmOperationalException e) {
|
|
|
|
- LOGGER.warn("unable to add email to queue: " + e.getMessage());
|
|
|
|
- }
|
|
|
|
- } else {
|
|
|
|
- try {
|
|
|
|
- final String syslogMsg = convertAuditRecordToSyslogMessage(event, configuration);
|
|
|
|
- workQueueProcessor.submit(syslogMsg);
|
|
|
|
- } catch (PwmOperationalException e) {
|
|
|
|
- LOGGER.warn("unable to add email to queue: " + e.getMessage());
|
|
|
|
- }
|
|
|
|
|
|
+ final String syslogMsg;
|
|
|
|
+
|
|
|
|
+ switch ( syslogOutputFormat ) {
|
|
|
|
+ case JSON:
|
|
|
|
+ syslogMsg = convertAuditRecordToSyslogMessage( event, configuration );
|
|
|
|
+ break;
|
|
|
|
+
|
|
|
|
+ case CEF:
|
|
|
|
+ syslogMsg = convertAuditRecordToCEFMessage( event, configuration );
|
|
|
|
+ break;
|
|
|
|
+
|
|
|
|
+ default:
|
|
|
|
+ JavaHelper.unhandledSwitchStatement( syslogOutputFormat );
|
|
|
|
+ throw new IllegalStateException( );
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ try {
|
|
|
|
+ workQueueProcessor.submit(syslogMsg);
|
|
|
|
+ } catch (PwmOperationalException e) {
|
|
|
|
+ LOGGER.warn("unable to add syslog message to queue: " + e.getMessage());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -287,7 +298,7 @@ public class SyslogAuditService {
|
|
return message.toString();
|
|
return message.toString();
|
|
}
|
|
}
|
|
|
|
|
|
- public static String convertAuditRecordToCEFMessage(final AuditRecord auditRecord, final Configuration configuration) {
|
|
|
|
|
|
+ private static String convertAuditRecordToCEFMessage(final AuditRecord auditRecord, final Configuration configuration) {
|
|
|
|
|
|
final String recordType = auditRecord.getType().name();
|
|
final String recordType = auditRecord.getType().name();
|
|
String recordString = "";
|
|
String recordString = "";
|
|
@@ -333,6 +344,8 @@ public class SyslogAuditService {
|
|
return (translatedString);
|
|
return (translatedString);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Getter
|
|
|
|
+ @AllArgsConstructor(access = AccessLevel.PRIVATE)
|
|
public static class SyslogConfig implements Serializable {
|
|
public static class SyslogConfig implements Serializable {
|
|
public enum Protocol { sslTcp, tcp, udp, tls }
|
|
public enum Protocol { sslTcp, tcp, udp, tls }
|
|
|
|
|
|
@@ -340,24 +353,6 @@ public class SyslogAuditService {
|
|
private String host;
|
|
private String host;
|
|
private int port;
|
|
private int port;
|
|
|
|
|
|
- public SyslogConfig(final Protocol protocol, final String host, final int port) {
|
|
|
|
- this.protocol = protocol;
|
|
|
|
- this.host = host;
|
|
|
|
- this.port = port;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public Protocol getProtocol() {
|
|
|
|
- return protocol;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public String getHost() {
|
|
|
|
- return host;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public int getPort() {
|
|
|
|
- return port;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
public static SyslogConfig fromConfigString(final String input) throws IllegalArgumentException {
|
|
public static SyslogConfig fromConfigString(final String input) throws IllegalArgumentException {
|
|
if (input == null) {
|
|
if (input == null) {
|
|
throw new IllegalArgumentException("input cannot be null");
|
|
throw new IllegalArgumentException("input cannot be null");
|