Search in sources :

Example 1 with ITwoWayPasswordEncoder

use of org.apache.hop.core.encryption.ITwoWayPasswordEncoder in project hop by apache.

the class HopConfig method buildMetadataProvider.

private void buildMetadataProvider() throws HopException {
    List<IHopMetadataProvider> providers = new ArrayList<>();
    String folder = variables.getVariable(Const.HOP_METADATA_FOLDER);
    if (StringUtils.isEmpty(folder)) {
        providers.add(new JsonMetadataProvider());
    } else {
        ITwoWayPasswordEncoder passwordEncoder = Encr.getEncoder();
        if (passwordEncoder == null) {
            passwordEncoder = new HopTwoWayPasswordEncoder();
        }
        providers.add(new JsonMetadataProvider(passwordEncoder, folder, variables));
    }
    metadataProvider = new MultiMetadataProvider(Encr.getEncoder(), providers, variables);
}
Also used : HopTwoWayPasswordEncoder(org.apache.hop.core.encryption.HopTwoWayPasswordEncoder) ITwoWayPasswordEncoder(org.apache.hop.core.encryption.ITwoWayPasswordEncoder) ArrayList(java.util.ArrayList) IHopMetadataProvider(org.apache.hop.metadata.api.IHopMetadataProvider) JsonMetadataProvider(org.apache.hop.metadata.serializer.json.JsonMetadataProvider) MultiMetadataProvider(org.apache.hop.metadata.serializer.multi.MultiMetadataProvider)

Example 2 with ITwoWayPasswordEncoder

use of org.apache.hop.core.encryption.ITwoWayPasswordEncoder in project hop by apache.

the class MetadataTestBase method setUp.

@Override
protected void setUp() throws Exception {
    HopClientEnvironment.init();
    PluginRegistry registry = PluginRegistry.getInstance();
    registry.registerPluginType(MetadataPluginType.class);
    registry.registerPluginClass(MetadataType1.class.getName(), MetadataPluginType.class, HopMetadata.class);
    assertNotNull(registry.findPluginWithId(MetadataPluginType.class, "type-1"));
    registry.registerPluginClass(MetadataType2.class.getName(), MetadataPluginType.class, HopMetadata.class);
    assertNotNull(registry.findPluginWithId(MetadataPluginType.class, "type-2"));
    IVariables variables = Variables.getADefaultVariableSpace();
    ITwoWayPasswordEncoder twoWayPasswordEncoder = new HopTwoWayPasswordEncoder();
    provider1 = new MemoryMetadataProvider(twoWayPasswordEncoder, variables);
    provider1.setDescription("Provider1");
    provider2 = new MemoryMetadataProvider(twoWayPasswordEncoder, variables);
    provider2.setDescription("Provider2");
    provider3 = new MemoryMetadataProvider(twoWayPasswordEncoder, variables);
    provider3.setDescription("Provider3");
    List<IHopMetadataProvider> providers = new ArrayList<>(Arrays.asList(provider1, provider2, provider3));
    multiMetadataProvider = new MultiMetadataProvider(twoWayPasswordEncoder, providers, variables);
}
Also used : HopTwoWayPasswordEncoder(org.apache.hop.core.encryption.HopTwoWayPasswordEncoder) ITwoWayPasswordEncoder(org.apache.hop.core.encryption.ITwoWayPasswordEncoder) MemoryMetadataProvider(org.apache.hop.metadata.serializer.memory.MemoryMetadataProvider) IVariables(org.apache.hop.core.variables.IVariables) PluginRegistry(org.apache.hop.core.plugins.PluginRegistry) ArrayList(java.util.ArrayList) IHopMetadataProvider(org.apache.hop.metadata.api.IHopMetadataProvider) MetadataPluginType(org.apache.hop.metadata.plugin.MetadataPluginType)

Example 3 with ITwoWayPasswordEncoder

use of org.apache.hop.core.encryption.ITwoWayPasswordEncoder in project hop by apache.

the class AesTwoWayPasswordEncoderTest method testEncodingInMetadata.

@Test
public void testEncodingInMetadata() throws HopException {
    MemoryMetadataProvider metadataProvider = new MemoryMetadataProvider();
    ITwoWayPasswordEncoder twoWayPasswordEncoder = metadataProvider.getTwoWayPasswordEncoder();
    assertNotNull(twoWayPasswordEncoder);
    assertEquals(AesTwoWayPasswordEncoder.class, twoWayPasswordEncoder.getClass());
    // Store something in there...
    // 
    DatabaseMeta databaseMeta = new DatabaseMeta();
    databaseMeta.setName("test");
    databaseMeta.setDatabaseType("None");
    databaseMeta.setUsername("user");
    databaseMeta.setPassword("password");
    IHopMetadataSerializer<DatabaseMeta> serializer = metadataProvider.getSerializer(DatabaseMeta.class);
    serializer.save(databaseMeta);
    String json = new SerializableMetadataProvider(metadataProvider).toJson();
    assertTrue(json.contains("\"password\":\"AES 86lpAqp+Xpa\\/zp6m3SYcFQ==\""));
    databaseMeta.setPassword("${DB_PASSWORD}");
    serializer.save(databaseMeta);
    json = new SerializableMetadataProvider(metadataProvider).toJson();
    assertTrue(json.contains("\"password\":\"${DB_PASSWORD}\""));
}
Also used : MemoryMetadataProvider(org.apache.hop.metadata.serializer.memory.MemoryMetadataProvider) ITwoWayPasswordEncoder(org.apache.hop.core.encryption.ITwoWayPasswordEncoder) SerializableMetadataProvider(org.apache.hop.core.metadata.SerializableMetadataProvider) DatabaseMeta(org.apache.hop.core.database.DatabaseMeta) Test(org.junit.Test)

Example 4 with ITwoWayPasswordEncoder

use of org.apache.hop.core.encryption.ITwoWayPasswordEncoder in project hop by apache.

the class HopSearch method buildMetadataProvider.

private void buildMetadataProvider() throws HopException {
    List<IHopMetadataProvider> providers = new ArrayList<>();
    String folder = variables.getVariable(Const.HOP_METADATA_FOLDER);
    if (StringUtils.isEmpty(folder)) {
        providers.add(new JsonMetadataProvider());
    } else {
        ITwoWayPasswordEncoder passwordEncoder = Encr.getEncoder();
        if (passwordEncoder == null) {
            passwordEncoder = new HopTwoWayPasswordEncoder();
        }
        providers.add(new JsonMetadataProvider(passwordEncoder, folder, variables));
    }
    metadataProvider = new MultiMetadataProvider(Encr.getEncoder(), providers, variables);
}
Also used : HopTwoWayPasswordEncoder(org.apache.hop.core.encryption.HopTwoWayPasswordEncoder) ITwoWayPasswordEncoder(org.apache.hop.core.encryption.ITwoWayPasswordEncoder) IHopMetadataProvider(org.apache.hop.metadata.api.IHopMetadataProvider) JsonMetadataProvider(org.apache.hop.metadata.serializer.json.JsonMetadataProvider) MultiMetadataProvider(org.apache.hop.metadata.serializer.multi.MultiMetadataProvider)

Example 5 with ITwoWayPasswordEncoder

use of org.apache.hop.core.encryption.ITwoWayPasswordEncoder in project hop by apache.

the class JsonMetadataParser method saveProperty.

private void saveProperty(JSONObject jObject, Object object, HopMetadataProperty metadataProperty, Field objectField) throws HopException {
    String key = objectField.getName();
    if (StringUtils.isNotEmpty(metadataProperty.key())) {
        key = metadataProperty.key();
    }
    Class<?> fieldType = objectField.getType();
    boolean isBoolean = Boolean.class.equals(fieldType) || boolean.class.equals(fieldType);
    try {
        Object fieldValue = ReflectionUtil.getFieldValue(object, objectField.getName(), isBoolean);
        if (fieldValue == null) {
            jObject.put(key, null);
        } else {
            // Enumeration?
            if (fieldType.isEnum()) {
                // Save the enum as its name
                jObject.put(key, ((Enum) fieldValue).name());
            } else if (String.class.equals(fieldType)) {
                String fieldStringValue = (String) fieldValue;
                if (metadataProperty.password()) {
                    ITwoWayPasswordEncoder passwordEncoder = metadataProvider.getTwoWayPasswordEncoder();
                    fieldStringValue = passwordEncoder.encode(fieldStringValue, true);
                }
                jObject.put(key, fieldStringValue);
            } else if (int.class.equals(fieldType) || Integer.class.equals(fieldType)) {
                jObject.put(key, fieldValue);
            } else if (long.class.equals(fieldType) || Long.class.equals(fieldType)) {
                jObject.put(key, fieldValue);
            } else if (isBoolean) {
                jObject.put(key, fieldValue);
            } else if (Date.class.equals(fieldType)) {
                String dateString = new SimpleDateFormat("yyyy/MM/dd'T'HH:mm:ss").format((Date) fieldValue);
                jObject.put(key, dateString);
            } else if (Map.class.equals(fieldType)) {
                jObject.put(key, new JSONObject((Map) fieldValue));
            } else if (List.class.equals(fieldType)) {
                JSONArray jListObjects = new JSONArray();
                ParameterizedType parameterizedType = (ParameterizedType) objectField.getGenericType();
                Class<?> listClass = (Class<?>) parameterizedType.getActualTypeArguments()[0];
                List<?> fieldListObjects = (List<?>) fieldValue;
                for (Object fieldListObject : fieldListObjects) {
                    if (String.class.equals(listClass)) {
                        jListObjects.add(fieldListObject);
                    } else if (metadataProperty.storeWithName()) {
                        String name = ReflectionUtil.getObjectName(fieldListObject);
                        jListObjects.add(name);
                    } else {
                        JSONObject jListObject = savePojoProperty(key, fieldListObject, listClass);
                        jListObjects.add(jListObject);
                    }
                }
                jObject.put(key, jListObjects);
            } else {
                if (metadataProperty.storeWithName()) {
                    // Just save the name
                    String name = ReflectionUtil.getObjectName(fieldValue);
                    jObject.put(key, name);
                } else {
                    JSONObject jPojo = savePojoProperty(key, fieldValue, fieldType);
                    jObject.put(key, jPojo);
                }
            }
        }
    } catch (Exception e) {
        throw new HopException("Error serializing field '" + objectField.getName() + "' with type '" + fieldType.toString() + "'", e);
    }
}
Also used : ITwoWayPasswordEncoder(org.apache.hop.core.encryption.ITwoWayPasswordEncoder) HopException(org.apache.hop.core.exception.HopException) JSONArray(org.json.simple.JSONArray) HopException(org.apache.hop.core.exception.HopException) ParameterizedType(java.lang.reflect.ParameterizedType) JSONObject(org.json.simple.JSONObject) JSONObject(org.json.simple.JSONObject) SimpleDateFormat(java.text.SimpleDateFormat)

Aggregations

ITwoWayPasswordEncoder (org.apache.hop.core.encryption.ITwoWayPasswordEncoder)5 HopTwoWayPasswordEncoder (org.apache.hop.core.encryption.HopTwoWayPasswordEncoder)3 IHopMetadataProvider (org.apache.hop.metadata.api.IHopMetadataProvider)3 ArrayList (java.util.ArrayList)2 JsonMetadataProvider (org.apache.hop.metadata.serializer.json.JsonMetadataProvider)2 MemoryMetadataProvider (org.apache.hop.metadata.serializer.memory.MemoryMetadataProvider)2 MultiMetadataProvider (org.apache.hop.metadata.serializer.multi.MultiMetadataProvider)2 ParameterizedType (java.lang.reflect.ParameterizedType)1 SimpleDateFormat (java.text.SimpleDateFormat)1 DatabaseMeta (org.apache.hop.core.database.DatabaseMeta)1 HopException (org.apache.hop.core.exception.HopException)1 SerializableMetadataProvider (org.apache.hop.core.metadata.SerializableMetadataProvider)1 PluginRegistry (org.apache.hop.core.plugins.PluginRegistry)1 IVariables (org.apache.hop.core.variables.IVariables)1 MetadataPluginType (org.apache.hop.metadata.plugin.MetadataPluginType)1 JSONArray (org.json.simple.JSONArray)1 JSONObject (org.json.simple.JSONObject)1 Test (org.junit.Test)1