This brings back in a change that was implemented in a pull request from 2017, but got lost in the chaos of multiple pull requests from intermingling branches. This does not only provide feedback when a SSH key cannot be parsed, but it also does so in a way that the warning goes away when a correct key is added. Admittedly, I have no idea how to properly do this with a Wicket FeedbackMessage, all I could find on Google was highly complicated. Not only does this bring back (or really in) the fix for issue #1226, but it also fixes #984.pull/1277/merge
@@ -738,6 +738,8 @@ gb.emailAddressDescription = The primary email address for receiving notificatio | |||
gb.sshKeys = SSH Keys | |||
gb.sshKeysDescription = SSH public key authentication is a secure alternative to password authentication | |||
gb.addSshKey = Add SSH Key | |||
gb.addSshKeyErrorEmpty = SSH public key empty. Please provide a valid SSH public key | |||
gb.addSshKeyErrorFormat = Not a valid SSH public key format. Please provide a valid SSH public key | |||
gb.key = Key | |||
gb.sshKeyComment = Comment | |||
gb.sshKeyCommentDescription = Enter an optional comment. If blank, the comment will be extracted from the key data. |
@@ -735,6 +735,8 @@ gb.emailAddressDescription = Die prim\u00e4re Emailadresse f\u00fcr den Empfang | |||
gb.sshKeys = SSH Keys | |||
gb.sshKeysDescription = SSH Public Key Authentifizierung ist eine sichere Alternative zur Authentifizierung mit Passwort | |||
gb.addSshKey = SSH Key hinzuf\u00fcgen | |||
gb.addSshKeyErrorEmpty = SSH Public Key leer. Bitte geben Sie einen g\u00fltigen SSH Public Key an | |||
gb.addSshKeyErrorFormat = SSH Public Key Format ungültig. Bitte geben Sie einen g\u00fltigen SSH Public Key an | |||
gb.key = Key | |||
gb.sshKeyComment = Kommentar | |||
gb.sshKeyCommentDescription = Geben Sie optional einen Kommentar ein. Falls Sie dies nicht tun, wird der Kommentar aus dem Key extrahiert. |
@@ -37,7 +37,8 @@ | |||
<div wicket:id="addKeyData"></div> | |||
<div wicket:id="addKeyPermission"></div> | |||
<div wicket:id="addKeyComment"></div> | |||
<div wicket:id="addKeyFeedback"></div> | |||
<div class="form-actions"><input class="btn btn-appmenu" type="submit" value="Add" wicket:message="value:gb.add" wicket:id="addKeyButton" /></div> | |||
</form> | |||
</div> |
@@ -19,6 +19,8 @@ import java.util.ArrayList; | |||
import java.util.Arrays; | |||
import java.util.List; | |||
import com.gitblit.wicket.WicketUtils; | |||
import org.apache.wicket.Component; | |||
import org.apache.wicket.ajax.AjaxRequestTarget; | |||
import org.apache.wicket.ajax.markup.html.AjaxLink; | |||
import org.apache.wicket.ajax.markup.html.form.AjaxButton; | |||
@@ -63,6 +65,7 @@ public class SshKeysPanel extends BasePanel { | |||
setOutputMarkupId(true); | |||
final IModel<String> keyFeedback = Model.of(""); | |||
final List<SshKey> keys = new ArrayList<SshKey>(app().keys().getKeys(user.username)); | |||
final ListDataProvider<SshKey> dp = new ListDataProvider<SshKey>(keys); | |||
final DataView<SshKey> keysView = new DataView<SshKey>("keys", dp) { | |||
@@ -90,6 +93,7 @@ public class SshKeysPanel extends BasePanel { | |||
// update the panel | |||
target.addComponent(SshKeysPanel.this); | |||
} | |||
keyFeedback.setObject(""); | |||
} | |||
}; | |||
if (!canWriteKeys) { | |||
@@ -123,6 +127,10 @@ public class SshKeysPanel extends BasePanel { | |||
"span5", | |||
keyComment)); | |||
Component addKeyFeedback = new Label("addKeyFeedback", keyFeedback).setOutputMarkupId(true); | |||
WicketUtils.setCssStyle(addKeyFeedback, "color: red; font-weight: bold;"); | |||
addKeyForm.add(addKeyFeedback); | |||
addKeyForm.add(new AjaxButton("addKeyButton") { | |||
private static final long serialVersionUID = 1L; | |||
@@ -134,6 +142,8 @@ public class SshKeysPanel extends BasePanel { | |||
String data = keyData.getObject(); | |||
if (StringUtils.isEmpty(data)) { | |||
// do not submit empty key | |||
keyFeedback.setObject(getString("gb.addSshKeyErrorEmpty")); | |||
target.addComponent(addKeyFeedback); | |||
return; | |||
} | |||
@@ -142,6 +152,8 @@ public class SshKeysPanel extends BasePanel { | |||
key.getPublicKey(); | |||
} catch (Exception e) { | |||
// failed to parse the key | |||
keyFeedback.setObject(getString("gb.addSshKeyErrorFormat")); | |||
target.addComponent(addKeyFeedback); | |||
return; | |||
} | |||
@@ -163,9 +175,12 @@ public class SshKeysPanel extends BasePanel { | |||
keys.clear(); | |||
keys.addAll(app().keys().getKeys(user.username)); | |||
keyFeedback.setObject(""); | |||
// update the panel | |||
target.addComponent(SshKeysPanel.this); | |||
} | |||
else keyFeedback.setObject("Key not added."); | |||
} | |||
}); | |||