<commit_before>/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.widgetfx.classloader;

import java.net.URL;
import java.net.URLClassLoader;
import java.net.URLStreamHandlerFactory;
import java.security.AllPermission;
import java.security.CodeSource;
import java.security.PermissionCollection;
import java.util.Arrays;

/**
 * @author <NAME>
 * @author <NAME>
 */
public class WidgetFXClassLoader extends URLClassLoader {

    public WidgetFXClassLoader(URL[] urls, ClassLoader parent, URLStreamHandlerFactory factory) {
        super(urls, parent, factory);
    }

    public WidgetFXClassLoader(URL[] urls) {
        super(urls);
    }

    public WidgetFXClassLoader(URL[] urls, ClassLoader parent) {
        super(urls, parent);
    }

    @Override
    protected PermissionCollection getPermissions(CodeSource codesource) {
        System.out.println("getPermissions called with codesigners: " + (codesource.getCodeSigners() == null ? null : Arrays.asList(codesource.getCodeSigners())));
        System.out.println("getPermissions called with codecertificates: " + (codesource.getCertificates() == null ? null : Arrays.asList(codesource.getCertificates())));
        if (codesource.getCertificates() != null && codesource.getCertificates().length > 0) {
            AllPermission all = new AllPermission();
            PermissionCollection permissions = all.newPermissionCollection();
            permissions.add(all);
            return permissions;
        } else {
            return super.getPermissions(codesource);
        }
    }
}<commit_msg>Security framework improvements.<commit_after>/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.widgetfx.classloader;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URL;
import java.net.URLClassLoader;
import java.net.URLStreamHandlerFactory;
import java.security.AllPermission;
import java.security.CodeSource;
import java.security.KeyStore;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.PermissionCollection;
import java.security.cert.Certificate;
import java.security.cert.CertificateException;
import java.util.Arrays;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 * @author <NAME>
 * @author <NAME>
 */
public class WidgetFXClassLoader extends URLClassLoader {

    public WidgetFXClassLoader(URL[] urls, ClassLoader parent, URLStreamHandlerFactory factory) {
        super(urls, parent, factory);
    }

    public WidgetFXClassLoader(URL[] urls) {
        super(urls);
    }

    public WidgetFXClassLoader(URL[] urls, ClassLoader parent) {
        super(urls, parent);
    }

    @Override
    protected PermissionCollection getPermissions(CodeSource codesource) {
        try {
            KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
            String trustedCerts = System.getProperty("deployment.user.security.trusted.certs");
            System.out.println(trustedCerts);
            FileInputStream fis = new FileInputStream(trustedCerts);
            try {
                ks.load(fis, null);
            } finally {
                fis.close();
            }
            Certificate[] certificates = codesource.getCertificates();
            if (certificates != null && certificates.length > 0) {
                for (Certificate cert : certificates) {
                    String alias = ks.getCertificateAlias(cert);
                    boolean trusted = alias != null && ks.isCertificateEntry(alias);
                    if (!trusted) {
                        alias = "deploymentusercert$tsflag-" + System.currentTimeMillis();
                        ks.setCertificateEntry(alias, cert);
                        System.out.println("storing key with alias = " + alias);
                        FileOutputStream fos = new FileOutputStream(trustedCerts);
                        try {
                            ks.store(fos, new char[0]);
                        } finally {
                            fos.close();
                        }
                    }
                }
                AllPermission all = new AllPermission();
                PermissionCollection permissions = all.newPermissionCollection();
                permissions.add(all);
                return permissions;
            }
        } catch (IOException ex) {
            Logger.getLogger(WidgetFXClassLoader.class.getName()).log(Level.SEVERE, null, ex);
        } catch (NoSuchAlgorithmException ex) {
            Logger.getLogger(WidgetFXClassLoader.class.getName()).log(Level.SEVERE, null, ex);
        } catch (CertificateException ex) {
            Logger.getLogger(WidgetFXClassLoader.class.getName()).log(Level.SEVERE, null, ex);
        } catch (KeyStoreException ex) {
            Logger.getLogger(WidgetFXClassLoader.class.getName()).log(Level.SEVERE, null, ex);
        }
        return super.getPermissions(codesource);
    }
}
{'fraction_non_alphanumeric': 0.10100216152485754, 'fraction_numerical': 0.0005895067793279622, 'mean_word_length': 2.612491128459901, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4822914', 'n_tokens_mistral': 1308, 'n_tokens_neox': 1296, 'n_words': 283}