Skip to content

Commit

Permalink
GUI fixes for Yubikey setup panel
Browse files Browse the repository at this point in the history
  • Loading branch information
car031 committed Apr 27, 2023
1 parent f3a0306 commit 530fa1e
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 42 deletions.
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
package com.logicaldoc.gui.frontend.client.security.twofactorsauth;

import com.google.gwt.user.client.rpc.AsyncCallback;
import com.logicaldoc.gui.common.client.Constants;
import com.logicaldoc.gui.common.client.beans.GUIUser;
import com.logicaldoc.gui.common.client.i18n.I18N;
import com.logicaldoc.gui.common.client.log.GuiLog;
import com.logicaldoc.gui.common.client.util.ItemFactory;
import com.logicaldoc.gui.frontend.client.services.TwoFactorsAuthenticationService;
import com.smartgwt.client.types.TitleOrientation;
import com.smartgwt.client.widgets.Label;
import com.smartgwt.client.widgets.form.DynamicForm;
import com.smartgwt.client.widgets.form.fields.TextItem;
import com.smartgwt.client.widgets.form.fields.events.KeyPressEvent;
import com.smartgwt.client.widgets.form.fields.events.KeyPressHandler;

/**
* Panel for setting up the YubiKey second factor.
Expand All @@ -22,58 +17,46 @@
*/
public class YubiKeySetup extends TwoFactorsAuthenticationSetup {

private GUIUser user;

private DynamicForm form;

private Label hint;

public YubiKeySetup(GUIUser user) {
super();
setWidth100();
setHeight100();
setMembersMargin(5);
setMargin(5);

this.user = user;
// The key contains the settings
String[] settings = new String[] { null, null };
if (user.getKey() != null && user.getKey().contains("|"))
settings = user.getKey().split("\\|");

// Prepare the form with account informations
TextItem keyItem = ItemFactory.newTextItem("key", null);
keyItem.setWidth(300);
keyItem.addKeyPressHandler(new KeyPressHandler() {
@Override
public void onKeyPress(KeyPressEvent event) {
if (event.getKeyName() != null && "enter".equals(event.getKeyName().toLowerCase())) {
onSubmitKey();
}
}
});
TextItem clientId = ItemFactory.newTextItem("clientid", settings[0]);
clientId.setWidth(80);
clientId.setRequired(true);

TextItem secretKey = ItemFactory.newPasswordItem("secretkey", "secretkey", settings[1]);
secretKey.setWidth(220);
secretKey.setStartRow(true);
secretKey.setRequired(true);

form = new DynamicForm();
form.setTitleOrientation(TitleOrientation.LEFT);
form.setNumCols(4);
form.setItems(keyItem);

hint = new Label(I18N.message(Constants.TWOFA_YUBIKEY + ".hint1"));
form.setItems(clientId, secretKey);

Label hint = new Label(I18N.message(Constants.TWOFA_YUBIKEY + ".hint1"));
hint.setAutoHeight();

setMembers(hint, form);
}

private void onSubmitKey() {
TwoFactorsAuthenticationService.Instance.get().generateYubiKeyCredentials(form.getValueAsString("key"),
new AsyncCallback<String>() {
@Override
public void onFailure(Throwable caught) {
GuiLog.serverError(caught);
}

@Override
public void onSuccess(String publicId) {
key = publicId;
user.setKey(publicId);
removeMember(form);
hint.setContents(I18N.message(Constants.TWOFA_YUBIKEY + ".hint2"));
}
});
@Override
public boolean validate() {
boolean valid = form.validate();
if (valid)
super.key = form.getValueAsString("clientid") + "|" + form.getValueAsString("secretkey");
return valid;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2152,7 +2152,7 @@ secretkey = Secret Key
ignoreemptyfields = Ignore empty fields
enableyubikey = Enable YubiKey
disable2fa = Disable Two Factors Authentication
yubikey.hint1 = Please insert your YubiKey device into your computer's USB port. Select the Key field below. Then touch the gold disk on your YubiKey device for one second. Afterwards, please save. If the code generated by your YubiKey is valid the Two Factor Authentication feature will be enabled and this YubiKey will be linked with your user account.
yubikey.hint1 = Put here below your <b>Client ID</b> and <b>Secret Key</b> retrieved from <a href="https://upgrade.yubico.com/getapikey" target="_blank">https://upgrade.yubico.com/getapikey</a>
yubikey.hint2 = Now press Save to link your YubiKey to your user account. If you want to unlink your YubiKey from your user account or use another YubiKey, please first disable two factor authentication and re-activate two factor authentication with the YubiKey method.
height = Height
autoclosefoldernodes = Auto close folder nodes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2152,7 +2152,7 @@ secretkey = Secret Key
ignoreemptyfields = Ignore empty fields
enableyubikey = Enable YubiKey
disable2fa = Disable Two Factors Authentication
yubikey.hint1 = Please insert your YubiKey device into your computer's USB port. Select the Key field below. Then touch the gold disk on your YubiKey device for one second. Afterwards, please save. If the code generated by your YubiKey is valid the Two Factor Authentication feature will be enabled and this YubiKey will be linked with your user account.
yubikey.hint1 = Put here below your <b>Client ID</b> and <b>Secret Key</b> retrieved from <a href="https://upgrade.yubico.com/getapikey" target="_blank">https://upgrade.yubico.com/getapikey</a>
yubikey.hint2 = Now press Save to link your YubiKey to your user account. If you want to unlink your YubiKey from your user account or use another YubiKey, please first disable two factor authentication and re-activate two factor authentication with the YubiKey method.
height = Height
autoclosefoldernodes = Auto close folder nodes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2152,7 +2152,7 @@ secretkey = Secret Key
ignoreemptyfields = Ignore empty fields
enableyubikey = Enable YubiKey
disable2fa = Disable Two Factors Authentication
yubikey.hint1 = Please insert your YubiKey device into your computer's USB port. Select the Key field below. Then touch the gold disk on your YubiKey device for one second. Afterwards, please save. If the code generated by your YubiKey is valid the Two Factor Authentication feature will be enabled and this YubiKey will be linked with your user account.
yubikey.hint1 = Put here below your <b>Client ID</b> and <b>Secret Key</b> retrieved from <a href="https://upgrade.yubico.com/getapikey" target="_blank">https://upgrade.yubico.com/getapikey</a>
yubikey.hint2 = Now press Save to link your YubiKey to your user account. If you want to unlink your YubiKey from your user account or use another YubiKey, please first disable two factor authentication and re-activate two factor authentication with the YubiKey method.
height = Height
autoclosefoldernodes = Auto close folder nodes
Expand Down

0 comments on commit 530fa1e

Please sign in to comment.