Search in sources :

Example 1 with UnresolvedPermission

use of java.security.UnresolvedPermission in project jdk8u_jdk by JetBrains.

the class AccessorMethods method main.

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");
    }
}
Also used : UnresolvedPermission(java.security.UnresolvedPermission)

Example 2 with UnresolvedPermission

use of java.security.UnresolvedPermission in project jdk8u_jdk by JetBrains.

the class PolicyPermissions method addGrantEntry.

/**
     * Add one policy entry to the vector.
     */
private void addGrantEntry(GrantEntry ge, KeyStore keyStore) {
    if (debug != null) {
        debug.println("Adding policy entry: ");
        debug.println("  signedBy " + ge.signedBy);
        debug.println("  codeBase " + ge.codeBase);
        if (ge.principals != null) {
            for (PrincipalEntry pppe : ge.principals) {
                debug.println("  " + pppe.getPrincipalClass() + " " + pppe.getPrincipalName());
            }
        }
        debug.println();
    }
    try {
        CodeSource codesource = getCodeSource(ge, keyStore);
        // skip if signedBy alias was unknown...
        if (codesource == null)
            return;
        PolicyEntry entry = new PolicyEntry(codesource);
        Enumeration<PermissionEntry> enum_ = ge.permissionElements();
        while (enum_.hasMoreElements()) {
            PermissionEntry pe = enum_.nextElement();
            try {
                // XXX special case PrivateCredentialPermission-SELF
                Permission perm;
                if (pe.permission.equals("javax.security.auth.PrivateCredentialPermission") && pe.name.endsWith(" self")) {
                    perm = getInstance(pe.permission, pe.name + " \"self\"", pe.action);
                } else {
                    perm = getInstance(pe.permission, pe.name, pe.action);
                }
                entry.add(perm);
                if (debug != null) {
                    debug.println("  " + perm);
                }
            } catch (ClassNotFoundException cnfe) {
                Certificate[] certs;
                if (pe.signedBy != null) {
                    certs = getCertificates(keyStore, pe.signedBy);
                } else {
                    certs = null;
                }
                // a signer and found the keys for it.
                if (certs != null || pe.signedBy == null) {
                    Permission perm = new UnresolvedPermission(pe.permission, pe.name, pe.action, certs);
                    entry.add(perm);
                    if (debug != null) {
                        debug.println("  " + perm);
                    }
                }
            } catch (java.lang.reflect.InvocationTargetException ite) {
                System.err.println(AUTH_POLICY + rb.getString(".error.adding.Permission.") + pe.permission + rb.getString("SPACE") + ite.getTargetException());
            } catch (Exception e) {
                System.err.println(AUTH_POLICY + rb.getString(".error.adding.Permission.") + pe.permission + rb.getString("SPACE") + e);
            }
        }
        policyEntries.addElement(entry);
    } catch (Exception e) {
        System.err.println(AUTH_POLICY + rb.getString(".error.adding.Entry.") + ge + rb.getString("SPACE") + e);
    }
    if (debug != null) {
        debug.println();
    }
}
Also used : UnresolvedPermission(java.security.UnresolvedPermission) java.lang.reflect(java.lang.reflect) PermissionEntry(sun.security.provider.PolicyParser.PermissionEntry) UnresolvedPermission(java.security.UnresolvedPermission) PrivateCredentialPermission(javax.security.auth.PrivateCredentialPermission) Permission(java.security.Permission) PrincipalEntry(sun.security.provider.PolicyParser.PrincipalEntry) CodeSource(java.security.CodeSource) KeyStoreException(java.security.KeyStoreException)

Example 3 with UnresolvedPermission

use of java.security.UnresolvedPermission in project Bytecoder by mirkosertic.

the class PolicyPermissions method addGrantEntry.

/**
 * Add one policy entry to the vector.
 */
private void addGrantEntry(GrantEntry ge, KeyStore keyStore) {
    if (debug != null) {
        debug.println("Adding policy entry: ");
        debug.println("  signedBy " + ge.signedBy);
        debug.println("  codeBase " + ge.codeBase);
        if (ge.principals != null) {
            for (PrincipalEntry pppe : ge.principals) {
                debug.println("  " + pppe.getPrincipalClass() + " " + pppe.getPrincipalName());
            }
        }
        debug.println();
    }
    try {
        CodeSource codesource = getCodeSource(ge, keyStore);
        // skip if signedBy alias was unknown...
        if (codesource == null)
            return;
        PolicyEntry entry = new PolicyEntry(codesource);
        Enumeration<PermissionEntry> enum_ = ge.permissionElements();
        while (enum_.hasMoreElements()) {
            PermissionEntry pe = enum_.nextElement();
            try {
                // XXX special case PrivateCredentialPermission-SELF
                Permission perm;
                if (pe.permission.equals("javax.security.auth.PrivateCredentialPermission") && pe.name.endsWith(" self")) {
                    perm = getInstance(pe.permission, pe.name + " \"self\"", pe.action);
                } else {
                    perm = getInstance(pe.permission, pe.name, pe.action);
                }
                entry.add(perm);
                if (debug != null) {
                    debug.println("  " + perm);
                }
            } catch (ClassNotFoundException cnfe) {
                Certificate[] certs;
                if (pe.signedBy != null) {
                    certs = getCertificates(keyStore, pe.signedBy);
                } else {
                    certs = null;
                }
                // a signer and found the keys for it.
                if (certs != null || pe.signedBy == null) {
                    Permission perm = new UnresolvedPermission(pe.permission, pe.name, pe.action, certs);
                    entry.add(perm);
                    if (debug != null) {
                        debug.println("  " + perm);
                    }
                }
            } catch (java.lang.reflect.InvocationTargetException ite) {
                System.err.println(AUTH_POLICY + rb.getString(".error.adding.Permission.") + pe.permission + rb.getString("SPACE") + ite.getTargetException());
            } catch (Exception e) {
                System.err.println(AUTH_POLICY + rb.getString(".error.adding.Permission.") + pe.permission + rb.getString("SPACE") + e);
            }
        }
        policyEntries.addElement(entry);
    } catch (Exception e) {
        System.err.println(AUTH_POLICY + rb.getString(".error.adding.Entry.") + ge + rb.getString("SPACE") + e);
    }
    if (debug != null) {
        debug.println();
    }
}
Also used : UnresolvedPermission(java.security.UnresolvedPermission) java.lang.reflect(java.lang.reflect) PermissionEntry(sun.security.provider.PolicyParser.PermissionEntry) UnresolvedPermission(java.security.UnresolvedPermission) PrivateCredentialPermission(javax.security.auth.PrivateCredentialPermission) Permission(java.security.Permission) PrincipalEntry(sun.security.provider.PolicyParser.PrincipalEntry) CodeSource(java.security.CodeSource) KeyStoreException(java.security.KeyStoreException)

Example 4 with UnresolvedPermission

use of java.security.UnresolvedPermission in project ant by apache.

the class Permissions method createPermission.

private java.security.Permission createPermission(final Permissions.Permission permission) {
    try {
        // First add explicitly already resolved permissions will not be
        // resolved when added as unresolved permission.
        final Class<? extends java.security.Permission> clazz = Class.forName(permission.getClassName()).asSubclass(java.security.Permission.class);
        final String name = permission.getName();
        final String actions = permission.getActions();
        final Constructor<? extends java.security.Permission> ctr = clazz.getConstructor(PARAMS);
        return ctr.newInstance(name, actions);
    } catch (final Exception e) {
        // Let the UnresolvedPermission handle it.
        return new UnresolvedPermission(permission.getClassName(), permission.getName(), permission.getActions(), null);
    }
}
Also used : UnresolvedPermission(java.security.UnresolvedPermission) BuildException(org.apache.tools.ant.BuildException) ExitException(org.apache.tools.ant.ExitException)

Example 5 with UnresolvedPermission

use of java.security.UnresolvedPermission in project scheduling by ow2-proactive.

the class ClientsPolicy method getPermissions.

@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();
                            // 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;
                            }
                            // 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();
    }
}
Also used : UnresolvedPermission(java.security.UnresolvedPermission) PermissionCollection(java.security.PermissionCollection) UnresolvedPermission(java.security.UnresolvedPermission) MBeanPermission(javax.management.MBeanPermission) AllPermission(java.security.AllPermission) Permission(java.security.Permission) ClientPermission(org.ow2.proactive.permissions.ClientPermission) PrincipalPermission(org.ow2.proactive.permissions.PrincipalPermission) AuthPermission(javax.security.auth.AuthPermission) PrincipalPermission(org.ow2.proactive.permissions.PrincipalPermission) AllPermission(java.security.AllPermission) IdentityPrincipal(org.ow2.proactive.authentication.principals.IdentityPrincipal) IdentityPrincipal(org.ow2.proactive.authentication.principals.IdentityPrincipal) Principal(java.security.Principal)

Aggregations

UnresolvedPermission (java.security.UnresolvedPermission)5 Permission (java.security.Permission)3 java.lang.reflect (java.lang.reflect)2 CodeSource (java.security.CodeSource)2 KeyStoreException (java.security.KeyStoreException)2 PrivateCredentialPermission (javax.security.auth.PrivateCredentialPermission)2 PermissionEntry (sun.security.provider.PolicyParser.PermissionEntry)2 PrincipalEntry (sun.security.provider.PolicyParser.PrincipalEntry)2 AllPermission (java.security.AllPermission)1 PermissionCollection (java.security.PermissionCollection)1 Principal (java.security.Principal)1 MBeanPermission (javax.management.MBeanPermission)1 AuthPermission (javax.security.auth.AuthPermission)1 BuildException (org.apache.tools.ant.BuildException)1 ExitException (org.apache.tools.ant.ExitException)1 IdentityPrincipal (org.ow2.proactive.authentication.principals.IdentityPrincipal)1 ClientPermission (org.ow2.proactive.permissions.ClientPermission)1 PrincipalPermission (org.ow2.proactive.permissions.PrincipalPermission)1