How to use Tunable for masked entry of user password?

18 views
Skip to first unread message

Mathias Kemeter

unread,
Aug 25, 2021, 3:37:39 AM8/25/21
to cytoscape-app-dev
Hi everyone,

in the past days, I have started looking into app development for Cytoscape. Thanks to the great documentation and the "App Ladder", which was a very helpful resource, I managed to develop a small app that connects to a graph workspace in SAP HANA.

To establish the database connection, I need to ask for connection credentials (host, port, user, password). This works like a charm using Tunables. However, I did not find a way to configure the password Tunable to show a text field masked by asterisks.

Is there any way to achieve this? I even tried to have a getter and setter and let the getter return asterisks. I did not succeed, but it was worth a try...

Regards,
Mathias 
(SAP HANA Graph dev team)

Scooter Morris

unread,
Aug 26, 2021, 11:21:26 AM8/26/21
to cytoscape-app-dev
Hi Mathias,
Welcome!  You are right, there is currently no way to use a Tunable for masked passwords.  I have two suggestions:
  1. File a bug using Help->Report a bug and request this as a new feature
  2. Use a pop-up dialog rather than a Tunable and implement it yourself.  This is (obviously) less desirable, particularly if you want to support automation (and believe me, you want to support automation), but it certainly will work.
  3. Okay, I guess I have three suggestions :-)  You could also add the capability yourself.  You could add a new parameter and then modify impl/work-swing-impl/impl/src/main/java/org/cytoscape/work/internal/tunables/StringHandler.java to modify how the String Tunable behaves.  This may be more than you want to tackle, but we're always happy for contributions!
-- scooter

Mike Kucera

unread,
Aug 26, 2021, 1:59:26 PM8/26/21
to cytoscape-app-dev
Hi Mathias,

There's a 4th suggestion. You could implement your own password tunable in your App.
You would have to do the following:

Create a wrapper class for the password string.

public class PasswordString {
   private String password;
   public void setPassword(String password) { ... }
   public String getPassword() { ... }
}

For the command side create a PasswordTunableHandler that extends AbstractStringTunableHandler. Here's an example for the File tunable, just return a new PasswordString(arg) instead:

Register the handler in your CyActivator like this:

StringTunableHandlerFactory<PasswordTunableHandler> passwordHandler = new SimpleStringTunableHandlerFactory<>(PasswordTunableHandler.class, PasswordString.class);

For the GUI side create a PasswordStringGUIHander that extends AbstractGUITunableHandler. Take a look at the implementation of StringHandler in cytoscape to see how this works.  You would have to figure out how to do the asterisk thing, and the calls to getValue() and setValue() would need to use instances of the PasswordString class.

Register the handler in your CyActivator, something like this:

SimpleGUITunableHandlerFactory<PasswordStringGUIHandler> passwordHandlerFactory = new SimpleGUITunableHandlerFactory<>(
PasswordStringGUIHandler.class, PasswordString.class);

registerService(bc, passwordHandlerFactory, GUITunableHandlerFactory.class);

And then you should be able to use the tunable like this:

@Tunable
public PasswordString password;

And if it works, you can always contribute the implementation back to Cytoscape so that others can use it in the future.

Thanks.
Mike.


--
You received this message because you are subscribed to the Google Groups "cytoscape-app-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cytoscape-app-...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cytoscape-app-dev/0b0cfcf4-89ba-4cec-b3e9-931211ca26a7n%40googlegroups.com.

Mathias Kemeter

unread,
Aug 27, 2021, 8:19:11 AM8/27/21
to cytoscape-app-dev
Many thanks Scooter & Mike for the great advice!

I went down Mike's path as I was hesitant to mess up code, that is not mine. The asterisk change boiled down to replacing the JTextField with a JPasswordField.

If you are interested, you can check out the implementation, which does the job for my app:

Is there a nicer way by using org.cytoscape.work.internal.tunables.utils.GUIDefaults directly?

Anyway, I filed a bug with the feature suggestion and linked my implementation. For productive use it would probably be nicer to offer an option (e.g. masked=true) for the String Tunable.

Many thanks again,
Mathias

Mike Kucera

unread,
Aug 27, 2021, 1:02:45 PM8/27/21
to cytoscape-app-dev
I think for cytoscape having a parameter "masked=true" or "password=true" for the String tunable is the way to go. It would be very easy to implement.

Thanks Mathias!


Reply all
Reply to author
Forward
0 new messages