java.security.UnresolvedPermission Java Examples

The following examples show how to use java.security.UnresolvedPermission. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PluginSecurity.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
/** Format permission type, name, and actions into a string */
static String formatPermission(Permission permission) {
    StringBuilder sb = new StringBuilder();
    
    String clazz = null;
    if (permission instanceof UnresolvedPermission) {
        clazz = ((UnresolvedPermission) permission).getUnresolvedType();
    } else {
        clazz = permission.getClass().getName();
    }
    sb.append(clazz);
    
    String name = null;
    if (permission instanceof UnresolvedPermission) {
        name = ((UnresolvedPermission) permission).getUnresolvedName();
    } else {
        name = permission.getName();
    }
    if (name != null && name.length() > 0) {
        sb.append(' ');
        sb.append(name);
    }
    
    String actions = null;
    if (permission instanceof UnresolvedPermission) {
        actions = ((UnresolvedPermission) permission).getUnresolvedActions();
    } else {
        actions = permission.getActions();
    }
    if (actions != null && actions.length() > 0) {
        sb.append(' ');
        sb.append(actions);
    }
    return sb.toString();
}
 
Example #2
Source File: AppEngineWebXml.java    From appengine-java-vm-runtime with Apache License 2.0 5 votes vote down vote up
public Permissions getUserPermissions() {
  Permissions permissions = new Permissions();
  for (UserPermission permission : userPermissions) {
    permissions.add(
        new UnresolvedPermission(
            permission.getClassName(), permission.getName(), permission.getActions(), null));
  }
  permissions.setReadOnly();
  return permissions;
}
 
Example #3
Source File: AccessorMethods.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {

        // set CA cert in chain
        File f = new File(System.getProperty("test.src", "."), CA);
        FileInputStream fis = new FileInputStream(f);
        CertificateFactory fac = CertificateFactory.getInstance("X.509");
        Certificate cacert = fac.generateCertificate(fis);
        Certificate[] signercerts = new Certificate[4];
        signercerts[1] = cacert;
        signercerts[3] = cacert;

        // set signer certs
        f = new File(System.getProperty("test.src", "."), SIGNER1);
        fis = new FileInputStream(f);
        Certificate signer1 = fac.generateCertificate(fis);
        signercerts[0] = signer1;

        f = new File(System.getProperty("test.src", "."), SIGNER2);
        fis = new FileInputStream(f);
        Certificate signer2 = fac.generateCertificate(fis);
        signercerts[2] = signer2;

        UnresolvedPermission up = new UnresolvedPermission
                        ("type", "name", "actions", signercerts);
        if (!up.getUnresolvedType().equals("type") ||
            !up.getUnresolvedName().equals("name") ||
            !up.getUnresolvedActions().equals("actions")) {
            throw new SecurityException("Test 1 Failed");
        }

        Certificate[] certs = up.getUnresolvedCerts();
        if (certs == null || certs.length != 2) {
            throw new SecurityException("Test 2 Failed");
        }

        boolean foundSigner1 = false;
        boolean foundSigner2 = false;
        if (certs[0].equals(signer1) || certs[1].equals(signer1)) {
            foundSigner1 = true;
        }
        if (certs[0].equals(signer2) || certs[1].equals(signer2)) {
            foundSigner2 = true;
        }
        if (!foundSigner1 || !foundSigner2) {
            throw new SecurityException("Test 3 Failed");
        }
    }
 
Example #4
Source File: AccessorMethods.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {

        // set CA cert in chain
        File f = new File(System.getProperty("test.src", "."), CA);
        FileInputStream fis = new FileInputStream(f);
        CertificateFactory fac = CertificateFactory.getInstance("X.509");
        Certificate cacert = fac.generateCertificate(fis);
        Certificate[] signercerts = new Certificate[4];
        signercerts[1] = cacert;
        signercerts[3] = cacert;

        // set signer certs
        f = new File(System.getProperty("test.src", "."), SIGNER1);
        fis = new FileInputStream(f);
        Certificate signer1 = fac.generateCertificate(fis);
        signercerts[0] = signer1;

        f = new File(System.getProperty("test.src", "."), SIGNER2);
        fis = new FileInputStream(f);
        Certificate signer2 = fac.generateCertificate(fis);
        signercerts[2] = signer2;

        UnresolvedPermission up = new UnresolvedPermission
                        ("type", "name", "actions", signercerts);
        if (!up.getUnresolvedType().equals("type") ||
            !up.getUnresolvedName().equals("name") ||
            !up.getUnresolvedActions().equals("actions")) {
            throw new SecurityException("Test 1 Failed");
        }

        Certificate[] certs = up.getUnresolvedCerts();
        if (certs == null || certs.length != 2) {
            throw new SecurityException("Test 2 Failed");
        }

        boolean foundSigner1 = false;
        boolean foundSigner2 = false;
        if (certs[0].equals(signer1) || certs[1].equals(signer1)) {
            foundSigner1 = true;
        }
        if (certs[0].equals(signer2) || certs[1].equals(signer2)) {
            foundSigner2 = true;
        }
        if (!foundSigner1 || !foundSigner2) {
            throw new SecurityException("Test 3 Failed");
        }
    }
 
Example #5
Source File: AccessorMethods.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {

        // set CA cert in chain
        File f = new File(System.getProperty("test.src", "."), CA);
        FileInputStream fis = new FileInputStream(f);
        CertificateFactory fac = CertificateFactory.getInstance("X.509");
        Certificate cacert = fac.generateCertificate(fis);
        Certificate[] signercerts = new Certificate[4];
        signercerts[1] = cacert;
        signercerts[3] = cacert;

        // set signer certs
        f = new File(System.getProperty("test.src", "."), SIGNER1);
        fis = new FileInputStream(f);
        Certificate signer1 = fac.generateCertificate(fis);
        signercerts[0] = signer1;

        f = new File(System.getProperty("test.src", "."), SIGNER2);
        fis = new FileInputStream(f);
        Certificate signer2 = fac.generateCertificate(fis);
        signercerts[2] = signer2;

        UnresolvedPermission up = new UnresolvedPermission
                        ("type", "name", "actions", signercerts);
        if (!up.getUnresolvedType().equals("type") ||
            !up.getUnresolvedName().equals("name") ||
            !up.getUnresolvedActions().equals("actions")) {
            throw new SecurityException("Test 1 Failed");
        }

        Certificate[] certs = up.getUnresolvedCerts();
        if (certs == null || certs.length != 2) {
            throw new SecurityException("Test 2 Failed");
        }

        boolean foundSigner1 = false;
        boolean foundSigner2 = false;
        if (certs[0].equals(signer1) || certs[1].equals(signer1)) {
            foundSigner1 = true;
        }
        if (certs[0].equals(signer2) || certs[1].equals(signer2)) {
            foundSigner2 = true;
        }
        if (!foundSigner1 || !foundSigner2) {
            throw new SecurityException("Test 3 Failed");
        }
    }
 
Example #6
Source File: AccessorMethods.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {

        // set CA cert in chain
        File f = new File(System.getProperty("test.src", "."), CA);
        FileInputStream fis = new FileInputStream(f);
        CertificateFactory fac = CertificateFactory.getInstance("X.509");
        Certificate cacert = fac.generateCertificate(fis);
        Certificate[] signercerts = new Certificate[4];
        signercerts[1] = cacert;
        signercerts[3] = cacert;

        // set signer certs
        f = new File(System.getProperty("test.src", "."), SIGNER1);
        fis = new FileInputStream(f);
        Certificate signer1 = fac.generateCertificate(fis);
        signercerts[0] = signer1;

        f = new File(System.getProperty("test.src", "."), SIGNER2);
        fis = new FileInputStream(f);
        Certificate signer2 = fac.generateCertificate(fis);
        signercerts[2] = signer2;

        UnresolvedPermission up = new UnresolvedPermission
                        ("type", "name", "actions", signercerts);
        if (!up.getUnresolvedType().equals("type") ||
            !up.getUnresolvedName().equals("name") ||
            !up.getUnresolvedActions().equals("actions")) {
            throw new SecurityException("Test 1 Failed");
        }

        Certificate[] certs = up.getUnresolvedCerts();
        if (certs == null || certs.length != 2) {
            throw new SecurityException("Test 2 Failed");
        }

        boolean foundSigner1 = false;
        boolean foundSigner2 = false;
        if (certs[0].equals(signer1) || certs[1].equals(signer1)) {
            foundSigner1 = true;
        }
        if (certs[0].equals(signer2) || certs[1].equals(signer2)) {
            foundSigner2 = true;
        }
        if (!foundSigner1 || !foundSigner2) {
            throw new SecurityException("Test 3 Failed");
        }
    }
 
Example #7
Source File: AccessorMethods.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {

        // set CA cert in chain
        File f = new File(System.getProperty("test.src", "."), CA);
        FileInputStream fis = new FileInputStream(f);
        CertificateFactory fac = CertificateFactory.getInstance("X.509");
        Certificate cacert = fac.generateCertificate(fis);
        Certificate[] signercerts = new Certificate[4];
        signercerts[1] = cacert;
        signercerts[3] = cacert;

        // set signer certs
        f = new File(System.getProperty("test.src", "."), SIGNER1);
        fis = new FileInputStream(f);
        Certificate signer1 = fac.generateCertificate(fis);
        signercerts[0] = signer1;

        f = new File(System.getProperty("test.src", "."), SIGNER2);
        fis = new FileInputStream(f);
        Certificate signer2 = fac.generateCertificate(fis);
        signercerts[2] = signer2;

        UnresolvedPermission up = new UnresolvedPermission
                        ("type", "name", "actions", signercerts);
        if (!up.getUnresolvedType().equals("type") ||
            !up.getUnresolvedName().equals("name") ||
            !up.getUnresolvedActions().equals("actions")) {
            throw new SecurityException("Test 1 Failed");
        }

        Certificate[] certs = up.getUnresolvedCerts();
        if (certs == null || certs.length != 2) {
            throw new SecurityException("Test 2 Failed");
        }

        boolean foundSigner1 = false;
        boolean foundSigner2 = false;
        if (certs[0].equals(signer1) || certs[1].equals(signer1)) {
            foundSigner1 = true;
        }
        if (certs[0].equals(signer2) || certs[1].equals(signer2)) {
            foundSigner2 = true;
        }
        if (!foundSigner1 || !foundSigner2) {
            throw new SecurityException("Test 3 Failed");
        }
    }
 
Example #8
Source File: AccessorMethods.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {

        // set CA cert in chain
        File f = new File(System.getProperty("test.src", "."), CA);
        FileInputStream fis = new FileInputStream(f);
        CertificateFactory fac = CertificateFactory.getInstance("X.509");
        Certificate cacert = fac.generateCertificate(fis);
        Certificate[] signercerts = new Certificate[4];
        signercerts[1] = cacert;
        signercerts[3] = cacert;

        // set signer certs
        f = new File(System.getProperty("test.src", "."), SIGNER1);
        fis = new FileInputStream(f);
        Certificate signer1 = fac.generateCertificate(fis);
        signercerts[0] = signer1;

        f = new File(System.getProperty("test.src", "."), SIGNER2);
        fis = new FileInputStream(f);
        Certificate signer2 = fac.generateCertificate(fis);
        signercerts[2] = signer2;

        UnresolvedPermission up = new UnresolvedPermission
                        ("type", "name", "actions", signercerts);
        if (!up.getUnresolvedType().equals("type") ||
            !up.getUnresolvedName().equals("name") ||
            !up.getUnresolvedActions().equals("actions")) {
            throw new SecurityException("Test 1 Failed");
        }

        Certificate[] certs = up.getUnresolvedCerts();
        if (certs == null || certs.length != 2) {
            throw new SecurityException("Test 2 Failed");
        }

        boolean foundSigner1 = false;
        boolean foundSigner2 = false;
        if (certs[0].equals(signer1) || certs[1].equals(signer1)) {
            foundSigner1 = true;
        }
        if (certs[0].equals(signer2) || certs[1].equals(signer2)) {
            foundSigner2 = true;
        }
        if (!foundSigner1 || !foundSigner2) {
            throw new SecurityException("Test 3 Failed");
        }
    }
 
Example #9
Source File: AccessorMethods.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {

        // set CA cert in chain
        File f = new File(System.getProperty("test.src", "."), CA);
        FileInputStream fis = new FileInputStream(f);
        CertificateFactory fac = CertificateFactory.getInstance("X.509");
        Certificate cacert = fac.generateCertificate(fis);
        Certificate[] signercerts = new Certificate[4];
        signercerts[1] = cacert;
        signercerts[3] = cacert;

        // set signer certs
        f = new File(System.getProperty("test.src", "."), SIGNER1);
        fis = new FileInputStream(f);
        Certificate signer1 = fac.generateCertificate(fis);
        signercerts[0] = signer1;

        f = new File(System.getProperty("test.src", "."), SIGNER2);
        fis = new FileInputStream(f);
        Certificate signer2 = fac.generateCertificate(fis);
        signercerts[2] = signer2;

        UnresolvedPermission up = new UnresolvedPermission
                        ("type", "name", "actions", signercerts);
        if (!up.getUnresolvedType().equals("type") ||
            !up.getUnresolvedName().equals("name") ||
            !up.getUnresolvedActions().equals("actions")) {
            throw new SecurityException("Test 1 Failed");
        }

        Certificate[] certs = up.getUnresolvedCerts();
        if (certs == null || certs.length != 2) {
            throw new SecurityException("Test 2 Failed");
        }

        boolean foundSigner1 = false;
        boolean foundSigner2 = false;
        if (certs[0].equals(signer1) || certs[1].equals(signer1)) {
            foundSigner1 = true;
        }
        if (certs[0].equals(signer2) || certs[1].equals(signer2)) {
            foundSigner2 = true;
        }
        if (!foundSigner1 || !foundSigner2) {
            throw new SecurityException("Test 3 Failed");
        }
    }
 
Example #10
Source File: AccessorMethods.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {

        // set CA cert in chain
        File f = new File(System.getProperty("test.src", "."), CA);
        FileInputStream fis = new FileInputStream(f);
        CertificateFactory fac = CertificateFactory.getInstance("X.509");
        Certificate cacert = fac.generateCertificate(fis);
        Certificate[] signercerts = new Certificate[4];
        signercerts[1] = cacert;
        signercerts[3] = cacert;

        // set signer certs
        f = new File(System.getProperty("test.src", "."), SIGNER1);
        fis = new FileInputStream(f);
        Certificate signer1 = fac.generateCertificate(fis);
        signercerts[0] = signer1;

        f = new File(System.getProperty("test.src", "."), SIGNER2);
        fis = new FileInputStream(f);
        Certificate signer2 = fac.generateCertificate(fis);
        signercerts[2] = signer2;

        UnresolvedPermission up = new UnresolvedPermission
                        ("type", "name", "actions", signercerts);
        if (!up.getUnresolvedType().equals("type") ||
            !up.getUnresolvedName().equals("name") ||
            !up.getUnresolvedActions().equals("actions")) {
            throw new SecurityException("Test 1 Failed");
        }

        Certificate[] certs = up.getUnresolvedCerts();
        if (certs == null || certs.length != 2) {
            throw new SecurityException("Test 2 Failed");
        }

        boolean foundSigner1 = false;
        boolean foundSigner2 = false;
        if (certs[0].equals(signer1) || certs[1].equals(signer1)) {
            foundSigner1 = true;
        }
        if (certs[0].equals(signer2) || certs[1].equals(signer2)) {
            foundSigner2 = true;
        }
        if (!foundSigner1 || !foundSigner2) {
            throw new SecurityException("Test 3 Failed");
        }
    }
 
Example #11
Source File: AccessorMethods.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {

        // set CA cert in chain
        File f = new File(System.getProperty("test.src", "."), CA);
        FileInputStream fis = new FileInputStream(f);
        CertificateFactory fac = CertificateFactory.getInstance("X.509");
        Certificate cacert = fac.generateCertificate(fis);
        Certificate[] signercerts = new Certificate[4];
        signercerts[1] = cacert;
        signercerts[3] = cacert;

        // set signer certs
        f = new File(System.getProperty("test.src", "."), SIGNER1);
        fis = new FileInputStream(f);
        Certificate signer1 = fac.generateCertificate(fis);
        signercerts[0] = signer1;

        f = new File(System.getProperty("test.src", "."), SIGNER2);
        fis = new FileInputStream(f);
        Certificate signer2 = fac.generateCertificate(fis);
        signercerts[2] = signer2;

        UnresolvedPermission up = new UnresolvedPermission
                        ("type", "name", "actions", signercerts);
        if (!up.getUnresolvedType().equals("type") ||
            !up.getUnresolvedName().equals("name") ||
            !up.getUnresolvedActions().equals("actions")) {
            throw new SecurityException("Test 1 Failed");
        }

        Certificate[] certs = up.getUnresolvedCerts();
        if (certs == null || certs.length != 2) {
            throw new SecurityException("Test 2 Failed");
        }

        boolean foundSigner1 = false;
        boolean foundSigner2 = false;
        if (certs[0].equals(signer1) || certs[1].equals(signer1)) {
            foundSigner1 = true;
        }
        if (certs[0].equals(signer2) || certs[1].equals(signer2)) {
            foundSigner2 = true;
        }
        if (!foundSigner1 || !foundSigner2) {
            throw new SecurityException("Test 3 Failed");
        }
    }
 
Example #12
Source File: AccessorMethods.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {

        // set CA cert in chain
        File f = new File(System.getProperty("test.src", "."), CA);
        FileInputStream fis = new FileInputStream(f);
        CertificateFactory fac = CertificateFactory.getInstance("X.509");
        Certificate cacert = fac.generateCertificate(fis);
        Certificate[] signercerts = new Certificate[4];
        signercerts[1] = cacert;
        signercerts[3] = cacert;

        // set signer certs
        f = new File(System.getProperty("test.src", "."), SIGNER1);
        fis = new FileInputStream(f);
        Certificate signer1 = fac.generateCertificate(fis);
        signercerts[0] = signer1;

        f = new File(System.getProperty("test.src", "."), SIGNER2);
        fis = new FileInputStream(f);
        Certificate signer2 = fac.generateCertificate(fis);
        signercerts[2] = signer2;

        UnresolvedPermission up = new UnresolvedPermission
                        ("type", "name", "actions", signercerts);
        if (!up.getUnresolvedType().equals("type") ||
            !up.getUnresolvedName().equals("name") ||
            !up.getUnresolvedActions().equals("actions")) {
            throw new SecurityException("Test 1 Failed");
        }

        Certificate[] certs = up.getUnresolvedCerts();
        if (certs == null || certs.length != 2) {
            throw new SecurityException("Test 2 Failed");
        }

        boolean foundSigner1 = false;
        boolean foundSigner2 = false;
        if (certs[0].equals(signer1) || certs[1].equals(signer1)) {
            foundSigner1 = true;
        }
        if (certs[0].equals(signer2) || certs[1].equals(signer2)) {
            foundSigner2 = true;
        }
        if (!foundSigner1 || !foundSigner2) {
            throw new SecurityException("Test 3 Failed");
        }
    }
 
Example #13
Source File: AccessorMethods.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {

        // set CA cert in chain
        File f = new File(System.getProperty("test.src", "."), CA);
        FileInputStream fis = new FileInputStream(f);
        CertificateFactory fac = CertificateFactory.getInstance("X.509");
        Certificate cacert = fac.generateCertificate(fis);
        Certificate[] signercerts = new Certificate[4];
        signercerts[1] = cacert;
        signercerts[3] = cacert;

        // set signer certs
        f = new File(System.getProperty("test.src", "."), SIGNER1);
        fis = new FileInputStream(f);
        Certificate signer1 = fac.generateCertificate(fis);
        signercerts[0] = signer1;

        f = new File(System.getProperty("test.src", "."), SIGNER2);
        fis = new FileInputStream(f);
        Certificate signer2 = fac.generateCertificate(fis);
        signercerts[2] = signer2;

        UnresolvedPermission up = new UnresolvedPermission
                        ("type", "name", "actions", signercerts);
        if (!up.getUnresolvedType().equals("type") ||
            !up.getUnresolvedName().equals("name") ||
            !up.getUnresolvedActions().equals("actions")) {
            throw new SecurityException("Test 1 Failed");
        }

        Certificate[] certs = up.getUnresolvedCerts();
        if (certs == null || certs.length != 2) {
            throw new SecurityException("Test 2 Failed");
        }

        boolean foundSigner1 = false;
        boolean foundSigner2 = false;
        if (certs[0].equals(signer1) || certs[1].equals(signer1)) {
            foundSigner1 = true;
        }
        if (certs[0].equals(signer2) || certs[1].equals(signer2)) {
            foundSigner2 = true;
        }
        if (!foundSigner1 || !foundSigner2) {
            throw new SecurityException("Test 3 Failed");
        }
    }
 
Example #14
Source File: ClientsPolicy.java    From scheduling with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public PermissionCollection getPermissions(final ProtectionDomain domain) {
    try {
        readLock.lock();
        PermissionCollection permissions = new Permissions();

        // Look up permissions
        Principal[] principals = domain.getPrincipals();
        boolean identityPrincipal = false;

        if (principals != null) {
            for (Principal principal : principals) {
                if (principal instanceof IdentityPrincipal) {
                    identityPrincipal = true;
                    PermissionCollection pc = original.getPermissions(domain);
                    if (pc != null) {
                        Permission permission = new PrincipalPermission((IdentityPrincipal) principal);
                        // always adding identity permission
                        permissions.add(permission);
                        if (debug) {
                            // WARNING cannot use log4j as it may lead to recursive permission check
                            System.out.println(principal + " has " + permission);
                        }

                        for (Enumeration<Permission> en = pc.elements(); en.hasMoreElements();) {
                            permission = en.nextElement();

                            // all "non standard" permissions like ClientPermissions are not presented in
                            // boot class path, so they were not correctly resolved at JVM start up time
                            if (permission instanceof UnresolvedPermission) {
                                permission = resolvePermission((UnresolvedPermission) permission);
                                if (permission == null)
                                    continue;
                            }

                            // we grant java.security.AllPermissions to everyone in the security.java.policy
                            // here we exclude it from IdentityPrincipal
                            //
                            // For IdentityPrincipal org.ow2.proactive.permissions.AllPermissions must be used
                            if (!permission.getClass().isAssignableFrom(AllPermission.class)) {
                                if (debug) {
                                    // WARNING cannot use log4j as it may lead to recursive permission check
                                    System.out.println(principal + " has " + permission);
                                }
                                permissions.add(permission);
                            }
                        }
                    }
                }
            }
        }

        if (!identityPrincipal) {
            return original.getPermissions(domain);
        }

        return permissions;
    } finally {
        readLock.unlock();
    }
}
 
Example #15
Source File: AccessorMethods.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {

        // set CA cert in chain
        File f = new File(System.getProperty("test.src", "."), CA);
        FileInputStream fis = new FileInputStream(f);
        CertificateFactory fac = CertificateFactory.getInstance("X.509");
        Certificate cacert = fac.generateCertificate(fis);
        Certificate[] signercerts = new Certificate[4];
        signercerts[1] = cacert;
        signercerts[3] = cacert;

        // set signer certs
        f = new File(System.getProperty("test.src", "."), SIGNER1);
        fis = new FileInputStream(f);
        Certificate signer1 = fac.generateCertificate(fis);
        signercerts[0] = signer1;

        f = new File(System.getProperty("test.src", "."), SIGNER2);
        fis = new FileInputStream(f);
        Certificate signer2 = fac.generateCertificate(fis);
        signercerts[2] = signer2;

        UnresolvedPermission up = new UnresolvedPermission
                        ("type", "name", "actions", signercerts);
        if (!up.getUnresolvedType().equals("type") ||
            !up.getUnresolvedName().equals("name") ||
            !up.getUnresolvedActions().equals("actions")) {
            throw new SecurityException("Test 1 Failed");
        }

        Certificate[] certs = up.getUnresolvedCerts();
        if (certs == null || certs.length != 2) {
            throw new SecurityException("Test 2 Failed");
        }

        boolean foundSigner1 = false;
        boolean foundSigner2 = false;
        if (certs[0].equals(signer1) || certs[1].equals(signer1)) {
            foundSigner1 = true;
        }
        if (certs[0].equals(signer2) || certs[1].equals(signer2)) {
            foundSigner2 = true;
        }
        if (!foundSigner1 || !foundSigner2) {
            throw new SecurityException("Test 3 Failed");
        }
    }
 
Example #16
Source File: AccessorMethods.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {

        // set CA cert in chain
        File f = new File(System.getProperty("test.src", "."), CA);
        FileInputStream fis = new FileInputStream(f);
        CertificateFactory fac = CertificateFactory.getInstance("X.509");
        Certificate cacert = fac.generateCertificate(fis);
        Certificate[] signercerts = new Certificate[4];
        signercerts[1] = cacert;
        signercerts[3] = cacert;

        // set signer certs
        f = new File(System.getProperty("test.src", "."), SIGNER1);
        fis = new FileInputStream(f);
        Certificate signer1 = fac.generateCertificate(fis);
        signercerts[0] = signer1;

        f = new File(System.getProperty("test.src", "."), SIGNER2);
        fis = new FileInputStream(f);
        Certificate signer2 = fac.generateCertificate(fis);
        signercerts[2] = signer2;

        UnresolvedPermission up = new UnresolvedPermission
                        ("type", "name", "actions", signercerts);
        if (!up.getUnresolvedType().equals("type") ||
            !up.getUnresolvedName().equals("name") ||
            !up.getUnresolvedActions().equals("actions")) {
            throw new SecurityException("Test 1 Failed");
        }

        Certificate[] certs = up.getUnresolvedCerts();
        if (certs == null || certs.length != 2) {
            throw new SecurityException("Test 2 Failed");
        }

        boolean foundSigner1 = false;
        boolean foundSigner2 = false;
        if (certs[0].equals(signer1) || certs[1].equals(signer1)) {
            foundSigner1 = true;
        }
        if (certs[0].equals(signer2) || certs[1].equals(signer2)) {
            foundSigner2 = true;
        }
        if (!foundSigner1 || !foundSigner2) {
            throw new SecurityException("Test 3 Failed");
        }
    }