diff --git a/src/main/java/com/hiveops/aria/controller/DevicePostureController.java b/src/main/java/com/hiveops/aria/controller/DevicePostureController.java index a01dbd7..9b9e57d 100644 --- a/src/main/java/com/hiveops/aria/controller/DevicePostureController.java +++ b/src/main/java/com/hiveops/aria/controller/DevicePostureController.java @@ -52,7 +52,7 @@ public class DevicePostureController { Pageable pageable = PageRequest.of(page, size); if (osEolStatus != null) { - return postureRepository.findByOsEolStatusNativeOrderByPostureScoreAsc(osEolStatus.name(), pageable); + return postureRepository.findByOsEolStatusOrderByPostureScoreAsc(osEolStatus, pageable); } if ("low".equals(scoreFilter)) { return postureRepository.findByPostureScoreLessThanOrderByPostureScoreAsc(50, pageable); diff --git a/src/main/java/com/hiveops/aria/controller/ThreatEventController.java b/src/main/java/com/hiveops/aria/controller/ThreatEventController.java index 29e706f..4cc4c74 100644 --- a/src/main/java/com/hiveops/aria/controller/ThreatEventController.java +++ b/src/main/java/com/hiveops/aria/controller/ThreatEventController.java @@ -1,5 +1,6 @@ package com.hiveops.aria.controller; +import com.hiveops.aria.entity.DeviceSecurityPosture; import com.hiveops.aria.entity.ThreatEvent; import com.hiveops.aria.repository.DeviceSecurityPostureRepository; import com.hiveops.aria.repository.PrecursorSequenceAlertRepository; @@ -50,13 +51,13 @@ public class ThreatEventController { @PreAuthorize("hasAnyRole('MSP_ADMIN','BCOS_ADMIN')") public ResponseEntity> getStats() { long totalEvents = eventRepository.count(); - long critical24h = eventRepository.countBySeverityNative("CRITICAL"); - long high24h = eventRepository.countBySeverityNative("HIGH"); + long critical24h = eventRepository.countBySeverity(ThreatEvent.ThreatSeverity.CRITICAL); + long high24h = eventRepository.countBySeverity(ThreatEvent.ThreatSeverity.HIGH); long activeIocs = iocRepository.findByActiveTrue().size(); long activeSequences = sequenceAlertRepository.countByResolvedAtIsNull(); long lowPostureCount = postureRepository.countByPostureScoreLessThan(50); - long eolDeviceCount = postureRepository.countByOsEolStatusNative("EOL"); + long eolDeviceCount = postureRepository.countByOsEolStatus(DeviceSecurityPosture.OsEolStatus.EOL); return ResponseEntity.ok(Map.of( "totalEvents", totalEvents, diff --git a/src/main/java/com/hiveops/aria/repository/DeviceSecurityPostureRepository.java b/src/main/java/com/hiveops/aria/repository/DeviceSecurityPostureRepository.java index 165419f..cc04887 100644 --- a/src/main/java/com/hiveops/aria/repository/DeviceSecurityPostureRepository.java +++ b/src/main/java/com/hiveops/aria/repository/DeviceSecurityPostureRepository.java @@ -4,8 +4,6 @@ import com.hiveops.aria.entity.DeviceSecurityPosture; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.Query; -import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; import java.util.Optional; @@ -22,9 +20,8 @@ public interface DeviceSecurityPostureRepository extends JpaRepository findByOsEolStatusNativeOrderByPostureScoreAsc(@Param("status") String status, Pageable pageable); + Page findByOsEolStatusOrderByPostureScoreAsc( + DeviceSecurityPosture.OsEolStatus osEolStatus, Pageable pageable); } diff --git a/src/main/java/com/hiveops/aria/repository/ThreatEventRepository.java b/src/main/java/com/hiveops/aria/repository/ThreatEventRepository.java index 5d0f723..8087277 100644 --- a/src/main/java/com/hiveops/aria/repository/ThreatEventRepository.java +++ b/src/main/java/com/hiveops/aria/repository/ThreatEventRepository.java @@ -4,8 +4,6 @@ import com.hiveops.aria.entity.ThreatEvent; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.Query; -import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; import java.time.Instant; @@ -24,8 +22,7 @@ public interface ThreatEventRepository extends JpaRepository Page findBySeverityOrderByDetectedAtDesc(ThreatEvent.ThreatSeverity severity, Pageable pageable); - @Query(value = "SELECT COUNT(*) FROM threat_event WHERE severity = CAST(:severity AS threat_severity)", nativeQuery = true) - long countBySeverityNative(@Param("severity") String severity); + long countBySeverity(ThreatEvent.ThreatSeverity severity); Page findAllByOrderByDetectedAtDesc(Pageable pageable); } diff --git a/src/main/resources/db/migration/V3__convert_enums_to_varchar.sql b/src/main/resources/db/migration/V3__convert_enums_to_varchar.sql new file mode 100644 index 0000000..a88e905 --- /dev/null +++ b/src/main/resources/db/migration/V3__convert_enums_to_varchar.sql @@ -0,0 +1,30 @@ +-- Convert all named PostgreSQL enum columns to VARCHAR. +-- Hibernate @Enumerated(EnumType.STRING) binds values as character varying; +-- named enum types reject implicit varchar casts on both INSERT and SELECT. + +ALTER TABLE threat_event + ALTER COLUMN severity TYPE VARCHAR(20) USING severity::VARCHAR, + ALTER COLUMN event_type TYPE VARCHAR(30) USING event_type::VARCHAR, + ALTER COLUMN attack_phase TYPE VARCHAR(40) USING attack_phase::VARCHAR; + +ALTER TABLE threat_ioc + ALTER COLUMN ioc_type TYPE VARCHAR(30) USING ioc_type::VARCHAR, + ALTER COLUMN ioc_source TYPE VARCHAR(20) USING ioc_source::VARCHAR, + ALTER COLUMN confidence_level TYPE VARCHAR(10) USING confidence_level::VARCHAR; + +ALTER TABLE precursor_sequence_alert + ALTER COLUMN sequence_type TYPE VARCHAR(20) USING sequence_type::VARCHAR, + ALTER COLUMN auto_response_action TYPE VARCHAR(20) USING auto_response_action::VARCHAR; + +ALTER TABLE device_security_posture + ALTER COLUMN os_eol_status TYPE VARCHAR(20) USING os_eol_status::VARCHAR; + +DROP TYPE IF EXISTS threat_severity CASCADE; +DROP TYPE IF EXISTS threat_event_type CASCADE; +DROP TYPE IF EXISTS attack_phase CASCADE; +DROP TYPE IF EXISTS ioc_type CASCADE; +DROP TYPE IF EXISTS ioc_source CASCADE; +DROP TYPE IF EXISTS confidence_level CASCADE; +DROP TYPE IF EXISTS sequence_type CASCADE; +DROP TYPE IF EXISTS auto_response_action CASCADE; +DROP TYPE IF EXISTS os_eol_status CASCADE;