Skip to content

Commit 1a3e072

Browse files
committed
15th commit - Security logs added (not tested), UI buttons and methods added.
1 parent a0a61ba commit 1a3e072

4 files changed

Lines changed: 103 additions & 11 deletions

File tree

src/main/java/com/project/authapi/system_log_analyzer/config/appConfig.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,15 @@ public class appConfig {
88
private String reportDir;
99
private boolean csvApplication;
1010
private boolean csvSystem;
11+
private boolean csvSecurity;
12+
13+
public boolean isCsvSecurity() {
14+
return csvSecurity;
15+
}
16+
17+
public void setCsvSecurity(boolean csvSecurity) {
18+
this.csvSecurity = csvSecurity;
19+
}
1120

1221
public boolean isCsvApplication() {
1322
return csvApplication;

src/main/java/com/project/authapi/system_log_analyzer/controller/WelcomeViewFXController.java

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,7 @@
88
import javafx.scene.Node;
99
import javafx.scene.Parent;
1010
import javafx.scene.Scene;
11-
import javafx.scene.control.Button;
12-
import javafx.scene.control.CheckBox;
13-
import javafx.scene.control.Label;
14-
import javafx.scene.control.TextField;
11+
import javafx.scene.control.*;
1512
import javafx.stage.DirectoryChooser;
1613
import javafx.stage.Stage;
1714
import org.springframework.beans.factory.annotation.Autowired;
@@ -29,6 +26,8 @@ public class WelcomeViewFXController {
2926
@FXML private Label informationLabel;
3027
@FXML private CheckBox appButton;
3128
@FXML private CheckBox systemButton;
29+
@FXML private CheckBox securityButton;
30+
@FXML private Label securityLabel;
3231

3332
@Autowired public appConfig appConfig;
3433

@@ -48,15 +47,17 @@ private void scan(ActionEvent event) throws IOException {
4847
return;
4948
}
5049

51-
if (!appButton.isSelected() && !systemButton.isSelected()) {
50+
if (!appButton.isSelected() && !systemButton.isSelected() && !securityButton.isSelected()) {
5251
informationLabel.setText("Please select at least one type of logs");
5352
return;
5453
}
5554

55+
56+
5657
ApplicationContext springContext = ApplicationContextProvider.getApplicationContext();
5758

5859
FXMLLoader loader = new FXMLLoader(getClass().getResource("/view/LoadingScreen.fxml"));
59-
loader.setControllerFactory(springContext::getBean); // <-- magiczna linia
60+
loader.setControllerFactory(springContext::getBean); // Spring Boot starter by JavaFX !!IMPORTANT!!
6061
Parent root = loader.load();
6162

6263
Stage stage = (Stage) ((Node) event.getSource()).getScene().getWindow();
@@ -99,4 +100,33 @@ private void systemButtonON(ActionEvent event) throws IOException {
99100
appConfig.setCsvSystem(systemButton.isSelected());
100101
IO.println("System logs export : " + appConfig.isCsvSystem());
101102
}
103+
104+
@FXML
105+
private void securityButtonON(ActionEvent event) throws IOException {
106+
if (securityButton.isSelected()) {
107+
boolean proceed = askForSecurityPermission();
108+
if (!proceed) {
109+
securityButton.setSelected(false);
110+
securityLabel.setText("Admin permission required!");
111+
appConfig.setCsvSecurity(false);
112+
return;
113+
} else {
114+
securityLabel.setText("Admin permission granted!");
115+
appConfig.setCsvSecurity(true);
116+
}
117+
} else {
118+
appConfig.setCsvSecurity(false);
119+
securityLabel.setText("(Requires Admin Permission)");
120+
}
121+
}
122+
123+
private boolean askForSecurityPermission() {
124+
Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
125+
alert.setTitle("Administrator permission required");
126+
alert.setHeaderText("Security log requires admin privileges");
127+
alert.setContentText("To read Security logs, Windows requires administrator approval.\n\n" +
128+
"Click OK to continue (you may see a UAC popup).");
129+
130+
return alert.showAndWait().filter(btn -> btn == ButtonType.OK).isPresent();
131+
}
102132
}

src/main/java/com/project/authapi/system_log_analyzer/io/WindowsEventExporter.java

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ public class WindowsEventExporter {
2020

2121
public enum LogType {
2222
APPLICATION("Application"),
23-
SYSTEM("System");
24-
//SECURITY("Security"); TODO: Handle permissions "System.UnauthorizedAccessException,Microsoft.PowerShell.Commands.GetWinEventCommand"
23+
SYSTEM("System"),
24+
SECURITY("Security"); // TODO - Test in real environment (.exe/.jar)
2525

2626
private final String logName;
2727
LogType(String logName) {
@@ -40,7 +40,7 @@ public WindowsEventExporter(appConfig config) {
4040
}
4141

4242

43-
public Path exportToCsv(LogType type) {
43+
public Path exportToCsv(LogType type) { // Method responsible for exporting logs from windows
4444
try {
4545
String baseDir = config.getLogsDir() != null && !config.getLogsDir().isEmpty()
4646
? config.getLogsDir() : "logs/exported";
@@ -78,6 +78,42 @@ public Path exportToCsv(LogType type) {
7878
}
7979
}
8080

81+
public Path exportSecurityLogsAsAdmin() { // Method responsible for exporting Security logs with admin permissions
82+
try {
83+
String baseDir = config.getLogsDir() != null && !config.getLogsDir().isEmpty()
84+
? config.getLogsDir() : "logs/exported";
85+
86+
File dir = new File(baseDir, "exported");
87+
if (!dir.exists()) dir.mkdirs();
88+
89+
String timestamp = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMdd_HHmmss"));
90+
Path outputFile = Path.of(dir.getAbsolutePath(), "Security_" + timestamp + ".csv");
91+
92+
String powershellCommand =
93+
"Start-Process powershell -Verb RunAs -ArgumentList " +
94+
"\"Get-WinEvent -LogName Security | " +
95+
"Select-Object TimeCreated, Id, LevelDisplayName, ProviderName, Message | " +
96+
"Export-Csv -Path '" + outputFile.toAbsolutePath() + "' -NoTypeInformation -Encoding UTF8\"";
97+
98+
ProcessBuilder pb = new ProcessBuilder("Powershell.exe", "-Command", powershellCommand);
99+
Process process = pb.start();
100+
101+
int exit = process.waitFor();
102+
103+
if (exit == 0) {
104+
IO.println("Security log exported successfully as admin: " + outputFile);
105+
return outputFile;
106+
} else {
107+
System.err.println("Powershell.exe security logs failed. Exit code: " + exit);
108+
}
109+
110+
} catch (IOException | InterruptedException e) {
111+
System.err.println("Security log exported failed: " + e.getMessage());
112+
return null;
113+
}
114+
return null;
115+
}
116+
81117
public List<Path> exportSelected() {
82118
List<Path> paths = new ArrayList<>();
83119

@@ -91,7 +127,14 @@ public List<Path> exportSelected() {
91127
if (p != null) paths.add(p);
92128
}
93129

130+
if (config.isCsvSecurity()) {
131+
Path p = exportSecurityLogsAsAdmin();
132+
if (p != null) paths.add(p);
133+
}
134+
94135
return paths;
95136
}
96137

138+
139+
97140
}

src/main/resources/view/WelcomeView.fxml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,25 @@
3333
</Label>
3434
<Button fx:id="logFilesDirButton" layoutX="661.0" layoutY="164.0" mnemonicParsing="false" onAction="#chooseLogDir" text="..." />
3535
<Button fx:id="reportDirButton" layoutX="661.0" layoutY="266.0" mnemonicParsing="false" onAction="#chooseReportDir" text="..." />
36-
<CheckBox fx:id="appButton" layoutX="206.0" layoutY="340.0" mnemonicParsing="false" onAction="#appButtonON" prefHeight="45.0" prefWidth="150.0" text="APPLICATION" textAlignment="CENTER">
36+
<CheckBox fx:id="appButton" layoutX="108.0" layoutY="340.0" mnemonicParsing="false" onAction="#appButtonON" prefHeight="45.0" prefWidth="196.0" text="Application Logs" textAlignment="CENTER">
3737
<font>
3838
<Font size="18.0" />
3939
</font>
4040
</CheckBox>
41-
<CheckBox fx:id="systemButton" layoutX="511.0" layoutY="340.0" mnemonicParsing="false" onAction="#systemButtonON" prefHeight="45.0" prefWidth="150.0" text="SYSTEM" textAlignment="CENTER">
41+
<CheckBox fx:id="systemButton" layoutX="359.0" layoutY="340.0" mnemonicParsing="false" onAction="#systemButtonON" prefHeight="45.0" prefWidth="150.0" text="System Logs" textAlignment="CENTER">
4242
<font>
4343
<Font size="18.0" />
4444
</font>
4545
</CheckBox>
46+
<CheckBox fx:id="securityButton" layoutX="586.0" layoutY="340.0" mnemonicParsing="false" onAction="#securityButtonON" prefHeight="45.0" prefWidth="150.0" text="Security Logs" textAlignment="CENTER">
47+
<font>
48+
<Font size="18.0" />
49+
</font>
50+
</CheckBox>
51+
<Label fx:id="securityLabel" layoutX="594.0" layoutY="367.0" prefHeight="37.0" prefWidth="134.0" text="(Requires Admin Permission)" textAlignment="JUSTIFY" wrapText="true">
52+
<font>
53+
<Font size="10.0" />
54+
</font>
55+
</Label>
4656
</children>
4757
</AnchorPane>

0 commit comments

Comments
 (0)