diff --git a/logicaldoc-gui/src/main/java/com/logicaldoc/gui/frontend/client/security/twofactorsauth/YubiKeySetup.java b/logicaldoc-gui/src/main/java/com/logicaldoc/gui/frontend/client/security/twofactorsauth/YubiKeySetup.java index e1c778b0a..4b3e88cc2 100644 --- a/logicaldoc-gui/src/main/java/com/logicaldoc/gui/frontend/client/security/twofactorsauth/YubiKeySetup.java +++ b/logicaldoc-gui/src/main/java/com/logicaldoc/gui/frontend/client/security/twofactorsauth/YubiKeySetup.java @@ -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. @@ -22,12 +17,8 @@ */ public class YubiKeySetup extends TwoFactorsAuthenticationSetup { - private GUIUser user; - private DynamicForm form; - private Label hint; - public YubiKeySetup(GUIUser user) { super(); setWidth100(); @@ -35,45 +26,37 @@ public YubiKeySetup(GUIUser user) { 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() { - @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; } } \ No newline at end of file diff --git a/logicaldoc-i18n/src/main/resources/i18n/messages.properties b/logicaldoc-i18n/src/main/resources/i18n/messages.properties index 6ddf8bf93..f500fedf3 100644 --- a/logicaldoc-i18n/src/main/resources/i18n/messages.properties +++ b/logicaldoc-i18n/src/main/resources/i18n/messages.properties @@ -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 Client ID and Secret Key retrieved from https://upgrade.yubico.com/getapikey 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 diff --git a/logicaldoc-i18n/src/main/resources/i18n/messages_en.properties b/logicaldoc-i18n/src/main/resources/i18n/messages_en.properties index 6ddf8bf93..f500fedf3 100644 --- a/logicaldoc-i18n/src/main/resources/i18n/messages_en.properties +++ b/logicaldoc-i18n/src/main/resources/i18n/messages_en.properties @@ -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 Client ID and Secret Key retrieved from https://upgrade.yubico.com/getapikey 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 diff --git a/logicaldoc-i18n/src/main/resources/i18n/messages_en_US.properties b/logicaldoc-i18n/src/main/resources/i18n/messages_en_US.properties index 9565e6775..c47eacf14 100644 --- a/logicaldoc-i18n/src/main/resources/i18n/messages_en_US.properties +++ b/logicaldoc-i18n/src/main/resources/i18n/messages_en_US.properties @@ -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 Client ID and Secret Key retrieved from https://upgrade.yubico.com/getapikey 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