Skip to content

Commit dd9a51f

Browse files
decouple paginationId validation from event type
1 parent 105681f commit dd9a51f

1 file changed

Lines changed: 10 additions & 7 deletions

File tree

backend/src/main/java/org/cryptomator/hub/api/AuditLogResource.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@
4444
@Path("/auditlog")
4545
public class AuditLogResource {
4646

47+
private static final Set<String> EVENT_TYPES = Set.of(DeviceRegisteredEvent.TYPE, DeviceRemovedEvent.TYPE, UserAccountResetEvent.TYPE, UserKeysChangeEvent.TYPE, UserSetupCodeChangeEvent.TYPE,
48+
SettingWotUpdateEvent.TYPE, SignedWotIdEvent.TYPE, VaultCreatedEvent.TYPE, VaultUpdatedEvent.TYPE, VaultAccessGrantedEvent.TYPE,
49+
VaultKeyRetrievedEvent.TYPE, VaultMemberAddedEvent.TYPE, VaultMemberRemovedEvent.TYPE, VaultMemberUpdatedEvent.TYPE, VaultOwnershipClaimedEvent.TYPE);
50+
4751
@Inject
4852
AuditEvent.Repository auditEventRepo;
4953
@Inject
@@ -78,17 +82,16 @@ public List<AuditEventDto> getAllEvents(@QueryParam("startDate") Instant startDa
7882
throw new BadRequestException("pageSize must be between 1 and 100");
7983
} else if (type == null) {
8084
throw new BadRequestException("type must be specified");
81-
} else if (!type.isEmpty()) {
82-
var validTypes = Set.of(DeviceRegisteredEvent.TYPE, DeviceRemovedEvent.TYPE, UserAccountResetEvent.TYPE, UserKeysChangeEvent.TYPE, UserSetupCodeChangeEvent.TYPE,
83-
SettingWotUpdateEvent.TYPE, SignedWotIdEvent.TYPE, VaultCreatedEvent.TYPE, VaultUpdatedEvent.TYPE, VaultAccessGrantedEvent.TYPE,
84-
VaultKeyRetrievedEvent.TYPE, VaultMemberAddedEvent.TYPE, VaultMemberRemovedEvent.TYPE, VaultMemberUpdatedEvent.TYPE, VaultOwnershipClaimedEvent.TYPE);
85-
if (!validTypes.containsAll(type)) {
86-
throw new BadRequestException("Invalid event type provided");
87-
}
8885
} else if (paginationId == null) {
8986
throw new BadRequestException("paginationId must be specified");
9087
}
9188

89+
if (!type.isEmpty()) {
90+
if (!EVENT_TYPES.containsAll(type)) {
91+
throw new BadRequestException("Invalid event type provided");
92+
}
93+
}
94+
9295
return auditEventRepo.findAllInPeriod(startDate, endDate, type, paginationId, order.equals("asc"), pageSize).map(AuditEventDto::fromEntity).toList();
9396
}
9497

0 commit comments

Comments
 (0)