Skip to content

Commit

Permalink
issue apache#3309 : Ability to store encrypted passwords as variables
Browse files Browse the repository at this point in the history
  • Loading branch information
mattcasters committed Nov 14, 2023
1 parent aa089c0 commit 7efa1c5
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@

package org.apache.hop.ui.core.dialog;

import java.util.List;
import org.apache.hop.core.Const;
import org.apache.hop.core.encryption.Encr;
import org.apache.hop.core.encryption.ITwoWayPasswordEncoder;
import org.apache.hop.core.variables.DescribedVariable;
import org.apache.hop.core.variables.Variables;
import org.apache.hop.i18n.BaseMessages;
Expand All @@ -38,8 +41,6 @@
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.TableItem;

import java.util.List;

/** Allows the user to edit the system settings of the hop.config file. */
public class HopDescribedVariablesDialog extends Dialog {
private static final Class<?> PKG = HopDescribedVariablesDialog.class; // For Translator
Expand Down Expand Up @@ -94,11 +95,15 @@ public List<DescribedVariable> open() {
wOk.setText(BaseMessages.getString(PKG, "System.Button.OK"));
wOk.addListener(SWT.Selection, e -> ok());

Button wEncode = new Button(shell, SWT.PUSH);
wEncode.setText(BaseMessages.getString(PKG, "HopDescribedVariablesDialog.Button.EncodeValue"));
wEncode.addListener(SWT.Selection, e -> encodeSelectedValue());

Button wCancel = new Button(shell, SWT.PUSH);
wCancel.setText(BaseMessages.getString(PKG, "System.Button.Cancel"));
wCancel.addListener(SWT.Selection, e -> cancel());

BaseTransformDialog.positionBottomButtons(shell, new Button[] {wOk, wCancel}, margin, wFields);
BaseTransformDialog.positionBottomButtons(shell, new Button[] {wOk, wEncode, wCancel}, margin, wFields);

// Message line at the top
//
Expand Down Expand Up @@ -216,4 +221,22 @@ private void ok() {

dispose();
}

private void encodeSelectedValue() {
try {
ITwoWayPasswordEncoder encoder = Encr.getEncoder();
for (int index : wFields.getSelectionIndices()) {
TableItem item = wFields.table.getItem(index);
String value = item.getText(2);
String encoded = encoder.encode(value, true);
item.setText(2, Const.NVL(encoded, ""));
}
// We can't undo after this operation
//
wFields.clearUndo();
wFields.optimizeTableView();
} catch (Exception e) {
new ErrorDialog(shell, "Error", "Error encoding the value on the selected lines", e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3404,7 +3404,7 @@ private ChangeAction viewNextUndo() {
return undo.get(undoPosition + 1);
}

private void clearUndo() {
public void clearUndo() {
undo = new ArrayList<>();
undoPosition = -1;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,3 +253,4 @@ TransformFieldsDialog.TableCol.StorageType=Storage
TransformFieldsDialog.TableCol.TrimType=Trim
TransformFieldsDialog.TableCol.Type=Type
TransformFieldsDialog.Title=Transform fields and their origin
HopDescribedVariablesDialog.Button.EncodeValue=Encode value

0 comments on commit 7efa1c5

Please sign in to comment.