/* * Copyright (c) 2017 NetApp * All rights reserved */ package com.onaro.util.jfc.wizard.field; import java.util.HashMap; import java.util.Map; import javax.swing.JTextField; import org.apache.commons.lang3.StringUtils; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import com.onaro.util.jfc.mixedvalue.MixedValuePasswordField; public class PasswordField extends StringField { /** * Caches encrypted passwords so same plain-text will always get the same encryption. This is needed as to avoid * generation of "audit" events when the password doesn't change. */ private Map encryptedByPassword = new HashMap<>(2); public PasswordField(FieldListener listner) { super(listner); encryptedByPassword.put(StringUtils.EMPTY, "EW84z6F3MDQ=m3Y5suTid40="); //$NON-NLS-1$ } /** * Gets the encrypted value. The method performes a cache so that multiple gets will not generate multiple encryption * operations. * * @return encrypted value */ public String getValue() { String value = super.getValue(); // Returns null if there is no value entered in this field, for example, in a situation where // the user clears up the text-box corresponding to the password value. // // HEADSUP: // If this field is "mandatory" by returning a NULL we guarantee that the validation against // empty data for mandatory field takes place. If we return an empty string (return "") is not the same effect, // due to the fact that the validation agaist empty data for mandatory field will check for NULL's and an empty string is a "value". if (value == null) return null; return value; } /** * Set the value as clear text. */ public void setValue(String value) { super.setValue(value); } protected JTextField createField() { return new MixedValuePasswordField(); } public void setMixedValue(boolean mixedValue) { ((MixedValuePasswordField)getComponent()).setMixed(mixedValue); } public boolean isMixedValue() { return ((MixedValuePasswordField)getComponent()).isMixed(); } }