Search in sources :

Example 1 with EncryptedProperty

use of com.evolveum.midpoint.studio.impl.EncryptedProperty in project midpoint-studio by Evolveum.

the class EncryptedPropertiesSerializer method serialize.

public void serialize(List<EncryptedProperty> properties, File file) throws IOException {
    if (file.exists()) {
        file.delete();
    }
    file.createNewFile();
    Properties props = new Properties() {

        /**
         * not very nice way to make properties sorted when stored to file
         */
        @Override
        public Set<Map.Entry<Object, Object>> entrySet() {
            Set<Map.Entry<Object, Object>> set = new TreeSet<>((o1, o2) -> String.CASE_INSENSITIVE_ORDER.compare((String) o1.getKey(), (String) o2.getKey()));
            set.addAll(super.entrySet());
            return set;
        }
    };
    int i = 0;
    for (EncryptedProperty property : properties) {
        String prefix = "property." + i + ".";
        putProperty(props, prefix + "key", property.getKey());
        putProperty(props, prefix + "value", property.getValue());
        putProperty(props, prefix + "description", property.getDescription());
        if (property.getEnvironment() != null) {
            Environment env = environmentService.get(property.getEnvironment());
            if (env != null) {
                putProperty(props, prefix + "environment", env.getName());
            }
        }
        i++;
    }
    try (Writer w = new FileWriter(file, StandardCharsets.UTF_8)) {
        props.store(w, null);
    }
}
Also used : EncryptedProperty(com.evolveum.midpoint.studio.impl.EncryptedProperty) FileWriter(java.io.FileWriter) Environment(com.evolveum.midpoint.studio.impl.Environment) FileWriter(java.io.FileWriter) Writer(java.io.Writer)

Example 2 with EncryptedProperty

use of com.evolveum.midpoint.studio.impl.EncryptedProperty in project midpoint-studio by Evolveum.

the class EncryptedPropertiesParser method parse.

public List<EncryptedProperty> parse(File file) throws IOException {
    Properties props = new Properties();
    try (Reader r = new FileReader(file, StandardCharsets.UTF_8)) {
        props.load(r);
    }
    List<EncryptedProperty> properties = new ArrayList<>();
    // <envName, envUUID>
    Map<String, String> environments = new HashMap<>();
    for (int i = 0; ; i++) {
        String prefix = "property." + i + ".";
        String key = getProperty(props, prefix + "key");
        if (key == null) {
            break;
        }
        String value = getProperty(props, prefix + "value");
        String description = getProperty(props, prefix + "description");
        String environment = getProperty(props, prefix + "environment");
        String environmentUUID = resolveEnvironment(environment, environments);
        properties.add(new EncryptedProperty(key, environmentUUID, value, description));
    }
    return properties;
}
Also used : EncryptedProperty(com.evolveum.midpoint.studio.impl.EncryptedProperty) FileReader(java.io.FileReader) Reader(java.io.Reader) FileReader(java.io.FileReader)

Aggregations

EncryptedProperty (com.evolveum.midpoint.studio.impl.EncryptedProperty)2 Environment (com.evolveum.midpoint.studio.impl.Environment)1 FileReader (java.io.FileReader)1 FileWriter (java.io.FileWriter)1 Reader (java.io.Reader)1 Writer (java.io.Writer)1