Fixed a few findbugs issues after the merge 0b83559

HttpUploadServerHandler.java:142, DM_BOXED_PRIMITIVE_FOR_PARSING
NfsSecondaryStorageResource.java:2630, DM_BOXED_PRIMITIVE_FOR_PARSING
NfsSecondaryStorageResource.java:2775, DM_DEFAULT_ENCODING
EncryptionUtil.java:59, DM_DEFAULT_ENCODING
This commit is contained in:
Rajani Karuturi 2015-04-30 12:00:42 +05:30
parent dc3c43e607
commit d39b993512
3 changed files with 14 additions and 7 deletions

View File

@ -139,7 +139,7 @@ public class HttpUploadServerHandler extends SimpleChannelInboundHandler<HttpObj
hostname = entry.getValue();
break;
case HttpHeaders.Names.CONTENT_LENGTH:
contentLength = Long.valueOf(entry.getValue());
contentLength = Long.parseLong(entry.getValue());
break;
}
}

View File

@ -32,6 +32,7 @@ import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.math.BigInteger;
import java.net.InetAddress;
import java.net.URI;
@ -2627,7 +2628,7 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S
}
throw new InvalidParameterValueException(errorMessage.toString());
}
int maxSizeInGB = Integer.valueOf(cmd.getMaxUploadSize());
int maxSizeInGB = Integer.parseInt(cmd.getMaxUploadSize());
int contentLengthInGB = getSizeInGB(contentLength);
if (contentLengthInGB > maxSizeInGB) {
String errorMessage = "Maximum file upload size exceeded. Content Length received: " + contentLengthInGB + "GB. Maximum allowed size: " + maxSizeInGB + "GB.";
@ -2772,7 +2773,11 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S
if (extension.equals("iso")) {
templateName = uploadEntity.getUuid().trim().replace(" ", "_");
} else {
templateName = java.util.UUID.nameUUIDFromBytes((uploadEntity.getFilename() + System.currentTimeMillis()).getBytes()).toString();
try {
templateName = UUID.nameUUIDFromBytes((uploadEntity.getFilename() + System.currentTimeMillis()).getBytes("UTF-8")).toString();
} catch (UnsupportedEncodingException e) {
templateName = uploadEntity.getUuid().trim().replace(" ", "_");
}
}
// run script to mv the temporary template file to the final template

View File

@ -18,6 +18,7 @@
*/
package com.cloud.utils;
import com.cloud.utils.exception.CloudRuntimeException;
import org.apache.commons.codec.binary.Base64;
import org.apache.log4j.Logger;
import org.jasypt.encryption.pbe.PBEStringEncryptor;
@ -25,6 +26,7 @@ import org.jasypt.encryption.pbe.StandardPBEStringEncryptor;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import java.io.UnsupportedEncodingException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
@ -56,14 +58,14 @@ public class EncryptionUtil {
public static String generateSignature(String data, String key) {
try {
final Mac mac = Mac.getInstance("HmacSHA1");
final SecretKeySpec keySpec = new SecretKeySpec(key.getBytes(), "HmacSHA1");
final SecretKeySpec keySpec = new SecretKeySpec(key.getBytes("UTF-8"), "HmacSHA1");
mac.init(keySpec);
mac.update(data.getBytes());
final byte[] encryptedBytes = mac.doFinal();
return Base64.encodeBase64String(encryptedBytes);
} catch (NoSuchAlgorithmException | InvalidKeyException e) {
s_logger.error("exception occurred which encoding the data.", e);
return null;
} catch (NoSuchAlgorithmException | InvalidKeyException | UnsupportedEncodingException e) {
s_logger.error("exception occurred which encoding the data." + e.getMessage());
throw new CloudRuntimeException("unable to generate signature", e);
}
}
}