Compare commits

...

5 Commits

2 changed files with 40 additions and 0 deletions

View File

@@ -7,6 +7,7 @@ package org.talend.designer.core.model.utils.emf.talendfile.impl;
import java.util.Collection;
import org.apache.commons.codec.binary.StringUtils;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;
import org.eclipse.emf.common.util.EList;
@@ -326,6 +327,10 @@ public class ElementParameterTypeImpl extends EObjectImpl implements ElementPara
public void setRawValue(String newValue) {
if (newValue != null && newValue.length() > 0 && PasswordEncryptUtil.isPasswordField(getField())) {
String oldValue = getValue();
if (StudioEncryption.isLatestKeyResult(oldValue) && StringUtils.equals(newValue, getRawValue())) {
return;
}
String encryptValue = StudioEncryption.getStudioEncryption(StudioEncryption.EncryptionKeyName.SYSTEM)
.encrypt(newValue);
if (encryptValue != null) {

View File

@@ -21,6 +21,7 @@ import java.io.OutputStream;
import java.security.Provider;
import java.security.Security;
import java.util.Base64;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties;
@@ -54,6 +55,8 @@ public class StudioEncryption {
private static final Pattern REG_ENCRYPTED_DATA_ROUTINE = Pattern
.compile("^enc\\:routine\\.encryption\\.key\\.v\\d\\:\\p{Print}+");
private static final Map <String, String> LATEST_KEY_DESC = new HashMap<String, String>();
private EncryptionKeyName keyName;
@@ -107,6 +110,38 @@ public class StudioEncryption {
LOGGER.error("Can not load encryption key: " + encryptionKeyName, e);
throw e;
}
public static boolean isLatestKeyResult(String input) {
if (input != null && hasEncryptionSymbol(input)) {
EncryptionKeyName keyName = null;
if (input.startsWith(PREFIX_PASSWORD + StudioKeyName.KEY_SYSTEM_PREFIX)) {
keyName = StudioEncryption.EncryptionKeyName.SYSTEM;
} else if (input.startsWith(PREFIX_PASSWORD + StudioKeyName.KEY_ROUTINE_PREFIX)) {
keyName = StudioEncryption.EncryptionKeyName.ROUTINE;
} else if (input.startsWith(PREFIX_PASSWORD + StudioKeyName.KEY_MIGRATION)) {
keyName = StudioEncryption.EncryptionKeyName.MIGRATION;
} else if (input.startsWith(PREFIX_PASSWORD + StudioKeyName.KEY_MIGRATION_TOKEN)) {
keyName = StudioEncryption.EncryptionKeyName.MIGRATION_TOKEN;
}
if (keyName != null) {
StudioKeySource ks = getKeySource(keyName.name, true);
String keyResult = LATEST_KEY_DESC.get(keyName.name);
if (keyResult == null) {
StringBuilder sb = new StringBuilder();
sb.append(PREFIX_PASSWORD);
sb.append(ks.getKeyName());
sb.append(":");
keyResult = sb.toString();
LATEST_KEY_DESC.put(keyName.name, keyResult);
}
if (input.startsWith(LATEST_KEY_DESC.get(keyName.name))) {
return true;
}
}
}
return false;
}
private Encryption getEncryption(StudioKeySource ks) {
CipherSource cs = null;