use of edu.umd.cs.findbugs.annotations.SuppressFBWarnings in project jaggery by wso2.
the class FileHostObject method loadMimeMap.
@SuppressFBWarnings("PATH_TRAVERSAL_IN")
private static FileTypeMap loadMimeMap() throws ScriptException {
String configDirPath = CarbonUtils.getEtcCarbonConfigDirPath();
File configFile = new File(configDirPath, RESOURCE_MEDIA_TYPE_MAPPINGS_FILE);
if (!configFile.exists()) {
String msg = "Resource media type definitions file (mime.types) file does " + "not exist in the path " + configDirPath;
log.error(msg);
throw new ScriptException(msg);
}
final Map<String, String> mimeMappings = new HashMap<String, String>();
final String mappings;
try {
mappings = FileUtils.readFileToString(configFile, "UTF-8");
} catch (IOException e) {
String msg = "Error opening resource media type definitions file " + "(mime.types) : " + e.getMessage();
throw new ScriptException(msg, e);
}
String[] lines = mappings.split("[\\r\\n]+");
for (String line : lines) {
if (!line.startsWith("#")) {
String[] parts = line.split("\\s+");
for (int i = 1; i < parts.length; i++) {
mimeMappings.put(parts[i], parts[0]);
}
}
}
return new FileTypeMap() {
@Override
public String getContentType(File file) {
return getContentType(file.getName());
}
@Override
public String getContentType(String fileName) {
int i = fileName.lastIndexOf('.');
if (i > 0) {
String mimeType = mimeMappings.get(fileName.substring(i + 1));
if (mimeType != null) {
return mimeType;
}
}
return "application/octet-stream";
}
};
}
use of edu.umd.cs.findbugs.annotations.SuppressFBWarnings in project jaggery by wso2.
the class JavaScriptFileImpl method open.
@SuppressFBWarnings({ "PATH_TRAVERSAL_IN", "PATH_TRAVERSAL_IN", "PATH_TRAVERSAL_IN", "PATH_TRAVERSAL_IN", "PATH_TRAVERSAL_IN", "PATH_TRAVERSAL_IN" })
@Override
public void open(String mode) throws ScriptException {
if ("r".equals(mode)) {
try {
file = new RandomAccessFile(path, "r");
} catch (FileNotFoundException e) {
log.error(e.getMessage(), e);
throw new ScriptException(e);
}
readable = true;
} else if ("r+".equals(mode)) {
try {
file = new RandomAccessFile(path, "rw");
file.seek(0);
} catch (FileNotFoundException e) {
log.error(e.getMessage(), e);
throw new ScriptException(e);
} catch (IOException e) {
log.error(e.getMessage(), e);
throw new ScriptException(e);
}
readable = true;
writable = true;
} else if ("w".equals(mode)) {
try {
file = new RandomAccessFile(path, "rw");
file.setLength(0);
} catch (FileNotFoundException e) {
log.error(e.getMessage(), e);
throw new ScriptException(e);
} catch (IOException e) {
log.error(e.getMessage(), e);
throw new ScriptException(e);
}
writable = true;
} else if ("w+".equals(mode)) {
try {
file = new RandomAccessFile(path, "rw");
file.setLength(0);
} catch (FileNotFoundException e) {
log.error(e.getMessage(), e);
throw new ScriptException(e);
} catch (IOException e) {
log.error(e.getMessage(), e);
throw new ScriptException(e);
}
readable = true;
writable = true;
} else if ("a".equals(mode)) {
try {
file = new RandomAccessFile(path, "rw");
file.seek(file.length());
} catch (FileNotFoundException e) {
log.error(e.getMessage(), e);
throw new ScriptException(e);
} catch (IOException e) {
log.error(e.getMessage(), e);
throw new ScriptException(e);
}
writable = true;
} else if ("a+".equals(mode)) {
try {
file = new RandomAccessFile(path, "rw");
file.seek(file.length());
} catch (FileNotFoundException e) {
log.error(e.getMessage(), e);
throw new ScriptException(e);
} catch (IOException e) {
log.error(e.getMessage(), e);
throw new ScriptException(e);
}
readable = true;
writable = true;
} else {
String msg = "Invalid file mode, path : " + path + ", mode : " + mode;
log.error(msg);
throw new ScriptException(msg);
}
opened = true;
}
use of edu.umd.cs.findbugs.annotations.SuppressFBWarnings in project jaggery by wso2.
the class WebAppManager method getScriptLastModified.
@SuppressFBWarnings({ "CRLF_INJECTION_LOGS", "CRLF_INJECTION_LOGS", "CRLF_INJECTION_LOGS" })
private static long getScriptLastModified(ServletContext context, String scriptPath) throws ScriptException {
long result = -1;
URLConnection uc = null;
try {
URL scriptUrl = context.getResource(canonicalURI(scriptPath));
if (scriptUrl == null) {
String msg = "Requested resource " + scriptPath + " cannot be found";
log.error(msg);
throw new ScriptException(msg);
}
uc = scriptUrl.openConnection();
if (uc instanceof JarURLConnection) {
result = ((JarURLConnection) uc).getJarEntry().getTime();
} else {
result = uc.getLastModified();
}
} catch (IOException e) {
log.warn("Error getting last modified time for " + scriptPath, e);
result = -1;
} finally {
if (uc != null) {
try {
uc.getInputStream().close();
} catch (IOException e) {
log.error("Error closing input stream for script " + scriptPath, e);
}
}
}
return result;
}
use of edu.umd.cs.findbugs.annotations.SuppressFBWarnings in project jaggery by wso2.
the class ResponseHostObject method jsFunction_sendRedirect.
@SuppressFBWarnings("UNVALIDATED_REDIRECT")
public static void jsFunction_sendRedirect(Context cx, Scriptable thisObj, Object[] args, Function funObj) throws ScriptException {
String functionName = "sendRedirect";
int argsCount = args.length;
if (argsCount != 1) {
HostObjectUtil.invalidNumberOfArgs(hostObjectName, functionName, argsCount, false);
}
if (!(args[0] instanceof String)) {
HostObjectUtil.invalidArgsError(hostObjectName, functionName, "1", "string", args[0], false);
}
ResponseHostObject rho = (ResponseHostObject) thisObj;
try {
rho.response.sendRedirect((String) args[0]);
} catch (IOException e) {
String msg = "Error sending redirect : " + args[0];
log.warn(msg, e);
throw new ScriptException(msg, e);
}
}
use of edu.umd.cs.findbugs.annotations.SuppressFBWarnings in project graylog2-server by Graylog2.
the class AESTools method decrypt.
@Nullable
public static String decrypt(String cipherText, String encryptionKey, String salt) {
try {
@SuppressFBWarnings("CIPHER_INTEGRITY") Cipher cipher = Cipher.getInstance("AES/CBC/ISO10126Padding", "SunJCE");
SecretKeySpec key = new SecretKeySpec(encryptionKey.getBytes("UTF-8"), "AES");
cipher.init(Cipher.DECRYPT_MODE, key, new IvParameterSpec(salt.getBytes("UTF-8")));
return new String(cipher.doFinal(Hex.decode(cipherText)), "UTF-8");
} catch (Exception e) {
LOG.error("Could not decrypt value.", e);
}
return null;
}
Aggregations