Search in sources :

Example 1 with PermissionEntry

use of sun.security.provider.PolicyParser.PermissionEntry 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 2 with PermissionEntry

use of sun.security.provider.PolicyParser.PermissionEntry 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)

Aggregations

java.lang.reflect (java.lang.reflect)2 CodeSource (java.security.CodeSource)2 KeyStoreException (java.security.KeyStoreException)2 Permission (java.security.Permission)2 UnresolvedPermission (java.security.UnresolvedPermission)2 PrivateCredentialPermission (javax.security.auth.PrivateCredentialPermission)2 PermissionEntry (sun.security.provider.PolicyParser.PermissionEntry)2 PrincipalEntry (sun.security.provider.PolicyParser.PrincipalEntry)2