@Test public void testProcessBatchWithLogSummaryStrategy() { when(mockAuditor.shouldLogFailedBatchSummary()).thenReturn(true); UUID expectedBatchId = UUID.randomUUID(); String expectedQuery = String.format("Apply batch failed: %s", expectedBatchId.toString()); 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.FAILED, TIMESTAMP); AuditEntry entry = getAuditEntry(); assertThat(entry.getClientAddress()).isEqualTo(clientSocketAddress); assertThat(entry.getCoordinatorAddress()).isEqualTo(FBUtilities.getBroadcastAddress()); assertThat(entry.getUser()).isEqualTo(USER); assertThat(entry.getBatchId()).contains(expectedBatchId); assertThat(entry.getStatus()).isEqualByComparingTo(Status.FAILED); assertThat(entry.getOperation().getOperationString()).isEqualTo(expectedQuery); assertThat(entry.getPermissions()).isEqualTo(PERMISSIONS); assertThat(entry.getResource()).isEqualTo(RESOURCE); assertThat(entry.getTimestamp()).isEqualTo(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();  }