From dd7a6702aca4d256f8ec0d0dd68db2fdd329e600 Mon Sep 17 00:00:00 2001 From: Alistair Ross <87852242+AlistairMRoss@users.noreply.github.com> Date: Sat, 7 Oct 2023 11:12:26 +0200 Subject: [PATCH 01/14] Setting up database --- cypress.config.js | 2 +- .../src/components/Charts/Dashboard.js | 8 ++++---- .../components/Charts/SystemAnalyticsChart.js | 20 +++++++++---------- .../src/components/Charts/TasksChart.js | 2 +- .../components/Charts/useCurrentDataScope.js | 10 +++++----- .../src/components/Charts/useCurrentTasks.js | 6 +++--- .../components/Create/CreateDataScopePopup.js | 6 +++--- .../components/Create/CreateDevicePopup.js | 4 ++-- .../src/components/Create/CreateRiskPopup.js | 2 +- .../src/components/Create/CreateTaskPopup.js | 4 ++-- .../src/components/Create/CreateUserPopup.js | 8 ++++---- .../src/components/Edit/ChangePassword.js | 4 ++-- .../src/components/Edit/EditAccessRequest.js | 2 +- .../src/components/Edit/EditDataScopePopup.js | 8 ++++---- .../src/components/Edit/EditDevice.js | 4 ++-- .../src/components/Edit/EditRisk.js | 2 +- .../src/components/Edit/EditSupportRequest.js | 2 +- .../src/components/Edit/EditTaskPopup.js | 6 +++--- .../src/components/Edit/EditUser.js | 4 ++-- .../src/components/ForgotPassword.js | 4 ++-- .../infosafe_frontend/src/components/Login.js | 2 +- .../RequestRequests/AccessRequestRequests.js | 4 ++-- .../RequestRequests/AssetRequestRequests.js | 2 +- .../RequestRequests/SupportRequestRequests.js | 2 +- .../Reviews/AccessRequestApproval.js | 2 +- .../components/Reviews/ReviewAssetRequest.js | 2 +- .../src/components/Reviews/ReviewRiskPopup.js | 2 +- .../src/components/Roles/RoleCreation.js | 6 +++--- .../src/components/Subsystems/DataScopes.js | 2 +- .../src/components/Subsystems/Devices.js | 2 +- .../src/components/Subsystems/Navbar.js | 4 ++-- .../src/components/Subsystems/Requests.js | 2 +- .../src/components/Subsystems/Users.js | 2 +- .../components/Subsystems/useRequestMaker.js | 8 ++++---- .../src/components/View/ViewDataScope.js | 2 +- .../src/components/View/ViewTaskPopup.js | 6 +++--- .../src/components/getData/getAR.js | 2 +- .../src/components/getData/getAllUser.js | 2 +- .../src/components/getData/getAssAR.js | 2 +- .../src/components/getData/getAsset.js | 2 +- .../src/components/getData/getDs.js | 4 ++-- .../src/components/getData/getPerms.js | 2 +- .../src/components/getData/getRisk.js | 2 +- .../src/components/getData/getSR.js | 4 ++-- .../src/components/getData/getTask.js | 4 ++-- 45 files changed, 91 insertions(+), 91 deletions(-) diff --git a/cypress.config.js b/cypress.config.js index 0adbba7ae..efa840e38 100644 --- a/cypress.config.js +++ b/cypress.config.js @@ -3,7 +3,7 @@ const { defineConfig } = require("cypress"); module.exports = defineConfig({ projectId: "8o48nn", e2e: { - baseUrl: "http://ec2-52-91-180-105.compute-1.amazonaws.com:8080", + baseUrl: "http://localhost:8080", viewportWidth: 1024, viewportHeight: 768, }, diff --git a/frontend/infosafe_frontend/src/components/Charts/Dashboard.js b/frontend/infosafe_frontend/src/components/Charts/Dashboard.js index b2560e47f..ee4f86225 100644 --- a/frontend/infosafe_frontend/src/components/Charts/Dashboard.js +++ b/frontend/infosafe_frontend/src/components/Charts/Dashboard.js @@ -22,25 +22,25 @@ export const Dashboard = () => { const accessToken = sessionStorage.getItem('accessToken'); const fetchPromises = [ - await fetch('http://ec2-52-91-180-105.compute-1.amazonaws.com:8080/api/notifications/getNotifications', { + await fetch('http://localhost:8080/api/notifications/getNotifications', { method: "GET", headers: { Authorization: "Bearer " + accessToken, }, }), - await fetch('http://ec2-52-91-180-105.compute-1.amazonaws.com:8080/api/supportrequest/getMyTotal', { + await fetch('http://localhost:8080/api/supportrequest/getMyTotal', { method: "GET", headers: { Authorization: "Bearer " + accessToken, }, }), - await fetch('http://ec2-52-91-180-105.compute-1.amazonaws.com:8080/api/accessrequest/getMyTotal', { + await fetch('http://localhost:8080/api/accessrequest/getMyTotal', { method: "GET", headers: { Authorization: "Bearer " + accessToken, }, }), - await fetch('http://ec2-52-91-180-105.compute-1.amazonaws.com:8080/api/assetrequest/getMyTotal', { + await fetch('http://localhost:8080/api/assetrequest/getMyTotal', { method: "GET", headers: { Authorization: "Bearer " + accessToken, diff --git a/frontend/infosafe_frontend/src/components/Charts/SystemAnalyticsChart.js b/frontend/infosafe_frontend/src/components/Charts/SystemAnalyticsChart.js index 6f94e1d8d..90fea86ec 100644 --- a/frontend/infosafe_frontend/src/components/Charts/SystemAnalyticsChart.js +++ b/frontend/infosafe_frontend/src/components/Charts/SystemAnalyticsChart.js @@ -11,61 +11,61 @@ const SystemAnalyticsChart = () => { const accessToken = sessionStorage.getItem('accessToken'); const fetchPromises = [ - await fetch('http://ec2-52-91-180-105.compute-1.amazonaws.com:8080/api/datascope/getTotal', { + await fetch('http://localhost:8080/api/datascope/getTotal', { method: "GET", headers: { Authorization: "Bearer " + accessToken, }, }), - await fetch('http://ec2-52-91-180-105.compute-1.amazonaws.com:8080/api/user/dataScopeCount', { + await fetch('http://localhost:8080/api/user/dataScopeCount', { method: "GET", headers: { Authorization: "Bearer " + accessToken, }, }), - await fetch('http://ec2-52-91-180-105.compute-1.amazonaws.com:8080/api/user/countDevices', { + await fetch('http://localhost:8080/api/user/countDevices', { method: "GET", headers: { Authorization: "Bearer " + accessToken, }, }), - await fetch('http://ec2-52-91-180-105.compute-1.amazonaws.com:8080/api/asset/getTotalAssets', { + await fetch('http://localhost:8080/api/asset/getTotalAssets', { method: "GET", headers: { Authorization: "Bearer " + accessToken, }, }), - await fetch('http://ec2-52-91-180-105.compute-1.amazonaws.com:8080/api/user/taskCount', { + await fetch('http://localhost:8080/api/user/taskCount', { method: "GET", headers: { Authorization: "Bearer " + accessToken, }, }), - await fetch('http://ec2-52-91-180-105.compute-1.amazonaws.com:8080/api/task/totalTasks', { + await fetch('http://localhost:8080/api/task/totalTasks', { method: "GET", headers: { Authorization: "Bearer " + accessToken, }, }), - await fetch('http://ec2-52-91-180-105.compute-1.amazonaws.com:8080/api/supportrequest/getTotal', { + await fetch('http://localhost:8080/api/supportrequest/getTotal', { method: "GET", headers: { Authorization: "Bearer " + accessToken, }, }), - await fetch('http://ec2-52-91-180-105.compute-1.amazonaws.com:8080/api/supportrequest/getMyTotal', { + await fetch('http://localhost:8080/api/supportrequest/getMyTotal', { method: "GET", headers: { Authorization: "Bearer " + accessToken, }, }), - await fetch('http://ec2-52-91-180-105.compute-1.amazonaws.com:8080/api/assetrequest/getTotal', { + await fetch('http://localhost:8080/api/assetrequest/getTotal', { method: "GET", headers: { Authorization: "Bearer " + accessToken, }, }), - await fetch('http://ec2-52-91-180-105.compute-1.amazonaws.com:8080/api/assetrequest/getMyTotal', { + await fetch('http://localhost:8080/api/assetrequest/getMyTotal', { method: "GET", headers: { Authorization: "Bearer " + accessToken, diff --git a/frontend/infosafe_frontend/src/components/Charts/TasksChart.js b/frontend/infosafe_frontend/src/components/Charts/TasksChart.js index 35c70f955..3a06dd84c 100644 --- a/frontend/infosafe_frontend/src/components/Charts/TasksChart.js +++ b/frontend/infosafe_frontend/src/components/Charts/TasksChart.js @@ -7,7 +7,7 @@ const TasksChart = () => { const [chartInstance, setChartInstance] = useState(null); useEffect(() => { - fetch('http://ec2-52-91-180-105.compute-1.amazonaws.com:8080/api/user/taskCount', { + fetch('http://localhost:8080/api/user/taskCount', { method: "GET", headers: { Authorization: "Bearer " + sessionStorage.getItem('accessToken') diff --git a/frontend/infosafe_frontend/src/components/Charts/useCurrentDataScope.js b/frontend/infosafe_frontend/src/components/Charts/useCurrentDataScope.js index 510103b69..9e5d6d281 100644 --- a/frontend/infosafe_frontend/src/components/Charts/useCurrentDataScope.js +++ b/frontend/infosafe_frontend/src/components/Charts/useCurrentDataScope.js @@ -5,7 +5,7 @@ export const useCurrentDataScope = () => { const [dataScopeCount, setDataScopeCount] = useState(0); const [myDataScopeCount, setMyDataScopeCount] = useState(0); useEffect(() => { - fetch('http://ec2-52-91-180-105.compute-1.amazonaws.com:8080/api/datascope/getTotal', { + fetch('http://localhost:8080/api/datascope/getTotal', { method: "GET", headers: { Authorization: "Bearer " + sessionStorage.getItem('accessToken') @@ -16,7 +16,7 @@ export const useCurrentDataScope = () => { }); }, []); useEffect(() => { - fetch('http://ec2-52-91-180-105.compute-1.amazonaws.com:8080/api/user/dataScopeCount', { + fetch('http://localhost:8080/api/user/dataScopeCount', { method: "GET", headers: { Authorization: "Bearer " + sessionStorage.getItem('accessToken') @@ -30,7 +30,7 @@ export const useCurrentDataScope = () => { const [assetCount, setAssetCount] = useState(0); const [myAssets, setMyAssets] = useState([]); useEffect(() => { - fetch('http://ec2-52-91-180-105.compute-1.amazonaws.com:8080/api/user/countDevices', { + fetch('http://localhost:8080/api/user/countDevices', { method: "GET", headers: { Authorization: "Bearer " + sessionStorage.getItem('accessToken') @@ -41,7 +41,7 @@ export const useCurrentDataScope = () => { }); }, []); useEffect(() => { - fetch('http://ec2-52-91-180-105.compute-1.amazonaws.com:8080/api/user/getAllDevices', { + fetch('http://localhost:8080/api/user/getAllDevices', { method: "GET", headers: { Authorization: "Bearer " + sessionStorage.getItem('accessToken') @@ -54,7 +54,7 @@ export const useCurrentDataScope = () => { const [totalAssets, setTotalAssets] = useState(0); useEffect(() => { - fetch('http://ec2-52-91-180-105.compute-1.amazonaws.com:8080/api/asset/getTotalAssets', { + fetch('http://localhost:8080/api/asset/getTotalAssets', { method: "GET", headers: { Authorization: "Bearer " + sessionStorage.getItem('accessToken') diff --git a/frontend/infosafe_frontend/src/components/Charts/useCurrentTasks.js b/frontend/infosafe_frontend/src/components/Charts/useCurrentTasks.js index a6104df3a..55695b1a0 100644 --- a/frontend/infosafe_frontend/src/components/Charts/useCurrentTasks.js +++ b/frontend/infosafe_frontend/src/components/Charts/useCurrentTasks.js @@ -5,7 +5,7 @@ export const useCurrentTasks = () => { const [myTasks, setMyTasks] = useState([]); const [totalTasks, setTotalTasks] = useState(0); useEffect(() => { - fetch('http://ec2-52-91-180-105.compute-1.amazonaws.com:8080/api/user/taskCount', { + fetch('http://localhost:8080/api/user/taskCount', { method: "GET", headers: { Authorization: "Bearer " + sessionStorage.getItem('accessToken') @@ -16,7 +16,7 @@ export const useCurrentTasks = () => { }); }, []); useEffect(() => { - fetch('http://ec2-52-91-180-105.compute-1.amazonaws.com:8080/api/user/getAllTasks', { + fetch('http://localhost:8080/api/user/getAllTasks', { method: "GET", headers: { Authorization: "Bearer " + sessionStorage.getItem('accessToken') @@ -27,7 +27,7 @@ export const useCurrentTasks = () => { }); }, []); useEffect(() => { - fetch('http://ec2-52-91-180-105.compute-1.amazonaws.com:8080/api/task/totalTasks', { + fetch('http://localhost:8080/api/task/totalTasks', { method: "GET", headers: { Authorization: "Bearer " + sessionStorage.getItem('accessToken') diff --git a/frontend/infosafe_frontend/src/components/Create/CreateDataScopePopup.js b/frontend/infosafe_frontend/src/components/Create/CreateDataScopePopup.js index 5b862743c..c4a97c7d5 100644 --- a/frontend/infosafe_frontend/src/components/Create/CreateDataScopePopup.js +++ b/frontend/infosafe_frontend/src/components/Create/CreateDataScopePopup.js @@ -25,7 +25,7 @@ export const CreateDataScopePopup = ({popupOpen, popupClose, onDsAdded}) => { const ds_status = "Pending"; const datascope = {date_captured: currentDate, ds_description, ds_name, ds_status, user_email: selectedUsers}; - fetch(`http://ec2-52-91-180-105.compute-1.amazonaws.com:8080/api/datascope/checkName?dsname=${ds_name}`, { + fetch(`http://localhost:8080/api/datascope/checkName?dsname=${ds_name}`, { method: "GET", headers: { "Content-Type": "application/json", @@ -38,7 +38,7 @@ export const CreateDataScopePopup = ({popupOpen, popupClose, onDsAdded}) => { console.log("DataScope name already exists"); } else { //console.log(datascope); - fetch("http://ec2-52-91-180-105.compute-1.amazonaws.com:8080/api/datascope/addDs", { + fetch("http://localhost:8080/api/datascope/addDs", { method: "POST", headers: { "Content-Type": "application/json", @@ -62,7 +62,7 @@ export const CreateDataScopePopup = ({popupOpen, popupClose, onDsAdded}) => { }; useEffect(() => { - fetch("http://ec2-52-91-180-105.compute-1.amazonaws.com:8080/api/user/findNotDatCustodian", { + fetch("http://localhost:8080/api/user/findNotDatCustodian", { method: "GET", headers: { "Content-Type": "application/json", diff --git a/frontend/infosafe_frontend/src/components/Create/CreateDevicePopup.js b/frontend/infosafe_frontend/src/components/Create/CreateDevicePopup.js index e87694753..0213d7122 100644 --- a/frontend/infosafe_frontend/src/components/Create/CreateDevicePopup.js +++ b/frontend/infosafe_frontend/src/components/Create/CreateDevicePopup.js @@ -48,7 +48,7 @@ export const CreateDevicePopup = ({popupOpen, popupClose, onAssetCreated}) => { //console.log(selectedUsers); // console.log(asset); popupClose() - fetch("http://ec2-52-91-180-105.compute-1.amazonaws.com:8080/api/asset/addAsset", { + fetch("http://localhost:8080/api/asset/addAsset", { method: "POST", headers: { "Content-Type": "application/json", @@ -61,7 +61,7 @@ export const CreateDevicePopup = ({popupOpen, popupClose, onAssetCreated}) => { }) } useEffect(() => { - fetch("http://ec2-52-91-180-105.compute-1.amazonaws.com:8080/api/user/getAll", { + fetch("http://localhost:8080/api/user/getAll", { method: "GET", headers: { Authorization: "Bearer " + sessionStorage.getItem('accessToken') diff --git a/frontend/infosafe_frontend/src/components/Create/CreateRiskPopup.js b/frontend/infosafe_frontend/src/components/Create/CreateRiskPopup.js index caa86a7f0..e6479f322 100644 --- a/frontend/infosafe_frontend/src/components/Create/CreateRiskPopup.js +++ b/frontend/infosafe_frontend/src/components/Create/CreateRiskPopup.js @@ -41,7 +41,7 @@ export const CreateRisk = ({ popupClose, popupOpen, onRiskAdded }) => { const risk = {risk_name, impact_rating, probability_rating, risk_description, risk_status: "Open", suggested_mitigation, dataScope_id: datascope.value,}; //console.log(risk); - fetch("http://ec2-52-91-180-105.compute-1.amazonaws.com:8080/api/risk/addRisk", { + fetch("http://localhost:8080/api/risk/addRisk", { method:"POST", headers:{"Content-Type":"application/json", Authorization: "Bearer " + sessionStorage.getItem('accessToken') diff --git a/frontend/infosafe_frontend/src/components/Create/CreateTaskPopup.js b/frontend/infosafe_frontend/src/components/Create/CreateTaskPopup.js index ca2663338..e5f8753b2 100644 --- a/frontend/infosafe_frontend/src/components/Create/CreateTaskPopup.js +++ b/frontend/infosafe_frontend/src/components/Create/CreateTaskPopup.js @@ -47,7 +47,7 @@ export const CreateTask = ({popupClose, popupOpen, onTaskAdded}) => { }; //console.log(task) - fetch("http://ec2-52-91-180-105.compute-1.amazonaws.com:8080/api/task/addTask", { + fetch("http://localhost:8080/api/task/addTask", { method: "POST", headers: { "Content-Type": "application/json", @@ -68,7 +68,7 @@ export const CreateTask = ({popupClose, popupOpen, onTaskAdded}) => { }; useEffect(() => { - fetch("http://ec2-52-91-180-105.compute-1.amazonaws.com:8080/api/user/getAll", { + fetch("http://localhost:8080/api/user/getAll", { method: "GET", headers: { Authorization: "Bearer " + sessionStorage.getItem('accessToken') diff --git a/frontend/infosafe_frontend/src/components/Create/CreateUserPopup.js b/frontend/infosafe_frontend/src/components/Create/CreateUserPopup.js index f77f51324..842ab6018 100644 --- a/frontend/infosafe_frontend/src/components/Create/CreateUserPopup.js +++ b/frontend/infosafe_frontend/src/components/Create/CreateUserPopup.js @@ -24,7 +24,7 @@ export const CreateUserPopup = ({ popupOpen, popupClose, onUserAdded }) => { return; } - fetch(`http://ec2-52-91-180-105.compute-1.amazonaws.com:8080/api/user/checkEmail?email=${email}`, { + fetch(`http://localhost:8080/api/user/checkEmail?email=${email}`, { method: "GET", headers: { "Content-Type": "application/json", @@ -37,7 +37,7 @@ export const CreateUserPopup = ({ popupOpen, popupClose, onUserAdded }) => { console.log("User already exists"); } else { //console.log(user); - fetch("http://ec2-52-91-180-105.compute-1.amazonaws.com:8080/api/user/add", { + fetch("http://localhost:8080/api/user/add", { method: "POST", headers: { "Content-Type": "application/json", @@ -66,7 +66,7 @@ export const CreateUserPopup = ({ popupOpen, popupClose, onUserAdded }) => { useEffect(() => { const fetchData = async () => { try { - const response = await fetch("http://ec2-52-91-180-105.compute-1.amazonaws.com:8080/api/randPass/generate", { + const response = await fetch("http://localhost:8080/api/randPass/generate", { method: "GET", headers: {"Content-Type":"application/json", Authorization: "Bearer " + sessionStorage.getItem('accessToken') @@ -88,7 +88,7 @@ export const CreateUserPopup = ({ popupOpen, popupClose, onUserAdded }) => { }, []); useEffect(() => { - fetch("http://ec2-52-91-180-105.compute-1.amazonaws.com:8080/api/role/getRoleNames", { + fetch("http://localhost:8080/api/role/getRoleNames", { method:"GET", headers:{"Content-Type":"application/json", Authorization: "Bearer " + sessionStorage.getItem('accessToken') diff --git a/frontend/infosafe_frontend/src/components/Edit/ChangePassword.js b/frontend/infosafe_frontend/src/components/Edit/ChangePassword.js index 2baeb8cd5..3d3906512 100644 --- a/frontend/infosafe_frontend/src/components/Edit/ChangePassword.js +++ b/frontend/infosafe_frontend/src/components/Edit/ChangePassword.js @@ -12,7 +12,7 @@ export const ChangePassword = ({ popupClose, popupOpen }) => { useEffect(() => { - fetch('http://ec2-52-91-180-105.compute-1.amazonaws.com:8080/api/user/getEmail', { + fetch('http://localhost:8080/api/user/getEmail', { method: "GET", headers: { "Content-Type": "application/json", @@ -47,7 +47,7 @@ export const ChangePassword = ({ popupClose, popupOpen }) => { } try { - await fetch('http://ec2-52-91-180-105.compute-1.amazonaws.com:8080/api/user/changePassword', { + await fetch('http://localhost:8080/api/user/changePassword', { method: "POST", headers: { "Content-Type": "application/json", diff --git a/frontend/infosafe_frontend/src/components/Edit/EditAccessRequest.js b/frontend/infosafe_frontend/src/components/Edit/EditAccessRequest.js index b1e0b043a..289ea1932 100644 --- a/frontend/infosafe_frontend/src/components/Edit/EditAccessRequest.js +++ b/frontend/infosafe_frontend/src/components/Edit/EditAccessRequest.js @@ -32,7 +32,7 @@ const EditAccessRequest = ({ access, popupClose, popupOpen, onArEdited }) => { e.preventDefault(); //console.log(values) - fetch('http://ec2-52-91-180-105.compute-1.amazonaws.com:8080/api/accessrequest/update/' + access.request_id, { + fetch('http://localhost:8080/api/accessrequest/update/' + access.request_id, { method:"PUT", headers:{"Content-Type":"application/json", Authorization: "Bearer " + sessionStorage.getItem('accessToken') diff --git a/frontend/infosafe_frontend/src/components/Edit/EditDataScopePopup.js b/frontend/infosafe_frontend/src/components/Edit/EditDataScopePopup.js index 97129e54a..589248f51 100644 --- a/frontend/infosafe_frontend/src/components/Edit/EditDataScopePopup.js +++ b/frontend/infosafe_frontend/src/components/Edit/EditDataScopePopup.js @@ -24,7 +24,7 @@ export const EditDataScopePopup = ({ datascope, popupOpen, popupClose, onDsEdite }); // useEffect(() => { - // fetch("http://ec2-52-91-180-105.compute-1.amazonaws.com:8080/api/user/findUsersNotInTask/" + task.task_id, { + // fetch("http://localhost:8080/api/user/findUsersNotInTask/" + task.task_id, { // method: "GET", // headers: { // Authorization: "Bearer " + sessionStorage.getItem('accessToken') @@ -54,7 +54,7 @@ export const EditDataScopePopup = ({ datascope, popupOpen, popupClose, onDsEdite //console.log(datascope); //console.log(values); - fetch('http://ec2-52-91-180-105.compute-1.amazonaws.com:8080/api/datascope/update/' + datascope.data_scope_id, { + fetch('http://localhost:8080/api/datascope/update/' + datascope.data_scope_id, { method: 'POST', headers: { "Content-Type": 'application/json', @@ -69,7 +69,7 @@ export const EditDataScopePopup = ({ datascope, popupOpen, popupClose, onDsEdite }; useEffect(() => { - fetch('http://ec2-52-91-180-105.compute-1.amazonaws.com:8080/api/dataScopeRole/rolesByDataScopeId/' + datascope.data_scope_id, { + fetch('http://localhost:8080/api/dataScopeRole/rolesByDataScopeId/' + datascope.data_scope_id, { method: 'GET', headers: { Authorization: 'Bearer ' + sessionStorage.getItem('accessToken') @@ -85,7 +85,7 @@ export const EditDataScopePopup = ({ datascope, popupOpen, popupClose, onDsEdite e.preventDefault(); const newRoleData = { datascope: datascope.data_scope_id, role_description: newRole.roledescription, role_type: newRole.role }; - fetch('http://ec2-52-91-180-105.compute-1.amazonaws.com:8080/api/dataScopeRole/addDataScopeRole', { + fetch('http://localhost:8080/api/dataScopeRole/addDataScopeRole', { method: 'POST', headers: { 'Content-Type': 'application/json', diff --git a/frontend/infosafe_frontend/src/components/Edit/EditDevice.js b/frontend/infosafe_frontend/src/components/Edit/EditDevice.js index 75d355c10..c0716246b 100644 --- a/frontend/infosafe_frontend/src/components/Edit/EditDevice.js +++ b/frontend/infosafe_frontend/src/components/Edit/EditDevice.js @@ -69,7 +69,7 @@ const EditDevice = ({ asset, popupClose, popupOpen, onAssesEdited }) => { } //console.log(request); - fetch('http://ec2-52-91-180-105.compute-1.amazonaws.com:8080/api/asset/update/' + asset.asset_id, { + fetch('http://localhost:8080/api/asset/update/' + asset.asset_id, { method:"PUT", headers:{"Content-Type":"application/json", Authorization: "Bearer " + sessionStorage.getItem('accessToken') @@ -83,7 +83,7 @@ const EditDevice = ({ asset, popupClose, popupOpen, onAssesEdited }) => { } useEffect(() => { - fetch("http://ec2-52-91-180-105.compute-1.amazonaws.com:8080/api/user/findUserNotAssigned/" + asset.asset_id, { + fetch("http://localhost:8080/api/user/findUserNotAssigned/" + asset.asset_id, { method: "GET", headers: { Authorization: "Bearer " + sessionStorage.getItem('accessToken') diff --git a/frontend/infosafe_frontend/src/components/Edit/EditRisk.js b/frontend/infosafe_frontend/src/components/Edit/EditRisk.js index ddcd93102..edd6c51c4 100644 --- a/frontend/infosafe_frontend/src/components/Edit/EditRisk.js +++ b/frontend/infosafe_frontend/src/components/Edit/EditRisk.js @@ -39,7 +39,7 @@ export const EditRisk = ({risk, popupClose, popupOpen, onRiskEdited}) => { e.preventDefault(); console.log(values) - fetch('http://ec2-52-91-180-105.compute-1.amazonaws.com:8080/api/risk/update/' + risk.risk_id, { + fetch('http://localhost:8080/api/risk/update/' + risk.risk_id, { method: "POST", headers: { "Content-Type": "application/json", diff --git a/frontend/infosafe_frontend/src/components/Edit/EditSupportRequest.js b/frontend/infosafe_frontend/src/components/Edit/EditSupportRequest.js index e7ef26f57..c50104a98 100644 --- a/frontend/infosafe_frontend/src/components/Edit/EditSupportRequest.js +++ b/frontend/infosafe_frontend/src/components/Edit/EditSupportRequest.js @@ -21,7 +21,7 @@ const EditSupportRequest = ({ support, popupOpen, popupClose, editAllSupport, ed e.preventDefault(); //console.log(values) - fetch('http://ec2-52-91-180-105.compute-1.amazonaws.com:8080/api/supportrequest/update/' + support.support_id, { + fetch('http://localhost:8080/api/supportrequest/update/' + support.support_id, { method:"PUT", headers:{"Content-Type":"application/json", Authorization: "Bearer " + sessionStorage.getItem('accessToken') diff --git a/frontend/infosafe_frontend/src/components/Edit/EditTaskPopup.js b/frontend/infosafe_frontend/src/components/Edit/EditTaskPopup.js index cdc41b832..04ee3e516 100644 --- a/frontend/infosafe_frontend/src/components/Edit/EditTaskPopup.js +++ b/frontend/infosafe_frontend/src/components/Edit/EditTaskPopup.js @@ -34,7 +34,7 @@ export const UpdateTask = ({ task, popupClose, popupOpen, onTaskEdited }) => { let finalUsers = []; useEffect(() => { - fetch("http://ec2-52-91-180-105.compute-1.amazonaws.com:8080/api/task/getUsersOfTask/" + task.task_id, { + fetch("http://localhost:8080/api/task/getUsersOfTask/" + task.task_id, { method: "GET", headers: { Authorization: "Bearer " + sessionStorage.getItem('accessToken') @@ -65,7 +65,7 @@ export const UpdateTask = ({ task, popupClose, popupOpen, onTaskEdited }) => { },[task]); useEffect(() => { - fetch("http://ec2-52-91-180-105.compute-1.amazonaws.com:8080/api/user/findUsersNotInTask/" + task.task_id, { + fetch("http://localhost:8080/api/user/findUsersNotInTask/" + task.task_id, { method: "GET", headers: { Authorization: "Bearer " + sessionStorage.getItem('accessToken') @@ -85,7 +85,7 @@ export const UpdateTask = ({ task, popupClose, popupOpen, onTaskEdited }) => { ...values, users: finalUsers }; - fetch("http://ec2-52-91-180-105.compute-1.amazonaws.com:8080/api/task/update/" + task.task_id, { + fetch("http://localhost:8080/api/task/update/" + task.task_id, { method: "POST", headers: { "Content-Type": "application/json", diff --git a/frontend/infosafe_frontend/src/components/Edit/EditUser.js b/frontend/infosafe_frontend/src/components/Edit/EditUser.js index d037d9d1e..7380af4f2 100644 --- a/frontend/infosafe_frontend/src/components/Edit/EditUser.js +++ b/frontend/infosafe_frontend/src/components/Edit/EditUser.js @@ -40,7 +40,7 @@ const EditUser = ({ user, popupClose, popupOpen , onUserEdited}) => { const handleSubmit = (e) => { e.preventDefault(); //console.log(values) - fetch('http://ec2-52-91-180-105.compute-1.amazonaws.com:8080/api/user/update/' + user.user_id, { + fetch('http://localhost:8080/api/user/update/' + user.user_id, { method:"PUT", headers:{"Content-Type":"application/json", Authorization: "Bearer " + sessionStorage.getItem('accessToken') @@ -55,7 +55,7 @@ const EditUser = ({ user, popupClose, popupOpen , onUserEdited}) => { useEffect(() => { async function fetchRoles() { - const response = await fetch("http://ec2-52-91-180-105.compute-1.amazonaws.com:8080/api/role/getRoleNames", { + const response = await fetch("http://localhost:8080/api/role/getRoleNames", { method: "GET", headers: { "Content-Type": "application/json", diff --git a/frontend/infosafe_frontend/src/components/ForgotPassword.js b/frontend/infosafe_frontend/src/components/ForgotPassword.js index ee971e6f8..e2c601191 100644 --- a/frontend/infosafe_frontend/src/components/ForgotPassword.js +++ b/frontend/infosafe_frontend/src/components/ForgotPassword.js @@ -10,7 +10,7 @@ export const ForgotPassword = () => { e.preventDefault(); const forgot = {email, otp, newPassword}; - fetch("http://ec2-52-91-180-105.compute-1.amazonaws.com:8080/api/forgot/request-reset", { + fetch("http://localhost:8080/api/forgot/request-reset", { method: "POST", headers: { "Content-Type": "application/json", @@ -34,7 +34,7 @@ export const ForgotPassword = () => { } const handleSecondClick = (e) => { const forgot = {email, otp, newPassword}; - fetch("http://http://ec2-52-91-180-105.compute-1.amazonaws.com:8080/api/forgot/reset-password", { + fetch("http://http://localhost:8080/api/forgot/reset-password", { method: "POST", headers: { "Content-Type": "application/json", diff --git a/frontend/infosafe_frontend/src/components/Login.js b/frontend/infosafe_frontend/src/components/Login.js index f5401e4e7..260145b58 100644 --- a/frontend/infosafe_frontend/src/components/Login.js +++ b/frontend/infosafe_frontend/src/components/Login.js @@ -7,7 +7,7 @@ function Login(){ const handleLogin = (e) => { e.preventDefault() const login = {email, password} - fetch("http://ec2-52-91-180-105.compute-1.amazonaws.com:8080/api/auth/login", { + fetch("http://localhost:8080/api/auth/login", { method:"POST", headers:{"Content-Type":"application/json"}, body:JSON.stringify(login) diff --git a/frontend/infosafe_frontend/src/components/RequestRequests/AccessRequestRequests.js b/frontend/infosafe_frontend/src/components/RequestRequests/AccessRequestRequests.js index 0c17475cc..921283ceb 100644 --- a/frontend/infosafe_frontend/src/components/RequestRequests/AccessRequestRequests.js +++ b/frontend/infosafe_frontend/src/components/RequestRequests/AccessRequestRequests.js @@ -5,7 +5,7 @@ export const useAccessRequests = () => { const [myDatascopeData, setMyDatascopeData] = useState([]); useEffect(() => { - fetch('http://ec2-52-91-180-105.compute-1.amazonaws.com:8080/api/datascope/availableDatascopes', { + fetch('http://localhost:8080/api/datascope/availableDatascopes', { method: "GET", headers: { Authorization: "Bearer " + sessionStorage.getItem('accessToken') @@ -18,7 +18,7 @@ export const useAccessRequests = () => { }, []); useEffect(() => { - fetch('http://ec2-52-91-180-105.compute-1.amazonaws.com:8080/api/datascope/getMyDatascopes', { + fetch('http://localhost:8080/api/datascope/getMyDatascopes', { method: "GET", headers: { Authorization: "Bearer " + sessionStorage.getItem('accessToken') diff --git a/frontend/infosafe_frontend/src/components/RequestRequests/AssetRequestRequests.js b/frontend/infosafe_frontend/src/components/RequestRequests/AssetRequestRequests.js index 0e6e24c4f..fc818f881 100644 --- a/frontend/infosafe_frontend/src/components/RequestRequests/AssetRequestRequests.js +++ b/frontend/infosafe_frontend/src/components/RequestRequests/AssetRequestRequests.js @@ -5,7 +5,7 @@ export const useAssetRequests = () => { const [availableAssets, setAvailableAssets] = useState(null); useEffect(() => { - fetch('http://ec2-52-91-180-105.compute-1.amazonaws.com:8080/api/asset/availableAssets', { + fetch('http://localhost:8080/api/asset/availableAssets', { method: "GET", headers: { Authorization: "Bearer " + sessionStorage.getItem('accessToken') diff --git a/frontend/infosafe_frontend/src/components/RequestRequests/SupportRequestRequests.js b/frontend/infosafe_frontend/src/components/RequestRequests/SupportRequestRequests.js index da9388580..230d93515 100644 --- a/frontend/infosafe_frontend/src/components/RequestRequests/SupportRequestRequests.js +++ b/frontend/infosafe_frontend/src/components/RequestRequests/SupportRequestRequests.js @@ -5,7 +5,7 @@ export const useSupportRequests = () => { const [myDataScopes, setMyDataScopes] = useState([]); useEffect(() => { - fetch('http://ec2-52-91-180-105.compute-1.amazonaws.com:8080/api/datascope/getMyDatascopes', { + fetch('http://localhost:8080/api/datascope/getMyDatascopes', { method: "GET", headers: { Authorization: "Bearer " + sessionStorage.getItem('accessToken') diff --git a/frontend/infosafe_frontend/src/components/Reviews/AccessRequestApproval.js b/frontend/infosafe_frontend/src/components/Reviews/AccessRequestApproval.js index eb1f2fda6..ab59661e0 100644 --- a/frontend/infosafe_frontend/src/components/Reviews/AccessRequestApproval.js +++ b/frontend/infosafe_frontend/src/components/Reviews/AccessRequestApproval.js @@ -8,7 +8,7 @@ const AccessRequestApproval = ({ access, popupClose, popupOpen, onArApprove }) = const handleReview = (reviewValue) => { const payload = {review: reviewValue, request_id: access.request_id, user_email: access.user_id.email, dataScope_id: access.data_scope_id.data_scope_id} //console.log(payload) - fetch('http://ec2-52-91-180-105.compute-1.amazonaws.com:8080/api/accessrequest/reviewAccess', { + fetch('http://localhost:8080/api/accessrequest/reviewAccess', { method: 'POST', headers: { 'Content-Type': 'application/json', diff --git a/frontend/infosafe_frontend/src/components/Reviews/ReviewAssetRequest.js b/frontend/infosafe_frontend/src/components/Reviews/ReviewAssetRequest.js index 940795158..2c462eec6 100644 --- a/frontend/infosafe_frontend/src/components/Reviews/ReviewAssetRequest.js +++ b/frontend/infosafe_frontend/src/components/Reviews/ReviewAssetRequest.js @@ -9,7 +9,7 @@ const ReviewAssetRequest = ({assetRequest, popupOpen, popupClose, onAssApproval} popupClose(); const payload = {review: reviewValue, request_id: assetRequest.asset_request_id, asset_id: assetRequest.asset.asset_id, user_email: assetRequest.user.email} //console.log(payload) - fetch('http://ec2-52-91-180-105.compute-1.amazonaws.com:8080/api/assetrequest/reviewAsset', { + fetch('http://localhost:8080/api/assetrequest/reviewAsset', { method: 'POST', headers: { 'Content-Type': 'application/json', diff --git a/frontend/infosafe_frontend/src/components/Reviews/ReviewRiskPopup.js b/frontend/infosafe_frontend/src/components/Reviews/ReviewRiskPopup.js index 331236521..adc2632df 100644 --- a/frontend/infosafe_frontend/src/components/Reviews/ReviewRiskPopup.js +++ b/frontend/infosafe_frontend/src/components/Reviews/ReviewRiskPopup.js @@ -23,7 +23,7 @@ export const ReviewRisk = ({ risk, popupClose, popupOpen, onRiskReview }) => { ds_id: risk.dataScope.data_scope_id }; if (newStatus !== "OPEN") { - fetch('http://ec2-52-91-180-105.compute-1.amazonaws.com:8080/api/risk/review', { + fetch('http://localhost:8080/api/risk/review', { method: 'POST', headers: { 'Content-Type': 'application/json', diff --git a/frontend/infosafe_frontend/src/components/Roles/RoleCreation.js b/frontend/infosafe_frontend/src/components/Roles/RoleCreation.js index ce0a784fa..41a217c1f 100644 --- a/frontend/infosafe_frontend/src/components/Roles/RoleCreation.js +++ b/frontend/infosafe_frontend/src/components/Roles/RoleCreation.js @@ -28,7 +28,7 @@ const RoleCreation = () => { const role = {role_name, permissions}; // add check to make sure role doesn't exist - fetch(`http://ec2-52-91-180-105.compute-1.amazonaws.com:8080/api/role/checkName?rolename=${role_name}`,{ + fetch(`http://localhost:8080/api/role/checkName?rolename=${role_name}`,{ method: "GET", headers: { "Content-Type": "application/json", @@ -41,7 +41,7 @@ const RoleCreation = () => { console.log("role name already exists"); } else { //console.log(role); - fetch("http://ec2-52-91-180-105.compute-1.amazonaws.com:8080/api/role/addRole", { + fetch("http://localhost:8080/api/role/addRole", { method: "POST", headers: { "Content-Type": "application/json", @@ -61,7 +61,7 @@ const RoleCreation = () => { }; useEffect(() => { - fetch("http://ec2-52-91-180-105.compute-1.amazonaws.com:8080/api/role/getRoleNames", { + fetch("http://localhost:8080/api/role/getRoleNames", { method:"GET", headers:{"Content-Type":"application/json", Authorization: "Bearer " + sessionStorage.getItem('accessToken') diff --git a/frontend/infosafe_frontend/src/components/Subsystems/DataScopes.js b/frontend/infosafe_frontend/src/components/Subsystems/DataScopes.js index d76a41eef..42bbe5f50 100644 --- a/frontend/infosafe_frontend/src/components/Subsystems/DataScopes.js +++ b/frontend/infosafe_frontend/src/components/Subsystems/DataScopes.js @@ -49,7 +49,7 @@ export const DataScopes = () => { const DeleteFunction = async (data_scope_id) => { try { - const response = await fetch("http://ec2-52-91-180-105.compute-1.amazonaws.com:8080/api/datascope/deleteDataScope/"+data_scope_id, { + const response = await fetch("http://localhost:8080/api/datascope/deleteDataScope/"+data_scope_id, { method: "DELETE", headers: { Authorization: "Bearer " + sessionStorage.getItem('accessToken') diff --git a/frontend/infosafe_frontend/src/components/Subsystems/Devices.js b/frontend/infosafe_frontend/src/components/Subsystems/Devices.js index f22153b32..c37e60bea 100644 --- a/frontend/infosafe_frontend/src/components/Subsystems/Devices.js +++ b/frontend/infosafe_frontend/src/components/Subsystems/Devices.js @@ -43,7 +43,7 @@ export const Devices = () => { const DeleteFunction = async (asset_id) => { try { - const response = await fetch("http://ec2-52-91-180-105.compute-1.amazonaws.com:8080/api/asset/deleteAsset/"+asset_id, { + const response = await fetch("http://localhost:8080/api/asset/deleteAsset/"+asset_id, { method: "DELETE", headers: { Authorization: "Bearer " + sessionStorage.getItem('accessToken') diff --git a/frontend/infosafe_frontend/src/components/Subsystems/Navbar.js b/frontend/infosafe_frontend/src/components/Subsystems/Navbar.js index dd9c64f68..eb95f5246 100644 --- a/frontend/infosafe_frontend/src/components/Subsystems/Navbar.js +++ b/frontend/infosafe_frontend/src/components/Subsystems/Navbar.js @@ -78,7 +78,7 @@ const NavBar = () => { useEffect(() => { const payload = {token: sessionStorage.getItem('accessToken')}; - fetch('http://ec2-52-91-180-105.compute-1.amazonaws.com:8080/api/user/tokenValid', { + fetch('http://localhost:8080/api/user/tokenValid', { method: 'POST', headers: { 'Authorization': 'Bearer ' + sessionStorage.getItem('accessToken'), @@ -111,7 +111,7 @@ const NavBar = () => { const [left, setLeft] = useState(0); useEffect(() => { - fetch('http://ec2-52-91-180-105.compute-1.amazonaws.com:8080/api/user/getUserName', { + fetch('http://localhost:8080/api/user/getUserName', { method: "GET", headers: { Authorization: "Bearer " + sessionStorage.getItem('accessToken') diff --git a/frontend/infosafe_frontend/src/components/Subsystems/Requests.js b/frontend/infosafe_frontend/src/components/Subsystems/Requests.js index 684b5268c..038a7026b 100644 --- a/frontend/infosafe_frontend/src/components/Subsystems/Requests.js +++ b/frontend/infosafe_frontend/src/components/Subsystems/Requests.js @@ -45,7 +45,7 @@ export const Requests = () => { const [myDataScopes, setMyDataScopes] = useState([]); useEffect(() => { - fetch('http://ec2-52-91-180-105.compute-1.amazonaws.com:8080/api/datascope/getMyDatascopes', { + fetch('http://localhost:8080/api/datascope/getMyDatascopes', { method: "GET", headers: { Authorization: "Bearer " + sessionStorage.getItem('accessToken') diff --git a/frontend/infosafe_frontend/src/components/Subsystems/Users.js b/frontend/infosafe_frontend/src/components/Subsystems/Users.js index a5092ab6c..2341344a9 100644 --- a/frontend/infosafe_frontend/src/components/Subsystems/Users.js +++ b/frontend/infosafe_frontend/src/components/Subsystems/Users.js @@ -69,7 +69,7 @@ export const Users = () => { const DeleteFunction = async (email) => { const deleteUser = {email} try { - const response = await fetch("http://ec2-52-91-180-105.compute-1.amazonaws.com:8080/api/user/deleteUser", { + const response = await fetch("http://localhost:8080/api/user/deleteUser", { method: "POST", headers: { "Content-Type": "application/json", diff --git a/frontend/infosafe_frontend/src/components/Subsystems/useRequestMaker.js b/frontend/infosafe_frontend/src/components/Subsystems/useRequestMaker.js index dc2dabe65..b0e410036 100644 --- a/frontend/infosafe_frontend/src/components/Subsystems/useRequestMaker.js +++ b/frontend/infosafe_frontend/src/components/Subsystems/useRequestMaker.js @@ -50,15 +50,15 @@ const useRequestMaker = () => { switch (selectedRequest) { case 'Support Request': - apiUrl = "http://ec2-52-91-180-105.compute-1.amazonaws.com:8080/api/supportrequest/addSr"; + apiUrl = "http://localhost:8080/api/supportrequest/addSr"; requestBody = support; break; case 'Asset Request': - apiUrl = "http://ec2-52-91-180-105.compute-1.amazonaws.com:8080/api/assetrequest/addAr"; + apiUrl = "http://localhost:8080/api/assetrequest/addAr"; requestBody = asset; break; case 'Access Request': - apiUrl = "http://ec2-52-91-180-105.compute-1.amazonaws.com:8080/api/accessrequest/addAr"; + apiUrl = "http://localhost:8080/api/accessrequest/addAr"; requestBody = access; break; default: @@ -79,7 +79,7 @@ const useRequestMaker = () => { }; useEffect(() => { - fetch('http://ec2-52-91-180-105.compute-1.amazonaws.com:8080/api/user/getEmail', { + fetch('http://localhost:8080/api/user/getEmail', { method: "GET", headers: { Authorization: "Bearer " + sessionStorage.getItem('accessToken') diff --git a/frontend/infosafe_frontend/src/components/View/ViewDataScope.js b/frontend/infosafe_frontend/src/components/View/ViewDataScope.js index c08532f9c..a97a24c5c 100644 --- a/frontend/infosafe_frontend/src/components/View/ViewDataScope.js +++ b/frontend/infosafe_frontend/src/components/View/ViewDataScope.js @@ -21,7 +21,7 @@ const ViewDataScope = ({ datascope, popupClose, popupOpen }) => { }; useEffect(() => { - fetch('http://ec2-52-91-180-105.compute-1.amazonaws.com:8080/api/dataScopeRole/rolesByDataScopeId/' + datascope.data_scope_id, { + fetch('http://localhost:8080/api/dataScopeRole/rolesByDataScopeId/' + datascope.data_scope_id, { method: 'GET', headers: { Authorization: 'Bearer ' + sessionStorage.getItem('accessToken') diff --git a/frontend/infosafe_frontend/src/components/View/ViewTaskPopup.js b/frontend/infosafe_frontend/src/components/View/ViewTaskPopup.js index 7801e244a..4a2d96ad1 100644 --- a/frontend/infosafe_frontend/src/components/View/ViewTaskPopup.js +++ b/frontend/infosafe_frontend/src/components/View/ViewTaskPopup.js @@ -19,7 +19,7 @@ export const ViewTask = ({task, popupClose, popupOpen}) => { }); useEffect(() => { - fetch("http://ec2-52-91-180-105.compute-1.amazonaws.com:8080/api/task/getUsersOfTask/" + task.task_id, { + fetch("http://localhost:8080/api/task/getUsersOfTask/" + task.task_id, { method: "GET", headers: { Authorization: "Bearer " + sessionStorage.getItem('accessToken') @@ -52,7 +52,7 @@ export const ViewTask = ({task, popupClose, popupOpen}) => { const handleCompleted = () => { console.log("Complete") const request = {completion: true, task_id: task.task_id}; - fetch("http://ec2-52-91-180-105.compute-1.amazonaws.com:8080/api/task/completeTask", { + fetch("http://localhost:8080/api/task/completeTask", { method: "POST", headers: { "Content-Type": "application/json", @@ -73,7 +73,7 @@ export const ViewTask = ({task, popupClose, popupOpen}) => { const handleIncomplete = () => { console.log("Incomplete") const request = {completion: false, task_id: task.task_id}; - fetch("http://ec2-52-91-180-105.compute-1.amazonaws.com:8080/api/task/completeTask", { + fetch("http://localhost:8080/api/task/completeTask", { method: "POST", headers: { "Content-Type": "application/json", diff --git a/frontend/infosafe_frontend/src/components/getData/getAR.js b/frontend/infosafe_frontend/src/components/getData/getAR.js index c10a74ea6..4a653eab0 100644 --- a/frontend/infosafe_frontend/src/components/getData/getAR.js +++ b/frontend/infosafe_frontend/src/components/getData/getAR.js @@ -6,7 +6,7 @@ export const useGetAr = () => { const fetchData = async () => { try { - const response = await fetch('http://ec2-52-91-180-105.compute-1.amazonaws.com:8080/api/accessrequest/getAr', { + const response = await fetch('http://localhost:8080/api/accessrequest/getAr', { method: "GET", headers: { Authorization: "Bearer " + sessionStorage.getItem('accessToken') diff --git a/frontend/infosafe_frontend/src/components/getData/getAllUser.js b/frontend/infosafe_frontend/src/components/getData/getAllUser.js index b6a3cab4e..6507f09ca 100644 --- a/frontend/infosafe_frontend/src/components/getData/getAllUser.js +++ b/frontend/infosafe_frontend/src/components/getData/getAllUser.js @@ -5,7 +5,7 @@ export const useGetAllUser = () => { const [loading, setLoading] = useState(true); const fetchData = async () => { try { - const response = await fetch("http://ec2-52-91-180-105.compute-1.amazonaws.com:8080/api/user/getAll", { + const response = await fetch("http://localhost:8080/api/user/getAll", { method: "GET", headers: { Authorization: "Bearer " + sessionStorage.getItem("accessToken"), diff --git a/frontend/infosafe_frontend/src/components/getData/getAssAR.js b/frontend/infosafe_frontend/src/components/getData/getAssAR.js index bf9c92f4d..948088ae8 100644 --- a/frontend/infosafe_frontend/src/components/getData/getAssAR.js +++ b/frontend/infosafe_frontend/src/components/getData/getAssAR.js @@ -6,7 +6,7 @@ export const useGetAssAR = () => { const fetchData = async () => { try { - const response = await fetch('http://ec2-52-91-180-105.compute-1.amazonaws.com:8080/api/assetrequest/getAr', { + const response = await fetch('http://localhost:8080/api/assetrequest/getAr', { method: "GET", headers: { Authorization: "Bearer " + sessionStorage.getItem('accessToken') diff --git a/frontend/infosafe_frontend/src/components/getData/getAsset.js b/frontend/infosafe_frontend/src/components/getData/getAsset.js index 4d0a626a4..fcc79acde 100644 --- a/frontend/infosafe_frontend/src/components/getData/getAsset.js +++ b/frontend/infosafe_frontend/src/components/getData/getAsset.js @@ -6,7 +6,7 @@ export const useGetAsset = () => { const fetchData = async () => { try { - const response = await fetch('http://ec2-52-91-180-105.compute-1.amazonaws.com:8080/api/asset/getAsset', { + const response = await fetch('http://localhost:8080/api/asset/getAsset', { method: "GET", headers: { Authorization: "Bearer " + sessionStorage.getItem('accessToken') diff --git a/frontend/infosafe_frontend/src/components/getData/getDs.js b/frontend/infosafe_frontend/src/components/getData/getDs.js index 5de776367..f7c4d03ed 100644 --- a/frontend/infosafe_frontend/src/components/getData/getDs.js +++ b/frontend/infosafe_frontend/src/components/getData/getDs.js @@ -7,7 +7,7 @@ export const useGetDS = () => { const fetchAllData = async () => { try { - const response = await fetch('http://ec2-52-91-180-105.compute-1.amazonaws.com:8080/api/datascope/getDs', { + const response = await fetch('http://localhost:8080/api/datascope/getDs', { method: "GET", headers: { Authorization: "Bearer " + sessionStorage.getItem('accessToken') @@ -26,7 +26,7 @@ export const useGetDS = () => { const fetchMyData = async () => { try { - const response = await fetch('http://ec2-52-91-180-105.compute-1.amazonaws.com:8080/api/datascope/getMyDatascopes', { + const response = await fetch('http://localhost:8080/api/datascope/getMyDatascopes', { method: "GET", headers: { Authorization: "Bearer " + sessionStorage.getItem('accessToken') diff --git a/frontend/infosafe_frontend/src/components/getData/getPerms.js b/frontend/infosafe_frontend/src/components/getData/getPerms.js index 035ce2225..f18379539 100644 --- a/frontend/infosafe_frontend/src/components/getData/getPerms.js +++ b/frontend/infosafe_frontend/src/components/getData/getPerms.js @@ -4,7 +4,7 @@ export const useGetPerms = () => { const [roles, setRoles] = useState([]); useEffect(() => { - fetch('http://ec2-52-91-180-105.compute-1.amazonaws.com:8080/api/role/getPermissions', { + fetch('http://localhost:8080/api/role/getPermissions', { method: "GET", headers: { Authorization: "Bearer " + sessionStorage.getItem('accessToken') diff --git a/frontend/infosafe_frontend/src/components/getData/getRisk.js b/frontend/infosafe_frontend/src/components/getData/getRisk.js index 125b2b908..f53c72d29 100644 --- a/frontend/infosafe_frontend/src/components/getData/getRisk.js +++ b/frontend/infosafe_frontend/src/components/getData/getRisk.js @@ -6,7 +6,7 @@ export const useGetRisk = () => { const fetchData = async () => { try { - const response = await fetch('http://ec2-52-91-180-105.compute-1.amazonaws.com:8080/api/risk/getRisk', { + const response = await fetch('http://localhost:8080/api/risk/getRisk', { method: "GET", headers: { Authorization: "Bearer " + sessionStorage.getItem('accessToken') diff --git a/frontend/infosafe_frontend/src/components/getData/getSR.js b/frontend/infosafe_frontend/src/components/getData/getSR.js index 0ea9a407f..7cb4387ac 100644 --- a/frontend/infosafe_frontend/src/components/getData/getSR.js +++ b/frontend/infosafe_frontend/src/components/getData/getSR.js @@ -7,7 +7,7 @@ export const useGetSR = () => { const fetchAllData = async () => { try { - const response = await fetch('http://ec2-52-91-180-105.compute-1.amazonaws.com:8080/api/supportrequest/getSr', { + const response = await fetch('http://localhost:8080/api/supportrequest/getSr', { method: "GET", headers: { Authorization: "Bearer " + sessionStorage.getItem('accessToken') @@ -30,7 +30,7 @@ export const useGetSR = () => { const fetchMyData = async () => { try { - const response = await fetch('http://ec2-52-91-180-105.compute-1.amazonaws.com:8080/api/supportrequest/getSrById', { + const response = await fetch('http://localhost:8080/api/supportrequest/getSrById', { method: "GET", headers: { Authorization: "Bearer " + sessionStorage.getItem('accessToken') diff --git a/frontend/infosafe_frontend/src/components/getData/getTask.js b/frontend/infosafe_frontend/src/components/getData/getTask.js index 22369820e..6daf7c376 100644 --- a/frontend/infosafe_frontend/src/components/getData/getTask.js +++ b/frontend/infosafe_frontend/src/components/getData/getTask.js @@ -8,7 +8,7 @@ export const useGetTask = () => { const fetchData = async () => { try { - const response = await fetch('http://ec2-52-91-180-105.compute-1.amazonaws.com:8080/api/task/getTask', { + const response = await fetch('http://localhost:8080/api/task/getTask', { method: "GET", headers: { Authorization: "Bearer " + sessionStorage.getItem('accessToken') @@ -28,7 +28,7 @@ export const useGetTask = () => { // useEffect(() => { // async function getTasks() { // try { - // const data = await fetch('http://ec2-52-91-180-105.compute-1.amazonaws.com:8080/api/task/getTask', { + // const data = await fetch('http://localhost:8080/api/task/getTask', { // method: "GET", // headers: { // Authorization: "Bearer " + sessionStorage.getItem('accessToken') From 0462a7307e2d72e92bff130a893db97931710c11 Mon Sep 17 00:00:00 2001 From: Alistair Ross <87852242+AlistairMRoss@users.noreply.github.com> Date: Tue, 10 Oct 2023 08:24:30 +0200 Subject: [PATCH 02/14] Encryption and other things working --- .../infosafe/InfosafeBackendApplication.java | 13 ++-- .../primary/auth/AuthenticationResponse.java | 2 - .../primary/auth/AuthenticationService.java | 54 ++++------------ .../primary/config/ApplicationConfig.java | 61 ++++++++++++++++++- .../config/JwtAuthenticationFilter.java | 6 +- .../infosafe/primary/config/JwtService.java | 27 ++++---- .../controller/AuthenticationController.java | 15 ++--- .../primary/controller/UserController.java | 25 +++----- .../fragile/infosafe/primary/model/User.java | 3 +- .../primary/service/AWSSecretService.java | 43 +++++++++++++ .../primary/service/EncryptionService.java | 35 +++++++++++ .../infosafe/primary/service/UserService.java | 22 ++++--- .../src/components/Create/CreateUserPopup.js | 37 +++-------- 13 files changed, 219 insertions(+), 124 deletions(-) create mode 100644 backend/infosafe_backend/src/main/java/com/fragile/infosafe/primary/service/EncryptionService.java diff --git a/backend/infosafe_backend/src/main/java/com/fragile/infosafe/InfosafeBackendApplication.java b/backend/infosafe_backend/src/main/java/com/fragile/infosafe/InfosafeBackendApplication.java index 341e8e564..cf682cdf7 100644 --- a/backend/infosafe_backend/src/main/java/com/fragile/infosafe/InfosafeBackendApplication.java +++ b/backend/infosafe_backend/src/main/java/com/fragile/infosafe/InfosafeBackendApplication.java @@ -25,16 +25,14 @@ public static void main(String[] args) { //Uncomment the below code if this is your first time use //This will create an admin role in the system and create your first profile -// @Autowired -// private RoleRepository roleRepository; + @Autowired + private RoleRepository roleRepository; // // @Bean // public CommandLineRunner cr (AuthenticationService service){ // return args -> { -// //Check if it exists // Role admin = roleRepository.findByRole_name("ADMIN"); // -// //Create role if it doesn't exist // if (admin == null){ // admin = new Role(); // admin.setRole_Name("ADMIN"); @@ -51,8 +49,11 @@ public static void main(String[] args) { // @Bean // public CommandLineRunner commandLineRunner(AuthenticationService service) { // return args -> { -// Role adminRole = roleRepository.findByRole_name("ADMIN"); -// +// var adminRole = roleRepository.findByRole_name("ADMIN"); +// if (adminRole == null) { +// System.err.println("'ADMIN' role not found in the database."); +// return; +// } // var admin = RegisterRequest.builder() // .first_name("John") // .last_name("Smith") diff --git a/backend/infosafe_backend/src/main/java/com/fragile/infosafe/primary/auth/AuthenticationResponse.java b/backend/infosafe_backend/src/main/java/com/fragile/infosafe/primary/auth/AuthenticationResponse.java index 8e8d8332f..991418d86 100644 --- a/backend/infosafe_backend/src/main/java/com/fragile/infosafe/primary/auth/AuthenticationResponse.java +++ b/backend/infosafe_backend/src/main/java/com/fragile/infosafe/primary/auth/AuthenticationResponse.java @@ -14,8 +14,6 @@ public class AuthenticationResponse { @JsonProperty("access_token") private String accessToken; - @JsonProperty("refresh_token") - private String refreshToken; private boolean error = false; public void setError(){ diff --git a/backend/infosafe_backend/src/main/java/com/fragile/infosafe/primary/auth/AuthenticationService.java b/backend/infosafe_backend/src/main/java/com/fragile/infosafe/primary/auth/AuthenticationService.java index e4f693fe2..8e5409732 100644 --- a/backend/infosafe_backend/src/main/java/com/fragile/infosafe/primary/auth/AuthenticationService.java +++ b/backend/infosafe_backend/src/main/java/com/fragile/infosafe/primary/auth/AuthenticationService.java @@ -1,69 +1,68 @@ package com.fragile.infosafe.primary.auth; -import com.fragile.infosafe.primary.model.Role; import com.fragile.infosafe.primary.model.User; import com.fragile.infosafe.primary.repository.RoleRepository; import com.fragile.infosafe.primary.repository.UserRepository; import com.fragile.infosafe.primary.requests.RegisterRequest; import com.fragile.infosafe.primary.config.JwtService; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fragile.infosafe.primary.service.EncryptionService; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.springframework.http.HttpHeaders; import org.springframework.security.authentication.AuthenticationManager; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.stereotype.Service; import org.springframework.security.core.AuthenticationException; +import javax.crypto.Cipher; +import org.springframework.security.crypto.codec.Hex; import java.io.IOException; @Service @RequiredArgsConstructor +@Slf4j public class AuthenticationService { private final UserRepository repository; private final PasswordEncoder passwordEncoder; private final JwtService jwtService; private final AuthenticationManager authenticationManager; private final RoleRepository roleRepository; + private final EncryptionService encryptionService; + public AuthenticationResponse register(RegisterRequest request) { var user = User.builder() - .first_name(request.getFirst_name()) - .last_name(request.getLast_name()) - .email(request.getEmail()) + .first_name(encryptionService.encryptString(request.getFirst_name())) + .last_name(encryptionService.encryptString(request.getLast_name())) + .email(encryptionService.encryptString(request.getEmail())) .password(passwordEncoder.encode(request.getPassword())) .role(roleRepository.findByRole_name(request.getRole().getRole_name())) .build(); repository.save(user); var jwtToken = jwtService.generateToken(user); - var refreshToken = jwtService.generateRefreshToken(user); return AuthenticationResponse.builder() .accessToken(jwtToken) - .refreshToken(refreshToken) .build(); } - - - - public AuthenticationResponse authenticate(AuthenticationRequest request) { try { authenticationManager.authenticate( new UsernamePasswordAuthenticationToken( - request.getEmail(), + encryptionService.encryptString(request.getEmail()), request.getPassword() ) ); - var user = repository.findByEmail(request.getEmail()) + var user = repository.findByEmail(encryptionService.encryptString(request.getEmail())) .orElseThrow(); + log.info(String.valueOf(user)); var jwtToken = jwtService.generateToken(user); - var refreshToken = jwtService.generateRefreshToken(user); return AuthenticationResponse.builder() .accessToken(jwtToken) - .refreshToken(refreshToken) .build(); } catch (AuthenticationException e) { AuthenticationResponse auth = new AuthenticationResponse(); @@ -71,31 +70,4 @@ public AuthenticationResponse authenticate(AuthenticationRequest request) { return auth; } } - - public void refreshToken( - HttpServletRequest request, - HttpServletResponse response - ) throws IOException { - final String authHeader = request.getHeader(HttpHeaders.AUTHORIZATION); - final String refreshToken; - final String userEmail; - if (authHeader == null ||!authHeader.startsWith("Bearer ")) { - return; - } - refreshToken = authHeader.substring(7); - userEmail = jwtService.extractUsername(refreshToken); - if (userEmail != null) { - var user = this.repository.findByEmail(userEmail) - .orElseThrow(); - if (jwtService.isTokenValid(refreshToken, user)) { - var accessToken = jwtService.generateToken(user); - var authResponse = AuthenticationResponse.builder() - .accessToken(accessToken) - .refreshToken(refreshToken) - .build(); - new ObjectMapper().writeValue(response.getOutputStream(), authResponse); - } - } - } - } diff --git a/backend/infosafe_backend/src/main/java/com/fragile/infosafe/primary/config/ApplicationConfig.java b/backend/infosafe_backend/src/main/java/com/fragile/infosafe/primary/config/ApplicationConfig.java index f0a5d2fb0..a40307b02 100644 --- a/backend/infosafe_backend/src/main/java/com/fragile/infosafe/primary/config/ApplicationConfig.java +++ b/backend/infosafe_backend/src/main/java/com/fragile/infosafe/primary/config/ApplicationConfig.java @@ -1,7 +1,10 @@ package com.fragile.infosafe.primary.config; import com.fragile.infosafe.primary.repository.UserRepository; +import com.fragile.infosafe.primary.service.AWSSecretService; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.cache.annotation.Cacheable; import org.springframework.cache.annotation.EnableCaching; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -12,16 +15,27 @@ import org.springframework.security.core.userdetails.UserDetailsService; import org.springframework.security.core.userdetails.UsernameNotFoundException; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; +import org.springframework.security.crypto.codec.Hex; import org.springframework.security.crypto.password.PasswordEncoder; -import java.util.List; +import javax.crypto.Cipher; +import javax.crypto.spec.IvParameterSpec; +import javax.crypto.spec.SecretKeySpec; + +import java.security.Key; +import java.util.Base64; @Configuration @RequiredArgsConstructor @EnableCaching +@Slf4j public class ApplicationConfig { private final UserRepository repository; - + private final AWSSecretService awsSecretService; + private String encryptionKeyString; + private String encryptionIV; + private String decryptionKeyString; + private String decryptionIV; @Bean public UserDetailsService userDetailsService(){ return username -> repository.findByEmail(username) @@ -46,6 +60,49 @@ public PasswordEncoder passwordEncoder() { return new BCryptPasswordEncoder(); } + @Bean + @Cacheable(value = {"encryptionKeyString", "encryptionIV"}) + public Cipher encryptionCipher() throws Exception { + if(encryptionKeyString == null){ + encryptionKeyString = awsSecretService.getEncryptionKey(); + } + if(encryptionIV == null){ + encryptionIV = awsSecretService.getIV(); + } + log.info(encryptionIV); + Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); + byte[] encryptionKeyBytes = Base64.getDecoder().decode(encryptionKeyString); + Key encryptionKey = new SecretKeySpec(encryptionKeyBytes, "AES"); + byte[] ivBytes = Base64.getDecoder().decode(encryptionIV); + IvParameterSpec ivSpec = new IvParameterSpec(ivBytes); + cipher.init(Cipher.ENCRYPT_MODE, encryptionKey, ivSpec); + return cipher; + } + + + + @Bean + @Cacheable(value = {"decryptionKeyString", "decryptionIV"}) + public Cipher decryptionCipher() throws Exception { + if(decryptionKeyString == null){ + decryptionKeyString = awsSecretService.getEncryptionKey(); + } + if(decryptionIV == null){ + decryptionIV = awsSecretService.getIV(); + } + + byte[] encryptionKeyBytes = Base64.getDecoder().decode(decryptionKeyString); + Key encryptionKey = new SecretKeySpec(encryptionKeyBytes, "AES"); + byte[] ivBytes = Base64.getDecoder().decode(decryptionIV); + + IvParameterSpec ivSpec = new IvParameterSpec(ivBytes); + Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); + cipher.init(Cipher.DECRYPT_MODE, encryptionKey, ivSpec); + return cipher; + } + + + } diff --git a/backend/infosafe_backend/src/main/java/com/fragile/infosafe/primary/config/JwtAuthenticationFilter.java b/backend/infosafe_backend/src/main/java/com/fragile/infosafe/primary/config/JwtAuthenticationFilter.java index 8b0ab8059..c9e543b27 100644 --- a/backend/infosafe_backend/src/main/java/com/fragile/infosafe/primary/config/JwtAuthenticationFilter.java +++ b/backend/infosafe_backend/src/main/java/com/fragile/infosafe/primary/config/JwtAuthenticationFilter.java @@ -1,5 +1,6 @@ package com.fragile.infosafe.primary.config; +import com.fragile.infosafe.primary.service.EncryptionService; import jakarta.servlet.FilterChain; import jakarta.servlet.ServletException; import jakarta.servlet.http.HttpServletRequest; @@ -17,12 +18,15 @@ import org.springframework.stereotype.Component; import org.springframework.web.filter.OncePerRequestFilter; +import javax.crypto.EncryptedPrivateKeyInfo; + @Component @RequiredArgsConstructor public class JwtAuthenticationFilter extends OncePerRequestFilter { private final JwtService jwtService; private final UserDetailsService userDetailsService; + private final EncryptionService encryptionService; @Override protected void doFilterInternal( @@ -42,7 +46,7 @@ protected void doFilterInternal( return; } jwt = authHeader.substring(7); - userEmail = jwtService.extractUsername(jwt); + userEmail = encryptionService.encryptString(jwtService.extractUsername(jwt)); if (userEmail != null && SecurityContextHolder.getContext().getAuthentication() == null) { UserDetails userDetails = this.userDetailsService.loadUserByUsername(userEmail); if (jwtService.isTokenValid(jwt, userDetails)) { diff --git a/backend/infosafe_backend/src/main/java/com/fragile/infosafe/primary/config/JwtService.java b/backend/infosafe_backend/src/main/java/com/fragile/infosafe/primary/config/JwtService.java index 5cb5ef851..8ea8f8201 100644 --- a/backend/infosafe_backend/src/main/java/com/fragile/infosafe/primary/config/JwtService.java +++ b/backend/infosafe_backend/src/main/java/com/fragile/infosafe/primary/config/JwtService.java @@ -1,14 +1,20 @@ package com.fragile.infosafe.primary.config; +import com.fragile.infosafe.primary.service.EncryptionService; import io.jsonwebtoken.Claims; import io.jsonwebtoken.Jwts; import io.jsonwebtoken.SignatureAlgorithm; import io.jsonwebtoken.io.Decoders; import io.jsonwebtoken.security.Keys; +import lombok.RequiredArgsConstructor; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cache.annotation.Cacheable; import org.springframework.security.core.userdetails.UserDetails; +import org.springframework.security.crypto.codec.Hex; import org.springframework.stereotype.Service; +import software.amazon.awssdk.services.controltower.model.EnableControlRequest; + +import javax.crypto.Cipher; import java.security.Key; import java.util.Date; import java.util.HashMap; @@ -16,18 +22,16 @@ import java.util.function.Function; @Service +@RequiredArgsConstructor public class JwtService { private final JwtAWSFetch fetch; private String cachedSecretKey; - - @Autowired - public JwtService(JwtAWSFetch fetch){ - this.fetch = fetch; - } private final int jwtExpiration = 86400000; private final int refreshExpiration = 604800000; + private final EncryptionService encryptionService; + public String extractUsername(String token) { return extractClaim(token, Claims::getSubject); } @@ -45,26 +49,20 @@ public String generateToken(Map extractClaims, UserDetails userD return buildToken(extractClaims, userDetails, jwtExpiration); } - public String generateRefreshToken( - UserDetails userDetails - ) { - return buildToken(new HashMap<>(), userDetails, refreshExpiration); - } - private String buildToken(Map extractClaims, UserDetails userDetails, long expiration) { return Jwts .builder() .setClaims(extractClaims) - .setSubject(userDetails.getUsername()) + .setSubject(encryptionService.decryptString(userDetails.getUsername())) .setIssuedAt(new Date(System.currentTimeMillis())) - .setExpiration(new Date(System.currentTimeMillis() + 1000 * 600 * 24)) + .setExpiration(new Date(System.currentTimeMillis() + expiration)) .signWith(getSignInKey(), SignatureAlgorithm.HS256) .compact(); } public boolean isTokenValid(String token, UserDetails userDetails) { final String username = extractUsername(token); - return (username.equals(userDetails.getUsername())) && !isTokenExpired(token); + return (username.equals(encryptionService.decryptString(userDetails.getUsername()))) && !isTokenExpired(token); } private boolean isTokenExpired(String token) { @@ -92,4 +90,5 @@ public Key getSignInKey() { byte[] keyBytes = Decoders.BASE64.decode(cachedSecretKey); return Keys.hmacShaKeyFor(keyBytes); } + } diff --git a/backend/infosafe_backend/src/main/java/com/fragile/infosafe/primary/controller/AuthenticationController.java b/backend/infosafe_backend/src/main/java/com/fragile/infosafe/primary/controller/AuthenticationController.java index bb90431f1..1cb12b1e3 100644 --- a/backend/infosafe_backend/src/main/java/com/fragile/infosafe/primary/controller/AuthenticationController.java +++ b/backend/infosafe_backend/src/main/java/com/fragile/infosafe/primary/controller/AuthenticationController.java @@ -35,13 +35,14 @@ public ResponseEntity authenticate( return ResponseEntity.ok(service.authenticate(request)); } - @PostMapping("/refresh-token") - public void refreshToken( - HttpServletRequest request, - HttpServletResponse response - ) throws IOException { - service.refreshToken(request, response); - } +// @PostMapping("/refresh-token") +// public void refreshToken( +// HttpServletRequest request, +// HttpServletResponse response +// ) throws IOException { +// service.refreshToken(request, response); +// } + @PostMapping("/login") public ResponseEntity login(@RequestBody AuthenticationRequest request) { AuthenticationResponse response = service.authenticate(request); diff --git a/backend/infosafe_backend/src/main/java/com/fragile/infosafe/primary/controller/UserController.java b/backend/infosafe_backend/src/main/java/com/fragile/infosafe/primary/controller/UserController.java index db3994e07..0513f81ee 100644 --- a/backend/infosafe_backend/src/main/java/com/fragile/infosafe/primary/controller/UserController.java +++ b/backend/infosafe_backend/src/main/java/com/fragile/infosafe/primary/controller/UserController.java @@ -20,8 +20,10 @@ import org.springframework.http.ResponseEntity; import org.springframework.security.core.Authentication; import org.springframework.security.core.context.SecurityContextHolder; +import org.springframework.security.crypto.codec.Hex; import org.springframework.web.bind.annotation.*; +import javax.crypto.Cipher; import javax.persistence.criteria.CriteriaBuilder; import java.util.*; @@ -38,15 +40,11 @@ public class UserController { private final AssetService assetService; private final DataScopeService dataScopeService; private final JwtService jwtService; + private final EncryptionService encryptionService; @GetMapping("/getAll") public List userlist() { return userService.getAllUsers(); } - @GetMapping("/getUser/{id}") - public Optional getUser(@PathVariable("id") int user_id, @RequestBody User user) { - return userService.getUser(user_id); - } - @PostMapping("/add") public ResponseEntity register( @RequestBody RegisterRequest request @@ -111,18 +109,12 @@ public ResponseEntity getCurrentUserName(){ Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); if (authentication != null && authentication.getPrincipal() instanceof User authenticatedUser) { - String userName = authenticatedUser.getFirst_name() + " " + authenticatedUser.getLast_name(); + String userName = encryptionService.decryptString(authenticatedUser.getFirst_name()) + " " + encryptionService.decryptString(authenticatedUser.getLast_name()); return ResponseEntity.ok("{\"username\": \"" + userName + "\"}"); } return null; } - @GetMapping("/checkEmail") - public ResponseEntity checkEmailExists(@RequestParam("email") String email) { - boolean emailExists = userService.checkEmailExists(email); - return ResponseEntity.ok(emailExists); - } - @PostMapping("/deleteUser") public ResponseEntity deleteUser(@RequestBody DeleteRequest deleteRequest){ try{ @@ -136,8 +128,7 @@ public ResponseEntity deleteUser(@RequestBody DeleteRequest deleteReque @PostMapping("/changePassword") public ResponseEntity changePassword(@RequestBody ChangePasswordRequest changePasswordRequest) { try { - Optional user = userService.getUserByEmail(changePasswordRequest.getUserEmail()); - log.info("Changing password for user with email: {}", changePasswordRequest.getUserEmail()); + Optional user = userService.getUserByEmail(encryptionService.encryptString(changePasswordRequest.getUserEmail())); if (user.isPresent()) { userService.changePassword(user.get(), changePasswordRequest.getNewPassword()); return ResponseEntity.ok(true); @@ -219,7 +210,11 @@ public ResponseEntity> getNotDataCustodian(){ Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); if (authentication != null && authentication.getPrincipal() instanceof User authenticatedUser) { List users = userService.findNotDataCustodian(authenticatedUser); - return ResponseEntity.ok(users); + List finalUsers = new ArrayList<>(); + for(String user : users){ + finalUsers.add(encryptionService.decryptString(user)); + } + return ResponseEntity.ok(finalUsers); }else { return ResponseEntity.notFound().build(); } diff --git a/backend/infosafe_backend/src/main/java/com/fragile/infosafe/primary/model/User.java b/backend/infosafe_backend/src/main/java/com/fragile/infosafe/primary/model/User.java index 3714f1f7b..09e763c60 100644 --- a/backend/infosafe_backend/src/main/java/com/fragile/infosafe/primary/model/User.java +++ b/backend/infosafe_backend/src/main/java/com/fragile/infosafe/primary/model/User.java @@ -35,7 +35,7 @@ public class User implements UserDetails { @Column(nullable = true) private String otp; - @ManyToOne(cascade = CascadeType.PERSIST) + @ManyToOne @JoinColumn(name = "role_name") private Role role; @@ -77,7 +77,6 @@ public Collection getAuthorities() { authorities.add(new SimpleGrantedAuthority(permission.name())); } } - return authorities; } diff --git a/backend/infosafe_backend/src/main/java/com/fragile/infosafe/primary/service/AWSSecretService.java b/backend/infosafe_backend/src/main/java/com/fragile/infosafe/primary/service/AWSSecretService.java index 111707835..75d5314a9 100644 --- a/backend/infosafe_backend/src/main/java/com/fragile/infosafe/primary/service/AWSSecretService.java +++ b/backend/infosafe_backend/src/main/java/com/fragile/infosafe/primary/service/AWSSecretService.java @@ -1,7 +1,11 @@ package com.fragile.infosafe.primary.service; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; import com.fragile.infosafe.primary.config.RDSLogin; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import software.amazon.awssdk.auth.credentials.AwsCredentials; @@ -14,8 +18,12 @@ @Service @RequiredArgsConstructor +@Slf4j public class AWSSecretService { private final String secretName = "rds_login"; + + private final String encryptionName = "client_encryption"; + private final String IVName = "IV"; private final String region = "us-east-1"; @Value("${AWS_ACCESS_KEY_ID}") @@ -42,6 +50,41 @@ public RDSLogin getRDSLogin() { return gson.fromJson(secret, RDSLogin.class); } + public String getEncryptionKey() throws JsonProcessingException { + SecretsManagerClient client = SecretsManagerClient.builder() + .region(Region.of(region)) + .credentialsProvider(createCredentialsProvider()) + .build(); + + GetSecretValueRequest getSecretValueRequest = GetSecretValueRequest.builder() + .secretId(encryptionName) + .build(); + + GetSecretValueResponse getSecretValueResponse = client.getSecretValue(getSecretValueRequest); + String secret = getSecretValueResponse.secretString(); + + ObjectMapper objectMapper = new ObjectMapper(); + JsonNode jsonNode = objectMapper.readTree(secret); + return jsonNode.get("client_encryption").asText(); + } + + public String getIV() throws JsonProcessingException { + SecretsManagerClient client = SecretsManagerClient.builder() + .region(Region.of(region)) + .credentialsProvider(createCredentialsProvider()) + .build(); + + GetSecretValueRequest getSecretValueRequest = GetSecretValueRequest.builder() + .secretId(IVName) + .build(); + + GetSecretValueResponse getSecretValueResponse = client.getSecretValue(getSecretValueRequest); + String secret = getSecretValueResponse.secretString(); + + ObjectMapper objectMapper = new ObjectMapper(); + JsonNode jsonNode = objectMapper.readTree(secret); + return jsonNode.get("IV").asText(); + } private AwsCredentialsProvider createCredentialsProvider() { return new AwsCredentialsProvider() { @Override diff --git a/backend/infosafe_backend/src/main/java/com/fragile/infosafe/primary/service/EncryptionService.java b/backend/infosafe_backend/src/main/java/com/fragile/infosafe/primary/service/EncryptionService.java new file mode 100644 index 000000000..613e85ff6 --- /dev/null +++ b/backend/infosafe_backend/src/main/java/com/fragile/infosafe/primary/service/EncryptionService.java @@ -0,0 +1,35 @@ +package com.fragile.infosafe.primary.service; + +import lombok.RequiredArgsConstructor; +import org.springframework.security.crypto.codec.Hex; +import org.springframework.stereotype.Service; + +import javax.crypto.Cipher; + +@Service +@RequiredArgsConstructor +public class EncryptionService { + private final Cipher encryptionCipher; + private final Cipher decryptionCipher; + + public String encryptString(String input) { + try { + byte[] inputBytes = input.getBytes("UTF-8"); + byte[] encryptedBytes = encryptionCipher.doFinal(inputBytes); + return new String(Hex.encode(encryptedBytes)); + } catch (Exception e) { + e.printStackTrace(); + return null; + } + } + public String decryptString(String encryptedHex) { + try { + byte[] encryptedBytes = Hex.decode(encryptedHex); + byte[] decryptedBytes = decryptionCipher.doFinal(encryptedBytes); + return new String(decryptedBytes, "UTF-8"); + } catch (Exception e) { + e.printStackTrace(); + return null; + } + } +} diff --git a/backend/infosafe_backend/src/main/java/com/fragile/infosafe/primary/service/UserService.java b/backend/infosafe_backend/src/main/java/com/fragile/infosafe/primary/service/UserService.java index 881746b12..33d2f86c1 100644 --- a/backend/infosafe_backend/src/main/java/com/fragile/infosafe/primary/service/UserService.java +++ b/backend/infosafe_backend/src/main/java/com/fragile/infosafe/primary/service/UserService.java @@ -6,9 +6,11 @@ import com.fragile.infosafe.primary.repository.RoleRepository; import com.fragile.infosafe.primary.repository.UserRepository; import lombok.RequiredArgsConstructor; +import org.springframework.security.crypto.codec.Hex; import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.stereotype.Service; +import javax.crypto.Cipher; import java.util.List; import java.util.Optional; @@ -19,17 +21,24 @@ public class UserService { private final EmailService emailService; private final PasswordEncoder passwordEncoder; private final RoleRepository roleRepository; + private final EncryptionService encryptionService; public List getAllUsers() { - return repository.findAll(); - } - - public Optional getUser(Integer user_id) { - return repository.findById(user_id); + List users = repository.findAll(); + for (User user : users) { + user.setFirst_name(encryptionService.decryptString(user.getFirst_name())); + user.setLast_name(encryptionService.decryptString(user.getLast_name())); + user.setEmail(encryptionService.decryptString(user.getEmail())); + } + return users; } public User updateUser(User user) { user.setRole(roleRepository.findByRole_name(user.getRole().getRole_name())); + user.setFirst_name(encryptionService.decryptString(user.getFirst_name())); + user.setLast_name(encryptionService.decryptString(user.getLast_name())); + user.setEmail(encryptionService.decryptString(user.getEmail())); + user.setPassword(encryptionService.decryptString(user.getPassword())); return repository.save(user); } @@ -39,7 +48,7 @@ public Optional getUserByEmail(String email) { public void changePassword(User user, String newPassword) { - user.setPassword(passwordEncoder.encode(newPassword)); + user.setPassword(encryptionService.encryptString(passwordEncoder.encode(newPassword))); repository.save(user); } @@ -73,7 +82,6 @@ public void generateAndSaveOtp(String email) { user.setOtp(otp); repository.save(user); emailService.sendEmail(user.getEmail(), "Forgot Password", "Your OTP is:\n" + otp); - } else { } } diff --git a/frontend/infosafe_frontend/src/components/Create/CreateUserPopup.js b/frontend/infosafe_frontend/src/components/Create/CreateUserPopup.js index 842ab6018..52b3357fb 100644 --- a/frontend/infosafe_frontend/src/components/Create/CreateUserPopup.js +++ b/frontend/infosafe_frontend/src/components/Create/CreateUserPopup.js @@ -17,49 +17,32 @@ export const CreateUserPopup = ({ popupOpen, popupClose, onUserAdded }) => { const useHandleClick = (e) => { e.preventDefault(); popupClose(); - const user = { first_name, last_name, email, password, role: { role_name: selectedRole } }; + const user = { first_name, last_name, email, password, role: {role_name: selectedRole} }; if ( document.getElementById("nameInput").value === '' || document.getElementById("surnameInput").value === '' || document.getElementById("emailInput").value === '' || selectedRole === '' ) { document.getElementById("createUserError").style.display = "block"; return; } - fetch(`http://localhost:8080/api/user/checkEmail?email=${email}`, { - method: "GET", + fetch("http://localhost:8080/api/user/add", { + method: "POST", headers: { "Content-Type": "application/json", Authorization: "Bearer " + sessionStorage.getItem('accessToken'), }, + body: JSON.stringify(user), }) - .then((response) => response.json()) - .then((data) => { - if (data) { - console.log("User already exists"); - } else { - //console.log(user); - fetch("http://localhost:8080/api/user/add", { - method: "POST", - headers: { - "Content-Type": "application/json", - Authorization: "Bearer " + sessionStorage.getItem('accessToken'), - }, - body: JSON.stringify(user), - }) - .then((response) => { - if(response.ok) { - console.log("New User added"); - onUserAdded(); - } - }) - .catch((error) => { - console.error("Error adding new user:", error); - }); + .then((response) => { + if (response.ok) { + console.log("New User added"); + onUserAdded(); } }) .catch((error) => { - console.error("Error checking email:", error); + console.error("Error adding new user:", error); }); + }; From a4693433eca3cfec088b87edf4c3739728eca217 Mon Sep 17 00:00:00 2001 From: Christof Steyn <56771007+P3TROOS@users.noreply.github.com> Date: Tue, 10 Oct 2023 11:59:05 +0200 Subject: [PATCH 03/14] Added a few .catch blocks to frontend --- .../components/Charts/useCurrentDataScope.js | 66 +++++++++++++------ .../RequestRequests/AccessRequestRequests.js | 24 ++++--- .../RequestRequests/AssetRequestRequests.js | 17 +++-- 3 files changed, 68 insertions(+), 39 deletions(-) diff --git a/frontend/infosafe_frontend/src/components/Charts/useCurrentDataScope.js b/frontend/infosafe_frontend/src/components/Charts/useCurrentDataScope.js index 9e5d6d281..d70b5ddf2 100644 --- a/frontend/infosafe_frontend/src/components/Charts/useCurrentDataScope.js +++ b/frontend/infosafe_frontend/src/components/Charts/useCurrentDataScope.js @@ -1,76 +1,100 @@ -import {useState, useEffect} from "react"; -import {useGetPerms} from "../getData/getPerms"; +import { useState, useEffect } from "react"; +import { useGetPerms } from "../getData/getPerms"; export const useCurrentDataScope = () => { const [dataScopeCount, setDataScopeCount] = useState(0); const [myDataScopeCount, setMyDataScopeCount] = useState(0); + useEffect(() => { fetch('http://localhost:8080/api/datascope/getTotal', { method: "GET", headers: { - Authorization: "Bearer " + sessionStorage.getItem('accessToken') - } - }).then((res) => res.json()) + Authorization: "Bearer " + sessionStorage.getItem('accessToken'), + }, + }) + .then((res) => res.json()) .then((result) => { setDataScopeCount(result); + }) + .catch((error) => { + console.error("Error fetching DataScope count:", error); }); }, []); + useEffect(() => { fetch('http://localhost:8080/api/user/dataScopeCount', { method: "GET", headers: { - Authorization: "Bearer " + sessionStorage.getItem('accessToken') - } - }).then((res) => res.json()) + Authorization: "Bearer " + sessionStorage.getItem('accessToken'), + }, + }) + .then((res) => res.json()) .then((result) => { setMyDataScopeCount(result); + }) + .catch((error) => { + console.error("Error fetching MyDataScope count:", error); }); }, []); const [assetCount, setAssetCount] = useState(0); const [myAssets, setMyAssets] = useState([]); + useEffect(() => { fetch('http://localhost:8080/api/user/countDevices', { method: "GET", headers: { - Authorization: "Bearer " + sessionStorage.getItem('accessToken') - } - }).then((res) => res.json()) + Authorization: "Bearer " + sessionStorage.getItem('accessToken'), + }, + }) + .then((res) => res.json()) .then((result) => { setAssetCount(result); + }) + .catch((error) => { + console.error("Error fetching asset count:", error); }); }, []); + useEffect(() => { fetch('http://localhost:8080/api/user/getAllDevices', { method: "GET", headers: { - Authorization: "Bearer " + sessionStorage.getItem('accessToken') - } - }).then((res) => res.json()) + Authorization: "Bearer " + sessionStorage.getItem('accessToken'), + }, + }) + .then((res) => res.json()) .then((result) => { setMyAssets(result); + }) + .catch((error) => { + console.error("Error fetching MyAssets:", error); }); }, []); const [totalAssets, setTotalAssets] = useState(0); + useEffect(() => { fetch('http://localhost:8080/api/asset/getTotalAssets', { method: "GET", headers: { - Authorization: "Bearer " + sessionStorage.getItem('accessToken') - } - }).then((res) => res.json()) + Authorization: "Bearer " + sessionStorage.getItem('accessToken'), + }, + }) + .then((res) => res.json()) .then((result) => { setTotalAssets(result); + }) + .catch((error) => { + console.error("Error fetching total assets:", error); }); }, []); - return { dataScopeCount, myDataScopeCount, assetCount, myAssets, - totalAssets - } -} \ No newline at end of file + totalAssets, + }; +}; diff --git a/frontend/infosafe_frontend/src/components/RequestRequests/AccessRequestRequests.js b/frontend/infosafe_frontend/src/components/RequestRequests/AccessRequestRequests.js index 921283ceb..cbb53b4e0 100644 --- a/frontend/infosafe_frontend/src/components/RequestRequests/AccessRequestRequests.js +++ b/frontend/infosafe_frontend/src/components/RequestRequests/AccessRequestRequests.js @@ -1,4 +1,4 @@ -import {useEffect, useState} from "react"; +import { useEffect, useState } from "react"; export const useAccessRequests = () => { const [datascopeData, setDatascopeData] = useState([]); @@ -8,12 +8,15 @@ export const useAccessRequests = () => { fetch('http://localhost:8080/api/datascope/availableDatascopes', { method: "GET", headers: { - Authorization: "Bearer " + sessionStorage.getItem('accessToken') - } + Authorization: "Bearer " + sessionStorage.getItem("accessToken"), + }, }) .then((res) => res.json()) .then((result) => { setDatascopeData(result); + }) + .catch((error) => { + console.error("Error fetching availableDatascopes:", error); }); }, []); @@ -21,17 +24,20 @@ export const useAccessRequests = () => { fetch('http://localhost:8080/api/datascope/getMyDatascopes', { method: "GET", headers: { - Authorization: "Bearer " + sessionStorage.getItem('accessToken') - } + Authorization: "Bearer " + sessionStorage.getItem("accessToken"), + }, }) .then((res) => res.json()) .then((result) => { setMyDatascopeData(result); + }) + .catch((error) => { + console.error("Error fetching getMyDatascopes:", error); }); }, []); + return { myDatascopeData, - datascopeData - } - -} \ No newline at end of file + datascopeData, + }; +}; diff --git a/frontend/infosafe_frontend/src/components/RequestRequests/AssetRequestRequests.js b/frontend/infosafe_frontend/src/components/RequestRequests/AssetRequestRequests.js index fc818f881..6d94c1d90 100644 --- a/frontend/infosafe_frontend/src/components/RequestRequests/AssetRequestRequests.js +++ b/frontend/infosafe_frontend/src/components/RequestRequests/AssetRequestRequests.js @@ -1,5 +1,4 @@ -import {useEffect, useState} from "react"; - +import { useEffect, useState } from "react"; export const useAssetRequests = () => { const [availableAssets, setAvailableAssets] = useState(null); @@ -8,17 +7,17 @@ export const useAssetRequests = () => { fetch('http://localhost:8080/api/asset/availableAssets', { method: "GET", headers: { - Authorization: "Bearer " + sessionStorage.getItem('accessToken') - } + Authorization: "Bearer " + sessionStorage.getItem('accessToken'), + }, }) .then((res) => res.json()) .then((result) => { setAvailableAssets(result); + }) + .catch((error) => { + console.error("Error fetching availableAssets:", error); }); }, []); - return ( - availableAssets - ) - -} + return availableAssets; +}; From abb7f838cceebc25abe565446951a786e8b2d27a Mon Sep 17 00:00:00 2001 From: Christof Steyn <56771007+P3TROOS@users.noreply.github.com> Date: Tue, 10 Oct 2023 12:15:49 +0200 Subject: [PATCH 04/14] Some more .catches --- .../src/components/Charts/useCurrentTasks.js | 41 ++-- .../components/Create/CreateDataScopePopup.js | 38 ++-- .../components/Create/CreateDevicePopup.js | 92 ++++---- .../src/components/Create/CreateRiskPopup.js | 60 +++--- .../src/components/Create/CreateTaskPopup.js | 200 +++++++++--------- .../src/components/Create/CreateUserPopup.js | 52 +++-- 6 files changed, 262 insertions(+), 221 deletions(-) diff --git a/frontend/infosafe_frontend/src/components/Charts/useCurrentTasks.js b/frontend/infosafe_frontend/src/components/Charts/useCurrentTasks.js index 55695b1a0..0279be339 100644 --- a/frontend/infosafe_frontend/src/components/Charts/useCurrentTasks.js +++ b/frontend/infosafe_frontend/src/components/Charts/useCurrentTasks.js @@ -1,46 +1,61 @@ -import {useState, useEffect} from "react"; +import { useState, useEffect } from "react"; export const useCurrentTasks = () => { const [taskCount, setTaskCount] = useState(0); const [myTasks, setMyTasks] = useState([]); const [totalTasks, setTotalTasks] = useState(0); + useEffect(() => { fetch('http://localhost:8080/api/user/taskCount', { method: "GET", headers: { - Authorization: "Bearer " + sessionStorage.getItem('accessToken') - } - }).then((res) => res.json()) + Authorization: "Bearer " + sessionStorage.getItem('accessToken'), + }, + }) + .then((res) => res.json()) .then((result) => { setTaskCount(result); + }) + .catch((error) => { + console.error("Error fetching task count:", error); }); }, []); + useEffect(() => { fetch('http://localhost:8080/api/user/getAllTasks', { method: "GET", headers: { - Authorization: "Bearer " + sessionStorage.getItem('accessToken') - } - }).then((res) => res.json()) + Authorization: "Bearer " + sessionStorage.getItem('accessToken'), + }, + }) + .then((res) => res.json()) .then((result) => { setMyTasks(result); + }) + .catch((error) => { + console.error("Error fetching MyTasks:", error); }); }, []); + useEffect(() => { fetch('http://localhost:8080/api/task/totalTasks', { method: "GET", headers: { - Authorization: "Bearer " + sessionStorage.getItem('accessToken') - } - }).then((res) => res.json()) + Authorization: "Bearer " + sessionStorage.getItem('accessToken'), + }, + }) + .then((res) => res.json()) .then((result) => { setTotalTasks(result); + }) + .catch((error) => { + console.error("Error fetching total tasks:", error); }); }, []); return { taskCount, myTasks, - totalTasks - } -} \ No newline at end of file + totalTasks, + }; +}; diff --git a/frontend/infosafe_frontend/src/components/Create/CreateDataScopePopup.js b/frontend/infosafe_frontend/src/components/Create/CreateDataScopePopup.js index c4a97c7d5..7058fae89 100644 --- a/frontend/infosafe_frontend/src/components/Create/CreateDataScopePopup.js +++ b/frontend/infosafe_frontend/src/components/Create/CreateDataScopePopup.js @@ -1,15 +1,15 @@ -import React, {useState, useEffect} from 'react'; +import React, { useState, useEffect } from 'react'; import '../../styling/CreateDataScopePopup.css'; import Popup from 'reactjs-popup'; -import {IoArrowBackOutline} from 'react-icons/io5'; +import { IoArrowBackOutline } from 'react-icons/io5'; import Select from "react-select"; -import {customStyles} from "../CustomStyling"; +import { customStyles } from "../CustomStyling"; -export const CreateDataScopePopup = ({popupOpen, popupClose, onDsAdded}) => { - const [ds_name, setDsName] = useState('') - const [ds_description, setDsDesc] = useState('') - const [users, setUsers] = useState([]) - const [selectedUsers, setSelectedUsers] = useState([]) +export const CreateDataScopePopup = ({ popupOpen, popupClose, onDsAdded }) => { + const [ds_name, setDsName] = useState(''); + const [ds_description, setDsDesc] = useState(''); + const [users, setUsers] = useState([]); + const [selectedUsers, setSelectedUsers] = useState([]); const handleClick = (e) => { const currentDate = new Date().toISOString().split('T')[0]; @@ -21,9 +21,8 @@ export const CreateDataScopePopup = ({popupOpen, popupClose, onDsAdded}) => { return; } - const ds_status = "Pending"; - const datascope = {date_captured: currentDate, ds_description, ds_name, ds_status, user_email: selectedUsers}; + const datascope = { date_captured: currentDate, ds_description, ds_name, ds_status, user_email: selectedUsers }; fetch(`http://localhost:8080/api/datascope/checkName?dsname=${ds_name}`, { method: "GET", @@ -37,7 +36,6 @@ export const CreateDataScopePopup = ({popupOpen, popupClose, onDsAdded}) => { if (data) { console.log("DataScope name already exists"); } else { - //console.log(datascope); fetch("http://localhost:8080/api/datascope/addDs", { method: "POST", headers: { @@ -48,12 +46,11 @@ export const CreateDataScopePopup = ({popupOpen, popupClose, onDsAdded}) => { }) .then(() => { console.log("New DataScope added"); - onDsAdded() + onDsAdded(); }) .catch((error) => { console.error("Error adding new DataScope:", error); }); - } }) .catch((error) => { @@ -68,16 +65,19 @@ export const CreateDataScopePopup = ({popupOpen, popupClose, onDsAdded}) => { "Content-Type": "application/json", Authorization: "Bearer " + sessionStorage.getItem('accessToken'), }, - }).then((res) => res.json()) + }) + .then((res) => res.json()) .then((result) => { setUsers(result); + }) + .catch((error) => { + console.error("Error fetching users:", error); }); }, []); const handleSelect = (selectedOptions) => { const selectedEmails = selectedOptions.map((option) => option.label); setSelectedUsers(selectedEmails); - //console.log(selectedEmails); }; return ( @@ -86,7 +86,7 @@ export const CreateDataScopePopup = ({popupOpen, popupClose, onDsAdded}) => {

Create Data Scope

@@ -116,7 +116,7 @@ export const CreateDataScopePopup = ({popupOpen, popupClose, onDsAdded}) => { {users && users.length > 0 ? ( setAsset_name(e.target.value)} + setAsset_name(e.target.value)} />

Device Type

{ onChange={(e) => setDevice_type(e.target.value)} />

Device Description

- -

Status

-

{access.status}

- -
- -
+
+

Edit Access Request

+
+

Data Scope

+

{access.data_scope_id.ds_name}

+

User

+

{access.user_id.first_name} {access.user_id.last_name}

+

Reason

+ +

Status

+

{access.status}

+ +
+
+ diff --git a/frontend/infosafe_frontend/src/components/Edit/EditDataScopePopup.js b/frontend/infosafe_frontend/src/components/Edit/EditDataScopePopup.js index 589248f51..adc2d3473 100644 --- a/frontend/infosafe_frontend/src/components/Edit/EditDataScopePopup.js +++ b/frontend/infosafe_frontend/src/components/Edit/EditDataScopePopup.js @@ -5,7 +5,7 @@ import { IoArrowBackOutline } from 'react-icons/io5'; import Dropdown from 'react-dropdown'; import ViewDataScope from "../View/ViewDataScope"; import Select from "react-select"; -import {customStyles} from "../CustomStyling"; +import { customStyles } from "../CustomStyling"; const STATUS = ['Pending', 'Approved', 'Revoked']; export const EditDataScopePopup = ({ datascope, popupOpen, popupClose, onDsEdited }) => { @@ -23,19 +23,6 @@ export const EditDataScopePopup = ({ datascope, popupOpen, popupClose, onDsEdite ds_status: datascope.ds_status }); - // useEffect(() => { - // fetch("http://localhost:8080/api/user/findUsersNotInTask/" + task.task_id, { - // method: "GET", - // headers: { - // Authorization: "Bearer " + sessionStorage.getItem('accessToken') - // } - // }) - // .then((res) => res.json()) - // .then((result) => { - // setUsers(result); - // }); - // }, []); - const handleInputChange = (e) => { const { name, value } = e.target; setNewRole((prevRole) => ({ ...prevRole, [name]: value })); @@ -51,8 +38,6 @@ export const EditDataScopePopup = ({ datascope, popupOpen, popupClose, onDsEdite const handleSubmit = (e) => { e.preventDefault(); - //console.log(datascope); - //console.log(values); fetch('http://localhost:8080/api/datascope/update/' + datascope.data_scope_id, { method: 'POST', @@ -61,10 +46,19 @@ export const EditDataScopePopup = ({ datascope, popupOpen, popupClose, onDsEdite Authorization: 'Bearer ' + sessionStorage.getItem('accessToken') }, body: JSON.stringify(values) - }).then(() => { - console.log('Updated Datascope'); - onDsEdited() - }); + }) + .then((response) => { + if (response.ok) { + console.log('Updated Datascope'); + onDsEdited(); + } else { + console.error('Error updating Datascope:', response.status); + } + }) + .catch((error) => { + console.error('Error updating Datascope:', error); + }); + popupClose(); }; @@ -78,6 +72,9 @@ export const EditDataScopePopup = ({ datascope, popupOpen, popupClose, onDsEdite .then((res) => res.json()) .then((result) => { setDataScopeRoles(result); + }) + .catch((error) => { + console.error('Error fetching DataScopeRoles:', error); }); }, []); @@ -93,10 +90,14 @@ export const EditDataScopePopup = ({ datascope, popupOpen, popupClose, onDsEdite }, body: JSON.stringify(newRoleData) }) - .then(() => { - console.log('New DataScopeRole added'); - setDataScopeRoles([...dataScopeRoles, newRoleData]); - setNewRole({ role: '', roledescription: '' }); + .then((response) => { + if (response.ok) { + console.log('New DataScopeRole added'); + setDataScopeRoles([...dataScopeRoles, newRoleData]); + setNewRole({ role: '', roledescription: '' }); + } else { + console.error('Error adding new DataScopeRole:', response.status); + } }) .catch((error) => { console.error('Error adding new DataScopeRole:', error); @@ -136,21 +137,6 @@ export const EditDataScopePopup = ({ datascope, popupOpen, popupClose, onDsEdite defaultValue={datascope.status} onChange={(selectedOption) => setValues({ ...values, ds_status: selectedOption.value })} /> - {/*

Assigned Users

*/} - {/*{users && users.length > 0 ? (*/} - {/* ({value: data.user_id, label: data.email}))}*/} - {/* value={selectedUsers.map((email) => ({ label: email }))}*/} - {/* className="editTaskAssignees"*/} - {/* name="editTaskAssignees"*/} - {/* placeholder={"Add Assignees"}*/} - {/* onChange={handleSelect}*/} - {/* isSearchable={true}*/} - {/* styles={customStyles}*/} - {/* isMulti*/} - {/* /> ) : (*/} - {/*

Loading...

*/} - {/*)}*/}

Data Scope Roles

{dataScopeRoles && dataScopeRoles.length > 0 ? ( setValues({...values, asset_name: e.target.value})} - /> + setValues({ ...values, asset_name: e.target.value })} + />

Description