Skip to content

Commit 892537c

Browse files
committed
scenario image and spy mode
1 parent 8283075 commit 892537c

File tree

7 files changed

+113
-8
lines changed

7 files changed

+113
-8
lines changed

rsa-backend/src/main/java/com/example/rsa/service/FileService.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.example.rsa.service;
22

33
import com.example.rsa.model.RsaFile;
4+
import com.example.rsa.model.User;
45
import org.springframework.beans.factory.annotation.Autowired;
56
import org.springframework.stereotype.Service;
67
import org.springframework.web.bind.annotation.PathVariable;
@@ -95,18 +96,27 @@ public byte[] getFile(String fileName, Integer userId) throws IOException {
9596
return fileEncryptionService.decryptFileByName(fileName);
9697
} else {
9798
RsaFile file = findFileByName(fileName);
98-
if (file != null) {
99-
if (file.getOwnerId().equals(userId) || file.getRecipientId().equals(userId)) {
100-
return fileEncryptionService.decryptFileByName(fileName); // User authorized - return decrypted
99+
if (file == null) {
100+
throw new FileNotFoundException("File not found");
101+
}
102+
User user = userService.getUserById(userId);
103+
if (user != null) {
104+
if (user.getPublicKey()) {
105+
if (file.getOwnerId().equals(userId) || file.getRecipientId().equals(userId)) {
106+
return fileEncryptionService.decryptFileByName(fileName); // User authorized - return decrypted
107+
} else {
108+
return fileEncryptionService.fileByName(fileName); // User not authorized - return encrypted
109+
}
101110
} else {
102111
return fileEncryptionService.fileByName(fileName); // User not authorized - return encrypted
103112
}
104113
} else {
105-
throw new FileNotFoundException("File not found");
114+
throw new IllegalArgumentException("Invalid user ID");
106115
}
107116
}
108117
}
109118

119+
110120
private RsaFile findFileByName(String fileName) {
111121
for (RsaFile file : files) {
112122
if (file.getName().equals(fileName)) {
2.77 KB
Loading

rsa-frontend/public/svg/scenario-1.svg

Lines changed: 11 additions & 0 deletions
Loading

rsa-frontend/public/svg/scenario-2.svg

Lines changed: 10 additions & 0 deletions
Loading

rsa-frontend/public/svg/scenario-3.svg

Lines changed: 11 additions & 0 deletions
Loading

rsa-frontend/src/routes/components/ScenarioArea.js

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ const UserContainer = ({ userId }) => {
1111
const [user, setUser] = useState(null);
1212
const [isReadModalOpen, setIsReadModalOpen] = useState(false);
1313
const [isReceiveModalOpen, setIsReceiveModalOpen] = useState(false);
14+
const [isSpyModalOpen, setIsSpyModalOpen] = useState(false);
1415
const [readFileList, setReadFileList] = useState([]);
1516
const [receiveFileList, setReceiveFileList] = useState([]);
17+
const [spyFileList, setSpyFileList] = useState([]);
1618
const [recipientId, setRecipientId] = useState(null);
1719
const [isUserSelectModalOpen, setIsUserSelectModalOpen] = useState(false);
1820

@@ -69,6 +71,17 @@ const UserContainer = ({ userId }) => {
6971
setLoading(false);
7072
};
7173

74+
const fetchSpyFiles = async () => {
75+
setLoading(true);
76+
try {
77+
const response = await axios.get(`${Endpoints.FILE}/all`);
78+
setSpyFileList(response.data);
79+
} catch (error) {
80+
console.error("Dosyalar alınırken hata oluştu:", error);
81+
}
82+
setLoading(false);
83+
};
84+
7285
const openReadModal = () => {
7386
setIsReadModalOpen(true);
7487
fetchReadFiles();
@@ -88,11 +101,21 @@ const UserContainer = ({ userId }) => {
88101
};
89102

90103
const openUserSelectModal = () => setIsUserSelectModalOpen(true);
104+
91105
const closeUserSelectModal = () => {
92106
setIsUserSelectModalOpen(false);
93107
setRecipientId(null);
94108
};
95109

110+
const openSpyModal = () => {
111+
setIsSpyModalOpen(true);
112+
fetchSpyFiles();
113+
};
114+
115+
const closeSpyModal = () => {
116+
setIsSpyModalOpen(false);
117+
};
118+
96119

97120
const handleFileChange = (event, userId, recipientId) => {
98121
setLoading(true);
@@ -178,8 +201,47 @@ const UserContainer = ({ userId }) => {
178201
{loading && <div className={"loading-overlay"}><div className={"main-spinner"}></div></div>}
179202
{(user != null && (
180203
<div className={"user-container"}>
181-
<p className={"font-bold"} style={{ color: "var(--orange-color-1)" }}>{user.name}</p>
204+
<div className={"custom-row"} style={{justifyContent:"space-between"}}>
205+
<p className={"font-bold"} style={{ color: "var(--orange-color-1)" }}>{user.name}</p>
206+
{(userId === 3 && user.fileRead && user.fileReceive) && <p><div
207+
className={"icon-box"}
208+
style={{ backgroundColor: "var(--red-color-1)", cursor: "pointer" }}
209+
onClick={openSpyModal}
210+
>
211+
<img src="/icon/hacker.png" alt="Open Spy Menu" className={"mini-icon"} />
212+
</div></p>}
213+
{isSpyModalOpen && (
214+
<Modal isOpen={isSpyModalOpen} onRequestClose={closeSpyModal} contentLabel="Casus Menüsü">
215+
<div className={"custom-row"} style={{justifyContent:"space-between"}}>
216+
<h2>{`Bütün Dosyalar`}</h2>
217+
<p onClick={closeSpyModal} style={{cursor:"pointer"}}>Kapat</p>
218+
</div>
219+
<p style={{marginTop:8,marginBottom:16}}>{spyFileList.length} adet dosya listelendi</p>
220+
{loading ? (<p>Yükleniyor...</p>) : (
221+
spyFileList.map((file) => (
222+
<div key={file.id} style={{backgroundColor:"var(--secondary-color-1)",padding:8,borderRadius:8,marginBottom:8}}>
223+
<div className={"custom-row"} style={{justifyContent:"space-between",alignItems:"center"}}>
224+
<div>
225+
<p>{file.originalName}</p>
226+
<p className={"x-small-text"}>{file.size} bayt</p>
227+
<p className={"x-small-text"}>{file.ownerId === 1 ? "Bu dosyayı Alice yükledi" : file.ownerId === 2 ? "Bu dosyayı Bob yükledi" : "Bu dosyayı Charlie yükledi"}</p>
228+
<p className={"x-small-text"}>{file.recipientId === 1 ? "Bu dosya Alice için yüklendi" : file.recipientId === 2 ? "Bu dosya Bob için yüklendi" : "Bu dosya Charlie için yüklendi"}</p>
229+
</div>
230+
<div
231+
className={"icon-box"}
232+
style={{ backgroundColor: "var(--green-color-1)", cursor: "pointer" }}
233+
onClick={() => openFile(file.name,userId)}
234+
>
235+
<img src="/icon/file.png" alt="Open File" className={"mini-icon"} />
236+
</div>
237+
</div>
182238

239+
</div>
240+
))
241+
)}
242+
</Modal>
243+
)}
244+
</div>
183245
<div className={"custom-row"} style={{gap:0}}>
184246
<Switch
185247
isOn={user.publicKey}

rsa-frontend/src/routes/components/Scenarios.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import React, { useState } from 'react';
22

33
const scenarios = [
4-
{ id: 1, text: 'Bu senaryoda tek kullanıcı vardır. Kullanıcı elinde bulunan açık anahtar ile sisteme bir dosya yükler bu dosya şifrelenerek kayıt edilir. Daha sonrasında kullanıcı dosyasına erişmek istediğinde dosyanın şifresi çözülerek kullanıcya iletilir.' },
5-
{ id: 2, text: 'Bu senaryoda iki kullanıcı vardır. İlk kullanıcı ikinci kullanıcıya bir dosya gönderir bu dosya şifreli olarak gider, ikinci kullanıcı ise bu şifreli dosyayı şifresi çözülmüş şekilde alır.' },
6-
{ id: 3, text: 'Bu senaryoda üç kullanıcı vardır. Üçüncü kullanıcı hiçbir anahtarı olmadan diğer kullanıcıların dosyalarına erişmek isteyecektir. Aynı zamanda senaryo 1 ve senaryo 2 içerisinde yapılan işlemlere izinsiz erişim sağlayacaktır. Burada şifrelenmiş dosyalarla karşılaşması beklenmektedir.' },
4+
{ id: 1, text: 'Bu senaryoda tek kullanıcı vardır. Kullanıcı elinde bulunan açık anahtar ile sisteme bir dosya yükler bu dosya şifrelenerek kayıt edilir. Daha sonrasında kullanıcı dosyasına erişmek istediğinde dosyanın şifresi çözülerek kullanıcya iletilir.',path:"/svg/scenario-1.svg" },
5+
{ id: 2, text: 'Bu senaryoda iki kullanıcı vardır. İlk kullanıcı ikinci kullanıcıya bir dosya gönderir bu dosya şifreli olarak gider, ikinci kullanıcı ise bu şifreli dosyayı şifresi çözülmüş şekilde alır.',path:"/svg/scenario-2.svg" },
6+
{ id: 3, text: 'Bu senaryoda üç kullanıcı vardır. Üçüncü kullanıcı hiçbir anahtarı olmadan diğer kullanıcıların dosyalarına erişmek isteyecektir. Aynı zamanda senaryo 1 ve senaryo 2 içerisinde yapılan işlemlere izinsiz erişim sağlayacaktır. Burada şifrelenmiş dosyalarla karşılaşması beklenmektedir.',path:"/svg/scenario-3.svg" },
77
];
88

99
const Scenarios = () => {
@@ -25,6 +25,7 @@ const Scenarios = () => {
2525
{activeScenario ? (
2626
<div>
2727
<p>{scenarios.find(scenario => scenario.id === activeScenario)?.text}</p>
28+
<img src={scenarios.find(scenario => scenario.id === activeScenario)?.path} alt="" width="60%" style={{marginTop:8}}/>
2829
</div>
2930

3031
) : (

0 commit comments

Comments
 (0)