Search in sources :

Example 21 with SuppressFBWarnings

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";
        }
    };
}
Also used : ScriptException(org.jaggeryjs.scriptengine.exceptions.ScriptException) HashMap(java.util.HashMap) FileTypeMap(javax.activation.FileTypeMap) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 22 with SuppressFBWarnings

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;
}
Also used : ScriptException(org.jaggeryjs.scriptengine.exceptions.ScriptException) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 23 with SuppressFBWarnings

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;
}
Also used : ScriptException(org.jaggeryjs.scriptengine.exceptions.ScriptException) JarURLConnection(java.net.JarURLConnection) URLConnection(java.net.URLConnection) JarURLConnection(java.net.JarURLConnection) URL(java.net.URL) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 24 with SuppressFBWarnings

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);
    }
}
Also used : ScriptException(org.jaggeryjs.scriptengine.exceptions.ScriptException) IOException(java.io.IOException) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 25 with SuppressFBWarnings

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;
}
Also used : SecretKeySpec(javax.crypto.spec.SecretKeySpec) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings) IvParameterSpec(javax.crypto.spec.IvParameterSpec) Cipher(javax.crypto.Cipher) Nullable(javax.annotation.Nullable)

Aggregations

SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)142 IOException (java.io.IOException)23 File (java.io.File)22 ArrayList (java.util.ArrayList)20 JPanel (javax.swing.JPanel)14 RollingStock (jmri.jmrit.operations.rollingstock.RollingStock)13 ScriptException (org.jaggeryjs.scriptengine.exceptions.ScriptException)13 FlowLayout (java.awt.FlowLayout)8 BoxLayout (javax.swing.BoxLayout)7 Location (jmri.jmrit.operations.locations.Location)7 Dimension (java.awt.Dimension)5 FileOutputStream (java.io.FileOutputStream)5 Connection (java.sql.Connection)5 PreparedStatement (java.sql.PreparedStatement)5 Iterator (java.util.Iterator)5 JScrollPane (javax.swing.JScrollPane)5 RouteLocation (jmri.jmrit.operations.routes.RouteLocation)5 JsonNode (com.fasterxml.jackson.databind.JsonNode)4 List (java.util.List)4 Entry (java.util.Map.Entry)4