sun.security.provider.PolicyParser.PrincipalEntry Java Examples

The following examples show how to use sun.security.provider.PolicyParser.PrincipalEntry. 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: SubjectCodeSource.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Return a String representation of this <code>SubjectCodeSource</code>.
 *
 * <p>
 *
 * @return a String representation of this <code>SubjectCodeSource</code>.
 */
public String toString() {
    String returnMe = super.toString();
    if (getSubject() != null) {
        if (debug != null) {
            final Subject finalSubject = getSubject();
            returnMe = returnMe + "\n" +
                    java.security.AccessController.doPrivileged
                            (new java.security.PrivilegedAction<String>() {
                            public String run() {
                                return finalSubject.toString();
                            }
                    });
        } else {
            returnMe = returnMe + "\n" + getSubject().toString();
        }
    }
    if (principals != null) {
        ListIterator<PrincipalEntry> li = principals.listIterator();
        while (li.hasNext()) {
            PrincipalEntry pppe = li.next();
            returnMe = returnMe + rb.getString("NEWLINE") +
                    pppe.getPrincipalClass() + " " +
                    pppe.getPrincipalName();
        }
    }
    return returnMe;
}
 
Example #2
Source File: SubjectCodeSource.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Return a String representation of this <code>SubjectCodeSource</code>.
 *
 * <p>
 *
 * @return a String representation of this <code>SubjectCodeSource</code>.
 */
public String toString() {
    String returnMe = super.toString();
    if (getSubject() != null) {
        if (debug != null) {
            final Subject finalSubject = getSubject();
            returnMe = returnMe + "\n" +
                    java.security.AccessController.doPrivileged
                            (new java.security.PrivilegedAction<String>() {
                            public String run() {
                                return finalSubject.toString();
                            }
                    });
        } else {
            returnMe = returnMe + "\n" + getSubject().toString();
        }
    }
    if (principals != null) {
        ListIterator<PrincipalEntry> li = principals.listIterator();
        while (li.hasNext()) {
            PrincipalEntry pppe = li.next();
            returnMe = returnMe + rb.getString("NEWLINE") +
                    pppe.getPrincipalClass() + " " +
                    pppe.getPrincipalName();
        }
    }
    return returnMe;
}
 
Example #3
Source File: SubjectCodeSource.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Return a String representation of this <code>SubjectCodeSource</code>.
 *
 * <p>
 *
 * @return a String representation of this <code>SubjectCodeSource</code>.
 */
public String toString() {
    String returnMe = super.toString();
    if (getSubject() != null) {
        if (debug != null) {
            final Subject finalSubject = getSubject();
            returnMe = returnMe + "\n" +
                    java.security.AccessController.doPrivileged
                            (new java.security.PrivilegedAction<String>() {
                            public String run() {
                                return finalSubject.toString();
                            }
                    });
        } else {
            returnMe = returnMe + "\n" + getSubject().toString();
        }
    }
    if (principals != null) {
        ListIterator<PrincipalEntry> li = principals.listIterator();
        while (li.hasNext()) {
            PrincipalEntry pppe = li.next();
            returnMe = returnMe + rb.getString("NEWLINE") +
                    pppe.getPrincipalClass() + " " +
                    pppe.getPrincipalName();
        }
    }
    return returnMe;
}
 
Example #4
Source File: SubjectCodeSource.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Return a String representation of this <code>SubjectCodeSource</code>.
 *
 * <p>
 *
 * @return a String representation of this <code>SubjectCodeSource</code>.
 */
public String toString() {
    String returnMe = super.toString();
    if (getSubject() != null) {
        if (debug != null) {
            final Subject finalSubject = getSubject();
            returnMe = returnMe + "\n" +
                    java.security.AccessController.doPrivileged
                            (new java.security.PrivilegedAction<String>() {
                            public String run() {
                                return finalSubject.toString();
                            }
                    });
        } else {
            returnMe = returnMe + "\n" + getSubject().toString();
        }
    }
    if (principals != null) {
        ListIterator<PrincipalEntry> li = principals.listIterator();
        while (li.hasNext()) {
            PrincipalEntry pppe = li.next();
            returnMe = returnMe + rb.getString("NEWLINE") +
                    pppe.getPrincipalClass() + " " +
                    pppe.getPrincipalName();
        }
    }
    return returnMe;
}
 
Example #5
Source File: SubjectCodeSource.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Return a String representation of this <code>SubjectCodeSource</code>.
 *
 * <p>
 *
 * @return a String representation of this <code>SubjectCodeSource</code>.
 */
public String toString() {
    String returnMe = super.toString();
    if (getSubject() != null) {
        if (debug != null) {
            final Subject finalSubject = getSubject();
            returnMe = returnMe + "\n" +
                    java.security.AccessController.doPrivileged
                            (new java.security.PrivilegedAction<String>() {
                            public String run() {
                                return finalSubject.toString();
                            }
                    });
        } else {
            returnMe = returnMe + "\n" + getSubject().toString();
        }
    }
    if (principals != null) {
        ListIterator<PrincipalEntry> li = principals.listIterator();
        while (li.hasNext()) {
            PrincipalEntry pppe = li.next();
            returnMe = returnMe + rb.getString("NEWLINE") +
                    pppe.getPrincipalClass() + " " +
                    pppe.getPrincipalName();
        }
    }
    return returnMe;
}
 
Example #6
Source File: SubjectCodeSource.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Return a String representation of this <code>SubjectCodeSource</code>.
 *
 * <p>
 *
 * @return a String representation of this <code>SubjectCodeSource</code>.
 */
public String toString() {
    String returnMe = super.toString();
    if (getSubject() != null) {
        if (debug != null) {
            final Subject finalSubject = getSubject();
            returnMe = returnMe + "\n" +
                    java.security.AccessController.doPrivileged
                            (new java.security.PrivilegedAction<String>() {
                            public String run() {
                                return finalSubject.toString();
                            }
                    });
        } else {
            returnMe = returnMe + "\n" + getSubject().toString();
        }
    }
    if (principals != null) {
        ListIterator<PrincipalEntry> li = principals.listIterator();
        while (li.hasNext()) {
            PrincipalEntry pppe = li.next();
            returnMe = returnMe + rb.getString("NEWLINE") +
                    pppe.getPrincipalClass() + " " +
                    pppe.getPrincipalName();
        }
    }
    return returnMe;
}
 
Example #7
Source File: SubjectCodeSource.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Return a String representation of this <code>SubjectCodeSource</code>.
 *
 * <p>
 *
 * @return a String representation of this <code>SubjectCodeSource</code>.
 */
public String toString() {
    String returnMe = super.toString();
    if (getSubject() != null) {
        if (debug != null) {
            final Subject finalSubject = getSubject();
            returnMe = returnMe + "\n" +
                    java.security.AccessController.doPrivileged
                            (new java.security.PrivilegedAction<String>() {
                            public String run() {
                                return finalSubject.toString();
                            }
                    });
        } else {
            returnMe = returnMe + "\n" + getSubject().toString();
        }
    }
    if (principals != null) {
        ListIterator<PrincipalEntry> li = principals.listIterator();
        while (li.hasNext()) {
            PrincipalEntry pppe = li.next();
            returnMe = returnMe + rb.getString("NEWLINE") +
                    pppe.getPrincipalClass() + " " +
                    pppe.getPrincipalName();
        }
    }
    return returnMe;
}
 
Example #8
Source File: SubjectCodeSource.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * Return a String representation of this <code>SubjectCodeSource</code>.
 *
 * <p>
 *
 * @return a String representation of this <code>SubjectCodeSource</code>.
 */
public String toString() {
    String returnMe = super.toString();
    if (getSubject() != null) {
        if (debug != null) {
            final Subject finalSubject = getSubject();
            returnMe = returnMe + "\n" +
                    java.security.AccessController.doPrivileged
                            (new java.security.PrivilegedAction<String>() {
                            public String run() {
                                return finalSubject.toString();
                            }
                    });
        } else {
            returnMe = returnMe + "\n" + getSubject().toString();
        }
    }
    if (principals != null) {
        ListIterator<PrincipalEntry> li = principals.listIterator();
        while (li.hasNext()) {
            PrincipalEntry pppe = li.next();
            returnMe = returnMe + ResourcesMgr.getAuthResourceString("NEWLINE") +
                    pppe.getPrincipalClass() + " " +
                    pppe.getPrincipalName();
        }
    }
    return returnMe;
}
 
Example #9
Source File: SubjectCodeSource.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Return a String representation of this <code>SubjectCodeSource</code>.
 *
 * <p>
 *
 * @return a String representation of this <code>SubjectCodeSource</code>.
 */
public String toString() {
    String returnMe = super.toString();
    if (getSubject() != null) {
        if (debug != null) {
            final Subject finalSubject = getSubject();
            returnMe = returnMe + "\n" +
                    java.security.AccessController.doPrivileged
                            (new java.security.PrivilegedAction<String>() {
                            public String run() {
                                return finalSubject.toString();
                            }
                    });
        } else {
            returnMe = returnMe + "\n" + getSubject().toString();
        }
    }
    if (principals != null) {
        ListIterator<PrincipalEntry> li = principals.listIterator();
        while (li.hasNext()) {
            PrincipalEntry pppe = li.next();
            returnMe = returnMe + rb.getString("NEWLINE") +
                    pppe.getPrincipalClass() + " " +
                    pppe.getPrincipalName();
        }
    }
    return returnMe;
}
 
Example #10
Source File: SubjectCodeSource.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Return a String representation of this <code>SubjectCodeSource</code>.
 *
 * <p>
 *
 * @return a String representation of this <code>SubjectCodeSource</code>.
 */
public String toString() {
    String returnMe = super.toString();
    if (getSubject() != null) {
        if (debug != null) {
            final Subject finalSubject = getSubject();
            returnMe = returnMe + "\n" +
                    java.security.AccessController.doPrivileged
                            (new java.security.PrivilegedAction<String>() {
                            public String run() {
                                return finalSubject.toString();
                            }
                    });
        } else {
            returnMe = returnMe + "\n" + getSubject().toString();
        }
    }
    if (principals != null) {
        ListIterator<PrincipalEntry> li = principals.listIterator();
        while (li.hasNext()) {
            PrincipalEntry pppe = li.next();
            returnMe = returnMe + rb.getString("NEWLINE") +
                    pppe.getPrincipalClass() + " " +
                    pppe.getPrincipalName();
        }
    }
    return returnMe;
}
 
Example #11
Source File: SubjectCodeSource.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Return a String representation of this <code>SubjectCodeSource</code>.
 *
 * <p>
 *
 * @return a String representation of this <code>SubjectCodeSource</code>.
 */
public String toString() {
    String returnMe = super.toString();
    if (getSubject() != null) {
        if (debug != null) {
            final Subject finalSubject = getSubject();
            returnMe = returnMe + "\n" +
                    java.security.AccessController.doPrivileged
                            (new java.security.PrivilegedAction<String>() {
                            public String run() {
                                return finalSubject.toString();
                            }
                    });
        } else {
            returnMe = returnMe + "\n" + getSubject().toString();
        }
    }
    if (principals != null) {
        ListIterator<PrincipalEntry> li = principals.listIterator();
        while (li.hasNext()) {
            PrincipalEntry pppe = li.next();
            returnMe = returnMe + rb.getString("NEWLINE") +
                    pppe.getPrincipalClass() + " " +
                    pppe.getPrincipalName();
        }
    }
    return returnMe;
}
 
Example #12
Source File: SubjectCodeSource.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Return a String representation of this <code>SubjectCodeSource</code>.
 *
 * <p>
 *
 * @return a String representation of this <code>SubjectCodeSource</code>.
 */
public String toString() {
    String returnMe = super.toString();
    if (getSubject() != null) {
        if (debug != null) {
            final Subject finalSubject = getSubject();
            returnMe = returnMe + "\n" +
                    java.security.AccessController.doPrivileged
                            (new java.security.PrivilegedAction<String>() {
                            public String run() {
                                return finalSubject.toString();
                            }
                    });
        } else {
            returnMe = returnMe + "\n" + getSubject().toString();
        }
    }
    if (principals != null) {
        ListIterator<PrincipalEntry> li = principals.listIterator();
        while (li.hasNext()) {
            PrincipalEntry pppe = li.next();
            returnMe = returnMe + rb.getString("NEWLINE") +
                    pppe.getPrincipalClass() + " " +
                    pppe.getPrincipalName();
        }
    }
    return returnMe;
}
 
Example #13
Source File: SubjectCodeSource.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Return a String representation of this <code>SubjectCodeSource</code>.
 *
 * <p>
 *
 * @return a String representation of this <code>SubjectCodeSource</code>.
 */
public String toString() {
    String returnMe = super.toString();
    if (getSubject() != null) {
        if (debug != null) {
            final Subject finalSubject = getSubject();
            returnMe = returnMe + "\n" +
                    java.security.AccessController.doPrivileged
                            (new java.security.PrivilegedAction<String>() {
                            public String run() {
                                return finalSubject.toString();
                            }
                    });
        } else {
            returnMe = returnMe + "\n" + getSubject().toString();
        }
    }
    if (principals != null) {
        ListIterator<PrincipalEntry> li = principals.listIterator();
        while (li.hasNext()) {
            PrincipalEntry pppe = li.next();
            returnMe = returnMe + ResourcesMgr.getAuthResourceString("NEWLINE") +
                    pppe.getPrincipalClass() + " " +
                    pppe.getPrincipalName();
        }
    }
    return returnMe;
}
 
Example #14
Source File: SubjectCodeSource.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Return a String representation of this <code>SubjectCodeSource</code>.
 *
 * <p>
 *
 * @return a String representation of this <code>SubjectCodeSource</code>.
 */
public String toString() {
    String returnMe = super.toString();
    if (getSubject() != null) {
        if (debug != null) {
            final Subject finalSubject = getSubject();
            returnMe = returnMe + "\n" +
                    java.security.AccessController.doPrivileged
                            (new java.security.PrivilegedAction<String>() {
                            public String run() {
                                return finalSubject.toString();
                            }
                    });
        } else {
            returnMe = returnMe + "\n" + getSubject().toString();
        }
    }
    if (principals != null) {
        ListIterator<PrincipalEntry> li = principals.listIterator();
        while (li.hasNext()) {
            PrincipalEntry pppe = li.next();
            returnMe = returnMe + rb.getString("NEWLINE") +
                    pppe.getPrincipalClass() + " " +
                    pppe.getPrincipalName();
        }
    }
    return returnMe;
}
 
Example #15
Source File: AuthPolicyFile.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns true if 'Self' permissions were added to the provided
 * 'perms', and false otherwise.
 *
 * <p>
 *
 * @param p check to see if this Permission is a "SELF"
 *                  PrivateCredentialPermission. <p>
 *
 * @param entryCs the codesource for the Policy entry.
 *
 * @param accCs the codesource for from the current AccessControlContext.
 *
 * @param perms the PermissionCollection where the individual
 *                  PrivateCredentialPermissions will be added.
 */
private boolean addSelfPermissions(final Permission p,
                                   CodeSource entryCs,
                                   CodeSource accCs,
                                   Permissions perms) {

    if (!(p instanceof PrivateCredentialPermission)) {
        return false;
    }

    if (!(entryCs instanceof SubjectCodeSource)) {
        return false;
    }

    PrivateCredentialPermission pcp = (PrivateCredentialPermission)p;
    SubjectCodeSource scs = (SubjectCodeSource)entryCs;

    // see if it is a SELF permission
    String[][] pPrincipals = pcp.getPrincipals();
    if (pPrincipals.length <= 0 ||
        !pPrincipals[0][0].equalsIgnoreCase("self") ||
        !pPrincipals[0][1].equalsIgnoreCase("self")) {

        // regular PrivateCredentialPermission
        return false;
    } else {

        // granted a SELF permission - create a
        // PrivateCredentialPermission for each
        // of the Policy entry's CodeSource Principals

        if (scs.getPrincipals() == null) {
            // XXX SubjectCodeSource has no Subject???
            return true;
        }

        for (PrincipalEntry principal : scs.getPrincipals()) {

            //      if the Policy entry's Principal does not contain a
            //              WILDCARD for the Principal name, then a
            //              new PrivateCredentialPermission is created
            //              for the Principal listed in the Policy entry.
            //      if the Policy entry's Principal contains a WILDCARD
            //              for the Principal name, then a new
            //              PrivateCredentialPermission is created
            //              for each Principal associated with the Subject
            //              in the current ACC.

            String[][] principalInfo = getPrincipalInfo(principal, accCs);

            for (int i = 0; i < principalInfo.length; i++) {

                // here's the new PrivateCredentialPermission

                PrivateCredentialPermission newPcp =
                    new PrivateCredentialPermission
                            (pcp.getCredentialClass() +
                                    " " +
                                    principalInfo[i][0] +
                                    " " +
                                    "\"" + principalInfo[i][1] + "\"",
                            "read");

                if (debug != null) {
                    debug.println("adding SELF permission: " +
                                    newPcp.toString());
                }

                perms.add(newPcp);
            }
        }
    }
    return true;
}
 
Example #16
Source File: SubjectCodeSource.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * This method returns, true, if the provided <i>subjectList</i>
 * "contains" the <code>Principal</code> specified
 * in the provided <i>pppe</i> argument.
 *
 * Note that the provided <i>pppe</i> argument may have
 * wildcards (*) for the <code>Principal</code> class and name,
 * which need to be considered.
 *
 * <p>
 *
 * @param subjectList a list of PolicyParser.PrincipalEntry objects
 *          that correspond to all the Principals in the Subject currently
 *          on this thread's AccessControlContext. <p>
 *
 * @param pppe the Principals specified in a grant entry.
 *
 * @return true if the provided <i>subjectList</i> "contains"
 *          the <code>Principal</code> specified in the provided
 *          <i>pppe</i> argument.
 */
private boolean subjectListImpliesPrincipalEntry(
            LinkedList<PrincipalEntry> subjectList, PrincipalEntry pppe) {

    ListIterator<PrincipalEntry> li = subjectList.listIterator(0);
    while (li.hasNext()) {
        PrincipalEntry listPppe = li.next();

        if (pppe.getPrincipalClass().equals
                    (PrincipalEntry.WILDCARD_CLASS) ||
            pppe.getPrincipalClass().equals(listPppe.getPrincipalClass()))
        {
            if (pppe.getPrincipalName().equals
                    (PrincipalEntry.WILDCARD_NAME) ||
                pppe.getPrincipalName().equals(listPppe.getPrincipalName()))
                return true;
        }
    }
    return false;
}
 
Example #17
Source File: AuthPolicyFile.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns true if 'Self' permissions were added to the provided
 * 'perms', and false otherwise.
 *
 * <p>
 *
 * @param p check to see if this Permission is a "SELF"
 *                  PrivateCredentialPermission. <p>
 *
 * @param entryCs the codesource for the Policy entry.
 *
 * @param accCs the codesource for from the current AccessControlContext.
 *
 * @param perms the PermissionCollection where the individual
 *                  PrivateCredentialPermissions will be added.
 */
private boolean addSelfPermissions(final Permission p,
                                   CodeSource entryCs,
                                   CodeSource accCs,
                                   Permissions perms) {

    if (!(p instanceof PrivateCredentialPermission)) {
        return false;
    }

    if (!(entryCs instanceof SubjectCodeSource)) {
        return false;
    }

    PrivateCredentialPermission pcp = (PrivateCredentialPermission)p;
    SubjectCodeSource scs = (SubjectCodeSource)entryCs;

    // see if it is a SELF permission
    String[][] pPrincipals = pcp.getPrincipals();
    if (pPrincipals.length <= 0 ||
        !pPrincipals[0][0].equalsIgnoreCase("self") ||
        !pPrincipals[0][1].equalsIgnoreCase("self")) {

        // regular PrivateCredentialPermission
        return false;
    } else {

        // granted a SELF permission - create a
        // PrivateCredentialPermission for each
        // of the Policy entry's CodeSource Principals

        if (scs.getPrincipals() == null) {
            // XXX SubjectCodeSource has no Subject???
            return true;
        }

        for (PrincipalEntry principal : scs.getPrincipals()) {

            //      if the Policy entry's Principal does not contain a
            //              WILDCARD for the Principal name, then a
            //              new PrivateCredentialPermission is created
            //              for the Principal listed in the Policy entry.
            //      if the Policy entry's Principal contains a WILDCARD
            //              for the Principal name, then a new
            //              PrivateCredentialPermission is created
            //              for each Principal associated with the Subject
            //              in the current ACC.

            String[][] principalInfo = getPrincipalInfo(principal, accCs);

            for (int i = 0; i < principalInfo.length; i++) {

                // here's the new PrivateCredentialPermission

                PrivateCredentialPermission newPcp =
                    new PrivateCredentialPermission
                            (pcp.getCredentialClass() +
                                    " " +
                                    principalInfo[i][0] +
                                    " " +
                                    "\"" + principalInfo[i][1] + "\"",
                            "read");

                if (debug != null) {
                    debug.println("adding SELF permission: " +
                                    newPcp.toString());
                }

                perms.add(newPcp);
            }
        }
    }
    return true;
}
 
Example #18
Source File: SubjectCodeSource.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Creates a new <code>SubjectCodeSource</code>
 * with the given <code>Subject</code>, principals, <code>URL</code>,
 * and signers (Certificates).  The <code>Subject</code>
 * represents the <code>Subject</code> associated with the current
 * <code>AccessControlContext</code>.
 * The Principals are given as a <code>LinkedList</code>
 * of <code>PolicyParser.PrincipalEntry</code> objects.
 * Typically either a <code>Subject</code> will be provided,
 * or a list of <code>principals</code> will be provided
 * (not both).
 *
 * <p>
 *
 * @param subject the <code>Subject</code> associated with this
 *                  <code>SubjectCodeSource</code> <p>
 *
 * @param url the <code>URL</code> associated with this
 *                  <code>SubjectCodeSource</code> <p>
 *
 * @param certs the signers associated with this
 *                  <code>SubjectCodeSource</code> <p>
 */
SubjectCodeSource(Subject subject,
    LinkedList<PrincipalEntry> principals,
    URL url, Certificate[] certs) {

    super(url, certs);
    this.subject = subject;
    this.principals = (principals == null ?
            new LinkedList<PrincipalEntry>() :
            new LinkedList<PrincipalEntry>(principals));
    sysClassLoader = java.security.AccessController.doPrivileged
    (new java.security.PrivilegedAction<ClassLoader>() {
        public ClassLoader run() {
                return ClassLoader.getSystemClassLoader();
        }
    });
}
 
Example #19
Source File: SubjectCodeSource.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * This method returns, true, if the provided <i>subjectList</i>
 * "contains" the <code>Principal</code> specified
 * in the provided <i>pppe</i> argument.
 *
 * Note that the provided <i>pppe</i> argument may have
 * wildcards (*) for the <code>Principal</code> class and name,
 * which need to be considered.
 *
 * <p>
 *
 * @param subjectList a list of PolicyParser.PrincipalEntry objects
 *          that correspond to all the Principals in the Subject currently
 *          on this thread's AccessControlContext. <p>
 *
 * @param pppe the Principals specified in a grant entry.
 *
 * @return true if the provided <i>subjectList</i> "contains"
 *          the <code>Principal</code> specified in the provided
 *          <i>pppe</i> argument.
 */
private boolean subjectListImpliesPrincipalEntry(
            LinkedList<PrincipalEntry> subjectList, PrincipalEntry pppe) {

    ListIterator<PrincipalEntry> li = subjectList.listIterator(0);
    while (li.hasNext()) {
        PrincipalEntry listPppe = li.next();

        if (pppe.getPrincipalClass().equals
                    (PrincipalEntry.WILDCARD_CLASS) ||
            pppe.getPrincipalClass().equals(listPppe.getPrincipalClass()))
        {
            if (pppe.getPrincipalName().equals
                    (PrincipalEntry.WILDCARD_NAME) ||
                pppe.getPrincipalName().equals(listPppe.getPrincipalName()))
                return true;
        }
    }
    return false;
}
 
Example #20
Source File: AuthPolicyFile.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns true if 'Self' permissions were added to the provided
 * 'perms', and false otherwise.
 *
 * <p>
 *
 * @param p check to see if this Permission is a "SELF"
 *                  PrivateCredentialPermission. <p>
 *
 * @param entryCs the codesource for the Policy entry.
 *
 * @param accCs the codesource for from the current AccessControlContext.
 *
 * @param perms the PermissionCollection where the individual
 *                  PrivateCredentialPermissions will be added.
 */
private boolean addSelfPermissions(final Permission p,
                                   CodeSource entryCs,
                                   CodeSource accCs,
                                   Permissions perms) {

    if (!(p instanceof PrivateCredentialPermission)) {
        return false;
    }

    if (!(entryCs instanceof SubjectCodeSource)) {
        return false;
    }

    PrivateCredentialPermission pcp = (PrivateCredentialPermission)p;
    SubjectCodeSource scs = (SubjectCodeSource)entryCs;

    // see if it is a SELF permission
    String[][] pPrincipals = pcp.getPrincipals();
    if (pPrincipals.length <= 0 ||
        !pPrincipals[0][0].equalsIgnoreCase("self") ||
        !pPrincipals[0][1].equalsIgnoreCase("self")) {

        // regular PrivateCredentialPermission
        return false;
    } else {

        // granted a SELF permission - create a
        // PrivateCredentialPermission for each
        // of the Policy entry's CodeSource Principals

        if (scs.getPrincipals() == null) {
            // XXX SubjectCodeSource has no Subject???
            return true;
        }

        for (PrincipalEntry principal : scs.getPrincipals()) {

            //      if the Policy entry's Principal does not contain a
            //              WILDCARD for the Principal name, then a
            //              new PrivateCredentialPermission is created
            //              for the Principal listed in the Policy entry.
            //      if the Policy entry's Principal contains a WILDCARD
            //              for the Principal name, then a new
            //              PrivateCredentialPermission is created
            //              for each Principal associated with the Subject
            //              in the current ACC.

            String[][] principalInfo = getPrincipalInfo(principal, accCs);

            for (int i = 0; i < principalInfo.length; i++) {

                // here's the new PrivateCredentialPermission

                PrivateCredentialPermission newPcp =
                    new PrivateCredentialPermission
                            (pcp.getCredentialClass() +
                                    " " +
                                    principalInfo[i][0] +
                                    " " +
                                    "\"" + principalInfo[i][1] + "\"",
                            "read");

                if (debug != null) {
                    debug.println("adding SELF permission: " +
                                    newPcp.toString());
                }

                perms.add(newPcp);
            }
        }
    }
    return true;
}
 
Example #21
Source File: SubjectCodeSource.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Creates a new <code>SubjectCodeSource</code>
 * with the given <code>Subject</code>, principals, <code>URL</code>,
 * and signers (Certificates).  The <code>Subject</code>
 * represents the <code>Subject</code> associated with the current
 * <code>AccessControlContext</code>.
 * The Principals are given as a <code>LinkedList</code>
 * of <code>PolicyParser.PrincipalEntry</code> objects.
 * Typically either a <code>Subject</code> will be provided,
 * or a list of <code>principals</code> will be provided
 * (not both).
 *
 * <p>
 *
 * @param subject the <code>Subject</code> associated with this
 *                  <code>SubjectCodeSource</code> <p>
 *
 * @param url the <code>URL</code> associated with this
 *                  <code>SubjectCodeSource</code> <p>
 *
 * @param certs the signers associated with this
 *                  <code>SubjectCodeSource</code> <p>
 */
SubjectCodeSource(Subject subject,
    LinkedList<PrincipalEntry> principals,
    URL url, Certificate[] certs) {

    super(url, certs);
    this.subject = subject;
    this.principals = (principals == null ?
            new LinkedList<PrincipalEntry>() :
            new LinkedList<PrincipalEntry>(principals));
    sysClassLoader = java.security.AccessController.doPrivileged
    (new java.security.PrivilegedAction<ClassLoader>() {
        public ClassLoader run() {
                return ClassLoader.getSystemClassLoader();
        }
    });
}
 
Example #22
Source File: SubjectCodeSource.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * This method returns, true, if the provided <i>subjectList</i>
 * "contains" the <code>Principal</code> specified
 * in the provided <i>pppe</i> argument.
 *
 * Note that the provided <i>pppe</i> argument may have
 * wildcards (*) for the <code>Principal</code> class and name,
 * which need to be considered.
 *
 * <p>
 *
 * @param subjectList a list of PolicyParser.PrincipalEntry objects
 *          that correspond to all the Principals in the Subject currently
 *          on this thread's AccessControlContext. <p>
 *
 * @param pppe the Principals specified in a grant entry.
 *
 * @return true if the provided <i>subjectList</i> "contains"
 *          the <code>Principal</code> specified in the provided
 *          <i>pppe</i> argument.
 */
private boolean subjectListImpliesPrincipalEntry(
            LinkedList<PrincipalEntry> subjectList, PrincipalEntry pppe) {

    ListIterator<PrincipalEntry> li = subjectList.listIterator(0);
    while (li.hasNext()) {
        PrincipalEntry listPppe = li.next();

        if (pppe.getPrincipalClass().equals
                    (PrincipalEntry.WILDCARD_CLASS) ||
            pppe.getPrincipalClass().equals(listPppe.getPrincipalClass()))
        {
            if (pppe.getPrincipalName().equals
                    (PrincipalEntry.WILDCARD_NAME) ||
                pppe.getPrincipalName().equals(listPppe.getPrincipalName()))
                return true;
        }
    }
    return false;
}
 
Example #23
Source File: SubjectCodeSource.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * This method returns, true, if the provided <i>subjectList</i>
 * "contains" the <code>Principal</code> specified
 * in the provided <i>pppe</i> argument.
 *
 * Note that the provided <i>pppe</i> argument may have
 * wildcards (*) for the <code>Principal</code> class and name,
 * which need to be considered.
 *
 * <p>
 *
 * @param subjectList a list of PolicyParser.PrincipalEntry objects
 *          that correspond to all the Principals in the Subject currently
 *          on this thread's AccessControlContext. <p>
 *
 * @param pppe the Principals specified in a grant entry.
 *
 * @return true if the provided <i>subjectList</i> "contains"
 *          the <code>Principal</code> specified in the provided
 *          <i>pppe</i> argument.
 */
private boolean subjectListImpliesPrincipalEntry(
            LinkedList<PrincipalEntry> subjectList, PrincipalEntry pppe) {

    ListIterator<PrincipalEntry> li = subjectList.listIterator(0);
    while (li.hasNext()) {
        PrincipalEntry listPppe = li.next();

        if (pppe.getPrincipalClass().equals
                    (PrincipalEntry.WILDCARD_CLASS) ||
            pppe.getPrincipalClass().equals(listPppe.getPrincipalClass()))
        {
            if (pppe.getPrincipalName().equals
                    (PrincipalEntry.WILDCARD_NAME) ||
                pppe.getPrincipalName().equals(listPppe.getPrincipalName()))
                return true;
        }
    }
    return false;
}
 
Example #24
Source File: SubjectCodeSource.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Creates a new <code>SubjectCodeSource</code>
 * with the given <code>Subject</code>, principals, <code>URL</code>,
 * and signers (Certificates).  The <code>Subject</code>
 * represents the <code>Subject</code> associated with the current
 * <code>AccessControlContext</code>.
 * The Principals are given as a <code>LinkedList</code>
 * of <code>PolicyParser.PrincipalEntry</code> objects.
 * Typically either a <code>Subject</code> will be provided,
 * or a list of <code>principals</code> will be provided
 * (not both).
 *
 * <p>
 *
 * @param subject the <code>Subject</code> associated with this
 *                  <code>SubjectCodeSource</code> <p>
 *
 * @param url the <code>URL</code> associated with this
 *                  <code>SubjectCodeSource</code> <p>
 *
 * @param certs the signers associated with this
 *                  <code>SubjectCodeSource</code> <p>
 */
SubjectCodeSource(Subject subject,
    LinkedList<PrincipalEntry> principals,
    URL url, Certificate[] certs) {

    super(url, certs);
    this.subject = subject;
    this.principals = (principals == null ?
            new LinkedList<PrincipalEntry>() :
            new LinkedList<PrincipalEntry>(principals));
    sysClassLoader = java.security.AccessController.doPrivileged
    (new java.security.PrivilegedAction<ClassLoader>() {
        public ClassLoader run() {
                return ClassLoader.getSystemClassLoader();
        }
    });
}
 
Example #25
Source File: SubjectCodeSource.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Creates a new <code>SubjectCodeSource</code>
 * with the given <code>Subject</code>, principals, <code>URL</code>,
 * and signers (Certificates).  The <code>Subject</code>
 * represents the <code>Subject</code> associated with the current
 * <code>AccessControlContext</code>.
 * The Principals are given as a <code>LinkedList</code>
 * of <code>PolicyParser.PrincipalEntry</code> objects.
 * Typically either a <code>Subject</code> will be provided,
 * or a list of <code>principals</code> will be provided
 * (not both).
 *
 * <p>
 *
 * @param subject the <code>Subject</code> associated with this
 *                  <code>SubjectCodeSource</code> <p>
 *
 * @param url the <code>URL</code> associated with this
 *                  <code>SubjectCodeSource</code> <p>
 *
 * @param certs the signers associated with this
 *                  <code>SubjectCodeSource</code> <p>
 */
SubjectCodeSource(Subject subject,
    LinkedList<PrincipalEntry> principals,
    URL url, Certificate[] certs) {

    super(url, certs);
    this.subject = subject;
    this.principals = (principals == null ?
            new LinkedList<PrincipalEntry>() :
            new LinkedList<PrincipalEntry>(principals));
    sysClassLoader = java.security.AccessController.doPrivileged
    (new java.security.PrivilegedAction<ClassLoader>() {
        public ClassLoader run() {
                return ClassLoader.getSystemClassLoader();
        }
    });
}
 
Example #26
Source File: AuthPolicyFile.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns true if 'Self' permissions were added to the provided
 * 'perms', and false otherwise.
 *
 * <p>
 *
 * @param p check to see if this Permission is a "SELF"
 *                  PrivateCredentialPermission. <p>
 *
 * @param entryCs the codesource for the Policy entry.
 *
 * @param accCs the codesource for from the current AccessControlContext.
 *
 * @param perms the PermissionCollection where the individual
 *                  PrivateCredentialPermissions will be added.
 */
private boolean addSelfPermissions(final Permission p,
                                   CodeSource entryCs,
                                   CodeSource accCs,
                                   Permissions perms) {

    if (!(p instanceof PrivateCredentialPermission)) {
        return false;
    }

    if (!(entryCs instanceof SubjectCodeSource)) {
        return false;
    }

    PrivateCredentialPermission pcp = (PrivateCredentialPermission)p;
    SubjectCodeSource scs = (SubjectCodeSource)entryCs;

    // see if it is a SELF permission
    String[][] pPrincipals = pcp.getPrincipals();
    if (pPrincipals.length <= 0 ||
        !pPrincipals[0][0].equalsIgnoreCase("self") ||
        !pPrincipals[0][1].equalsIgnoreCase("self")) {

        // regular PrivateCredentialPermission
        return false;
    } else {

        // granted a SELF permission - create a
        // PrivateCredentialPermission for each
        // of the Policy entry's CodeSource Principals

        if (scs.getPrincipals() == null) {
            // XXX SubjectCodeSource has no Subject???
            return true;
        }

        for (PrincipalEntry principal : scs.getPrincipals()) {

            //      if the Policy entry's Principal does not contain a
            //              WILDCARD for the Principal name, then a
            //              new PrivateCredentialPermission is created
            //              for the Principal listed in the Policy entry.
            //      if the Policy entry's Principal contains a WILDCARD
            //              for the Principal name, then a new
            //              PrivateCredentialPermission is created
            //              for each Principal associated with the Subject
            //              in the current ACC.

            String[][] principalInfo = getPrincipalInfo(principal, accCs);

            for (int i = 0; i < principalInfo.length; i++) {

                // here's the new PrivateCredentialPermission

                PrivateCredentialPermission newPcp =
                    new PrivateCredentialPermission
                            (pcp.getCredentialClass() +
                                    " " +
                                    principalInfo[i][0] +
                                    " " +
                                    "\"" + principalInfo[i][1] + "\"",
                            "read");

                if (debug != null) {
                    debug.println("adding SELF permission: " +
                                    newPcp.toString());
                }

                perms.add(newPcp);
            }
        }
    }
    return true;
}
 
Example #27
Source File: SubjectCodeSource.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * This method returns, true, if the provided <i>subjectList</i>
 * "contains" the <code>Principal</code> specified
 * in the provided <i>pppe</i> argument.
 *
 * Note that the provided <i>pppe</i> argument may have
 * wildcards (*) for the <code>Principal</code> class and name,
 * which need to be considered.
 *
 * <p>
 *
 * @param subjectList a list of PolicyParser.PrincipalEntry objects
 *          that correspond to all the Principals in the Subject currently
 *          on this thread's AccessControlContext. <p>
 *
 * @param pppe the Principals specified in a grant entry.
 *
 * @return true if the provided <i>subjectList</i> "contains"
 *          the <code>Principal</code> specified in the provided
 *          <i>pppe</i> argument.
 */
private boolean subjectListImpliesPrincipalEntry(
            LinkedList<PrincipalEntry> subjectList, PrincipalEntry pppe) {

    ListIterator<PrincipalEntry> li = subjectList.listIterator(0);
    while (li.hasNext()) {
        PrincipalEntry listPppe = li.next();

        if (pppe.getPrincipalClass().equals
                    (PrincipalEntry.WILDCARD_CLASS) ||
            pppe.getPrincipalClass().equals(listPppe.getPrincipalClass()))
        {
            if (pppe.getPrincipalName().equals
                    (PrincipalEntry.WILDCARD_NAME) ||
                pppe.getPrincipalName().equals(listPppe.getPrincipalName()))
                return true;
        }
    }
    return false;
}
 
Example #28
Source File: SubjectCodeSource.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/**
 * This method returns, true, if the provided <i>subjectList</i>
 * "contains" the <code>Principal</code> specified
 * in the provided <i>pppe</i> argument.
 *
 * Note that the provided <i>pppe</i> argument may have
 * wildcards (*) for the <code>Principal</code> class and name,
 * which need to be considered.
 *
 * <p>
 *
 * @param subjectList a list of PolicyParser.PrincipalEntry objects
 *          that correspond to all the Principals in the Subject currently
 *          on this thread's AccessControlContext. <p>
 *
 * @param pppe the Principals specified in a grant entry.
 *
 * @return true if the provided <i>subjectList</i> "contains"
 *          the <code>Principal</code> specified in the provided
 *          <i>pppe</i> argument.
 */
private boolean subjectListImpliesPrincipalEntry(
            LinkedList<PrincipalEntry> subjectList, PrincipalEntry pppe) {

    ListIterator<PrincipalEntry> li = subjectList.listIterator(0);
    while (li.hasNext()) {
        PrincipalEntry listPppe = li.next();

        if (pppe.getPrincipalClass().equals
                    (PrincipalEntry.WILDCARD_CLASS) ||
            pppe.getPrincipalClass().equals(listPppe.getPrincipalClass()))
        {
            if (pppe.getPrincipalName().equals
                    (PrincipalEntry.WILDCARD_NAME) ||
                pppe.getPrincipalName().equals(listPppe.getPrincipalName()))
                return true;
        }
    }
    return false;
}
 
Example #29
Source File: AuthPolicyFile.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns true if 'Self' permissions were added to the provided
 * 'perms', and false otherwise.
 *
 * <p>
 *
 * @param p check to see if this Permission is a "SELF"
 *                  PrivateCredentialPermission. <p>
 *
 * @param entryCs the codesource for the Policy entry.
 *
 * @param accCs the codesource for from the current AccessControlContext.
 *
 * @param perms the PermissionCollection where the individual
 *                  PrivateCredentialPermissions will be added.
 */
private boolean addSelfPermissions(final Permission p,
                                   CodeSource entryCs,
                                   CodeSource accCs,
                                   Permissions perms) {

    if (!(p instanceof PrivateCredentialPermission)) {
        return false;
    }

    if (!(entryCs instanceof SubjectCodeSource)) {
        return false;
    }

    PrivateCredentialPermission pcp = (PrivateCredentialPermission)p;
    SubjectCodeSource scs = (SubjectCodeSource)entryCs;

    // see if it is a SELF permission
    String[][] pPrincipals = pcp.getPrincipals();
    if (pPrincipals.length <= 0 ||
        !pPrincipals[0][0].equalsIgnoreCase("self") ||
        !pPrincipals[0][1].equalsIgnoreCase("self")) {

        // regular PrivateCredentialPermission
        return false;
    } else {

        // granted a SELF permission - create a
        // PrivateCredentialPermission for each
        // of the Policy entry's CodeSource Principals

        if (scs.getPrincipals() == null) {
            // XXX SubjectCodeSource has no Subject???
            return true;
        }

        for (PrincipalEntry principal : scs.getPrincipals()) {

            //      if the Policy entry's Principal does not contain a
            //              WILDCARD for the Principal name, then a
            //              new PrivateCredentialPermission is created
            //              for the Principal listed in the Policy entry.
            //      if the Policy entry's Principal contains a WILDCARD
            //              for the Principal name, then a new
            //              PrivateCredentialPermission is created
            //              for each Principal associated with the Subject
            //              in the current ACC.

            String[][] principalInfo = getPrincipalInfo(principal, accCs);

            for (int i = 0; i < principalInfo.length; i++) {

                // here's the new PrivateCredentialPermission

                PrivateCredentialPermission newPcp =
                    new PrivateCredentialPermission
                            (pcp.getCredentialClass() +
                                    " " +
                                    principalInfo[i][0] +
                                    " " +
                                    "\"" + principalInfo[i][1] + "\"",
                            "read");

                if (debug != null) {
                    debug.println("adding SELF permission: " +
                                    newPcp.toString());
                }

                perms.add(newPcp);
            }
        }
    }
    return true;
}
 
Example #30
Source File: SubjectCodeSource.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Creates a new <code>SubjectCodeSource</code>
 * with the given <code>Subject</code>, principals, <code>URL</code>,
 * and signers (Certificates).  The <code>Subject</code>
 * represents the <code>Subject</code> associated with the current
 * <code>AccessControlContext</code>.
 * The Principals are given as a <code>LinkedList</code>
 * of <code>PolicyParser.PrincipalEntry</code> objects.
 * Typically either a <code>Subject</code> will be provided,
 * or a list of <code>principals</code> will be provided
 * (not both).
 *
 * <p>
 *
 * @param subject the <code>Subject</code> associated with this
 *                  <code>SubjectCodeSource</code> <p>
 *
 * @param url the <code>URL</code> associated with this
 *                  <code>SubjectCodeSource</code> <p>
 *
 * @param certs the signers associated with this
 *                  <code>SubjectCodeSource</code> <p>
 */
SubjectCodeSource(Subject subject,
    LinkedList<PrincipalEntry> principals,
    URL url, Certificate[] certs) {

    super(url, certs);
    this.subject = subject;
    this.principals = (principals == null ?
            new LinkedList<PrincipalEntry>() :
            new LinkedList<PrincipalEntry>(principals));
    sysClassLoader = java.security.AccessController.doPrivileged
    (new java.security.PrivilegedAction<ClassLoader>() {
        public ClassLoader run() {
                return ClassLoader.getSystemClassLoader();
        }
    });
}