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);
}
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);
}
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}\""));
}
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);
}
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);
}
}
Aggregations