/** * Retrieves the actual value from a restricted format string. * * @param value * @return */ public static String retrieveValue(String value) { if (!isRestrictedFormat(value)) { return null; } StringTokenizer tokenizer = new StringTokenizer(value, "::"); if (!tokenizer.hasMoreTokens()) { return null; } tokenizer.nextToken(); if (tokenizer.hasMoreTokens()) { return tokenizer.nextToken(); } return null; }
@SuppressWarnings("rawtypes") public ObfuscatedPreferences(Preferences actualPreferences, Class classz) { this.actualPreferences = actualPreferences; for (Field field : classz.getFields()) { Restricted restricted = field.getAnnotation(Restricted.class); if (restricted != null) { try { String restrictedProperty = field.get(classz).toString(); restrictedPreferences.add(restrictedProperty); this.get(restrictedProperty, null); } catch (Exception e) { //nothing to do, the field is just not accesible } } } try{ for (String key : actualPreferences.keys()) { if (!restrictedPreferences.contains(key)) { String storedValue = actualPreferences.get(key, null); if (storedValue != null && RestrictedFormat.isRestrictedFormat(storedValue)) { userRestrictedPreferences.add(key); } } } } catch (Exception e) { //nothing to do since this was just an exploration to see if the //user requested any other properties to be restricted } }
if (isRestricted) { String actualSystemPropertyValue = systemPropertyValue; if (RestrictedFormat.isRestrictedFormat(actualSystemPropertyValue)) { actualSystemPropertyValue = RestrictedFormat.retrieveValue(actualSystemPropertyValue);
if (restrictedPreferences.contains(key) || userRestrictedPreferences.contains(key)) { try { if (RestrictedFormat.isRestrictedFormat(value)) { value = RestrictedFormat.retrieveValue(value); value = PicketBoxObfuscator.decode(value); if (RestrictedFormat.isRestrictedFormat(value)) { userRestrictedPreferences.add(key);
@Override public String get(String key, String def) { String value = actualPreferences.get(key, null); if (value == null) { return def; } if (restrictedPreferences.contains(key) || userRestrictedPreferences.contains(key)) { try { if (RestrictedFormat.isRestrictedFormat(value)) { value = RestrictedFormat.retrieveValue(value); return PicketBoxObfuscator.decode(value); } else { throw new Exception("Value not in a restricted format"); } } catch (Exception ex) { this.put(key, value); return value; } } else { return value; } }