use of com.emc.storageos.db.client.impl.EncryptionProviderImpl in project coprhd-controller by CoprHD.
the class ImageServerControllerImpl method decryptImageURLPassword.
/**
* Method to decrypt the imageURL password before it can be used.
* This method also takes care of encoding the password before use.
* @param imageUrl {@link String} compute image URL string
* @return {@link String}
*/
private String decryptImageURLPassword(String imageUrl) {
String password = extractPasswordFromImageUrl(imageUrl);
if (StringUtils.isNotBlank(password)) {
String encPwd = null;
try {
EncryptionProviderImpl encryptionProviderImpl = new EncryptionProviderImpl();
encryptionProviderImpl.setCoordinator(_coordinator);
encryptionProviderImpl.start();
EncryptionProvider encryptionProvider = encryptionProviderImpl;
encPwd = URLEncoder.encode(encryptionProvider.decrypt(Base64.decodeBase64(password)), "UTF-8");
return StringUtils.replace(imageUrl, ":" + password + "@", ":" + encPwd + "@");
} catch (UnsupportedEncodingException e) {
log.warn("Unable to encode compute image password '{}'." + "Special characters may cause issues loading compute image.", imageUrl, e.getMessage());
} catch (Exception e) {
log.error("Cannot decrypt compute image password :" + e.getLocalizedMessage());
e.printStackTrace();
throw e;
}
}
return imageUrl;
}
use of com.emc.storageos.db.client.impl.EncryptionProviderImpl in project coprhd-controller by CoprHD.
the class ComputeImageService method encryptImageURLPassword.
/**
* Method to mask/encrypt password of the ImageUrl
* @param imageUrl {@link String} compute image URL string
* @param isEncrypted boolean indicating if password is already encrypted.
* @return
*/
private String encryptImageURLPassword(String imageUrl, boolean isEncrypted) {
String password = ImageServerControllerImpl.extractPasswordFromImageUrl(imageUrl);
String encryptedPassword = password;
if (!isEncrypted && StringUtils.isNotBlank(password)) {
EncryptionProviderImpl encryptionProviderImpl = new EncryptionProviderImpl();
encryptionProviderImpl.setCoordinator(_coordinator);
encryptionProviderImpl.start();
EncryptionProvider encryptionProvider = encryptionProviderImpl;
encryptedPassword = encryptionProvider.getEncryptedString(password);
imageUrl = StringUtils.replace(imageUrl, ":" + password + "@", ":" + encryptedPassword + "@");
}
return imageUrl;
}
Aggregations