@Override public PropertySimple deepCopy(boolean keepId) { return new ObfuscatedPropertySimple(this, keepId); }
@Override public void mask() { if (getStringValue() != null) { setValue(MASKED_VALUE); } }
/** * The value of this property as string. Note that this is always in "clear text". I.e. the value * you get from this method is NOT obfuscated (but it gets stored in the database obfuscated). */ @Override public String getStringValue() { if (clearTextValue == null) { initClearTextValue(); } return clearTextValue; }
private static void replace(PropertySimple prop) { ObfuscatedPropertySimple replacement = new ObfuscatedPropertySimple(prop); replacement.setParentList(prop.getParentList()); replacement.setParentMap(prop.getParentMap()); replacement.setConfiguration(prop.getConfiguration()); if (prop.getParentList() != null) { List<Property> list = prop.getParentList().getList(); int idx = list.indexOf(prop); list.remove(prop); list.add(idx, replacement); } else if (prop.getParentMap() != null) { Map<String, Property> map = prop.getParentMap().getMap(); replaceInMap(replacement, map); } else { Configuration conf = prop.getConfiguration(); replaceInMap(replacement, conf.getMap()); } }
@PostLoad protected void initClearTextValue() { clearTextValue = deobfuscate(getObfuscatedStringValue()); }
/** * Overriden to not leak the unobfuscated value in the toString() method, output of which * might end up in logs, etc. */ @Override protected void appendToStringInternals(StringBuilder str) { str.append(", obfuscated-value=").append(getObfuscatedStringValue()); str.append(", override=").append(getOverride()); };
@Override public Boolean getBooleanValue() { String val = getStringValue(); return val == null ? null : Boolean.valueOf(val); }
private static void replaceInMap(ObfuscatedPropertySimple replacement, Map<String, Property> map) { //we need to maintain the order, so let's take a slightly more //complicated approach Iterator<Map.Entry<String, Property>> it = map.entrySet().iterator(); while(it.hasNext()) { Map.Entry<String, Property> entry = it.next(); if (entry.getKey().equals(replacement.getName())) { entry.setValue(replacement); break; } } } }
/** * Sets the value of this property. You should pass the "clear text" value - the obfuscation of * the value in the database is done for you behind the scenes. */ @Override public void setValue(Object value) { //just use the logic in the superclass to set the value super.setValue(value); //and obtain the result this.clearTextValue = super.getStringValue(); //now set the underlying value to the obfuscated one super.setValue(obfuscate(clearTextValue)); //now we have the clear text string representation of the value in "clearTextValue", //the stringValue in the superclass contains the corresponding obfuscated string. }
@Override public Float getFloatValue() { String val = getStringValue(); return val == null ? null : Float.valueOf(val); }
@Override public Double getDoubleValue() { String val = getStringValue(); return val == null ? null : Double.valueOf(val); }
private void readObject(ObjectInputStream str) throws IOException, ClassNotFoundException { str.defaultReadObject(); initClearTextValue(); } }
@Override public Long getLongValue() { String val = getStringValue(); return val == null ? null : Long.valueOf(val); }
@Override public Integer getIntegerValue() { String val = getStringValue(); return val == null ? null : Integer.valueOf(val); }
@Override public boolean isMasked() { return MASKED_VALUE.equals(getStringValue()); }