001/* 002 * The contents of this file are subject to the terms of the Common Development and 003 * Distribution License (the License). You may not use this file except in compliance with the 004 * License. 005 * 006 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the 007 * specific language governing permission and limitations under the License. 008 * 009 * When distributing Covered Software, include this CDDL Header Notice in each file and include 010 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL 011 * Header, with the fields enclosed by brackets [] replaced by your own identifying 012 * information: "Portions copyright [year] [name of copyright owner]". 013 * 014 * Copyright 2015 ForgeRock AS. 015 */ 016package org.forgerock.audit.handlers.syslog; 017 018import org.forgerock.audit.handlers.syslog.SyslogAuditEventHandlerConfiguration.EventBufferingConfiguration; 019 020import java.net.InetSocketAddress; 021 022/** 023 * Transport protocol over which Syslog messages should be published. 024 */ 025public enum TransportProtocol { 026 027 /** 028 * Publish Syslog messages over TCP. 029 */ 030 TCP { 031 @Override 032 SyslogConnection getSyslogConnection(InetSocketAddress socket, SyslogAuditEventHandlerConfiguration config) { 033 return new TcpSyslogConnection(socket, config.getConnectTimeout()); 034 } 035 }, 036 037 /** 038 * Publish Syslog messages over UDP. 039 */ 040 UDP { 041 @Override 042 SyslogConnection getSyslogConnection(InetSocketAddress socket, SyslogAuditEventHandlerConfiguration config) { 043 return new UdpSyslogConnection(socket); 044 } 045 }; 046 047 public SyslogPublisher getPublisher(InetSocketAddress socket, SyslogAuditEventHandlerConfiguration config) { 048 SyslogConnection syslogConnection = getSyslogConnection(socket, config); 049 EventBufferingConfiguration buffering = config.getBuffering(); 050 if (buffering.isEnabled()) { 051 return new AsynchronousSyslogPublisher("SyslogHandler", syslogConnection); 052 } else { 053 return new SynchronousSyslogPublisher(syslogConnection); 054 } 055 } 056 057 abstract SyslogConnection getSyslogConnection(InetSocketAddress socket, SyslogAuditEventHandlerConfiguration config); 058 059}