From 97e4f79c432a9e0b23b05e3725c69e7ab201097d Mon Sep 17 00:00:00 2001
From: Michael Burgardt <burgardt@itc.rwth-aachen.de>
Date: Thu, 27 Oct 2022 15:27:21 +0200
Subject: [PATCH] ISSUE-205 Reload page after deploying new SSH key

By reloading the page after deploy the key becomes "fully accessable" and immediate deletion is no longer a problem
---
 .../kit/scc/webreg/bean/UserSshKeyManagementBean.java    | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/bwreg-webapp/src/main/java/edu/kit/scc/webreg/bean/UserSshKeyManagementBean.java b/bwreg-webapp/src/main/java/edu/kit/scc/webreg/bean/UserSshKeyManagementBean.java
index 93f62986..3612a4e7 100644
--- a/bwreg-webapp/src/main/java/edu/kit/scc/webreg/bean/UserSshKeyManagementBean.java
+++ b/bwreg-webapp/src/main/java/edu/kit/scc/webreg/bean/UserSshKeyManagementBean.java
@@ -30,6 +30,10 @@ import edu.kit.scc.webreg.service.identity.IdentityService;
 import edu.kit.scc.webreg.service.ssh.SshPubKeyService;
 import edu.kit.scc.webreg.session.SessionManager;
 import edu.kit.scc.webreg.util.FacesMessageGenerator;
+import java.io.IOException;
+import jakarta.faces.context.ExternalContext;
+import jakarta.faces.context.FacesContext;
+import jakarta.servlet.http.HttpServletRequest;
 
 @Named
 @ViewScoped
@@ -125,12 +129,17 @@ public class UserSshKeyManagementBean implements Serializable {
 			newKey = "";
 			newName = "";
 			messageGenerator.addResolvedInfoMessage("info", "ssh_key_deployed", true);
+			ExternalContext ec = FacesContext.getCurrentInstance().getExternalContext();
+			ec.redirect(((HttpServletRequest) ec.getRequest()).getRequestURI());
 		} catch (UnsupportedKeyTypeException e) {
 			logger.warn("An error occured whilst deploying key: " + e.getMessage());
 			messageGenerator.addResolvedErrorMessage("sshKeyMessage", "error_msg", e.toString(), false);
 		} catch (SshPubKeyBlacklistedException e) {
 			logger.warn("User {} tried to deploy blacklisted key", identity.getId());
 			messageGenerator.addResolvedErrorMessage("sshKeyMessage", "error", "key_blacklisted", true);
+		} catch (IOException e) {
+			logger.warn("An error occured trying to reload page after deploying key: " + e.getMessage());
+			messageGenerator.addResolvedErrorMessage("sshKeyMessage", "error_msg", e.toString(), false);
 		}
 	}
 
-- 
GitLab