Depends on the threat, and what measures would be needed to defeat it.
In WWI and WWII, entire groups of people were detained or imprisoned without any benefit of due process or habeus corpus. In the case of Korematsu v. US, the SCOTUS (IMO, wrongly) upheld EO 9066 which allowed for Japanese detention, and to this day, no court has specifically overturned it. However, Duncan v. Kahanamoku did allow for martial law in Hawaii during the aftermath of Pearl Harbor until it was suspended in 1944.
The threat (whether real or imagined potential) of Japanese espionage simply didn't rise to the level justifying wholesale detention. Neither did Wilson's "Palmer Raids".
OTOH, the threat to the very existence of the Republic under Lincoln was VERY real, and debate has been going on for decades as to the validity of his suspending Habeas Corpus in order to preserve public order.
Where the balance truly lies is determining if NOT taking an action will irreparably harm the Republic or the Constitution, or will greater damage be done long term by taking action to preserve it. There is no "one-size fits all" mentality, and the courts, along with a RESPONSIBLE Executive and Legislative branches, need to look at how best to balance the two.