@SuppressWarnings("unchecked") @Test public void testProcessBatchRegularStatements() { UUID expectedBatchId = UUID.randomUUID(); List<Object> expectedQueries = Arrays.asList("query1", "query2", "query3"); when(mockBatchOptions.getQueryOrIdList()).thenReturn(expectedQueries); when(mockUser.getName()).thenReturn(USER); when(mockState.getRemoteAddress()).thenReturn(clientSocketAddress); AuditEntry.Builder entryBuilder = AuditEntry.newBuilder().permissions(PERMISSIONS).resource(RESOURCE); when(mockAuditEntryBuilderFactory.createBatchEntryBuilder()).thenReturn(entryBuilder); auditAdapter.auditBatch(mockBatchStatement, expectedBatchId, mockState, mockBatchOptions, Status.ATTEMPT, TIMESTAMP); List<AuditEntry> entries = getAuditEntries(3); assertThat(entries).extracting(AuditEntry::getClientAddress).containsOnly(clientSocketAddress); assertThat(entries).extracting(AuditEntry::getUser).containsOnly(USER); assertThat(entries).extracting(AuditEntry::getBatchId).containsOnly(Optional.of(expectedBatchId)); assertThat(entries).extracting(AuditEntry::getStatus).containsOnly(Status.ATTEMPT); assertThat(entries).extracting(AuditEntry::getOperation).extracting(AuditOperation::getOperationString).containsExactly("query1", "query2", "query3"); assertThat(entries).extracting(AuditEntry::getPermissions).containsOnly(PERMISSIONS); assertThat(entries).extracting(AuditEntry::getResource).containsOnly(RESOURCE); assertThat(entries).extracting(AuditEntry::getTimestamp).containsOnly(TIMESTAMP); }
public void auditBatch(BatchStatement statement, UUID uuid, ClientState state, BatchQueryOptions options, Status status, long timestamp) { if (auditor.shouldLogForStatus(status)) { AuditEntry.Builder builder = entryBuilderFactory.createBatchEntryBuilder() .client(state.getRemoteAddress()) .coordinator(FBUtilities.getBroadcastAddress()) .user(state.getUser().getName()) .batch(uuid) .status(status) .timestamp(timestamp); if (status == Status.FAILED && auditor.shouldLogFailedBatchSummary()) { String failedBatchStatement = String.format(BATCH_FAILURE, uuid.toString()); auditor.audit(builder.operation(new SimpleAuditOperation(failedBatchStatement)).build()); } else { for (AuditEntry entry : getBatchOperations(builder, statement, state, options)) { auditor.audit(entry); } } } }
AuditAdapter { public void auditBatch(BatchStatement statement, UUID uuid, ClientState state, BatchQueryOptions options, Status status, long timestamp) { if (auditor.shouldLogForStatus(status)) { AuditEntry.Builder builder = entryBuilderFactory.createBatchEntryBuilder() .client(state.getRemoteAddress()) .coordinator(FBUtilities.getBroadcastAddress()) .user(state.getUser().getName()) .batch(uuid) .status(status) .timestamp(timestamp); if (status == Status.FAILED && auditor.shouldLogFailedBatchSummary()) { String failedBatchStatement = String.format(BATCH_FAILURE, uuid.toString()); auditor.audit(builder.operation(new SimpleAuditOperation(failedBatchStatement)).build()); } else { for (AuditEntry entry : getBatchOperations(builder, statement, state, options)) { auditor.audit(entry); } } } } }
AuditAdapter { public void auditBatch(BatchStatement statement, UUID uuid, ClientState state, BatchQueryOptions options, Status status, long timestamp) { if (auditor.shouldLogForStatus(status)) { AuditEntry.Builder builder = entryBuilderFactory.createBatchEntryBuilder() .client(state.getRemoteAddress()) .coordinator(FBUtilities.getBroadcastAddress()) .user(state.getUser().getName()) .batch(uuid) .status(status) .timestamp(timestamp); if (status == Status.FAILED && auditor.shouldLogFailedBatchSummary()) { String failedBatchStatement = String.format(BATCH_FAILURE, uuid.toString()); auditor.audit(builder.operation(new SimpleAuditOperation(failedBatchStatement)).build()); } else { for (AuditEntry entry : getBatchOperations(builder, statement, state, options)) { auditor.audit(entry); } } } } AuditAdapter(Auditor auditor, AuditEntryBuilderFactory entryBuilderFactory, BoundValueSuppressor boundValueSuppressor); }
AuditAdapter { public void auditBatch(BatchStatement statement, UUID uuid, ClientState state, BatchQueryOptions options, Status status, long timestamp) { if (auditor.shouldLogForStatus(status)) { AuditEntry.Builder builder = entryBuilderFactory.createBatchEntryBuilder() .client(state.getRemoteAddress()) .coordinator(FBUtilities.getBroadcastAddress()) .user(state.getUser().getName()) .batch(uuid) .status(status) .timestamp(timestamp); if (status == Status.FAILED && auditor.shouldLogFailedBatchSummary()) { String failedBatchStatement = String.format(BATCH_FAILURE, uuid.toString()); auditor.audit(builder.operation(new SimpleAuditOperation(failedBatchStatement)).build()); } else { for (AuditEntry entry : getBatchOperations(builder, statement, state, options)) { auditor.audit(entry); } } } } AuditAdapter(Auditor auditor, AuditEntryBuilderFactory entryBuilderFactory, BoundValueSuppressor boundValueSuppressor); static AuditAdapter getInstance(); void setup(); void auditRegular(String operation, ClientState state, Status status, long timestamp); void auditPrepared(MD5Digest id, CQLStatement statement, ClientState state, QueryOptions options, Status status, long timestamp); void auditBatch(BatchStatement statement, UUID uuid, ClientState state, BatchQueryOptions options, Status status, long timestamp); void auditAuth(String username, Status status, long timestamp); void auditAuth(String userName, String subject, Status status, long timestamp); void mapIdToQuery(MD5Digest id, String query); Auditor getAuditor(); @VisibleForTesting void setBoundValueSuppressor(BoundValueSuppressor suppressor); @VisibleForTesting BoundValueSuppressor getBoundValueSuppressor(); }
AuditAdapter { public void auditBatch(BatchStatement statement, UUID uuid, ClientState state, BatchQueryOptions options, Status status, long timestamp) { if (auditor.shouldLogForStatus(status)) { AuditEntry.Builder builder = entryBuilderFactory.createBatchEntryBuilder() .client(state.getRemoteAddress()) .coordinator(FBUtilities.getBroadcastAddress()) .user(state.getUser().getName()) .batch(uuid) .status(status) .timestamp(timestamp); if (status == Status.FAILED && auditor.shouldLogFailedBatchSummary()) { String failedBatchStatement = String.format(BATCH_FAILURE, uuid.toString()); auditor.audit(builder.operation(new SimpleAuditOperation(failedBatchStatement)).build()); } else { for (AuditEntry entry : getBatchOperations(builder, statement, state, options)) { auditor.audit(entry); } } } } AuditAdapter(Auditor auditor, AuditEntryBuilderFactory entryBuilderFactory, BoundValueSuppressor boundValueSuppressor); static AuditAdapter getInstance(); void setup(); void auditRegular(String operation, ClientState state, Status status, long timestamp); void auditPrepared(MD5Digest id, CQLStatement statement, ClientState state, QueryOptions options, Status status, long timestamp); void auditBatch(BatchStatement statement, UUID uuid, ClientState state, BatchQueryOptions options, Status status, long timestamp); void auditAuth(String username, Status status, long timestamp); void auditAuth(String userName, String subject, Status status, long timestamp); void mapIdToQuery(MD5Digest id, String query); Auditor getAuditor(); @VisibleForTesting void setBoundValueSuppressor(BoundValueSuppressor suppressor); @VisibleForTesting BoundValueSuppressor getBoundValueSuppressor();  }