Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package org.csstudio.display.builder.editor.properties;
import org.csstudio.display.builder.model.properties.HashPasswordProperty;

import javafx.event.ActionEvent;
import javafx.event.EventHandler;
Expand Down Expand Up @@ -545,6 +546,47 @@ public void bind() {

field = points_field;
}
else if (property instanceof HashPasswordProperty) {
final Button hashButton = new Button("Open menu");
hashButton.setMnemonicParsing(false);
hashButton.setMaxWidth(Double.MAX_VALUE);

hashButton.setOnAction(event -> {
final WidgetProperty<?> passwordProperty = widget.getProperty("password");

if (passwordProperty == null)
return;

final Object currentValue = passwordProperty.getValue();
final String currentPassword = currentValue != null
? currentValue.toString()
: "";

final MultiLineInputDialog dialog =
new MultiLineInputDialog(hashButton, currentPassword);

DialogHelper.positionDialog(dialog, hashButton, -600, 0);

final Optional<String> result = dialog.showAndWait();

if (!result.isPresent())
return;

final String password = result.get();

if (password.isEmpty())
return;

final String hashedPassword = HashPasswordProperty.crypt(password);

final WidgetProperty<String> stringPasswordProperty =
(WidgetProperty<String>) passwordProperty;

stringPasswordProperty.setValue(hashedPassword);
});

field = hashButton;
}
return field;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public class Messages
GroupWidget_Description,
GroupWidget_Name,
HighlightActiveRegion,
InformativeTooltipHashPassword,
InformativeTooltipActions,
InformativeTooltipAlarmBorder,
InformativeTooltipHeight,
Expand Down Expand Up @@ -231,6 +232,7 @@ public class Messages
WidgetProperties_GridStepX,
WidgetProperties_GridStepY,
WidgetProperties_GridVisible,
WidgetProperties_HashPassword,
WidgetProperties_Height,
WidgetProperties_HeightPVName,
WidgetProperties_HighlightBar,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -771,6 +771,22 @@ public EnumWidgetProperty<ConfirmDialog> createProperty(final Widget widget, fin
public static final WidgetPropertyDescriptor<String> propPassword =
newStringPropertyDescriptor(WidgetPropertyCategory.BEHAVIOR, "password", Messages.WidgetProperties_Password);


public static final WidgetPropertyDescriptor<String> propHashPassword =
new WidgetPropertyDescriptor<>(WidgetPropertyCategory.BEHAVIOR, "hash_password", Messages.WidgetProperties_HashPassword)
{
@Override
public WidgetProperty<String> createProperty(
final Widget widget,
final String default_value)
{
return new HashPasswordProperty(
this,
widget,
default_value);
}
};

/**
* Runtime 'pv_value' property: Typically read from primary PV
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package org.csstudio.display.builder.model.properties;

import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;

import org.csstudio.display.builder.model.Widget;
import org.csstudio.display.builder.model.WidgetProperty;
import org.csstudio.display.builder.model.WidgetPropertyDescriptor;
import org.csstudio.display.builder.model.persist.ModelReader;
import org.csstudio.display.builder.model.persist.ModelWriter;
import org.w3c.dom.Element;

import javax.xml.stream.XMLStreamWriter;

@SuppressWarnings("nls")
public class HashPasswordProperty extends WidgetProperty<String>
{
public HashPasswordProperty(
final WidgetPropertyDescriptor<String> descriptor,
final Widget widget,
final String default_value)
{
super(descriptor, widget, default_value);
}

@Override
public void setValueFromObject(final Object value)
{
if (value == null)
setValue("");
else
setValue(value.toString());
}

@Override
public void writeToXML(ModelWriter model_writer, XMLStreamWriter writer) throws Exception {

Check failure on line 36 in app/display/model/src/main/java/org/csstudio/display/builder/model/properties/HashPasswordProperty.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Add a nested comment explaining why this method is empty, throw an UnsupportedOperationException or complete the implementation.

See more on https://sonarcloud.io/project/issues?id=ControlSystemStudio_phoebus&issues=AaEcFOS0kaFsZPR4ZroR&open=AaEcFOS0kaFsZPR4ZroR&pullRequest=3924

Check warning on line 36 in app/display/model/src/main/java/org/csstudio/display/builder/model/properties/HashPasswordProperty.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Rename this local variable to match the regular expression '^[a-z][a-zA-Z0-9]*$'.

See more on https://sonarcloud.io/project/issues?id=ControlSystemStudio_phoebus&issues=AaEcFOS0kaFsZPR4ZroO&open=AaEcFOS0kaFsZPR4ZroO&pullRequest=3924

}

@Override
public void readFromXML(ModelReader model_reader, Element property_xml) throws Exception {

Check warning on line 41 in app/display/model/src/main/java/org/csstudio/display/builder/model/properties/HashPasswordProperty.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Rename this local variable to match the regular expression '^[a-z][a-zA-Z0-9]*$'.

See more on https://sonarcloud.io/project/issues?id=ControlSystemStudio_phoebus&issues=AaEcFOS0kaFsZPR4ZroQ&open=AaEcFOS0kaFsZPR4ZroQ&pullRequest=3924

Check failure on line 41 in app/display/model/src/main/java/org/csstudio/display/builder/model/properties/HashPasswordProperty.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Add a nested comment explaining why this method is empty, throw an UnsupportedOperationException or complete the implementation.

See more on https://sonarcloud.io/project/issues?id=ControlSystemStudio_phoebus&issues=AaEcFOS0kaFsZPR4ZroS&open=AaEcFOS0kaFsZPR4ZroS&pullRequest=3924

Check warning on line 41 in app/display/model/src/main/java/org/csstudio/display/builder/model/properties/HashPasswordProperty.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Rename this local variable to match the regular expression '^[a-z][a-zA-Z0-9]*$'.

See more on https://sonarcloud.io/project/issues?id=ControlSystemStudio_phoebus&issues=AaEcFOS0kaFsZPR4ZroP&open=AaEcFOS0kaFsZPR4ZroP&pullRequest=3924

}

public static String crypt(final String password)
{
if (password == null || password.isEmpty())
return password;

try
{
final MessageDigest md = MessageDigest.getInstance("SHA-256");
final byte[] hash =
md.digest(password.getBytes(StandardCharsets.UTF_8));

final StringBuilder hex = new StringBuilder(hash.length * 2);

for (final byte b : hash)
hex.append(String.format("%02x", b));

return hex.toString();
}
catch (Exception e)
{
throw new RuntimeException("Unable to hash password", e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import static org.csstudio.display.builder.model.properties.CommonWidgetProperties.propEnabled;
import static org.csstudio.display.builder.model.properties.CommonWidgetProperties.propFont;
import static org.csstudio.display.builder.model.properties.CommonWidgetProperties.propForegroundColor;
import static org.csstudio.display.builder.model.properties.CommonWidgetProperties.propHashPassword;
import static org.csstudio.display.builder.model.properties.CommonWidgetProperties.propHorizontalAlignment;
import static org.csstudio.display.builder.model.properties.CommonWidgetProperties.propVerticalAlignment;
import static org.csstudio.display.builder.model.properties.CommonWidgetProperties.propPassword;
Expand All @@ -25,6 +26,7 @@
import java.util.List;

import org.csstudio.display.builder.model.MacroizedWidgetProperty;
import org.csstudio.display.builder.model.Messages;
import org.csstudio.display.builder.model.Version;
import org.csstudio.display.builder.model.Widget;
import org.csstudio.display.builder.model.WidgetCategory;
Expand Down Expand Up @@ -237,7 +239,7 @@
private volatile WidgetProperty<Boolean> confirm_dialog;
private volatile WidgetProperty<String> confirm_message;
private volatile WidgetProperty<String> password;

private volatile WidgetProperty<String> hash_password;

Check warning on line 242 in app/display/model/src/main/java/org/csstudio/display/builder/model/widgets/ActionButtonWidget.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Rename this field "hash_password" to match the regular expression '^[a-z][a-zA-Z0-9]*$'.

See more on https://sonarcloud.io/project/issues?id=ControlSystemStudio_phoebus&issues=AaEcFOdvkaFsZPR4Zroa&open=AaEcFOdvkaFsZPR4Zroa&pullRequest=3924
/** Constructor */
public ActionButtonWidget()
{
Expand Down Expand Up @@ -271,6 +273,8 @@
properties.add(confirm_dialog = propConfirmDialog.createProperty(this, false));
properties.add(confirm_message = propConfirmMessage.createProperty(this, "Are your sure you want to do this?"));
properties.add(password = propPassword.createProperty(this, ""));
properties.add(hash_password = propHashPassword.createProperty(this, ""));

Check warning on line 276 in app/display/model/src/main/java/org/csstudio/display/builder/model/widgets/ActionButtonWidget.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Extract the assignment out of this expression.

See more on https://sonarcloud.io/project/issues?id=ControlSystemStudio_phoebus&issues=AaEcFOdvkaFsZPR4ZroZ&open=AaEcFOdvkaFsZPR4ZroZ&pullRequest=3924
hash_password.setInformativeTooltip(Messages.InformativeTooltipHashPassword);
}

@Override
Expand Down Expand Up @@ -310,13 +314,13 @@
{
return transparent;
}

/** @return 'horizontal_alignment' property */
public WidgetProperty<HorizontalAlignment> propHorizontalAlignment()
{
return horizontal_alignment;
}

/** @return 'vertical_alignment' property */
public WidgetProperty<VerticalAlignment> propVerticalAlignment()
{
Expand Down Expand Up @@ -353,9 +357,16 @@
return confirm_message;
}

/** @return 'hash_password' property */
public WidgetProperty<String> propHashPassword()
{
return hash_password;
}

/** @return 'password' property */
public WidgetProperty<String> propPassword()
{
return password;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import static org.csstudio.display.builder.model.properties.CommonWidgetProperties.propEnabled;
import static org.csstudio.display.builder.model.properties.CommonWidgetProperties.propFont;
import static org.csstudio.display.builder.model.properties.CommonWidgetProperties.propForegroundColor;
import static org.csstudio.display.builder.model.properties.CommonWidgetProperties.propHashPassword;
import static org.csstudio.display.builder.model.properties.CommonWidgetProperties.propHorizontalAlignment;
import static org.csstudio.display.builder.model.properties.CommonWidgetProperties.propVerticalAlignment;
import static org.csstudio.display.builder.model.properties.CommonWidgetProperties.propLabelsFromPV;
Expand Down Expand Up @@ -182,6 +183,7 @@
private volatile WidgetProperty<ConfirmDialog> confirm_dialog;
private volatile WidgetProperty<String> confirm_message;
private volatile WidgetProperty<String> password;
private volatile WidgetProperty<String> hash_password;

Check warning on line 186 in app/display/model/src/main/java/org/csstudio/display/builder/model/widgets/BoolButtonWidget.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Rename this field "hash_password" to match the regular expression '^[a-z][a-zA-Z0-9]*$'.

See more on https://sonarcloud.io/project/issues?id=ControlSystemStudio_phoebus&issues=AaEcFOYXkaFsZPR4ZroU&open=AaEcFOYXkaFsZPR4ZroU&pullRequest=3924

/** Constructor */
public BoolButtonWidget()
Expand All @@ -200,6 +202,7 @@
protected void defineProperties(final List<WidgetProperty<?>> properties)
{
super.defineProperties(properties);

properties.add(bit = propBit.createProperty(this, 0));
properties.add(off_label = propOffLabel.createProperty(this, "Off"));
properties.add(off_color = propOffColor.createProperty(this, new WidgetColor(60, 100, 60)));
Expand All @@ -219,6 +222,8 @@
properties.add(confirm_dialog = propConfirmDialogOptions.createProperty(this, ConfirmDialog.NONE));
properties.add(confirm_message = propConfirmMessage.createProperty(this, "Are your sure you want to do this?"));
properties.add(password = propPassword.createProperty(this, ""));
properties.add(hash_password = propHashPassword.createProperty(this, ""));

Check warning on line 225 in app/display/model/src/main/java/org/csstudio/display/builder/model/widgets/BoolButtonWidget.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Extract the assignment out of this expression.

See more on https://sonarcloud.io/project/issues?id=ControlSystemStudio_phoebus&issues=AaEcFOYXkaFsZPR4ZroT&open=AaEcFOYXkaFsZPR4ZroT&pullRequest=3924
hash_password.setInformativeTooltip(Messages.InformativeTooltipHashPassword);
}

/** @return 'bit' property */
Expand Down Expand Up @@ -286,13 +291,13 @@
{
return foreground;
}

/** @return 'horizontal_alignment' property */
public WidgetProperty<HorizontalAlignment> propHorizontalAlignment()
{
return horizontal_alignment;
}

/** @return 'vertical_alignment' property */
public WidgetProperty<VerticalAlignment> propVerticalAlignment()
{
Expand Down Expand Up @@ -334,4 +339,10 @@
{
return password;
}

/** @return 'hash_password' property */
public WidgetProperty<String> propHashPassword()
{
return hash_password;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import static org.csstudio.display.builder.model.properties.CommonWidgetProperties.propEnabled;
import static org.csstudio.display.builder.model.properties.CommonWidgetProperties.propFont;
import static org.csstudio.display.builder.model.properties.CommonWidgetProperties.propForegroundColor;
import static org.csstudio.display.builder.model.properties.CommonWidgetProperties.propHashPassword;
import static org.csstudio.display.builder.model.properties.CommonWidgetProperties.propPassword;

import java.util.Arrays;
Expand Down Expand Up @@ -73,6 +74,7 @@
private volatile WidgetProperty<ConfirmDialog> confirm_dialog;
private volatile WidgetProperty<String> confirm_message;
private volatile WidgetProperty<String> password;
private volatile WidgetProperty<String> hash_password;

Check warning on line 77 in app/display/model/src/main/java/org/csstudio/display/builder/model/widgets/CheckBoxWidget.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Rename this field "hash_password" to match the regular expression '^[a-z][a-zA-Z0-9]*$'.

See more on https://sonarcloud.io/project/issues?id=ControlSystemStudio_phoebus&issues=AaEcFOhSkaFsZPR4Zroe&open=AaEcFOhSkaFsZPR4Zroe&pullRequest=3924

@Override
protected void defineProperties(final List<WidgetProperty<?>> properties)
Expand All @@ -87,6 +89,8 @@
properties.add(confirm_dialog = propConfirmDialogOptions.createProperty(this, ConfirmDialog.NONE));
properties.add(confirm_message = propConfirmMessage.createProperty(this, "Are your sure you want to do this?"));
properties.add(password = propPassword.createProperty(this, ""));
properties.add(hash_password = propHashPassword.createProperty(this, ""));

Check warning on line 92 in app/display/model/src/main/java/org/csstudio/display/builder/model/widgets/CheckBoxWidget.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Extract the assignment out of this expression.

See more on https://sonarcloud.io/project/issues?id=ControlSystemStudio_phoebus&issues=AaEcFOhSkaFsZPR4Zrod&open=AaEcFOhSkaFsZPR4Zrod&pullRequest=3924
hash_password.setInformativeTooltip(Messages.InformativeTooltipHashPassword);
}

/** Constructor */
Expand Down Expand Up @@ -148,4 +152,11 @@
{
return password;
}

/** @return 'hash_password' property */
public WidgetProperty<String> propHashPassword()
{
return hash_password;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import static org.csstudio.display.builder.model.properties.CommonWidgetProperties.propEnabled;
import static org.csstudio.display.builder.model.properties.CommonWidgetProperties.propFont;
import static org.csstudio.display.builder.model.properties.CommonWidgetProperties.propForegroundColor;
import static org.csstudio.display.builder.model.properties.CommonWidgetProperties.propHashPassword;
import static org.csstudio.display.builder.model.properties.CommonWidgetProperties.propHorizontal;
import static org.csstudio.display.builder.model.properties.CommonWidgetProperties.propHorizontalAlignment;
import static org.csstudio.display.builder.model.properties.CommonWidgetProperties.propVerticalAlignment;
Expand Down Expand Up @@ -77,7 +78,7 @@
private volatile WidgetProperty<Boolean> confirm_dialog;
private volatile WidgetProperty<String> confirm_message;
private volatile WidgetProperty<String> password;

private volatile WidgetProperty<String> hash_password;

Check warning on line 81 in app/display/model/src/main/java/org/csstudio/display/builder/model/widgets/ChoiceButtonWidget.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Rename this field "hash_password" to match the regular expression '^[a-z][a-zA-Z0-9]*$'.

See more on https://sonarcloud.io/project/issues?id=ControlSystemStudio_phoebus&issues=AaEcFOb-kaFsZPR4ZroY&open=AaEcFOb-kaFsZPR4ZroY&pullRequest=3924
/** Constructor */
public ChoiceButtonWidget()
{
Expand Down Expand Up @@ -110,6 +111,8 @@
properties.add(confirm_dialog = propConfirmDialog.createProperty(this, false));
properties.add(confirm_message = propConfirmMessage.createProperty(this, "Are your sure you want to do this?"));
properties.add(password = propPassword.createProperty(this, ""));
properties.add(hash_password = propHashPassword.createProperty(this, ""));

Check warning on line 114 in app/display/model/src/main/java/org/csstudio/display/builder/model/widgets/ChoiceButtonWidget.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Extract the assignment out of this expression.

See more on https://sonarcloud.io/project/issues?id=ControlSystemStudio_phoebus&issues=AaEcFOb-kaFsZPR4ZroX&open=AaEcFOb-kaFsZPR4ZroX&pullRequest=3924
hash_password.setInformativeTooltip(Messages.InformativeTooltipHashPassword);
}

/** @return 'foreground_color' property */
Expand Down Expand Up @@ -147,13 +150,13 @@
{
return items;
}

/** @return 'horizontal_alignment' property */
public WidgetProperty<HorizontalAlignment> propHorizontalAlignment()
{
return horizontal_alignment;
}

/** @return 'vertical_alignment' property */
public WidgetProperty<VerticalAlignment> propVerticalAlignment()
{
Expand Down Expand Up @@ -189,4 +192,11 @@
{
return password;
}

/** @return 'hash_password' property */
public WidgetProperty<String> propHashPassword()
{
return hash_password;
}

}
Loading
Loading