Package org.wildfly.security.audit
Class FileAuditEndpoint
- java.lang.Object
-
- org.wildfly.security.audit.FileAuditEndpoint
-
- All Implemented Interfaces:
Closeable,AutoCloseable,org.wildfly.common.function.ExceptionBiConsumer<EventPriority,String,IOException>,AuditEndpoint
- Direct Known Subclasses:
PeriodicRotatingFileAuditEndpoint,SizeRotatingFileAuditEndpoint
public class FileAuditEndpoint extends Object implements AuditEndpoint
An audit endpoint to record all audit events to a local file.- Author:
- Darran Lofthouse
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classFileAuditEndpoint.BuilderA builder for file audit endpoints.
-
Field Summary
Fields Modifier and Type Field Description private booleanacceptingprotected ClockclockClock providing access to current time.private Supplier<DateTimeFormatter>dateTimeFormatterSupplierprivate Filefileprivate FileDescriptorfileDescriptorprivate booleanflushOnAcceptprivate static byte[]LINE_TERMINATORprivate OutputStreamoutputStreamprivate booleansyncOnAccept
-
Constructor Summary
Constructors Constructor Description FileAuditEndpoint(FileAuditEndpoint.Builder builder)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaccept(EventPriority priority, String message)Accept formatted security event message to be processed written into target local file.static FileAuditEndpoint.Builderbuilder()Obtain a newFileAuditEndpoint.Buildercapable of building aFileAuditEndpoint.voidclose()Close the endpoint and stop handling further events immediately.(package private) voidcloseStreams()Close opened file streams.(package private) FilegetFile()(package private) voidpreWrite(Instant instant)Method called before writing into local file.private voidsafeClose(Closeable c)(package private) voidsetFile(File file)(package private) voidwrite(byte[] bytes)Method called to write given byte array to the target local file.
-
-
-
Field Detail
-
LINE_TERMINATOR
private static final byte[] LINE_TERMINATOR
-
accepting
private volatile boolean accepting
-
dateTimeFormatterSupplier
private final Supplier<DateTimeFormatter> dateTimeFormatterSupplier
-
syncOnAccept
private final boolean syncOnAccept
-
flushOnAccept
private final boolean flushOnAccept
-
file
private File file
-
fileDescriptor
private FileDescriptor fileDescriptor
-
outputStream
private OutputStream outputStream
-
clock
protected final Clock clock
Clock providing access to current time.
-
-
Constructor Detail
-
FileAuditEndpoint
FileAuditEndpoint(FileAuditEndpoint.Builder builder) throws IOException
- Throws:
IOException
-
-
Method Detail
-
setFile
void setFile(File file) throws IOException
- Throws:
IOException
-
getFile
File getFile()
-
safeClose
private void safeClose(Closeable c)
-
write
void write(byte[] bytes) throws IOExceptionMethod called to write given byte array to the target local file. This method can be overridden by subclasses to modify data written into file (to encrypt them for example), or just for counting amount of written bytes for needs of log rotation and similar. This method can be invoked only in synchronization block surrounding one log message processing.- Parameters:
bytes- the data to be written into the target local file- Throws:
IOException
-
preWrite
void preWrite(Instant instant)
Method called before writing into local file. This method is NO-OP by default. It is intended to be overridden by subclasses which need to perform some operation before every writing into the target local file. This method can be invoked only in synchronization block surrounding one log message processing.- Parameters:
instant- time of the message acceptance
-
accept
public void accept(EventPriority priority, String message) throws IOException
Accept formatted security event message to be processed written into target local file.- Specified by:
acceptin interfaceorg.wildfly.common.function.ExceptionBiConsumer<EventPriority,String,IOException>- Parameters:
priority- priority of the logged messagemessage- the logged message- Throws:
IOException- when writing into the target local file fails
-
close
public void close() throws IOExceptionDescription copied from interface:AuditEndpointClose the endpoint and stop handling further events immediately.- Specified by:
closein interfaceAuditEndpoint- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException- if an error occurs closing the endpoint.
-
closeStreams
void closeStreams() throws IOExceptionClose opened file streams. Can be called by subclasses for needs of target file changing. Must be called in synchronized block together with reopening usingsetFile().- Throws:
IOException
-
builder
public static FileAuditEndpoint.Builder builder()
Obtain a newFileAuditEndpoint.Buildercapable of building aFileAuditEndpoint.- Returns:
- a new
FileAuditEndpoint.Buildercapable of building aFileAuditEndpoint.
-
-