Java Code Examples for sun.security.util.ResourcesMgr#getString()

The following examples show how to use sun.security.util.ResourcesMgr#getString() . 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: Subject.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Reads this object from a stream (i.e., deserializes it)
 */
@SuppressWarnings("unchecked")
private void readObject(java.io.ObjectInputStream s)
            throws java.io.IOException, ClassNotFoundException {

    ObjectInputStream.GetField gf = s.readFields();

    readOnly = gf.get("readOnly", false);

    Set<Principal> inputPrincs = (Set<Principal>)gf.get("principals", null);

    // Rewrap the principals into a SecureSet
    if (inputPrincs == null) {
        throw new NullPointerException
            (ResourcesMgr.getString("invalid.null.input.s."));
    }
    try {
        principals = Collections.synchronizedSet(new SecureSet<Principal>
                            (this, PRINCIPAL_SET, inputPrincs));
    } catch (NullPointerException npe) {
        // Sometimes people deserialize the principals set only.
        // Subject is not accessible, so just don't fail.
        principals = Collections.synchronizedSet
                    (new SecureSet<Principal>(this, PRINCIPAL_SET));
    }

    // The Credential {@code Set} is not serialized, but we do not
    // want the default deserialization routine to set it to null.
    this.pubCredentials = Collections.synchronizedSet
                    (new SecureSet<Object>(this, PUB_CREDENTIAL_SET));
    this.privCredentials = Collections.synchronizedSet
                    (new SecureSet<Object>(this, PRIV_CREDENTIAL_SET));
}
 
Example 2
Source File: PolicyParser.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
void add(KeyStoreEntry entry) throws ParsingException {
    String keystoreName = entry.getName();
    if (!entries.containsKey(keystoreName)) {
        entries.put(keystoreName, entry);
    } else {
        MessageFormat form = new MessageFormat(ResourcesMgr.getString(
            "duplicate.keystore.name"));
        Object[] source = {keystoreName};
        throw new ParsingException(form.format(source));
    }
}
 
Example 3
Source File: PolicyParser.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Reads a policy configuration into the Policy object using a
 * Reader object. <p>
 *
 * @param policy the policy Reader object.
 *
 * @exception ParsingException if the policy configuration contains
 *          a syntax error.
 *
 * @exception IOException if an error occurs while reading the policy
 *          configuration.
 */

public void read(Reader policy)
    throws ParsingException, IOException
{
    if (!(policy instanceof BufferedReader)) {
        policy = new BufferedReader(policy);
    }

    /**
     * Configure the stream tokenizer:
     *      Recognize strings between "..."
     *      Don't convert words to lowercase
     *      Recognize both C-style and C++-style comments
     *      Treat end-of-line as white space, not as a token
     */
    st   = new StreamTokenizer(policy);

    st.resetSyntax();
    st.wordChars('a', 'z');
    st.wordChars('A', 'Z');
    st.wordChars('.', '.');
    st.wordChars('0', '9');
    st.wordChars('_', '_');
    st.wordChars('$', '$');
    st.wordChars(128 + 32, 255);
    st.whitespaceChars(0, ' ');
    st.commentChar('/');
    st.quoteChar('\'');
    st.quoteChar('"');
    st.lowerCaseMode(false);
    st.ordinaryChar('/');
    st.slashSlashComments(true);
    st.slashStarComments(true);

    /**
     * The main parsing loop.  The loop is executed once
     * for each entry in the config file.      The entries
     * are delimited by semicolons.   Once we've read in
     * the information for an entry, go ahead and try to
     * add it to the policy vector.
     *
     */

    lookahead = st.nextToken();
    GrantEntry ge = null;
    while (lookahead != StreamTokenizer.TT_EOF) {
        if (peek("grant")) {
            ge = parseGrantEntry();
            // could be null if we couldn't expand a property
            if (ge != null)
                add(ge);
        } else if (peek("keystore") && keyStoreUrlString==null) {
            // only one keystore entry per policy file, others will be
            // ignored
            parseKeyStoreEntry();
        } else if (peek("keystorePasswordURL") && storePassURL==null) {
            // only one keystore passwordURL per policy file, others will be
            // ignored
            parseStorePassURL();
        } else if (ge == null && keyStoreUrlString == null &&
            storePassURL == null && peek("domain")) {
            if (domainEntries == null) {
                domainEntries = new TreeMap<>();
            }
            DomainEntry de = parseDomainEntry();
            if (de != null) {
                String domainName = de.getName();
                if (!domainEntries.containsKey(domainName)) {
                    domainEntries.put(domainName, de);
                } else {
                    MessageFormat form =
                        new MessageFormat(ResourcesMgr.getString(
                            "duplicate.keystore.domain.name"));
                    Object[] source = {domainName};
                    throw new ParsingException(form.format(source));
                }
            }
        } else {
            // error?
        }
        match(";");
    }

    if (keyStoreUrlString == null && storePassURL != null) {
        throw new ParsingException(ResourcesMgr.getString
            ("keystorePasswordURL.can.not.be.specified.without.also.specifying.keystore"));
    }
}
 
Example 4
Source File: Subject.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Perform work as a particular {@code Subject}.
 *
 * <p> This method first retrieves the current Thread's
 * {@code AccessControlContext} via
 * {@code AccessController.getContext},
 * and then instantiates a new {@code AccessControlContext}
 * using the retrieved context along with a new
 * {@code SubjectDomainCombiner} (constructed using
 * the provided {@code Subject}).
 * Finally, this method invokes {@code AccessController.doPrivileged},
 * passing it the provided {@code PrivilegedAction},
 * as well as the newly constructed {@code AccessControlContext}.
 *
 * <p>
 *
 * @param subject the {@code Subject} that the specified
 *                  {@code action} will run as.  This parameter
 *                  may be {@code null}. <p>
 *
 * @param <T> the type of the value returned by the PrivilegedAction's
 *                  {@code run} method.
 *
 * @param action the code to be run as the specified
 *                  {@code Subject}. <p>
 *
 * @return the value returned by the PrivilegedAction's
 *                  {@code run} method.
 *
 * @exception NullPointerException if the {@code PrivilegedAction}
 *                  is {@code null}. <p>
 *
 * @exception SecurityException if the caller does not have permission
 *                  to invoke this method.
 */
public static <T> T doAs(final Subject subject,
                    final java.security.PrivilegedAction<T> action) {

    java.lang.SecurityManager sm = System.getSecurityManager();
    if (sm != null) {
        sm.checkPermission(AuthPermissionHolder.DO_AS_PERMISSION);
    }
    if (action == null)
        throw new NullPointerException
            (ResourcesMgr.getString("invalid.null.action.provided"));

    // set up the new Subject-based AccessControlContext
    // for doPrivileged
    final AccessControlContext currentAcc = AccessController.getContext();

    // call doPrivileged and push this new context on the stack
    return java.security.AccessController.doPrivileged
                                    (action,
                                    createContext(subject, currentAcc));
}
 
Example 5
Source File: Subject.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Perform work as a particular {@code Subject}.
 *
 * <p> This method first retrieves the current Thread's
 * {@code AccessControlContext} via
 * {@code AccessController.getContext},
 * and then instantiates a new {@code AccessControlContext}
 * using the retrieved context along with a new
 * {@code SubjectDomainCombiner} (constructed using
 * the provided {@code Subject}).
 * Finally, this method invokes {@code AccessController.doPrivileged},
 * passing it the provided {@code PrivilegedExceptionAction},
 * as well as the newly constructed {@code AccessControlContext}.
 *
 * <p>
 *
 * @param subject the {@code Subject} that the specified
 *                  {@code action} will run as.  This parameter
 *                  may be {@code null}. <p>
 *
 * @param <T> the type of the value returned by the
 *                  PrivilegedExceptionAction's {@code run} method.
 *
 * @param action the code to be run as the specified
 *                  {@code Subject}. <p>
 *
 * @return the value returned by the
 *                  PrivilegedExceptionAction's {@code run} method.
 *
 * @exception PrivilegedActionException if the
 *                  {@code PrivilegedExceptionAction.run}
 *                  method throws a checked exception. <p>
 *
 * @exception NullPointerException if the specified
 *                  {@code PrivilegedExceptionAction} is
 *                  {@code null}. <p>
 *
 * @exception SecurityException if the caller does not have permission
 *                  to invoke this method.
 */
public static <T> T doAs(final Subject subject,
                    final java.security.PrivilegedExceptionAction<T> action)
                    throws java.security.PrivilegedActionException {

    java.lang.SecurityManager sm = System.getSecurityManager();
    if (sm != null) {
        sm.checkPermission(AuthPermissionHolder.DO_AS_PERMISSION);
    }

    if (action == null)
        throw new NullPointerException
            (ResourcesMgr.getString("invalid.null.action.provided"));

    // set up the new Subject-based AccessControlContext for doPrivileged
    final AccessControlContext currentAcc = AccessController.getContext();

    // call doPrivileged and push this new context on the stack
    return java.security.AccessController.doPrivileged
                                    (action,
                                    createContext(subject, currentAcc));
}
 
Example 6
Source File: ConfigFile.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
private IOException ioException(String resourceKey, Object... args) {
    MessageFormat form = new MessageFormat(ResourcesMgr.getString
        (resourceKey, "sun.security.util.AuthResources"));
    return new IOException(form.format(args));
}
 
Example 7
Source File: Subject.java    From Java8CN with Apache License 2.0 4 votes vote down vote up
/**
 * Perform work as a particular {@code Subject}.
 *
 * <p> This method first retrieves the current Thread's
 * {@code AccessControlContext} via
 * {@code AccessController.getContext},
 * and then instantiates a new {@code AccessControlContext}
 * using the retrieved context along with a new
 * {@code SubjectDomainCombiner} (constructed using
 * the provided {@code Subject}).
 * Finally, this method invokes {@code AccessController.doPrivileged},
 * passing it the provided {@code PrivilegedAction},
 * as well as the newly constructed {@code AccessControlContext}.
 *
 * <p>
 *
 * @param subject the {@code Subject} that the specified
 *                  {@code action} will run as.  This parameter
 *                  may be {@code null}. <p>
 *
 * @param <T> the type of the value returned by the PrivilegedAction's
 *                  {@code run} method.
 *
 * @param action the code to be run as the specified
 *                  {@code Subject}. <p>
 *
 * @return the value returned by the PrivilegedAction's
 *                  {@code run} method.
 *
 * @exception NullPointerException if the {@code PrivilegedAction}
 *                  is {@code null}. <p>
 *
 * @exception SecurityException if the caller does not have permission
 *                  to invoke this method.
 */
public static <T> T doAs(final Subject subject,
                    final java.security.PrivilegedAction<T> action) {

    java.lang.SecurityManager sm = System.getSecurityManager();
    if (sm != null) {
        sm.checkPermission(AuthPermissionHolder.DO_AS_PERMISSION);
    }
    if (action == null)
        throw new NullPointerException
            (ResourcesMgr.getString("invalid.null.action.provided"));

    // set up the new Subject-based AccessControlContext
    // for doPrivileged
    final AccessControlContext currentAcc = AccessController.getContext();

    // call doPrivileged and push this new context on the stack
    return java.security.AccessController.doPrivileged
                                    (action,
                                    createContext(subject, currentAcc));
}
 
Example 8
Source File: PolicyParser.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Reads a policy configuration into the Policy object using a
 * Reader object. <p>
 *
 * @param policy the policy Reader object.
 *
 * @exception ParsingException if the policy configuration contains
 *          a syntax error.
 *
 * @exception IOException if an error occurs while reading the policy
 *          configuration.
 */

public void read(Reader policy)
    throws ParsingException, IOException
{
    if (!(policy instanceof BufferedReader)) {
        policy = new BufferedReader(policy);
    }

    /**
     * Configure the stream tokenizer:
     *      Recognize strings between "..."
     *      Don't convert words to lowercase
     *      Recognize both C-style and C++-style comments
     *      Treat end-of-line as white space, not as a token
     */
    st   = new StreamTokenizer(policy);

    st.resetSyntax();
    st.wordChars('a', 'z');
    st.wordChars('A', 'Z');
    st.wordChars('.', '.');
    st.wordChars('0', '9');
    st.wordChars('_', '_');
    st.wordChars('$', '$');
    st.wordChars(128 + 32, 255);
    st.whitespaceChars(0, ' ');
    st.commentChar('/');
    st.quoteChar('\'');
    st.quoteChar('"');
    st.lowerCaseMode(false);
    st.ordinaryChar('/');
    st.slashSlashComments(true);
    st.slashStarComments(true);

    /**
     * The main parsing loop.  The loop is executed once
     * for each entry in the config file.      The entries
     * are delimited by semicolons.   Once we've read in
     * the information for an entry, go ahead and try to
     * add it to the policy vector.
     *
     */

    lookahead = st.nextToken();
    GrantEntry ge = null;
    while (lookahead != StreamTokenizer.TT_EOF) {
        if (peek("grant")) {
            ge = parseGrantEntry();
            // could be null if we couldn't expand a property
            if (ge != null)
                add(ge);
        } else if (peek("keystore") && keyStoreUrlString==null) {
            // only one keystore entry per policy file, others will be
            // ignored
            parseKeyStoreEntry();
        } else if (peek("keystorePasswordURL") && storePassURL==null) {
            // only one keystore passwordURL per policy file, others will be
            // ignored
            parseStorePassURL();
        } else if (ge == null && keyStoreUrlString == null &&
            storePassURL == null && peek("domain")) {
            if (domainEntries == null) {
                domainEntries = new TreeMap<>();
            }
            DomainEntry de = parseDomainEntry();
            if (de != null) {
                String domainName = de.getName();
                if (!domainEntries.containsKey(domainName)) {
                    domainEntries.put(domainName, de);
                } else {
                    MessageFormat form =
                        new MessageFormat(ResourcesMgr.getString(
                            "duplicate.keystore.domain.name"));
                    Object[] source = {domainName};
                    throw new ParsingException(form.format(source));
                }
            }
        } else {
            // error?
        }
        match(";");
    }

    if (keyStoreUrlString == null && storePassURL != null) {
        throw new ParsingException(ResourcesMgr.getString
            ("keystorePasswordURL.can.not.be.specified.without.also.specifying.keystore"));
    }
}
 
Example 9
Source File: Subject.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Perform work as a particular {@code Subject}.
 *
 * <p> This method first retrieves the current Thread's
 * {@code AccessControlContext} via
 * {@code AccessController.getContext},
 * and then instantiates a new {@code AccessControlContext}
 * using the retrieved context along with a new
 * {@code SubjectDomainCombiner} (constructed using
 * the provided {@code Subject}).
 * Finally, this method invokes {@code AccessController.doPrivileged},
 * passing it the provided {@code PrivilegedAction},
 * as well as the newly constructed {@code AccessControlContext}.
 *
 * <p>
 *
 * @param subject the {@code Subject} that the specified
 *                  {@code action} will run as.  This parameter
 *                  may be {@code null}. <p>
 *
 * @param <T> the type of the value returned by the PrivilegedAction's
 *                  {@code run} method.
 *
 * @param action the code to be run as the specified
 *                  {@code Subject}. <p>
 *
 * @return the value returned by the PrivilegedAction's
 *                  {@code run} method.
 *
 * @exception NullPointerException if the {@code PrivilegedAction}
 *                  is {@code null}. <p>
 *
 * @exception SecurityException if the caller does not have permission
 *                  to invoke this method.
 */
public static <T> T doAs(final Subject subject,
                    final java.security.PrivilegedAction<T> action) {

    java.lang.SecurityManager sm = System.getSecurityManager();
    if (sm != null) {
        sm.checkPermission(AuthPermissionHolder.DO_AS_PERMISSION);
    }
    if (action == null)
        throw new NullPointerException
            (ResourcesMgr.getString("invalid.null.action.provided"));

    // set up the new Subject-based AccessControlContext
    // for doPrivileged
    final AccessControlContext currentAcc = AccessController.getContext();

    // call doPrivileged and push this new context on the stack
    return java.security.AccessController.doPrivileged
                                    (action,
                                    createContext(subject, currentAcc));
}
 
Example 10
Source File: ConfigFile.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
private IOException ioException(String resourceKey, Object... args) {
    MessageFormat form = new MessageFormat(ResourcesMgr.getString
        (resourceKey, "sun.security.util.AuthResources"));
    return new IOException(form.format(args));
}
 
Example 11
Source File: Subject.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Perform privileged work as a particular {@code Subject}.
 *
 * <p> This method behaves exactly as {@code Subject.doAs},
 * except that instead of retrieving the current Thread's
 * {@code AccessControlContext}, it uses the provided
 * {@code AccessControlContext}.  If the provided
 * {@code AccessControlContext} is {@code null},
 * this method instantiates a new {@code AccessControlContext}
 * with an empty collection of ProtectionDomains.
 *
 * <p>
 *
 * @param subject the {@code Subject} that the specified
 *                  {@code action} will run as.  This parameter
 *                  may be {@code null}. <p>
 *
 * @param <T> the type of the value returned by the PrivilegedAction's
 *                  {@code run} method.
 *
 * @param action the code to be run as the specified
 *                  {@code Subject}. <p>
 *
 * @param acc the {@code AccessControlContext} to be tied to the
 *                  specified <i>subject</i> and <i>action</i>. <p>
 *
 * @return the value returned by the PrivilegedAction's
 *                  {@code run} method.
 *
 * @exception NullPointerException if the {@code PrivilegedAction}
 *                  is {@code null}. <p>
 *
 * @exception SecurityException if the caller does not have permission
 *                  to invoke this method.
 */
public static <T> T doAsPrivileged(final Subject subject,
                    final java.security.PrivilegedAction<T> action,
                    final java.security.AccessControlContext acc) {

    java.lang.SecurityManager sm = System.getSecurityManager();
    if (sm != null) {
        sm.checkPermission(AuthPermissionHolder.DO_AS_PRIVILEGED_PERMISSION);
    }

    if (action == null)
        throw new NullPointerException
            (ResourcesMgr.getString("invalid.null.action.provided"));

    // set up the new Subject-based AccessControlContext
    // for doPrivileged
    final AccessControlContext callerAcc =
            (acc == null ?
            new AccessControlContext(NULL_PD_ARRAY) :
            acc);

    // call doPrivileged and push this new context on the stack
    return java.security.AccessController.doPrivileged
                                    (action,
                                    createContext(subject, callerAcc));
}
 
Example 12
Source File: LoginContext.java    From openjdk-jdk8u with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Instantiate a new {@code LoginContext} object with a name
 * and a {@code CallbackHandler} object.
 *
 * <p>
 *
 * @param name the name used as the index into the
 *          {@code Configuration}. <p>
 *
 * @param callbackHandler the {@code CallbackHandler} object used by
 *          LoginModules to communicate with the user.
 *
 * @exception LoginException if the caller-specified {@code name}
 *          does not appear in the {@code Configuration}
 *          and there is no {@code Configuration} entry
 *          for "<i>other</i>", or if the caller-specified
 *          {@code callbackHandler} is {@code null}.
 *          <p>
 * @exception SecurityException if a SecurityManager is set and
 *          the caller does not have
 *          AuthPermission("createLoginContext.<i>name</i>"),
 *          or if a configuration entry for <i>name</i> does not exist and
 *          the caller does not additionally have
 *          AuthPermission("createLoginContext.other")
 */
public LoginContext(String name, CallbackHandler callbackHandler)
throws LoginException {
    init(name);
    if (callbackHandler == null)
        throw new LoginException(ResourcesMgr.getString
                            ("invalid.null.CallbackHandler.provided"));
    this.callbackHandler = new SecureCallbackHandler
                            (java.security.AccessController.getContext(),
                            callbackHandler);
}
 
Example 13
Source File: LoginContext.java    From openjdk-8-source with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Instantiate a new {@code LoginContext} object with a name
 * and a {@code CallbackHandler} object.
 *
 * <p>
 *
 * @param name the name used as the index into the
 *          {@code Configuration}. <p>
 *
 * @param callbackHandler the {@code CallbackHandler} object used by
 *          LoginModules to communicate with the user.
 *
 * @exception LoginException if the caller-specified {@code name}
 *          does not appear in the {@code Configuration}
 *          and there is no {@code Configuration} entry
 *          for "<i>other</i>", or if the caller-specified
 *          {@code callbackHandler} is {@code null}.
 *          <p>
 * @exception SecurityException if a SecurityManager is set and
 *          the caller does not have
 *          AuthPermission("createLoginContext.<i>name</i>"),
 *          or if a configuration entry for <i>name</i> does not exist and
 *          the caller does not additionally have
 *          AuthPermission("createLoginContext.other")
 */
public LoginContext(String name, CallbackHandler callbackHandler)
throws LoginException {
    init(name);
    if (callbackHandler == null)
        throw new LoginException(ResourcesMgr.getString
                            ("invalid.null.CallbackHandler.provided"));
    this.callbackHandler = new SecureCallbackHandler
                            (java.security.AccessController.getContext(),
                            callbackHandler);
}
 
Example 14
Source File: LoginContext.java    From dragonwell8_jdk with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Instantiate a new {@code LoginContext} object with a name
 * and a {@code Subject} object.
 *
 * <p>
 *
 * @param name the name used as the index into the
 *          {@code Configuration}. <p>
 *
 * @param subject the {@code Subject} to authenticate.
 *
 * @exception LoginException if the caller-specified {@code name}
 *          does not appear in the {@code Configuration}
 *          and there is no {@code Configuration} entry
 *          for "<i>other</i>", if the caller-specified {@code subject}
 *          is {@code null}, or if the
 *          <i>auth.login.defaultCallbackHandler</i>
 *          security property was set, but the implementation
 *          class could not be loaded.
 *          <p>
 * @exception SecurityException if a SecurityManager is set and
 *          the caller does not have
 *          AuthPermission("createLoginContext.<i>name</i>"),
 *          or if a configuration entry for <i>name</i> does not exist and
 *          the caller does not additionally have
 *          AuthPermission("createLoginContext.other")
 */
public LoginContext(String name, Subject subject)
throws LoginException {
    init(name);
    if (subject == null)
        throw new LoginException
            (ResourcesMgr.getString("invalid.null.Subject.provided"));
    this.subject = subject;
    subjectProvided = true;
    loadDefaultCallbackHandler();
}
 
Example 15
Source File: Subject.java    From Java8CN with Apache License 2.0 3 votes vote down vote up
/**
 * Return a {@code Set} of Principals associated with this
 * {@code Subject} that are instances or subclasses of the specified
 * {@code Class}.
 *
 * <p> The returned {@code Set} is not backed by this Subject's
 * internal {@code Principal} {@code Set}.  A new
 * {@code Set} is created and returned for each method invocation.
 * Modifications to the returned {@code Set}
 * will not affect the internal {@code Principal} {@code Set}.
 *
 * <p>
 *
 * @param <T> the type of the class modeled by {@code c}
 *
 * @param c the returned {@code Set} of Principals will all be
 *          instances of this class.
 *
 * @return a {@code Set} of Principals that are instances of the
 *          specified {@code Class}.
 *
 * @exception NullPointerException if the specified {@code Class}
 *                  is {@code null}.
 */
public <T extends Principal> Set<T> getPrincipals(Class<T> c) {

    if (c == null)
        throw new NullPointerException
            (ResourcesMgr.getString("invalid.null.Class.provided"));

    // always return an empty Set instead of null
    // so LoginModules can add to the Set if necessary
    return new ClassSet<T>(PRINCIPAL_SET, c);
}
 
Example 16
Source File: PolicyParser.java    From jdk8u60 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * A PrincipalEntry consists of the Principal class and Principal name.
 *
 * @param principalClass the Principal class
 * @param principalName the Principal name
 * @throws NullPointerException if principalClass or principalName
 *                              are null
 */
public PrincipalEntry(String principalClass, String principalName) {
    if (principalClass == null || principalName == null)
        throw new NullPointerException(ResourcesMgr.getString(
                          "null.principalClass.or.principalName"));
    this.principalClass = principalClass;
    this.principalName = principalName;
}
 
Example 17
Source File: Subject.java    From JDKSourceCode1.8 with MIT License 3 votes vote down vote up
/**
 * Return a {@code Set} of Principals associated with this
 * {@code Subject} that are instances or subclasses of the specified
 * {@code Class}.
 *
 * <p> The returned {@code Set} is not backed by this Subject's
 * internal {@code Principal} {@code Set}.  A new
 * {@code Set} is created and returned for each method invocation.
 * Modifications to the returned {@code Set}
 * will not affect the internal {@code Principal} {@code Set}.
 *
 * <p>
 *
 * @param <T> the type of the class modeled by {@code c}
 *
 * @param c the returned {@code Set} of Principals will all be
 *          instances of this class.
 *
 * @return a {@code Set} of Principals that are instances of the
 *          specified {@code Class}.
 *
 * @exception NullPointerException if the specified {@code Class}
 *                  is {@code null}.
 */
public <T extends Principal> Set<T> getPrincipals(Class<T> c) {

    if (c == null)
        throw new NullPointerException
            (ResourcesMgr.getString("invalid.null.Class.provided"));

    // always return an empty Set instead of null
    // so LoginModules can add to the Set if necessary
    return new ClassSet<T>(PRINCIPAL_SET, c);
}
 
Example 18
Source File: PrivateCredentialPermission.java    From jdk8u-jdk with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Creates a new {@code PrivateCredentialPermission}
 * with the specified {@code name}.  The {@code name}
 * specifies both a Credential class and a {@code Principal} Set.
 *
 * <p>
 *
 * @param name the name specifying the Credential class and
 *          {@code Principal} Set. <p>
 *
 * @param actions the actions specifying that the Credential can be read.
 *
 * @throws IllegalArgumentException if {@code name} does not conform
 *          to the correct syntax or if {@code actions} is not "read".
 */
public PrivateCredentialPermission(String name, String actions) {
    super(name);

    if (!"read".equalsIgnoreCase(actions))
        throw new IllegalArgumentException
            (ResourcesMgr.getString("actions.can.only.be.read."));
    init(name);
}
 
Example 19
Source File: Subject.java    From openjdk-jdk8u with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Return a {@code Set} of public credentials associated with this
 * {@code Subject} that are instances or subclasses of the specified
 * {@code Class}.
 *
 * <p> The returned {@code Set} is not backed by this Subject's
 * internal public Credential {@code Set}.  A new
 * {@code Set} is created and returned for each method invocation.
 * Modifications to the returned {@code Set}
 * will not affect the internal public Credential {@code Set}.
 *
 * <p>
 *
 * @param <T> the type of the class modeled by {@code c}
 *
 * @param c the returned {@code Set} of public credentials will all be
 *          instances of this class.
 *
 * @return a {@code Set} of public credentials that are instances
 *          of the  specified {@code Class}.
 *
 * @exception NullPointerException if the specified {@code Class}
 *          is {@code null}.
 */
public <T> Set<T> getPublicCredentials(Class<T> c) {

    if (c == null)
        throw new NullPointerException
            (ResourcesMgr.getString("invalid.null.Class.provided"));

    // always return an empty Set instead of null
    // so LoginModules can add to the Set if necessary
    return new ClassSet<T>(PUB_CREDENTIAL_SET, c);
}
 
Example 20
Source File: LoginContext.java    From openjdk-jdk9 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Logout the {@code Subject}.
 *
 * <p> This method invokes the {@code logout} method for each
 * {@code LoginModule} configured for this {@code LoginContext}.
 * Each {@code LoginModule} performs its respective logout procedure
 * which may include removing/destroying
 * {@code Principal} and {@code Credential} information
 * from the {@code Subject} and state cleanup.
 *
 * <p> Note that this method invokes all LoginModules configured for the
 * application regardless of their respective
 * {@code Configuration} flag parameters.  Essentially this means
 * that {@code Requisite} and {@code Sufficient} semantics are
 * ignored for this method.  This guarantees that proper cleanup
 * and state restoration can take place.
 *
 * @exception LoginException if the logout fails.
 */
public void logout() throws LoginException {
    if (subject == null) {
        throw new LoginException(ResourcesMgr.getString
            ("null.subject.logout.called.before.login"));
    }

    // module invoked in doPrivileged
    invokePriv(LOGOUT_METHOD);
}