Skip to content
Permalink
Browse files

#4527 Mask *password* properties

  • Loading branch information...
serge-rider committed Nov 18, 2018
1 parent 661b28f commit 3b813819a8ea9dbd215bdc7ad1e3a9240272234d
@@ -109,6 +109,11 @@ public void run() {
}
}

@Override
protected boolean isHidePropertyValue(DBPPropertyDescriptor property) {
return CommonUtils.toString(property.getId()).toLowerCase(Locale.ENGLISH).contains("password");
}

private void createNewProperty(Object node, String category) {
// Ask user for new property name
String propName = EnterNameDialog.chooseName(getControl().getShell(), CoreMessages.controls_connection_properties_dialog_new_property_title);
@@ -127,7 +132,7 @@ private void createNewProperty(Object node, String category) {
if (includeCustom && customProperties != null) {
propertyDescriptors.addAll(customProperties);
}
Collections.sort(propertyDescriptors, PROPERTIES_COMPARATOR);
propertyDescriptors.sort(PROPERTIES_COMPARATOR);
return propertyDescriptors;
}

@@ -171,7 +176,7 @@ private void loadCustomProperties(DBPDriver driver, Map<Object, Object> properti
true));
}
}
Collections.sort(customProperties, PROPERTIES_COMPARATOR);
customProperties.sort(PROPERTIES_COMPARATOR);
}

private static Comparator<DBPPropertyDescriptor> PROPERTIES_COMPARATOR = new Comparator<DBPPropertyDescriptor>() {
@@ -1350,7 +1350,7 @@ public static CellEditor createCellEditor(Composite parent, Object object, DBPPr
if (property instanceof ObjectPropertyDescriptor && ((ObjectPropertyDescriptor) property).isMultiLine()) {
return new AdvancedTextCellEditor(parent);
} else {
return new CustomTextCellEditor(parent);
return new CustomTextCellEditor(parent, SWT.SINGLE | ((style & SWT.PASSWORD) != 0 ? SWT.PASSWORD : SWT.NONE));
}
} else if (BeanUtils.isNumericType(propertyType)) {
return new CustomNumberCellEditor(parent, propertyType);
@@ -34,6 +34,10 @@ public CustomTextCellEditor(Composite parent)
super(parent);
}

public CustomTextCellEditor(Composite parent, int style) {
super(parent, style);
}

@Override
protected Object doGetValue()
{
@@ -410,7 +410,11 @@ private void showEditor(final TreeItem item, boolean isDef)
if (prop.property == null || !prop.isEditable()) {
return;
}
final CellEditor cellEditor = UIUtils.createPropertyEditor(UIUtils.getActiveWorkbenchWindow(), treeControl, prop.propertySource, prop.property, SWT.LEFT);
int editStyle = SWT.LEFT;
if (isHidePropertyValue(prop.property)) {
editStyle |= SWT.PASSWORD;
}
final CellEditor cellEditor = UIUtils.createPropertyEditor(UIUtils.getActiveWorkbenchWindow(), treeControl, prop.propertySource, prop.property, editStyle);
if (cellEditor == null) {
return;
}
@@ -793,6 +797,9 @@ public String getText(Object obj, int columnIndex)
final Object propertyValue = getPropertyValue(node);
if (propertyValue == null || renderer.isHyperlink(propertyValue)) {
return ""; //$NON-NLS-1$
} else if (isHidePropertyValue(node.property)) {
// Mask value
return maskHiddenPropertyValue(propertyValue);
} else if (BeanUtils.isCollectionType(propertyValue.getClass())) {
StringBuilder str = new StringBuilder();
str.append("[");
@@ -941,6 +948,14 @@ public void update(ViewerCell cell)

}

private String maskHiddenPropertyValue(Object propertyValue) {
return CommonUtils.isEmpty(CommonUtils.toString(propertyValue)) ? "" : "**********";
}

protected boolean isHidePropertyValue(DBPPropertyDescriptor property) {
return false;
}

private class SortListener implements Listener {
int sortDirection = SWT.DOWN;
TreeColumn prevColumn = null;

0 comments on commit 3b81381

Please sign in to comment.
You can’t perform that action at this time.