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 class
FileAuditEndpoint.Builder
A builder for file audit endpoints.
-
Field Summary
Fields Modifier and Type Field Description private boolean
accepting
protected Clock
clock
Clock providing access to current time.private Supplier<DateTimeFormatter>
dateTimeFormatterSupplier
private File
file
private FileDescriptor
fileDescriptor
private boolean
flushOnAccept
private static byte[]
LINE_TERMINATOR
private OutputStream
outputStream
private boolean
syncOnAccept
-
Constructor Summary
Constructors Constructor Description FileAuditEndpoint(FileAuditEndpoint.Builder builder)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
accept(EventPriority priority, String message)
Accept formatted security event message to be processed written into target local file.static FileAuditEndpoint.Builder
builder()
Obtain a newFileAuditEndpoint.Builder
capable of building aFileAuditEndpoint
.void
close()
Close the endpoint and stop handling further events immediately.(package private) void
closeStreams()
Close opened file streams.(package private) File
getFile()
(package private) void
preWrite(Instant instant)
Method called before writing into local file.private void
safeClose(Closeable c)
(package private) void
setFile(File file)
(package private) void
write(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 IOException
Method 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:
accept
in 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 IOException
Description copied from interface:AuditEndpoint
Close the endpoint and stop handling further events immediately.- Specified by:
close
in interfaceAuditEndpoint
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
- if an error occurs closing the endpoint.
-
closeStreams
void closeStreams() throws IOException
Close 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.Builder
capable of building aFileAuditEndpoint
.- Returns:
- a new
FileAuditEndpoint.Builder
capable of building aFileAuditEndpoint
.
-
-