From f180a7e254d204aaa645ff4fd4e5fff7b1d7c47b Mon Sep 17 00:00:00 2001 From: Jakob Heher Date: Wed, 5 Oct 2022 13:58:26 +0200 Subject: add waiting-for-app support (starting to rip some old stuff out) --- .../composites/MobileBKUEnterNumberComposite.java | 289 ----------------- .../gui/composites/MobileBKUEnterTANComposite.java | 350 --------------------- .../composites/MobileBKUFingerprintComposite.java | 296 ----------------- .../gui/composites/MobileBKUQRComposite.java | 252 --------------- .../gui/composites/WaitingForAppComposite.java | 192 ----------- .../composites/configuration/AboutComposite.java | 5 - .../mobilebku/MobileBKUEnterNumberComposite.java | 289 +++++++++++++++++ .../mobilebku/MobileBKUEnterTANComposite.java | 349 ++++++++++++++++++++ .../mobilebku/MobileBKUFingerprintComposite.java | 292 +++++++++++++++++ .../composites/mobilebku/MobileBKUQRComposite.java | 252 +++++++++++++++ .../mobilebku/WaitingForAppComposite.java | 121 +++++++ 11 files changed, 1303 insertions(+), 1384 deletions(-) delete mode 100644 pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/MobileBKUEnterNumberComposite.java delete mode 100644 pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/MobileBKUEnterTANComposite.java delete mode 100644 pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/MobileBKUFingerprintComposite.java delete mode 100644 pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/MobileBKUQRComposite.java delete mode 100644 pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/WaitingForAppComposite.java create mode 100644 pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/mobilebku/MobileBKUEnterNumberComposite.java create mode 100644 pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/mobilebku/MobileBKUEnterTANComposite.java create mode 100644 pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/mobilebku/MobileBKUFingerprintComposite.java create mode 100644 pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/mobilebku/MobileBKUQRComposite.java create mode 100644 pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/mobilebku/WaitingForAppComposite.java (limited to 'pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites') diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/MobileBKUEnterNumberComposite.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/MobileBKUEnterNumberComposite.java deleted file mode 100644 index 6c75b160..00000000 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/MobileBKUEnterNumberComposite.java +++ /dev/null @@ -1,289 +0,0 @@ -/* - * Copyright 2012 by A-SIT, Secure Information Technology Center Austria - * - * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by - * the European Commission - subsequent versions of the EUPL (the "Licence"); - * You may not use this work except in compliance with the Licence. - * You may obtain a copy of the Licence at: - * http://joinup.ec.europa.eu/software/page/eupl - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the Licence is distributed on an "AS IS" basis, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the Licence for the specific language governing permissions and - * limitations under the Licence. - */ -package at.asit.pdfover.gui.composites; - -// Imports -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.events.SelectionListener; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.graphics.ImageData; -import org.eclipse.swt.graphics.Rectangle; -import org.eclipse.swt.layout.FormLayout; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Text; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import at.asit.pdfover.commons.Constants; -import at.asit.pdfover.gui.bku.OLDmobile.MobileBKUHelper; -import at.asit.pdfover.gui.exceptions.InvalidPasswordException; -import at.asit.pdfover.gui.utils.SWTUtils; -import at.asit.pdfover.commons.Messages; -import at.asit.pdfover.gui.workflow.states.State; - -/** - * Composite for entering the phone number for the mobile BKU - */ -public class MobileBKUEnterNumberComposite extends StateComposite { - /** - * SLF4J Logger instance - **/ - static final Logger log = LoggerFactory.getLogger(MobileBKUEnterNumberComposite.class); - - /** - * - */ - private final SelectionListener okListener = new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - if (!MobileBKUEnterNumberComposite.this.btn_ok.isEnabled()) { - return; - } - - try { - String number = MobileBKUEnterNumberComposite.this.txt_number.getText(); - - MobileBKUEnterNumberComposite.this.setMobileNumber(number); - - String password = MobileBKUEnterNumberComposite.this.txt_password.getText(); - - MobileBKUHelper.validatePassword(password); - - MobileBKUEnterNumberComposite.this.mobilePassword = password; - MobileBKUEnterNumberComposite.this.userAck = true; - - MobileBKUEnterNumberComposite.this.btn_ok.setEnabled(false); - - } catch(InvalidPasswordException ex) { - log.info("Validating input for Mobile BKU failed!", ex); - MobileBKUEnterNumberComposite.this.setErrorMessage(ex.getMessage()); - MobileBKUEnterNumberComposite.this.txt_password.setFocus(); - } catch (Exception ex) { - log.info("Validating input for Mobile BKU failed!", ex); - MobileBKUEnterNumberComposite.this.setErrorMessage(Messages.getString("error.InvalidPhoneNumber")); - MobileBKUEnterNumberComposite.this.txt_number.setFocus(); - return; - } - } - }; - - /** - * - */ - private final SelectionListener cancelListener = new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - MobileBKUEnterNumberComposite.this.userCancel = true; - } - }; - - - String mobileNumber; - - String mobilePassword; - - Text txt_number; - - Text txt_password; - - String errorMessage = null; - - public boolean userAck = false; - public boolean userCancel = false; - - - private Label lbl_error; - private Label lbl_password; - private Label lbl_number; - - Button btn_ok; - Button btn_cancel; - Button btn_remember; - - /** - * @return the errorMessage - */ - public String getErrorMessage() { - return this.errorMessage; - } - - /** - * @param errorMessage - * the errorMessage to set - */ - public void setErrorMessage(String errorMessage) { - this.errorMessage = errorMessage; - - if (this.errorMessage != null) { - this.lbl_error.setText(this.errorMessage); - } else { - this.lbl_error.setText(""); - } - } - - public boolean isRememberPassword() { return this.btn_remember.getSelection(); } - public void setRememberPassword(boolean state) { this.btn_remember.setSelection(state); } - - /** - * Create the composite. - * - * @param parent - * @param style - * @param state - */ - public MobileBKUEnterNumberComposite(Composite parent, int style, State state) { - super(parent, style, state); - setLayout(new FormLayout()); - - final Composite containerComposite = new Composite(this, SWT.NATIVE); - containerComposite.addPaintListener(e -> { - Rectangle clientArea = containerComposite.getClientArea(); - - //e.gc.setForeground(); - e.gc.setForeground(Constants.MAINBAR_ACTIVE_BACK_DARK); - e.gc.setLineWidth(3); - e.gc.setLineStyle(SWT.LINE_SOLID); - e.gc.drawRoundRectangle(clientArea.x, - clientArea.y, clientArea.width - 2, clientArea.height - 2, - 10, 10); - }); - containerComposite.setLayout(new FormLayout()); - SWTUtils.anchor(containerComposite).top(50, -120).bottom(50, 120).left(50, -200).right(50, 200); - - this.txt_number = new Text(containerComposite, SWT.SINGLE | SWT.NATIVE | SWT.BORDER); - SWTUtils.anchor(txt_number).bottom(50, -10).left(50, 10).right(100, -20); - this.txt_number.setEditable(true); - - this.lbl_number = new Label(containerComposite, SWT.NATIVE); - this.lbl_number.setAlignment(SWT.RIGHT); - SWTUtils.anchor(lbl_number).bottom(50, -10).right(50, -10); - - ImageData mobileIconData = new ImageData(this.getClass().getResourceAsStream(Constants.RES_IMG_MOBILE)); - Image mobileIcon = new Image(getDisplay(), mobileIconData); - - Label lbl_image = new Label(containerComposite, SWT.NATIVE); - SWTUtils.anchor(lbl_image).top(20, -1 * (mobileIconData.width / 2)).bottom(20, mobileIconData.width / 2).left(0, 10).width(mobileIconData.width); - lbl_image.setImage(mobileIcon); - - this.txt_password = new Text(containerComposite, SWT.SINGLE | SWT.PASSWORD | SWT.BORDER | SWT.NATIVE); - SWTUtils.anchor(txt_password).top(50, 10).left(50, 10).right(100, -20); - this.txt_password.setEditable(true); - - this.lbl_password = new Label(containerComposite, SWT.NATIVE); - SWTUtils.anchor(lbl_password).top(50, 10).right(50, -10); - this.lbl_password.setAlignment(SWT.RIGHT); - - this.btn_ok = new Button(containerComposite, SWT.NATIVE); - SWTUtils.anchor(btn_ok).bottom(100, -20).right(100, -20); - this.btn_ok.addSelectionListener(this.okListener); - - this.btn_cancel = new Button(containerComposite, SWT.NATIVE); - SWTUtils.anchor(btn_cancel).bottom(100, -20).right(btn_ok, -10); - this.btn_cancel.addSelectionListener(this.cancelListener); - - this.lbl_error = new Label(containerComposite, SWT.WRAP | SWT.NATIVE ); - SWTUtils.anchor(lbl_error).bottom(103, -20).left(5, 0).right(btn_cancel, -10); - - this.btn_remember = new Button(containerComposite, SWT.CHECK); - SWTUtils.anchor(btn_remember).right(100, -10).top(0, 5); - } - - @Override - protected void checkSubclass() { - // Disable the check that prevents subclassing of SWT components - } - - /** - * enables submit button - */ - public void enableButton() { - this.btn_ok.setEnabled(true); - } - - /** - * (non-Javadoc) - * - * @see at.asit.pdfover.gui.composites.StateComposite#doLayout() - */ - @Override - public void doLayout() { - getShell().setDefaultButton(this.btn_ok); - } - - /** - * @return the mobileNumber - */ - public String getMobileNumber() { - return this.mobileNumber; - } - - /** - * @param mobileNumber - * the mobileNumber to set - */ - public void setMobileNumber(String mobileNumber) { - this.mobileNumber = mobileNumber; - - if (this.mobileNumber != null && !this.mobileNumber.isEmpty()) { - this.txt_number.setText(this.mobileNumber); - this.txt_password.setFocus(); - } else { - this.txt_number.setText(""); - } - } - - /** - * @return the mobilePassword - */ - public String getMobilePassword() { - return this.mobilePassword; - } - - - - /** - * @param mobilePassword - * the mobilePassword to set - */ - public void setMobilePassword(String mobilePassword) { - this.mobilePassword = mobilePassword; - - if (this.mobilePassword != null) { - this.txt_password.setText(this.mobilePassword); - } else { - this.txt_password.setText(""); - } - } - - /** (non-Javadoc) - * @see at.asit.pdfover.gui.composites.StateComposite#reloadResources() - */ - @Override - public void reloadResources() { - SWTUtils.setLocalizedText(lbl_number, "mobileBKU.number"); - SWTUtils.setLocalizedText(lbl_password, "mobileBKU.password"); - SWTUtils.setLocalizedText(btn_remember, "mobileBKU.rememberPassword"); - SWTUtils.setLocalizedText(btn_ok, "common.Ok"); - SWTUtils.setLocalizedText(btn_cancel, "common.Cancel"); - - SWTUtils.setLocalizedToolTipText(btn_remember, "mobileBKU.rememberPasswordNote"); - } - -} diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/MobileBKUEnterTANComposite.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/MobileBKUEnterTANComposite.java deleted file mode 100644 index 6b52709e..00000000 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/MobileBKUEnterTANComposite.java +++ /dev/null @@ -1,350 +0,0 @@ -/* - * Copyright 2012 by A-SIT, Secure Information Technology Center Austria - * - * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by - * the European Commission - subsequent versions of the EUPL (the "Licence"); - * You may not use this work except in compliance with the Licence. - * You may obtain a copy of the Licence at: - * http://joinup.ec.europa.eu/software/page/eupl - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the Licence is distributed on an "AS IS" basis, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the Licence for the specific language governing permissions and - * limitations under the Licence. - */ -package at.asit.pdfover.gui.composites; - -// Imports -import java.awt.Desktop; -import java.net.URI; - -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.ModifyEvent; -import org.eclipse.swt.events.ModifyListener; -import org.eclipse.swt.events.PaintEvent; -import org.eclipse.swt.events.PaintListener; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.events.TraverseEvent; -import org.eclipse.swt.events.TraverseListener; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.graphics.ImageData; -import org.eclipse.swt.graphics.Rectangle; -import org.eclipse.swt.layout.FormLayout; -import org.eclipse.swt.program.Program; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Link; -import org.eclipse.swt.widgets.Text; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.beust.jcommander.internal.Nullable; - -import at.asit.pdfover.commons.Constants; -import at.asit.pdfover.commons.Messages; -import at.asit.pdfover.gui.bku.OLDmobile.ATrustStatus; -import at.asit.pdfover.gui.utils.SWTUtils; -import at.asit.pdfover.gui.workflow.states.State; - -/** - * Composite for entering the TAN for the mobile BKU - */ -public class MobileBKUEnterTANComposite extends StateComposite { - - /** - * - */ - private final class OkSelectionListener extends SelectionAdapter { - - @Override - public void widgetSelected(SelectionEvent e) { - if(!MobileBKUEnterTANComposite.this.btn_ok.getEnabled()) { - return; - } - - String tan = MobileBKUEnterTANComposite.this.txt_tan.getText(); - - tan = tan.trim(); - - if (tan.isEmpty()) { - MobileBKUEnterTANComposite.this.setMessage(Messages - .getString("error.NoTan")); - return; - } - - if (MobileBKUEnterTANComposite.this.refVal.startsWith(tan)) { - MobileBKUEnterTANComposite.this.setMessage(Messages - .getString("error.EnteredReferenceValue")); - return; - } - - if (tan.length() > 6) { - MobileBKUEnterTANComposite.this.setMessage(Messages - .getString("error.TanTooLong")); - return; - } - - MobileBKUEnterTANComposite.this.tan = tan; - MobileBKUEnterTANComposite.this.userAck = true; - } - } - - /** - * SLF4J Logger instance - **/ - static final Logger log = LoggerFactory.getLogger(MobileBKUEnterTANComposite.class); - - private Text txt_tan; - - private boolean userAck = false; - private boolean userCancel = false; - private boolean userFido2 = false; - - private Label lblRefVal; - - private String refVal; - - private URI signatureDataURI; - - /** - * @param signatureData - * the signatureData to set - */ - public void setSignatureDataURI(@Nullable URI uri) { - this.signatureDataURI = uri; - this.lnk_sig_data.setEnabled(uri != null); - } - - private String tan; - - private Link lnk_sig_data; - - private Label lblTries; - private Label lblRefValLabel; - private Label lblTan; - - private Button btn_ok; - private Button btn_cancel; - private Button btn_fido2; - - public boolean isDone() { return (this.userAck || this.userCancel || this.userFido2); } - public boolean isUserAck() { return this.userAck; } - public boolean isUserCancel() { return this.userCancel; } - public boolean isUserFido2() { return this.userFido2; } - - public void reset() { this.userAck = this.userCancel = this.userFido2 = false; } - - /** - * Set how many tries are left - * - * @param tries - */ - public void setTries(int tries) { - if ((tries > 0) && (tries < ATrustStatus.MOBILE_MAX_TAN_TRIES)) { - if (tries > 1) - SWTUtils.setLocalizedText(lblTries, "tanEnter.try"); - else - SWTUtils.setLocalizedText(lblTries, "tanEnter.tries", tries); - } - } - - /** - * Set an error message - * @param errorMessage the error message - */ - public void setErrorMessage(String errorMessage) { - if (errorMessage == null) - this.lblTries.setText(""); - else - this.lblTries.setText( - Messages.getString("error.Title") + ": " + errorMessage); - } - - public void setFIDO2Enabled(boolean state) { - this.btn_fido2.setEnabled(state); - } - - /** - * Sets the message - * - * @param msg - */ - public void setMessage(String msg) { - this.lblTries.setText(msg); - this.lblTries.redraw(); - this.lblTries.getParent().layout(true, true); - } - - /** - * @return the reference value - */ - public String getRefVal() { - return this.refVal; - } - - /** - * @param refVal - * the reference value to set - */ - public void setRefVal(String refVal) { - this.refVal = refVal.trim(); - - if (this.refVal != null) { - this.lblRefVal.setText(this.refVal); - } else { - this.lblRefVal.setText(""); - } - - } - - /** - * @return the tan - */ - public String getTan() { - return this.tan; - } - - /** - * @param tan - * the tan to set - */ - public void setTan(String tan) { - this.tan = tan; - - if (this.tan == null) { - this.txt_tan.setText(""); - } else { - this.txt_tan.setText(this.tan); - } - } - - /** - * Create the composite. - * - * @param parent - * @param style - * @param state - */ - public MobileBKUEnterTANComposite(Composite parent, int style, State state) { - super(parent, style, state); - setLayout(new FormLayout()); - - final Composite containerComposite = new Composite(this, SWT.NATIVE); - containerComposite.addPaintListener(new PaintListener() { - @Override - public void paintControl(PaintEvent e) { - Rectangle clientArea = containerComposite.getClientArea(); - - // e.gc.setForeground(); - e.gc.setForeground(Constants.MAINBAR_ACTIVE_BACK_DARK); - e.gc.setLineWidth(3); - e.gc.setLineStyle(SWT.LINE_SOLID); - e.gc.drawRoundRectangle(clientArea.x, clientArea.y, - clientArea.width - 2, clientArea.height - 2, 10, 10); - } - }); - containerComposite.setLayout(new FormLayout()); - SWTUtils.anchor(containerComposite).top(50, -120).bottom(50, 120).left(50, -200).right(50, 200); - - this.lblRefValLabel = new Label(containerComposite, SWT.NATIVE); - SWTUtils.anchor(lblRefValLabel).right(50, -10).bottom(50,-10); - SWTUtils.setLocalizedText(lblRefValLabel, "tanEnter.ReferenceValue"); - this.lblRefValLabel.setAlignment(SWT.RIGHT); - - ImageData mobileIcon = new ImageData(this.getClass().getResourceAsStream(Constants.RES_IMG_MOBILE)); - Label lbl_image = new Label(containerComposite, SWT.NATIVE); - SWTUtils.anchor(lbl_image).top(50, -1 * (mobileIcon.width / 2)).bottom(50, mobileIcon.width / 2).left(0, 10).width(mobileIcon.width); - lbl_image.setImage(new Image(getDisplay(), mobileIcon)); - - this.lblRefVal = new Label(containerComposite, SWT.NATIVE); - SWTUtils.anchor(lblRefVal).left(50,10).right(100,-20).bottom(50,-10); - this.lblRefVal.setText(""); - - this.lblTan = new Label(containerComposite, SWT.NATIVE); - SWTUtils.anchor(lblTan).right(50,-10).top(50,10); - SWTUtils.setLocalizedText(lblTan, "tanEnter.TAN"); - this.lblTan.setAlignment(SWT.RIGHT); - - this.txt_tan = new Text(containerComposite, SWT.BORDER | SWT.NATIVE); - SWTUtils.anchor(txt_tan).left(50,10).right(100,-20).top(50,10); - this.txt_tan.setEditable(true); - - this.txt_tan.addTraverseListener(new TraverseListener() { - @Override - public void keyTraversed(TraverseEvent e) { - if (e.detail == SWT.TRAVERSE_RETURN) { - if(MobileBKUEnterTANComposite.this.btn_ok.isEnabled()) { - (new OkSelectionListener()).widgetSelected(null); - } - } - } - }); - - this.txt_tan.addModifyListener(new ModifyListener() { - @Override - public void modifyText(ModifyEvent e) { - - String text = MobileBKUEnterTANComposite.this.txt_tan.getText(); - //log.debug("Current TAN: " + text); - if (text.length() > 3 - && MobileBKUEnterTANComposite.this.getRefVal() - .startsWith(text.trim())) { - MobileBKUEnterTANComposite.this.setMessage(Messages.getString("error.EnteredReferenceValue")); - } - } - }); - - this.lnk_sig_data = new Link(containerComposite, SWT.NATIVE | SWT.RESIZE); - SWTUtils.anchor(lnk_sig_data).right(100,-20).top(0,20); - lnk_sig_data.setEnabled(true); - SWTUtils.addSelectionListener(lnk_sig_data, (e) -> { SWTUtils.openURL(this.signatureDataURI); }); - - this.btn_ok = new Button(containerComposite, SWT.NATIVE); - SWTUtils.anchor(btn_ok).right(100,-20).bottom(100,-20); - this.btn_ok.addSelectionListener(new OkSelectionListener()); - - this.btn_cancel = new Button(containerComposite, SWT.NATIVE); - SWTUtils.anchor(btn_cancel).right(btn_ok, -20).bottom(100, -20); - SWTUtils.addSelectionListener(btn_cancel, (e) -> { this.userCancel = true; }); - - this.btn_fido2 = new Button(containerComposite, SWT.NATIVE); - SWTUtils.anchor(btn_fido2).right(btn_cancel, -20).bottom(100, -20); - SWTUtils.addSelectionListener(btn_fido2, (e) -> { this.userFido2 = true; }); - - this.lblTries = new Label(containerComposite, SWT.WRAP | SWT.NATIVE); - SWTUtils.anchor(lblTries).right(btn_fido2, -10).bottom(100, -20); - } - - @Override - protected void checkSubclass() { - // Disable the check that prevents subclassing of SWT components - } - - /* - * (non-Javadoc) - * - * @see at.asit.pdfover.gui.composites.StateComposite#doLayout() - */ - @Override - public void doLayout() { - // Nothing to do - } - - /* - * (non-Javadoc) - * - * @see at.asit.pdfover.gui.composites.StateComposite#reloadResources() - */ - @Override - public void reloadResources() { - SWTUtils.setLocalizedText(lnk_sig_data, "mobileBKU.show"); - SWTUtils.setLocalizedToolTipText(lnk_sig_data, "mobileBKU.show_tooltip"); - SWTUtils.setLocalizedText(lblRefValLabel, "tanEnter.ReferenceValue"); - SWTUtils.setLocalizedText(lblTan, "tanEnter.TAN"); - SWTUtils.setLocalizedText(btn_cancel, "common.Cancel"); - SWTUtils.setLocalizedText(btn_ok, "common.Ok"); - } -} diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/MobileBKUFingerprintComposite.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/MobileBKUFingerprintComposite.java deleted file mode 100644 index afa71f9f..00000000 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/MobileBKUFingerprintComposite.java +++ /dev/null @@ -1,296 +0,0 @@ -/* - * Copyright 2012 by A-SIT, Secure Information Technology Center Austria - * - * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by - * the European Commission - subsequent versions of the EUPL (the "Licence"); - * You may not use this work except in compliance with the Licence. - * You may obtain a copy of the Licence at: - * http://joinup.ec.europa.eu/software/page/eupl - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the Licence is distributed on an "AS IS" basis, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the Licence for the specific language governing permissions and - * limitations under the Licence. - */ -package at.asit.pdfover.gui.composites; - -// Imports -import java.awt.Desktop; -import java.net.URI; - -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.PaintEvent; -import org.eclipse.swt.events.PaintListener; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.graphics.ImageData; -import org.eclipse.swt.graphics.Rectangle; -import org.eclipse.swt.layout.FormLayout; -import org.eclipse.swt.program.Program; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Link; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import at.asit.pdfover.commons.Constants; -import at.asit.pdfover.commons.Messages; -import at.asit.pdfover.gui.utils.SWTUtils; -import at.asit.pdfover.gui.workflow.states.State; - -/** - * Composite for displaying the QR code for the mobile BKU - */ -public class MobileBKUFingerprintComposite extends StateComposite { - - /** - * - */ - private final class SMSSelectionListener extends SelectionAdapter { - /** - * Empty constructor - */ - public SMSSelectionListener() { - } - - @Override - public void widgetSelected(SelectionEvent e) { - if(!MobileBKUFingerprintComposite.this.btn_sms.getEnabled()) { - return; - } - - MobileBKUFingerprintComposite.this.setUserSMS(true); - MobileBKUFingerprintComposite.this.btn_sms.setEnabled(false); - } - } - - /** - * - */ - private final class CancelSelectionListener extends SelectionAdapter { - /** - * Empty constructor - */ - public CancelSelectionListener() { - } - - @Override - public void widgetSelected(SelectionEvent e) { - MobileBKUFingerprintComposite.this.setUserCancel(true); - } - } - - /** - * SLF4J Logger instance - **/ - static final Logger log = LoggerFactory.getLogger(MobileBKUFingerprintComposite.class); - - boolean userCancel = false; - boolean userSMS = false; - boolean done = false; - - private Label lblRefVal; - - String refVal; - - String signatureData; - - /** - * @return the signatureData - */ - public String getSignatureData() { - return this.signatureData; - } - - /** - * @param signatureData - * the signatureData to set - */ - public void setSignatureData(String signatureData) { - this.signatureData = signatureData; - } - - private Label lblError; - private Label lblRefValLabel; - private Label lblFPLabel; - - Button btn_sms; - Button btn_cancel; - - Link lnk_sig_data; - - /** - * @return the userCancel - */ - public boolean isUserCancel() { - return this.userCancel; - } - - /** - * @return the userSMS - */ - public boolean isUserSMS() { - return this.userSMS; - } - - /** - * @return the done - */ - public boolean isDone() { - return this.done; - } - - /** - * Set an error message - * @param errorMessage the error message - */ - public void setErrorMessage(String errorMessage) { - if (errorMessage == null) - this.lblError.setText(""); - else - this.lblError.setText( - Messages.getString("error.Title") + ": " + errorMessage); - } - - /** - * @param userCancel - * the userCancel to set - */ - public void setUserCancel(boolean userCancel) { - this.userCancel = userCancel; - } - - /** - * @param userSMS - * the userSMS to set - */ - public void setUserSMS(boolean userSMS) { - this.userSMS = userSMS; - } - - /** - * @param done - * the done to set - */ - public void setDone(boolean done) { - this.done = done; - } - - /** - * @return the reference value - */ - public String getRefVal() { - return this.refVal; - } - - /** - * @param refVal - * the reference value to set - */ - public void setRefVal(String refVal) { - - if (this.refVal != null) { - this.refVal = refVal.trim(); - this.lblRefVal.setText(this.refVal); - } else { - this.lblRefVal.setText(""); - } - - } - - /** - * Create the composite. - * - * @param parent - * @param style - * @param state - */ - public MobileBKUFingerprintComposite(Composite parent, int style, State state) { - super(parent, style, state); - setLayout(new FormLayout()); - - final Composite containerComposite = new Composite(this, SWT.NATIVE); - containerComposite.addPaintListener(new PaintListener() { - @Override - public void paintControl(PaintEvent e) { - Rectangle clientArea = containerComposite.getClientArea(); - - // e.gc.setForeground(); - e.gc.setForeground(Constants.MAINBAR_ACTIVE_BACK_DARK); - e.gc.setLineWidth(3); - e.gc.setLineStyle(SWT.LINE_SOLID); - e.gc.drawRoundRectangle(clientArea.x, clientArea.y, - clientArea.width - 2, clientArea.height - 2, 10, 10); - } - }); - containerComposite.setLayout(new FormLayout()); - SWTUtils.anchor(containerComposite).top(50, -140).bottom(50, 140).left(50, -200).right(50, 200); - - this.lblRefValLabel = new Label(containerComposite, SWT.NATIVE); - SWTUtils.anchor(lblRefValLabel).right(50, -10).top(30, -10); - this.lblRefValLabel.setAlignment(SWT.RIGHT); - - ImageData mobileIcon = new ImageData(this.getClass().getResourceAsStream(Constants.RES_IMG_MOBILE)); - Label lbl_image = new Label(containerComposite, SWT.NATIVE); - SWTUtils.anchor(lbl_image).top(50, -1 * (mobileIcon.width / 2)).bottom(50, mobileIcon.width / 2).left(0, 10).width(mobileIcon.width); - lbl_image.setImage(new Image(getDisplay(), mobileIcon)); - - this.lblRefVal = new Label(containerComposite, SWT.NATIVE); - SWTUtils.anchor(lblRefVal).left(50, 10).right(100, -20).top(30, -10); - - this.lblFPLabel = new Label(containerComposite, SWT.NATIVE); - SWTUtils.anchor(lblFPLabel).left(25, 10).top(lblRefValLabel, 10); - this.lblFPLabel.setAlignment(SWT.LEFT); - - this.lnk_sig_data = new Link(containerComposite, SWT.NATIVE | SWT.RESIZE); - SWTUtils.anchor(lnk_sig_data).right(100, -20).top(0, 20); - this.lnk_sig_data.setEnabled(true); - SWTUtils.addSelectionListener(lnk_sig_data, (e) -> { SWTUtils.openURL(getSignatureData()); }); - - this.btn_cancel = new Button(containerComposite, SWT.NATIVE); - SWTUtils.anchor(btn_cancel).right(100, -20).bottom(100, -20); - this.btn_cancel.addSelectionListener(new CancelSelectionListener()); - - this.btn_sms = new Button(containerComposite, SWT.NATIVE); - SWTUtils.anchor(btn_sms).right(btn_cancel, -20).bottom(100, -20); - this.btn_sms.addSelectionListener(new SMSSelectionListener()); - - this.lblError = new Label(containerComposite, SWT.WRAP | SWT.NATIVE); - SWTUtils.anchor(lblError).right(btn_sms, -10).bottom(100, -20); - - reloadResources(); - } - - @Override - protected void checkSubclass() { - // Disable the check that prevents subclassing of SWT components - } - - /* - * (non-Javadoc) - * - * @see at.asit.pdfover.gui.composites.StateComposite#doLayout() - */ - @Override - public void doLayout() { - // Nothing to do - } - - /* - * (non-Javadoc) - * - * @see at.asit.pdfover.gui.composites.StateComposite#reloadResources() - */ - @Override - public void reloadResources() { - SWTUtils.setLocalizedText(lblRefValLabel, "tanEnter.ReferenceValue"); - SWTUtils.setLocalizedText(lblFPLabel, "tanEnter.FP"); - SWTUtils.setLocalizedText(lnk_sig_data, "mobileBKU.show"); - SWTUtils.setLocalizedToolTipText(lnk_sig_data, "mobileBKU.show_tooltip"); - SWTUtils.setLocalizedText(btn_cancel, "common.Cancel"); - SWTUtils.setLocalizedText(btn_sms, "tanEnter.SMS"); - } -} diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/MobileBKUQRComposite.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/MobileBKUQRComposite.java deleted file mode 100644 index baabc192..00000000 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/MobileBKUQRComposite.java +++ /dev/null @@ -1,252 +0,0 @@ -/* - * Copyright 2012 by A-SIT, Secure Information Technology Center Austria - * - * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by - * the European Commission - subsequent versions of the EUPL (the "Licence"); - * You may not use this work except in compliance with the Licence. - * You may obtain a copy of the Licence at: - * http://joinup.ec.europa.eu/software/page/eupl - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the Licence is distributed on an "AS IS" basis, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the Licence for the specific language governing permissions and - * limitations under the Licence. - */ -package at.asit.pdfover.gui.composites; - -// Imports -import java.io.ByteArrayInputStream; -import java.net.URI; -import java.util.Objects; - -import javax.annotation.Nullable; - -import org.eclipse.swt.SWT; -import org.eclipse.swt.SWTException; -import org.eclipse.swt.events.PaintEvent; -import org.eclipse.swt.events.PaintListener; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.graphics.ImageData; -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.graphics.Rectangle; -import org.eclipse.swt.layout.FormLayout; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Link; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import at.asit.pdfover.commons.Constants; -import at.asit.pdfover.commons.Messages; -import at.asit.pdfover.gui.utils.SWTUtils; -import at.asit.pdfover.gui.workflow.states.State; - -/** - * Composite for displaying the QR code for the mobile BKU - */ -public class MobileBKUQRComposite extends StateComposite { - - /** - * SLF4J Logger instance - **/ - private static final Logger log = LoggerFactory.getLogger(MobileBKUQRComposite.class); - - private Label lblQR; - - private boolean userCancelClicked = false; - private boolean userSMSClicked = false; - private boolean userFIDO2Clicked = false; - private boolean pollingDone = false; - - private Label lblRefVal; - - private String refVal; - - private ImageData currentQRImage; - - private URI signatureDataURI; - - private Label lblError; - private Label lblRefValLabel; - private Label lblQRLabel; - - private Button btn_fido2; - private Button btn_sms; - private Button btn_cancel; - - private Link lnk_sig_data; - - public void signalPollingDone() { this.pollingDone = true; getDisplay().wake(); } - public boolean isDone() { return (this.userCancelClicked || this.userSMSClicked || this.userFIDO2Clicked || this.pollingDone); } - public boolean wasCancelClicked() { return this.userCancelClicked; } - public boolean wasSMSClicked() { return this.userSMSClicked; } - public boolean wasFIDO2Clicked() { return this.userFIDO2Clicked; } - public void reset() { this.userCancelClicked = this.userSMSClicked = this.userFIDO2Clicked = this.pollingDone = false; } - - /** - * Set an error message - * @param errorMessage the error message - */ - public void setErrorMessage(String errorMessage) { - if (errorMessage == null) - this.lblError.setText(""); - else - this.lblError.setText( - Messages.getString("error.Title") + ": " + errorMessage); - } - - public String getRefVal() { return this.refVal; } - public void setRefVal(String refVal) { - this.refVal = (refVal != null) ? refVal.trim() : null; - this.lblRefVal.setText(Objects.requireNonNullElse(this.refVal, "")); - } - - private void updateQRImage() { - if (this.currentQRImage == null) - return; - - Point availableSize = this.lblQR.getSize(); - int targetSize = Math.min(availableSize.x, availableSize.y); - if (targetSize <= 0) - return; - - this.lblQR.setImage(new Image(this.lblQR.getDisplay(), this.currentQRImage.scaledTo(targetSize, targetSize))); - } - - /** - * @param qrcode - * the qrcode to set - */ - public void setQR(byte[] qrcode) { - if (qrcode == null) { - setErrorMessage(Messages.getString("error.FailedToLoadQRCode")); - return; - } - try { - this.currentQRImage = new ImageData(new ByteArrayInputStream(qrcode)); - } catch (SWTException e) { - log.warn("Failed to load QR code", e); - setErrorMessage(Messages.getString("error.FailedToLoadQRCode")); - return; - } - updateQRImage(); - } - - public void setSMSEnabled(boolean state) { - this.btn_sms.setEnabled(state); - } - - public void setFIDO2Enabled(boolean state) { - this.btn_fido2.setEnabled(state); - } - - public void setSignatureDataURI(@Nullable URI uri) { - this.signatureDataURI = uri; - this.lnk_sig_data.setEnabled(uri != null); - } - - /** - * Create the composite. - * - * @param parent - * @param style - * @param state - */ - public MobileBKUQRComposite(Composite parent, int style, State state) { - super(parent, style, state); - setLayout(new FormLayout()); - - final Composite containerComposite = new Composite(this, SWT.NATIVE); - SWTUtils.anchor(containerComposite).top(50, -140).bottom(50, 140).left(50, -200).right(50, 200); - containerComposite.addPaintListener(new PaintListener() { - @Override - public void paintControl(PaintEvent e) { - Rectangle clientArea = containerComposite.getClientArea(); - - // e.gc.setForeground(); - e.gc.setForeground(Constants.MAINBAR_ACTIVE_BACK_DARK); - e.gc.setLineWidth(3); - e.gc.setLineStyle(SWT.LINE_SOLID); - e.gc.drawRoundRectangle(clientArea.x, clientArea.y, - clientArea.width - 2, clientArea.height - 2, 10, 10); - } - }); - containerComposite.setLayout(new FormLayout()); - - this.lblRefValLabel = new Label(containerComposite, SWT.NATIVE); - SWTUtils.anchor(lblRefValLabel).right(50, -10).top(30, -10); - this.lblRefValLabel.setAlignment(SWT.RIGHT); - - ImageData mobileIcon = new ImageData(this.getClass().getResourceAsStream(Constants.RES_IMG_MOBILE)); - Label lbl_image = new Label(containerComposite, SWT.NATIVE); - SWTUtils.anchor(lbl_image).top(50, -1 * (mobileIcon.width / 2)).bottom(50, mobileIcon.width / 2).left(0, 10).width(mobileIcon.width); - lbl_image.setImage(new Image(getDisplay(), mobileIcon)); - - this.lblRefVal = new Label(containerComposite, SWT.NATIVE); - SWTUtils.anchor(lblRefVal).left(50, 10).right(100, -20).top(30, -10); - - this.lblQRLabel = new Label(containerComposite, SWT.NATIVE); - SWTUtils.anchor(lblQRLabel).right(50, -10).top(lblRefValLabel, 10); - this.lblQRLabel.setAlignment(SWT.RIGHT); - - this.lblQR = new Label(containerComposite, SWT.NATIVE); - this.lblQR.addListener(SWT.Resize, (e) -> { updateQRImage(); }); - - this.lnk_sig_data = new Link(containerComposite, SWT.NATIVE | SWT.RESIZE); - SWTUtils.anchor(lnk_sig_data).right(100, -20).top(0, 20); - SWTUtils.addSelectionListener(lnk_sig_data, (e) -> { SWTUtils.openURL(this.signatureDataURI); }); - - this.btn_cancel = new Button(containerComposite, SWT.NATIVE); - SWTUtils.anchor(btn_cancel).right(100, -20).bottom(100, -5); - SWTUtils.addSelectionListener(btn_cancel, (e) -> { this.userCancelClicked = true; }); - - this.btn_sms = new Button(containerComposite, SWT.NATIVE); - SWTUtils.anchor(btn_sms).right(btn_cancel, -20).bottom(100, -5); - SWTUtils.addSelectionListener(btn_sms, (e) -> { this.userSMSClicked = true; }); - - this.btn_fido2 = new Button(containerComposite, SWT.NATIVE); - SWTUtils.anchor(btn_fido2).right(btn_sms, -20).bottom(100, -5); - SWTUtils.addSelectionListener(btn_fido2, (e) -> {this.userFIDO2Clicked = true; }); - - - SWTUtils.anchor(lblQR).left(50, 10).right(100, -20).top(lblRefVal, 10).bottom(btn_sms, -10); - - this.lblError = new Label(containerComposite, SWT.WRAP | SWT.NATIVE); - SWTUtils.anchor(lblError).right(btn_sms, -10).bottom(100, -20); - - reloadResources(); - } - - @Override - protected void checkSubclass() { - // Disable the check that prevents subclassing of SWT components - } - - /* - * (non-Javadoc) - * - * @see at.asit.pdfover.gui.composites.StateComposite#doLayout() - */ - @Override - public void doLayout() { - // Nothing to do - } - - /* - * (non-Javadoc) - * - * @see at.asit.pdfover.gui.composites.StateComposite#reloadResources() - */ - @Override - public void reloadResources() { - SWTUtils.setLocalizedText(lblRefValLabel, "tanEnter.ReferenceValue"); - SWTUtils.setLocalizedText(lblQRLabel, "tanEnter.QR"); - SWTUtils.setLocalizedText(lnk_sig_data, "mobileBKU.show"); - SWTUtils.setLocalizedToolTipText(lnk_sig_data, "mobileBKU.show_tooltip"); - SWTUtils.setLocalizedText(btn_cancel, "common.Cancel"); - SWTUtils.setLocalizedText(btn_sms, "tanEnter.SMS"); - SWTUtils.setLocalizedText(btn_fido2, "tanEnter.FIDO2"); - } -} diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/WaitingForAppComposite.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/WaitingForAppComposite.java deleted file mode 100644 index ecdece98..00000000 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/WaitingForAppComposite.java +++ /dev/null @@ -1,192 +0,0 @@ -/* - * Copyright 2012 by A-SIT, Secure Information Technology Center Austria - * - * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by - * the European Commission - subsequent versions of the EUPL (the "Licence"); - * You may not use this work except in compliance with the Licence. - * You may obtain a copy of the Licence at: - * http://joinup.ec.europa.eu/software/page/eupl - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the Licence is distributed on an "AS IS" basis, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the Licence for the specific language governing permissions and - * limitations under the Licence. - */ -package at.asit.pdfover.gui.composites; - - -// Imports -import org.eclipse.swt.SWT; -import org.eclipse.swt.layout.FormAttachment; -import org.eclipse.swt.layout.FormData; -import org.eclipse.swt.layout.FormLayout; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.ProgressBar; -import at.asit.pdfover.gui.utils.SWTUtils; -import at.asit.pdfover.gui.workflow.states.State; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; - -/** - * - */ -public class WaitingForAppComposite extends StateComposite { - private Label lbl_description; - private Button btn_sms; - private Button btn_cancel; - private Boolean isUserSMS = false; - private Boolean userCancel = false; - private Boolean isDone = false; - - /** - * @return the isDone - */ - public Boolean getIsDone() { - return this.isDone; - } - - /** - * @param isDone the isDone to set - */ - public void setIsDone(Boolean isDone) { - this.isDone = isDone; - } - - /** - * Create the composite. - * @param parent - * @param style - * @param state - */ - public WaitingForAppComposite(Composite parent, int style, State state) { - super(parent, style, state); - setLayout(new FormLayout()); - - this.lbl_description = new Label(this, SWT.NATIVE); - FormData fd_lbl_description = new FormData(); - fd_lbl_description.bottom = new FormAttachment(50, -10); - fd_lbl_description.left = new FormAttachment(0, +10); - fd_lbl_description.right = new FormAttachment(100, -10); - this.lbl_description.setLayoutData(fd_lbl_description); - this.lbl_description.setAlignment(SWT.CENTER); - SWTUtils.setLocalizedText(lbl_description, "waiting_for_app.message"); - - ProgressBar progressBar = new ProgressBar(this, SWT.HORIZONTAL | SWT.INDETERMINATE); - FormData fd_progressBar = new FormData(); - fd_progressBar.top = new FormAttachment(50, +10); - fd_progressBar.bottom = new FormAttachment(50, +40); - fd_progressBar.left = new FormAttachment(50, -100); - fd_progressBar.right = new FormAttachment(50, +100); - progressBar.setLayoutData(fd_progressBar); - - this.btn_sms = new Button(this, SWT.NONE); - this.btn_sms.addSelectionListener(new SMSSelectionListener()); - - FormData fd_btnSMS = new FormData(); - fd_btnSMS.top = new FormAttachment(progressBar, 24); - fd_btnSMS.right = new FormAttachment(progressBar, 0, SWT.RIGHT); - this.btn_sms.setLayoutData(fd_btnSMS); - SWTUtils.setLocalizedText(btn_sms, "SMS tan"); - - this.btn_cancel = new Button(this, SWT.NONE); - this.btn_cancel.addSelectionListener(new CancelSelectionListener()); - FormData fd_btnCancel = new FormData(); - fd_btnCancel.top = new FormAttachment(btn_sms, 0, SWT.TOP); - fd_btnCancel.right = new FormAttachment(btn_sms, -6); - this.btn_cancel.setLayoutData(fd_btnCancel); - SWTUtils.setLocalizedText(btn_cancel, "WaitingForAppComposite.btnCancel.text"); - - reloadResources(); - - } - - /** - * - */ - private final class CancelSelectionListener extends SelectionAdapter { - /** - * Empty constructor - */ - public CancelSelectionListener() { - } - - @Override - public void widgetSelected(SelectionEvent e) { - WaitingForAppComposite.this.setUserCancel(true); - WaitingForAppComposite.this.btn_cancel.setEnabled(false); - WaitingForAppComposite.this.btn_sms.setEnabled(false); - } - } - - private final class SMSSelectionListener extends SelectionAdapter { - /** - * Empty constructor - */ - public SMSSelectionListener() { - } - - @Override - public void widgetSelected(SelectionEvent e) { - if(!WaitingForAppComposite.this.btn_sms.getEnabled()) { - return; - } - - WaitingForAppComposite.this.setUserSMS(true); - WaitingForAppComposite.this.btn_sms.setEnabled(false); - WaitingForAppComposite.this.btn_cancel.setEnabled(false); - } - } - - public void setUserSMS(boolean b) { - this.isUserSMS = b; - } - - @Override - protected void checkSubclass() { - // Disable the check that prevents subclassing of SWT components - } - - /* (non-Javadoc) - * @see at.asit.pdfover.gui.composites.StateComposite#doLayout() - */ - @Override - public void doLayout() { - // Nothing to do here - } - - /* (non-Javadoc) - * @see at.asit.pdfover.gui.composites.StateComposite#reloadResources() - */ - @Override - public void reloadResources() { - SWTUtils.setLocalizedText(lbl_description, "waiting_for_app.message"); - SWTUtils.setLocalizedText(btn_sms, "tanEnter.SMS"); - SWTUtils.setLocalizedText(btn_cancel, "common.Cancel"); - SWTUtils.setLocalizedText(btn_sms, "tanEnter.SMS"); - } - - /** - * @return - */ - public boolean getUserCancel() { - return this.userCancel; - } - - /** - * @param b - */ - public void setUserCancel(boolean b) { - this.userCancel = b; - - } - - /** - * @return - */ - public boolean getUserSMS() { - return this.isUserSMS; - } -} diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/configuration/AboutComposite.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/configuration/AboutComposite.java index b4675e2a..07b62421 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/configuration/AboutComposite.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/configuration/AboutComposite.java @@ -2,13 +2,8 @@ package at.asit.pdfover.gui.composites.configuration; import java.awt.Desktop; import java.io.File; -import java.io.IOException; -import java.net.URI; -import java.net.URISyntaxException; import org.eclipse.swt.SWT; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.layout.FormLayout; import org.eclipse.swt.program.Program; import org.eclipse.swt.widgets.Button; diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/mobilebku/MobileBKUEnterNumberComposite.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/mobilebku/MobileBKUEnterNumberComposite.java new file mode 100644 index 00000000..575c2ad7 --- /dev/null +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/mobilebku/MobileBKUEnterNumberComposite.java @@ -0,0 +1,289 @@ +/* + * Copyright 2012 by A-SIT, Secure Information Technology Center Austria + * + * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by + * the European Commission - subsequent versions of the EUPL (the "Licence"); + * You may not use this work except in compliance with the Licence. + * You may obtain a copy of the Licence at: + * http://joinup.ec.europa.eu/software/page/eupl + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the Licence is distributed on an "AS IS" basis, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the Licence for the specific language governing permissions and + * limitations under the Licence. + */ +package at.asit.pdfover.gui.composites; + +// Imports +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.graphics.ImageData; +import org.eclipse.swt.graphics.Rectangle; +import org.eclipse.swt.layout.FormLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Text; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import at.asit.pdfover.commons.Constants; +import at.asit.pdfover.gui.bku.OLDmobile.MobileBKUHelper; +import at.asit.pdfover.gui.exceptions.InvalidPasswordException; +import at.asit.pdfover.gui.utils.SWTUtils; +import at.asit.pdfover.commons.Messages; +import at.asit.pdfover.gui.workflow.states.State; + +/** + * Composite for entering the phone number for the mobile BKU + */ +public class MobileBKUEnterNumberComposite extends StateComposite { + /** + * SLF4J Logger instance + **/ + static final Logger log = LoggerFactory.getLogger(MobileBKUEnterNumberComposite.class); + + /** + * + */ + private final SelectionListener okListener = new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + if (!MobileBKUEnterNumberComposite.this.btn_ok.isEnabled()) { + return; + } + + try { + String number = MobileBKUEnterNumberComposite.this.txt_number.getText(); + + MobileBKUEnterNumberComposite.this.setMobileNumber(number); + + String password = MobileBKUEnterNumberComposite.this.txt_password.getText(); + + MobileBKUHelper.validatePassword(password); + + MobileBKUEnterNumberComposite.this.mobilePassword = password; + MobileBKUEnterNumberComposite.this.userAck = true; + + MobileBKUEnterNumberComposite.this.btn_ok.setEnabled(false); + + } catch(InvalidPasswordException ex) { + log.info("Validating input for Mobile BKU failed!", ex); + MobileBKUEnterNumberComposite.this.setErrorMessage(ex.getMessage()); + MobileBKUEnterNumberComposite.this.txt_password.setFocus(); + } catch (Exception ex) { + log.info("Validating input for Mobile BKU failed!", ex); + MobileBKUEnterNumberComposite.this.setErrorMessage(Messages.getString("error.InvalidPhoneNumber")); + MobileBKUEnterNumberComposite.this.txt_number.setFocus(); + return; + } + } + }; + + /** + * + */ + private final SelectionListener cancelListener = new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + MobileBKUEnterNumberComposite.this.userCancel = true; + } + }; + + + String mobileNumber; + + String mobilePassword; + + Text txt_number; + + Text txt_password; + + String errorMessage = null; + + public boolean userAck = false; + public boolean userCancel = false; + + + private Label lbl_error; + private Label lbl_password; + private Label lbl_number; + + Button btn_ok; + Button btn_cancel; + Button btn_remember; + + /** + * @return the errorMessage + */ + public String getErrorMessage() { + return this.errorMessage; + } + + /** + * @param errorMessage + * the errorMessage to set + */ + public void setErrorMessage(String errorMessage) { + this.errorMessage = errorMessage; + + if (this.errorMessage != null) { + this.lbl_error.setText(this.errorMessage); + } else { + this.lbl_error.setText(""); + } + } + + public boolean isRememberPassword() { return this.btn_remember.getSelection(); } + public void setRememberPassword(boolean state) { this.btn_remember.setSelection(state); } + + /** + * Create the composite. + * + * @param parent + * @param style + * @param state + */ + public MobileBKUEnterNumberComposite(Composite parent, int style, State state) { + super(parent, style, state); + setLayout(new FormLayout()); + + final Composite containerComposite = new Composite(this, SWT.NATIVE); + containerComposite.addPaintListener(e -> { + Rectangle clientArea = containerComposite.getClientArea(); + + //e.gc.setForeground(); + e.gc.setForeground(Constants.MAINBAR_ACTIVE_BACK_DARK); + e.gc.setLineWidth(3); + e.gc.setLineStyle(SWT.LINE_SOLID); + e.gc.drawRoundRectangle(clientArea.x, + clientArea.y, clientArea.width - 2, clientArea.height - 2, + 10, 10); + }); + containerComposite.setLayout(new FormLayout()); + SWTUtils.anchor(containerComposite).top(50, -120).bottom(50, 120).left(50, -200).right(50, 200); + + this.txt_number = new Text(containerComposite, SWT.SINGLE | SWT.NATIVE | SWT.BORDER); + SWTUtils.anchor(txt_number).bottom(50, -10).left(50, 10).right(100, -20); + this.txt_number.setEditable(true); + + this.lbl_number = new Label(containerComposite, SWT.NATIVE); + this.lbl_number.setAlignment(SWT.RIGHT); + SWTUtils.anchor(lbl_number).bottom(50, -10).right(50, -10); + + ImageData mobileIconData = new ImageData(this.getClass().getResourceAsStream(Constants.RES_IMG_MOBILE)); + Image mobileIcon = new Image(getDisplay(), mobileIconData); + + Label lbl_image = new Label(containerComposite, SWT.NATIVE); + SWTUtils.anchor(lbl_image).top(20, -1 * (mobileIconData.width / 2)).bottom(20, mobileIconData.width / 2).left(0, 10).width(mobileIconData.width); + lbl_image.setImage(mobileIcon); + + this.txt_password = new Text(containerComposite, SWT.SINGLE | SWT.PASSWORD | SWT.BORDER | SWT.NATIVE); + SWTUtils.anchor(txt_password).top(50, 10).left(50, 10).right(100, -20); + this.txt_password.setEditable(true); + + this.lbl_password = new Label(containerComposite, SWT.NATIVE); + SWTUtils.anchor(lbl_password).top(50, 10).right(50, -10); + this.lbl_password.setAlignment(SWT.RIGHT); + + this.btn_ok = new Button(containerComposite, SWT.NATIVE); + SWTUtils.anchor(btn_ok).bottom(100, -20).right(100, -20); + this.btn_ok.addSelectionListener(this.okListener); + + this.btn_cancel = new Button(containerComposite, SWT.NATIVE); + SWTUtils.anchor(btn_cancel).bottom(100, -20).right(btn_ok, -10); + this.btn_cancel.addSelectionListener(this.cancelListener); + + this.lbl_error = new Label(containerComposite, SWT.WRAP | SWT.NATIVE ); + SWTUtils.anchor(lbl_error).bottom(103, -20).left(5, 0).right(btn_cancel, -10); + + this.btn_remember = new Button(containerComposite, SWT.CHECK); + SWTUtils.anchor(btn_remember).right(100, -10).top(0, 5); + } + + @Override + protected void checkSubclass() { + // Disable the check that prevents subclassing of SWT components + } + + /** + * enables submit button + */ + public void enableButton() { + this.btn_ok.setEnabled(true); + } + + /** + * (non-Javadoc) + * + * @see at.asit.pdfover.gui.composites.StateComposite#doLayout() + */ + @Override + public void doLayout() { + getShell().setDefaultButton(this.btn_ok); + } + + /** + * @return the mobileNumber + */ + public String getMobileNumber() { + return this.mobileNumber; + } + + /** + * @param mobileNumber + * the mobileNumber to set + */ + public void setMobileNumber(String mobileNumber) { + this.mobileNumber = mobileNumber; + + if (this.mobileNumber != null && !this.mobileNumber.isEmpty()) { + this.txt_number.setText(this.mobileNumber); + this.txt_password.setFocus(); + } else { + this.txt_number.setText(""); + } + } + + /** + * @return the mobilePassword + */ + public String getMobilePassword() { + return this.mobilePassword; + } + + + + /** + * @param mobilePassword + * the mobilePassword to set + */ + public void setMobilePassword(String mobilePassword) { + this.mobilePassword = mobilePassword; + + if (this.mobilePassword != null) { + this.txt_password.setText(this.mobilePassword); + } else { + this.txt_password.setText(""); + } + } + + /** (non-Javadoc) + * @see at.asit.pdfover.gui.composites.StateComposite#reloadResources() + */ + @Override + public void reloadResources() { + SWTUtils.setLocalizedText(lbl_number, "mobileBKU.number"); + SWTUtils.setLocalizedText(lbl_password, "mobileBKU.password"); + SWTUtils.setLocalizedText(btn_remember, "mobileBKU.rememberPassword"); + SWTUtils.setLocalizedText(btn_ok, "common.Ok"); + SWTUtils.setLocalizedText(btn_cancel, "common.Cancel"); + + SWTUtils.setLocalizedToolTipText(btn_remember, "mobileBKU.rememberPasswordNote"); + } + +} diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/mobilebku/MobileBKUEnterTANComposite.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/mobilebku/MobileBKUEnterTANComposite.java new file mode 100644 index 00000000..83913c74 --- /dev/null +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/mobilebku/MobileBKUEnterTANComposite.java @@ -0,0 +1,349 @@ +/* + * Copyright 2012 by A-SIT, Secure Information Technology Center Austria + * + * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by + * the European Commission - subsequent versions of the EUPL (the "Licence"); + * You may not use this work except in compliance with the Licence. + * You may obtain a copy of the Licence at: + * http://joinup.ec.europa.eu/software/page/eupl + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the Licence is distributed on an "AS IS" basis, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the Licence for the specific language governing permissions and + * limitations under the Licence. + */ +package at.asit.pdfover.gui.composites; + +// Imports +import java.net.URI; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.events.PaintEvent; +import org.eclipse.swt.events.PaintListener; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.TraverseEvent; +import org.eclipse.swt.events.TraverseListener; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.graphics.ImageData; +import org.eclipse.swt.graphics.Rectangle; +import org.eclipse.swt.layout.FormLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Link; +import org.eclipse.swt.widgets.Text; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.beust.jcommander.internal.Nullable; + +import at.asit.pdfover.commons.Constants; +import at.asit.pdfover.commons.Messages; +import at.asit.pdfover.gui.bku.OLDmobile.ATrustStatus; +import at.asit.pdfover.gui.utils.SWTUtils; +import at.asit.pdfover.gui.workflow.states.State; + +/** + * Composite for entering the TAN for the mobile BKU + */ +public class MobileBKUEnterTANComposite extends StateComposite { + + /** + * + */ + private final class OkSelectionListener extends SelectionAdapter { + + @Override + public void widgetSelected(SelectionEvent e) { + if(!MobileBKUEnterTANComposite.this.btn_ok.getEnabled()) { + return; + } + + String tan = MobileBKUEnterTANComposite.this.txt_tan.getText(); + + tan = tan.trim(); + + if (tan.isEmpty()) { + MobileBKUEnterTANComposite.this.setMessage(Messages + .getString("error.NoTan")); + return; + } + + if (MobileBKUEnterTANComposite.this.refVal.startsWith(tan)) { + MobileBKUEnterTANComposite.this.setMessage(Messages + .getString("error.EnteredReferenceValue")); + return; + } + + if (tan.length() > 6) { + MobileBKUEnterTANComposite.this.setMessage(Messages + .getString("error.TanTooLong")); + return; + } + + MobileBKUEnterTANComposite.this.tan = tan; + MobileBKUEnterTANComposite.this.userAck = true; + } + } + + /** + * SLF4J Logger instance + **/ + static final Logger log = LoggerFactory.getLogger(MobileBKUEnterTANComposite.class); + + private Text txt_tan; + + private boolean userAck = false; + private boolean userCancel = false; + private boolean userFido2 = false; + + private Label lblRefVal; + + private String refVal; + + private URI signatureDataURI; + + /** + * @param signatureData + * the signatureData to set + */ + public void setSignatureDataURI(@Nullable URI uri) { + this.signatureDataURI = uri; + this.lnk_sig_data.setEnabled(uri != null); + } + + private String tan; + + private Link lnk_sig_data; + + private Label lblTries; + private Label lblRefValLabel; + private Label lblTan; + + private Button btn_ok; + private Button btn_cancel; + private Button btn_fido2; + + public boolean isDone() { return (this.userAck || this.userCancel || this.userFido2); } + public boolean isUserAck() { return this.userAck; } + public boolean isUserCancel() { return this.userCancel; } + public boolean isUserFido2() { return this.userFido2; } + + public void reset() { this.userAck = this.userCancel = this.userFido2 = false; } + + /** + * Set how many tries are left + * + * @param tries + */ + public void setTries(int tries) { + if ((tries > 0) && (tries < ATrustStatus.MOBILE_MAX_TAN_TRIES)) { + if (tries > 1) + SWTUtils.setLocalizedText(lblTries, "tanEnter.try"); + else + SWTUtils.setLocalizedText(lblTries, "tanEnter.tries", tries); + } + } + + /** + * Set an error message + * @param errorMessage the error message + */ + public void setErrorMessage(String errorMessage) { + if (errorMessage == null) + this.lblTries.setText(""); + else + this.lblTries.setText( + Messages.getString("error.Title") + ": " + errorMessage); + } + + public void setFIDO2Enabled(boolean state) { + this.btn_fido2.setEnabled(state); + } + + /** + * Sets the message + * + * @param msg + */ + public void setMessage(String msg) { + this.lblTries.setText(msg); + this.lblTries.redraw(); + this.lblTries.getParent().layout(true, true); + } + + /** + * @return the reference value + */ + public String getRefVal() { + return this.refVal; + } + + /** + * @param refVal + * the reference value to set + */ + public void setRefVal(String refVal) { + this.refVal = refVal.trim(); + + if (this.refVal != null) { + this.lblRefVal.setText(this.refVal); + } else { + this.lblRefVal.setText(""); + } + + } + + /** + * @return the tan + */ + public String getTan() { + return this.tan; + } + + /** + * @param tan + * the tan to set + */ + public void setTan(String tan) { + this.tan = tan; + + if (this.tan == null) { + this.txt_tan.setText(""); + } else { + this.txt_tan.setText(this.tan); + } + } + + /** + * Create the composite. + * + * @param parent + * @param style + * @param state + */ + public MobileBKUEnterTANComposite(Composite parent, int style, State state) { + super(parent, style, state); + setLayout(new FormLayout()); + + final Composite containerComposite = new Composite(this, SWT.NATIVE); + containerComposite.addPaintListener(new PaintListener() { + @Override + public void paintControl(PaintEvent e) { + Rectangle clientArea = containerComposite.getClientArea(); + + // e.gc.setForeground(); + e.gc.setForeground(Constants.MAINBAR_ACTIVE_BACK_DARK); + e.gc.setLineWidth(3); + e.gc.setLineStyle(SWT.LINE_SOLID); + e.gc.drawRoundRectangle(clientArea.x, clientArea.y, + clientArea.width - 2, clientArea.height - 2, 10, 10); + } + }); + containerComposite.setLayout(new FormLayout()); + SWTUtils.anchor(containerComposite).top(50, -120).bottom(50, 120).left(50, -200).right(50, 200); + + this.lblRefValLabel = new Label(containerComposite, SWT.NATIVE); + SWTUtils.anchor(lblRefValLabel).right(50, -10).bottom(50,-10); + SWTUtils.setLocalizedText(lblRefValLabel, "tanEnter.ReferenceValue"); + this.lblRefValLabel.setAlignment(SWT.RIGHT); + + ImageData mobileIcon = new ImageData(this.getClass().getResourceAsStream(Constants.RES_IMG_MOBILE)); + Label lbl_image = new Label(containerComposite, SWT.NATIVE); + SWTUtils.anchor(lbl_image).top(50, -1 * (mobileIcon.width / 2)).bottom(50, mobileIcon.width / 2).left(0, 10).width(mobileIcon.width); + lbl_image.setImage(new Image(getDisplay(), mobileIcon)); + + this.lblRefVal = new Label(containerComposite, SWT.NATIVE); + SWTUtils.anchor(lblRefVal).left(50,10).right(100,-20).bottom(50,-10); + this.lblRefVal.setText(""); + + this.lblTan = new Label(containerComposite, SWT.NATIVE); + SWTUtils.anchor(lblTan).right(50,-10).top(50,10); + SWTUtils.setLocalizedText(lblTan, "tanEnter.TAN"); + this.lblTan.setAlignment(SWT.RIGHT); + + this.txt_tan = new Text(containerComposite, SWT.BORDER | SWT.NATIVE); + SWTUtils.anchor(txt_tan).left(50,10).right(100,-20).top(50,10); + this.txt_tan.setEditable(true); + + this.txt_tan.addTraverseListener(new TraverseListener() { + @Override + public void keyTraversed(TraverseEvent e) { + if (e.detail == SWT.TRAVERSE_RETURN) { + if(MobileBKUEnterTANComposite.this.btn_ok.isEnabled()) { + (new OkSelectionListener()).widgetSelected(null); + } + } + } + }); + + this.txt_tan.addModifyListener(new ModifyListener() { + @Override + public void modifyText(ModifyEvent e) { + + String text = MobileBKUEnterTANComposite.this.txt_tan.getText(); + //log.debug("Current TAN: " + text); + if (text.length() > 3 + && MobileBKUEnterTANComposite.this.getRefVal() + .startsWith(text.trim())) { + MobileBKUEnterTANComposite.this.setMessage(Messages.getString("error.EnteredReferenceValue")); + } + } + }); + + this.lnk_sig_data = new Link(containerComposite, SWT.NATIVE | SWT.RESIZE); + SWTUtils.anchor(lnk_sig_data).right(100,-20).top(0,20); + lnk_sig_data.setEnabled(true); + SWTUtils.addSelectionListener(lnk_sig_data, (e) -> { SWTUtils.openURL(this.signatureDataURI); }); + + this.btn_ok = new Button(containerComposite, SWT.NATIVE); + SWTUtils.anchor(btn_ok).right(100,-20).bottom(100,-20); + this.btn_ok.addSelectionListener(new OkSelectionListener()); + + this.btn_cancel = new Button(containerComposite, SWT.NATIVE); + SWTUtils.anchor(btn_cancel).right(btn_ok, -20).bottom(100, -20); + SWTUtils.addSelectionListener(btn_cancel, (e) -> { this.userCancel = true; }); + + this.btn_fido2 = new Button(containerComposite, SWT.NATIVE); + SWTUtils.anchor(btn_fido2).right(btn_cancel, -20).bottom(100, -20); + SWTUtils.addSelectionListener(btn_fido2, (e) -> { this.userFido2 = true; }); + + this.lblTries = new Label(containerComposite, SWT.WRAP | SWT.NATIVE); + SWTUtils.anchor(lblTries).right(btn_fido2, -10).bottom(100, -20); + } + + @Override + protected void checkSubclass() { + // Disable the check that prevents subclassing of SWT components + } + + /* + * (non-Javadoc) + * + * @see at.asit.pdfover.gui.composites.StateComposite#doLayout() + */ + @Override + public void doLayout() { + // Nothing to do + } + + /* + * (non-Javadoc) + * + * @see at.asit.pdfover.gui.composites.StateComposite#reloadResources() + */ + @Override + public void reloadResources() { + SWTUtils.setLocalizedText(lnk_sig_data, "mobileBKU.show"); + SWTUtils.setLocalizedToolTipText(lnk_sig_data, "mobileBKU.show_tooltip"); + SWTUtils.setLocalizedText(lblRefValLabel, "tanEnter.ReferenceValue"); + SWTUtils.setLocalizedText(lblTan, "tanEnter.TAN"); + SWTUtils.setLocalizedText(btn_cancel, "common.Cancel"); + SWTUtils.setLocalizedText(btn_ok, "common.Ok"); + SWTUtils.setLocalizedText(btn_fido2, "tanEnter.FIDO2"); + } +} diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/mobilebku/MobileBKUFingerprintComposite.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/mobilebku/MobileBKUFingerprintComposite.java new file mode 100644 index 00000000..c0561fe4 --- /dev/null +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/mobilebku/MobileBKUFingerprintComposite.java @@ -0,0 +1,292 @@ +/* + * Copyright 2012 by A-SIT, Secure Information Technology Center Austria + * + * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by + * the European Commission - subsequent versions of the EUPL (the "Licence"); + * You may not use this work except in compliance with the Licence. + * You may obtain a copy of the Licence at: + * http://joinup.ec.europa.eu/software/page/eupl + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the Licence is distributed on an "AS IS" basis, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the Licence for the specific language governing permissions and + * limitations under the Licence. + */ +package at.asit.pdfover.gui.composites; + +// Imports +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.PaintEvent; +import org.eclipse.swt.events.PaintListener; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.graphics.ImageData; +import org.eclipse.swt.graphics.Rectangle; +import org.eclipse.swt.layout.FormLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Link; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import at.asit.pdfover.commons.Constants; +import at.asit.pdfover.commons.Messages; +import at.asit.pdfover.gui.utils.SWTUtils; +import at.asit.pdfover.gui.workflow.states.State; + +/** + * Composite for displaying the QR code for the mobile BKU + */ +public class MobileBKUFingerprintComposite extends StateComposite { + + /** + * + */ + private final class SMSSelectionListener extends SelectionAdapter { + /** + * Empty constructor + */ + public SMSSelectionListener() { + } + + @Override + public void widgetSelected(SelectionEvent e) { + if(!MobileBKUFingerprintComposite.this.btn_sms.getEnabled()) { + return; + } + + MobileBKUFingerprintComposite.this.setUserSMS(true); + MobileBKUFingerprintComposite.this.btn_sms.setEnabled(false); + } + } + + /** + * + */ + private final class CancelSelectionListener extends SelectionAdapter { + /** + * Empty constructor + */ + public CancelSelectionListener() { + } + + @Override + public void widgetSelected(SelectionEvent e) { + MobileBKUFingerprintComposite.this.setUserCancel(true); + } + } + + /** + * SLF4J Logger instance + **/ + static final Logger log = LoggerFactory.getLogger(MobileBKUFingerprintComposite.class); + + boolean userCancel = false; + boolean userSMS = false; + boolean done = false; + + private Label lblRefVal; + + String refVal; + + String signatureData; + + /** + * @return the signatureData + */ + public String getSignatureData() { + return this.signatureData; + } + + /** + * @param signatureData + * the signatureData to set + */ + public void setSignatureData(String signatureData) { + this.signatureData = signatureData; + } + + private Label lblError; + private Label lblRefValLabel; + private Label lblFPLabel; + + Button btn_sms; + Button btn_cancel; + + Link lnk_sig_data; + + /** + * @return the userCancel + */ + public boolean isUserCancel() { + return this.userCancel; + } + + /** + * @return the userSMS + */ + public boolean isUserSMS() { + return this.userSMS; + } + + /** + * @return the done + */ + public boolean isDone() { + return this.done; + } + + /** + * Set an error message + * @param errorMessage the error message + */ + public void setErrorMessage(String errorMessage) { + if (errorMessage == null) + this.lblError.setText(""); + else + this.lblError.setText( + Messages.getString("error.Title") + ": " + errorMessage); + } + + /** + * @param userCancel + * the userCancel to set + */ + public void setUserCancel(boolean userCancel) { + this.userCancel = userCancel; + } + + /** + * @param userSMS + * the userSMS to set + */ + public void setUserSMS(boolean userSMS) { + this.userSMS = userSMS; + } + + /** + * @param done + * the done to set + */ + public void setDone(boolean done) { + this.done = done; + } + + /** + * @return the reference value + */ + public String getRefVal() { + return this.refVal; + } + + /** + * @param refVal + * the reference value to set + */ + public void setRefVal(String refVal) { + + if (this.refVal != null) { + this.refVal = refVal.trim(); + this.lblRefVal.setText(this.refVal); + } else { + this.lblRefVal.setText(""); + } + + } + + /** + * Create the composite. + * + * @param parent + * @param style + * @param state + */ + public MobileBKUFingerprintComposite(Composite parent, int style, State state) { + super(parent, style, state); + setLayout(new FormLayout()); + + final Composite containerComposite = new Composite(this, SWT.NATIVE); + containerComposite.addPaintListener(new PaintListener() { + @Override + public void paintControl(PaintEvent e) { + Rectangle clientArea = containerComposite.getClientArea(); + + // e.gc.setForeground(); + e.gc.setForeground(Constants.MAINBAR_ACTIVE_BACK_DARK); + e.gc.setLineWidth(3); + e.gc.setLineStyle(SWT.LINE_SOLID); + e.gc.drawRoundRectangle(clientArea.x, clientArea.y, + clientArea.width - 2, clientArea.height - 2, 10, 10); + } + }); + containerComposite.setLayout(new FormLayout()); + SWTUtils.anchor(containerComposite).top(50, -140).bottom(50, 140).left(50, -200).right(50, 200); + + this.lblRefValLabel = new Label(containerComposite, SWT.NATIVE); + SWTUtils.anchor(lblRefValLabel).right(50, -10).top(30, -10); + this.lblRefValLabel.setAlignment(SWT.RIGHT); + + ImageData mobileIcon = new ImageData(this.getClass().getResourceAsStream(Constants.RES_IMG_MOBILE)); + Label lbl_image = new Label(containerComposite, SWT.NATIVE); + SWTUtils.anchor(lbl_image).top(50, -1 * (mobileIcon.width / 2)).bottom(50, mobileIcon.width / 2).left(0, 10).width(mobileIcon.width); + lbl_image.setImage(new Image(getDisplay(), mobileIcon)); + + this.lblRefVal = new Label(containerComposite, SWT.NATIVE); + SWTUtils.anchor(lblRefVal).left(50, 10).right(100, -20).top(30, -10); + + this.lblFPLabel = new Label(containerComposite, SWT.NATIVE); + SWTUtils.anchor(lblFPLabel).left(25, 10).top(lblRefValLabel, 10); + this.lblFPLabel.setAlignment(SWT.LEFT); + + this.lnk_sig_data = new Link(containerComposite, SWT.NATIVE | SWT.RESIZE); + SWTUtils.anchor(lnk_sig_data).right(100, -20).top(0, 20); + this.lnk_sig_data.setEnabled(true); + SWTUtils.addSelectionListener(lnk_sig_data, (e) -> { SWTUtils.openURL(getSignatureData()); }); + + this.btn_cancel = new Button(containerComposite, SWT.NATIVE); + SWTUtils.anchor(btn_cancel).right(100, -20).bottom(100, -20); + this.btn_cancel.addSelectionListener(new CancelSelectionListener()); + + this.btn_sms = new Button(containerComposite, SWT.NATIVE); + SWTUtils.anchor(btn_sms).right(btn_cancel, -20).bottom(100, -20); + this.btn_sms.addSelectionListener(new SMSSelectionListener()); + + this.lblError = new Label(containerComposite, SWT.WRAP | SWT.NATIVE); + SWTUtils.anchor(lblError).right(btn_sms, -10).bottom(100, -20); + + reloadResources(); + } + + @Override + protected void checkSubclass() { + // Disable the check that prevents subclassing of SWT components + } + + /* + * (non-Javadoc) + * + * @see at.asit.pdfover.gui.composites.StateComposite#doLayout() + */ + @Override + public void doLayout() { + // Nothing to do + } + + /* + * (non-Javadoc) + * + * @see at.asit.pdfover.gui.composites.StateComposite#reloadResources() + */ + @Override + public void reloadResources() { + SWTUtils.setLocalizedText(lblRefValLabel, "tanEnter.ReferenceValue"); + SWTUtils.setLocalizedText(lblFPLabel, "tanEnter.FP"); + SWTUtils.setLocalizedText(lnk_sig_data, "mobileBKU.show"); + SWTUtils.setLocalizedToolTipText(lnk_sig_data, "mobileBKU.show_tooltip"); + SWTUtils.setLocalizedText(btn_cancel, "common.Cancel"); + SWTUtils.setLocalizedText(btn_sms, "tanEnter.SMS"); + } +} diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/mobilebku/MobileBKUQRComposite.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/mobilebku/MobileBKUQRComposite.java new file mode 100644 index 00000000..91765610 --- /dev/null +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/mobilebku/MobileBKUQRComposite.java @@ -0,0 +1,252 @@ +/* + * Copyright 2012 by A-SIT, Secure Information Technology Center Austria + * + * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by + * the European Commission - subsequent versions of the EUPL (the "Licence"); + * You may not use this work except in compliance with the Licence. + * You may obtain a copy of the Licence at: + * http://joinup.ec.europa.eu/software/page/eupl + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the Licence is distributed on an "AS IS" basis, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the Licence for the specific language governing permissions and + * limitations under the Licence. + */ +package at.asit.pdfover.gui.composites; + +// Imports +import java.io.ByteArrayInputStream; +import java.net.URI; +import java.util.Objects; + +import javax.annotation.Nullable; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.SWTException; +import org.eclipse.swt.events.PaintEvent; +import org.eclipse.swt.events.PaintListener; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.graphics.ImageData; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.graphics.Rectangle; +import org.eclipse.swt.layout.FormLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Link; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import at.asit.pdfover.commons.Constants; +import at.asit.pdfover.commons.Messages; +import at.asit.pdfover.gui.utils.SWTUtils; +import at.asit.pdfover.gui.workflow.states.State; + +/** + * Composite for displaying the QR code for the mobile BKU + */ +public class MobileBKUQRComposite extends StateComposite { + + /** + * SLF4J Logger instance + **/ + private static final Logger log = LoggerFactory.getLogger(MobileBKUQRComposite.class); + + private Label lblQR; + + private boolean userCancelClicked = false; + private boolean userSMSClicked = false; + private boolean userFIDO2Clicked = false; + private boolean pollingDone = false; + + private Label lblRefVal; + + private String refVal; + + private ImageData currentQRImage; + + private URI signatureDataURI; + + private Label lblError; + private Label lblRefValLabel; + private Label lblQRLabel; + + private Button btn_fido2; + private Button btn_sms; + private Button btn_cancel; + + private Link lnk_sig_data; + + public void signalPollingDone() { this.pollingDone = true; getDisplay().wake(); } + public boolean isDone() { return (this.userCancelClicked || this.userSMSClicked || this.userFIDO2Clicked || this.pollingDone); } + public boolean wasCancelClicked() { return this.userCancelClicked; } + public boolean wasSMSClicked() { return this.userSMSClicked; } + public boolean wasFIDO2Clicked() { return this.userFIDO2Clicked; } + public void reset() { this.userCancelClicked = this.userSMSClicked = this.userFIDO2Clicked = this.pollingDone = false; } + + /** + * Set an error message + * @param errorMessage the error message + */ + public void setErrorMessage(String errorMessage) { + if (errorMessage == null) + this.lblError.setText(""); + else + this.lblError.setText( + Messages.getString("error.Title") + ": " + errorMessage); + } + + public String getRefVal() { return this.refVal; } + public void setRefVal(String refVal) { + this.refVal = (refVal != null) ? refVal.trim() : null; + this.lblRefVal.setText(Objects.requireNonNullElse(this.refVal, "")); + } + + private void updateQRImage() { + if (this.currentQRImage == null) + return; + + Point availableSize = this.lblQR.getSize(); + int targetSize = Math.min(availableSize.x, availableSize.y); + if (targetSize <= 0) + return; + + this.lblQR.setImage(new Image(this.lblQR.getDisplay(), this.currentQRImage.scaledTo(targetSize, targetSize))); + } + + /** + * @param qrcode + * the qrcode to set + */ + public void setQR(byte[] qrcode) { + if (qrcode == null) { + setErrorMessage(Messages.getString("error.FailedToLoadQRCode")); + return; + } + try { + this.currentQRImage = new ImageData(new ByteArrayInputStream(qrcode)); + } catch (SWTException e) { + log.warn("Failed to load QR code", e); + setErrorMessage(Messages.getString("error.FailedToLoadQRCode")); + return; + } + updateQRImage(); + } + + public void setSMSEnabled(boolean state) { + this.btn_sms.setEnabled(state); + } + + public void setFIDO2Enabled(boolean state) { + this.btn_fido2.setEnabled(state); + } + + public void setSignatureDataURI(@Nullable URI uri) { + this.signatureDataURI = uri; + this.lnk_sig_data.setEnabled(uri != null); + } + + /** + * Create the composite. + * + * @param parent + * @param style + * @param state + */ + public MobileBKUQRComposite(Composite parent, int style, State state) { + super(parent, style, state); + setLayout(new FormLayout()); + + final Composite containerComposite = new Composite(this, SWT.NATIVE); + SWTUtils.anchor(containerComposite).top(50, -140).bottom(50, 140).left(50, -200).right(50, 200); + containerComposite.addPaintListener(new PaintListener() { + @Override + public void paintControl(PaintEvent e) { + Rectangle clientArea = containerComposite.getClientArea(); + + // e.gc.setForeground(); + e.gc.setForeground(Constants.MAINBAR_ACTIVE_BACK_DARK); + e.gc.setLineWidth(3); + e.gc.setLineStyle(SWT.LINE_SOLID); + e.gc.drawRoundRectangle(clientArea.x, clientArea.y, + clientArea.width - 2, clientArea.height - 2, 10, 10); + } + }); + containerComposite.setLayout(new FormLayout()); + + this.lblRefValLabel = new Label(containerComposite, SWT.NATIVE); + SWTUtils.anchor(lblRefValLabel).right(50, -10).top(30, -10); + this.lblRefValLabel.setAlignment(SWT.RIGHT); + + ImageData mobileIcon = new ImageData(this.getClass().getResourceAsStream(Constants.RES_IMG_MOBILE)); + Label lbl_image = new Label(containerComposite, SWT.NATIVE); + SWTUtils.anchor(lbl_image).top(50, -1 * (mobileIcon.width / 2)).bottom(50, mobileIcon.width / 2).left(0, 10).width(mobileIcon.width); + lbl_image.setImage(new Image(getDisplay(), mobileIcon)); + + this.lblRefVal = new Label(containerComposite, SWT.NATIVE); + SWTUtils.anchor(lblRefVal).left(50, 10).right(100, -20).top(30, -10); + + this.lblQRLabel = new Label(containerComposite, SWT.NATIVE); + SWTUtils.anchor(lblQRLabel).right(50, -10).top(lblRefValLabel, 10); + this.lblQRLabel.setAlignment(SWT.RIGHT); + + this.lblQR = new Label(containerComposite, SWT.NATIVE); + this.lblQR.addListener(SWT.Resize, (e) -> { updateQRImage(); }); + + this.lnk_sig_data = new Link(containerComposite, SWT.NATIVE | SWT.RESIZE); + SWTUtils.anchor(lnk_sig_data).right(100, -20).top(0, 20); + SWTUtils.addSelectionListener(lnk_sig_data, (e) -> { SWTUtils.openURL(this.signatureDataURI); }); + + this.btn_cancel = new Button(containerComposite, SWT.NATIVE); + SWTUtils.anchor(btn_cancel).right(100, -20).bottom(100, -5); + SWTUtils.addSelectionListener(btn_cancel, (e) -> { this.userCancelClicked = true; }); + + this.btn_sms = new Button(containerComposite, SWT.NATIVE); + SWTUtils.anchor(btn_sms).right(btn_cancel, -20).bottom(100, -5); + SWTUtils.addSelectionListener(btn_sms, (e) -> { this.userSMSClicked = true; }); + + this.btn_fido2 = new Button(containerComposite, SWT.NATIVE); + SWTUtils.anchor(btn_fido2).right(btn_sms, -20).bottom(100, -5); + SWTUtils.addSelectionListener(btn_fido2, (e) -> {this.userFIDO2Clicked = true; }); + + + SWTUtils.anchor(lblQR).left(50, 10).right(100, -20).top(lblRefVal, 10).bottom(btn_sms, -10); + + this.lblError = new Label(containerComposite, SWT.WRAP | SWT.NATIVE); + SWTUtils.anchor(lblError).right(btn_sms, -10).bottom(100, -20); + + reloadResources(); + } + + @Override + protected void checkSubclass() { + // Disable the check that prevents subclassing of SWT components + } + + /* + * (non-Javadoc) + * + * @see at.asit.pdfover.gui.composites.StateComposite#doLayout() + */ + @Override + public void doLayout() { + // Nothing to do + } + + /* + * (non-Javadoc) + * + * @see at.asit.pdfover.gui.composites.StateComposite#reloadResources() + */ + @Override + public void reloadResources() { + SWTUtils.setLocalizedText(lblRefValLabel, "tanEnter.ReferenceValue"); + SWTUtils.setLocalizedText(lblQRLabel, "tanEnter.QR"); + SWTUtils.setLocalizedText(lnk_sig_data, "mobileBKU.show"); + SWTUtils.setLocalizedToolTipText(lnk_sig_data, "mobileBKU.show_tooltip"); + SWTUtils.setLocalizedText(btn_cancel, "common.Cancel"); + SWTUtils.setLocalizedText(btn_sms, "tanEnter.SMS"); + SWTUtils.setLocalizedText(btn_fido2, "tanEnter.FIDO2"); + } +} diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/mobilebku/WaitingForAppComposite.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/mobilebku/WaitingForAppComposite.java new file mode 100644 index 00000000..7d5b4dfd --- /dev/null +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/mobilebku/WaitingForAppComposite.java @@ -0,0 +1,121 @@ +/* + * Copyright 2012 by A-SIT, Secure Information Technology Center Austria + * + * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by + * the European Commission - subsequent versions of the EUPL (the "Licence"); + * You may not use this work except in compliance with the Licence. + * You may obtain a copy of the Licence at: + * http://joinup.ec.europa.eu/software/page/eupl + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the Licence is distributed on an "AS IS" basis, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the Licence for the specific language governing permissions and + * limitations under the Licence. + */ +package at.asit.pdfover.gui.composites; + + +// Imports +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.FormLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.ProgressBar; +import at.asit.pdfover.gui.utils.SWTUtils; +import at.asit.pdfover.gui.workflow.states.State; +import org.eclipse.swt.widgets.Button; + +/** + * + */ +public class WaitingForAppComposite extends StateComposite { + private Label lbl_description; + private Button btn_sms; + private Button btn_cancel; + private Button btn_fido2; + private boolean userSMSClicked = false; + private boolean userCancelClicked = false; + private boolean userFIDO2Clicked = false; + private boolean pollingDone = false; + + /** + * @return the isDone + */ + public Boolean getIsDone() { + return this.pollingDone; + } + + public void signalPollingDone() { this.pollingDone = true; getDisplay().wake(); } + public boolean isDone() { return (this.userCancelClicked || this.userSMSClicked || this.userFIDO2Clicked || this.pollingDone); } + public boolean wasCancelClicked() { return this.userCancelClicked; } + public boolean wasSMSClicked() { return this.userSMSClicked; } + public boolean wasFIDO2Clicked() { return this.userFIDO2Clicked; } + public void reset() { this.userCancelClicked = this.userSMSClicked = this.userFIDO2Clicked = this.pollingDone = false; } + + public void setSMSEnabled(boolean state) { + this.btn_sms.setEnabled(state); + } + + public void setFIDO2Enabled(boolean state) { + this.btn_fido2.setEnabled(state); + } + + /** + * Create the composite. + * @param parent + * @param style + * @param state + */ + public WaitingForAppComposite(Composite parent, int style, State state) { + super(parent, style, state); + setLayout(new FormLayout()); + + this.lbl_description = new Label(this, SWT.NATIVE); + SWTUtils.anchor(lbl_description).bottom(50, -1).left(0, 10).right(100, -10); + this.lbl_description.setAlignment(SWT.CENTER); + SWTUtils.setLocalizedText(lbl_description, "waiting_for_app.message"); + + ProgressBar progressBar = new ProgressBar(this, SWT.HORIZONTAL | SWT.INDETERMINATE); + SWTUtils.anchor(progressBar).top(50, 10).bottom(50, 40).left(50,-100).right(50,100); + + this.btn_sms = new Button(this, SWT.NONE); + SWTUtils.anchor(btn_sms).top(progressBar, 24).right(progressBar, 0, SWT.RIGHT); + SWTUtils.addSelectionListener(btn_sms, (e) -> { this.userSMSClicked = true; }); + + this.btn_cancel = new Button(this, SWT.NONE); + SWTUtils.anchor(btn_cancel).top(btn_sms, 0, SWT.TOP).right(btn_sms, -6); + SWTUtils.addSelectionListener(btn_cancel, (e) -> { this.userCancelClicked = true; }); + + this.btn_fido2 = new Button(this, SWT.NONE); + SWTUtils.anchor(btn_fido2).top(btn_cancel, 0, SWT.TOP).right(btn_cancel, -6); + SWTUtils.addSelectionListener(btn_fido2, (e) -> { this.userFIDO2Clicked = true; }); + + reloadResources(); + + } + + @Override + protected void checkSubclass() { + // Disable the check that prevents subclassing of SWT components + } + + /* (non-Javadoc) + * @see at.asit.pdfover.gui.composites.StateComposite#doLayout() + */ + @Override + public void doLayout() { + // Nothing to do here + } + + /* (non-Javadoc) + * @see at.asit.pdfover.gui.composites.StateComposite#reloadResources() + */ + @Override + public void reloadResources() { + SWTUtils.setLocalizedText(lbl_description, "waiting_for_app.message"); + SWTUtils.setLocalizedText(btn_sms, "tanEnter.SMS"); + SWTUtils.setLocalizedText(btn_fido2, "tanEnter.FIDO2"); + SWTUtils.setLocalizedText(btn_cancel, "common.Cancel"); + } +} -- cgit v1.2.3