use of org.apache.archiva.metadata.model.facets.AuditEvent in project archiva by apache.
the class ArchivaDavResource method triggerAuditEvent.
private void triggerAuditEvent(DavResource member, String action) throws DavException {
String path = logicalResource + "/" + member.getDisplayName();
ArchivaDavResource resource = checkDavResourceIsArchivaDavResource(member);
AuditEvent auditEvent = new AuditEvent(locator.getRepositoryId(), resource.principal, path, action);
auditEvent.setRemoteIP(resource.remoteAddr);
for (AuditListener listener : auditListeners) {
listener.auditEvent(auditEvent);
}
}
use of org.apache.archiva.metadata.model.facets.AuditEvent in project archiva by apache.
the class ArchivaDavResourceFactory method triggerAuditEvent.
// TODO: remove?
private void triggerAuditEvent(String remoteIP, String repositoryId, String resource, String action, String principal) {
AuditEvent event = new AuditEvent(repositoryId, principal, resource, action);
event.setRemoteIP(remoteIP);
for (AuditListener listener : auditListeners) {
listener.auditEvent(event);
}
}
use of org.apache.archiva.metadata.model.facets.AuditEvent in project archiva by apache.
the class AbstractRestService method triggerAuditEvent.
protected void triggerAuditEvent(String repositoryId, String filePath, String action) {
AuditEvent auditEvent = new AuditEvent(repositoryId, getPrincipal(), filePath, action);
AuditInformation auditInformation = getAuditInformation();
auditEvent.setUserId(auditInformation.getUser() == null ? "" : auditInformation.getUser().getUsername());
auditEvent.setRemoteIP(auditInformation.getRemoteAddr());
for (AuditListener auditListener : getAuditListeners()) {
auditListener.auditEvent(auditEvent);
}
}
use of org.apache.archiva.metadata.model.facets.AuditEvent in project archiva by apache.
the class DefaultAuditManager method getMostRecentAuditEvents.
@Override
public List<AuditEvent> getMostRecentAuditEvents(MetadataRepository metadataRepository, List<String> repositoryIds) throws MetadataRepositoryException {
// TODO: consider a more efficient implementation that directly gets the last ten from the content repository
List<AuditRecord> records = new ArrayList<>();
for (String repositoryId : repositoryIds) {
List<String> names = metadataRepository.getMetadataFacets(repositoryId, AuditEvent.FACET_ID);
for (String name : names) {
records.add(new AuditRecord(repositoryId, name));
}
}
Collections.sort(records);
records = records.subList(0, records.size() < NUM_RECENT_EVENTS ? records.size() : NUM_RECENT_EVENTS);
List<AuditEvent> events = new ArrayList<>(records.size());
for (AuditRecord record : records) {
AuditEvent auditEvent = (AuditEvent) metadataRepository.getMetadataFacet(record.repositoryId, AuditEvent.FACET_ID, record.name);
events.add(auditEvent);
}
return events;
}
use of org.apache.archiva.metadata.model.facets.AuditEvent in project archiva by apache.
the class AuditManagerTest method testGetMostRecentEventsLessThan10.
@Test
public void testGetMostRecentEventsLessThan10() throws Exception {
int numEvents = 5;
List<AuditEvent> expectedEvents = new ArrayList<>(numEvents);
for (int i = 0; i < numEvents; i++) {
expectedEvents.add(createEvent(AUDIT_EVENT_BASE + MILLIS_FORMAT.format(i)));
}
EasyMock.expect(metadataRepository.getMetadataFacets(TEST_REPO_ID, AuditEvent.FACET_ID)).andReturn(getEventNames(expectedEvents));
for (AuditEvent event : expectedEvents) {
EasyMock.expect(metadataRepository.getMetadataFacet(TEST_REPO_ID, AuditEvent.FACET_ID, event.getName())).andReturn(event);
}
metadataRepositoryControl.replay();
List<AuditEvent> events = auditManager.getMostRecentAuditEvents(metadataRepository, Collections.singletonList(TEST_REPO_ID));
assertNotNull(events);
assertEquals(numEvents, events.size());
int expectedTimestampCounter = numEvents - 1;
for (AuditEvent event : events) {
String num = MILLIS_FORMAT.format(expectedTimestampCounter);
assertTestEvent(event, AUDIT_EVENT_BASE + num, getDefaultTestResourceName(num));
expectedTimestampCounter--;
}
metadataRepositoryControl.verify();
}
Aggregations