|
From: <ls...@us...> - 2007-11-18 16:23:30
|
Revision: 3598
http://jnode.svn.sourceforge.net/jnode/?rev=3598&view=rev
Author: lsantha
Date: 2007-11-18 08:23:27 -0800 (Sun, 18 Nov 2007)
Log Message:
-----------
OpenJDK integration.
Added Paths:
-----------
trunk/core/src/openjdk/javax/javax/security/auth/AuthPermission.java
trunk/core/src/openjdk/javax/javax/security/auth/DestroyFailedException.java
trunk/core/src/openjdk/javax/javax/security/auth/Destroyable.java
trunk/core/src/openjdk/javax/javax/security/auth/Policy.java
trunk/core/src/openjdk/javax/javax/security/auth/PrivateCredentialPermission.java
trunk/core/src/openjdk/javax/javax/security/auth/RefreshFailedException.java
trunk/core/src/openjdk/javax/javax/security/auth/Refreshable.java
trunk/core/src/openjdk/javax/javax/security/auth/Subject.java
trunk/core/src/openjdk/javax/javax/security/auth/SubjectDomainCombiner.java
trunk/core/src/openjdk/javax/javax/security/auth/callback/
trunk/core/src/openjdk/javax/javax/security/auth/callback/Callback.java
trunk/core/src/openjdk/javax/javax/security/auth/callback/CallbackHandler.java
trunk/core/src/openjdk/javax/javax/security/auth/callback/ChoiceCallback.java
trunk/core/src/openjdk/javax/javax/security/auth/callback/ConfirmationCallback.java
trunk/core/src/openjdk/javax/javax/security/auth/callback/LanguageCallback.java
trunk/core/src/openjdk/javax/javax/security/auth/callback/NameCallback.java
trunk/core/src/openjdk/javax/javax/security/auth/callback/PasswordCallback.java
trunk/core/src/openjdk/javax/javax/security/auth/callback/TextInputCallback.java
trunk/core/src/openjdk/javax/javax/security/auth/callback/TextOutputCallback.java
trunk/core/src/openjdk/javax/javax/security/auth/callback/UnsupportedCallbackException.java
trunk/core/src/openjdk/javax/javax/security/auth/callback/package.html
trunk/core/src/openjdk/javax/javax/security/auth/kerberos/DelegationPermission.java
trunk/core/src/openjdk/javax/javax/security/auth/kerberos/KerberosPrincipal.java
trunk/core/src/openjdk/javax/javax/security/auth/kerberos/ServicePermission.java
trunk/core/src/openjdk/javax/javax/security/auth/kerberos/package.html
trunk/core/src/openjdk/javax/javax/security/auth/login/AccountException.java
trunk/core/src/openjdk/javax/javax/security/auth/login/AccountExpiredException.java
trunk/core/src/openjdk/javax/javax/security/auth/login/AccountLockedException.java
trunk/core/src/openjdk/javax/javax/security/auth/login/AccountNotFoundException.java
trunk/core/src/openjdk/javax/javax/security/auth/login/AppConfigurationEntry.java
trunk/core/src/openjdk/javax/javax/security/auth/login/CredentialException.java
trunk/core/src/openjdk/javax/javax/security/auth/login/CredentialExpiredException.java
trunk/core/src/openjdk/javax/javax/security/auth/login/CredentialNotFoundException.java
trunk/core/src/openjdk/javax/javax/security/auth/login/FailedLoginException.java
trunk/core/src/openjdk/javax/javax/security/auth/login/LoginException.java
trunk/core/src/openjdk/javax/javax/security/auth/login/package.html
trunk/core/src/openjdk/javax/javax/security/auth/package.html
trunk/core/src/openjdk/javax/javax/security/auth/spi/
trunk/core/src/openjdk/javax/javax/security/auth/spi/LoginModule.java
trunk/core/src/openjdk/javax/javax/security/auth/spi/package.html
trunk/core/src/openjdk/javax/javax/security/auth/x500/
trunk/core/src/openjdk/javax/javax/security/auth/x500/X500Principal.java
trunk/core/src/openjdk/javax/javax/security/auth/x500/X500PrivateCredential.java
trunk/core/src/openjdk/javax/javax/security/auth/x500/package.html
Removed Paths:
-------------
trunk/core/src/classpath/javax/javax/security/auth/
Added: trunk/core/src/openjdk/javax/javax/security/auth/AuthPermission.java
===================================================================
--- trunk/core/src/openjdk/javax/javax/security/auth/AuthPermission.java (rev 0)
+++ trunk/core/src/openjdk/javax/javax/security/auth/AuthPermission.java 2007-11-18 16:23:27 UTC (rev 3598)
@@ -0,0 +1,173 @@
+/*
+ * Copyright 1998-2005 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package javax.security.auth;
+
+/**
+ * This class is for authentication permissions.
+ * An AuthPermission contains a name
+ * (also referred to as a "target name")
+ * but no actions list; you either have the named permission
+ * or you don't.
+ *
+ * <p> The target name is the name of a security configuration parameter
+ * (see below). Currently the AuthPermission object is used to
+ * guard access to the Policy, Subject, LoginContext,
+ * and Configuration objects.
+ *
+ * <p> The possible target names for an Authentication Permission are:
+ *
+ * <pre>
+ * doAs - allow the caller to invoke the
+ * <code>Subject.doAs</code> methods.
+ *
+ * doAsPrivileged - allow the caller to invoke the
+ * <code>Subject.doAsPrivileged</code> methods.
+ *
+ * getSubject - allow for the retrieval of the
+ * Subject(s) associated with the
+ * current Thread.
+ *
+ * getSubjectFromDomainCombiner - allow for the retrieval of the
+ * Subject associated with the
+ * a <code>SubjectDomainCombiner</code>.
+ *
+ * setReadOnly - allow the caller to set a Subject
+ * to be read-only.
+ *
+ * modifyPrincipals - allow the caller to modify the <code>Set</code>
+ * of Principals associated with a
+ * <code>Subject</code>
+ *
+ * modifyPublicCredentials - allow the caller to modify the
+ * <code>Set</code> of public credentials
+ * associated with a <code>Subject</code>
+ *
+ * modifyPrivateCredentials - allow the caller to modify the
+ * <code>Set</code> of private credentials
+ * associated with a <code>Subject</code>
+ *
+ * refreshCredential - allow code to invoke the <code>refresh</code>
+ * method on a credential which implements
+ * the <code>Refreshable</code> interface.
+ *
+ * destroyCredential - allow code to invoke the <code>destroy</code>
+ * method on a credential <code>object</code>
+ * which implements the <code>Destroyable</code>
+ * interface.
+ *
+ * createLoginContext.{name} - allow code to instantiate a
+ * <code>LoginContext</code> with the
+ * specified <i>name</i>. <i>name</i>
+ * is used as the index into the installed login
+ * <code>Configuration</code>
+ * (that returned by
+ * <code>Configuration.getConfiguration()</code>).
+ * <i>name</i> can be wildcarded (set to '*')
+ * to allow for any name.
+ *
+ * getLoginConfiguration - allow for the retrieval of the system-wide
+ * login Configuration.
+ *
+ * createLoginConfiguration.{type} - allow code to obtain a Configuration
+ * object via
+ * <code>Configuration.getInstance</code>.
+ *
+ * setLoginConfiguration - allow for the setting of the system-wide
+ * login Configuration.
+ *
+ * refreshLoginConfiguration - allow for the refreshing of the system-wide
+ * login Configuration.
+ * </pre>
+ *
+ * <p> The following target name has been deprecated in favor of
+ * <code>createLoginContext.{name}</code>.
+ *
+ * <pre>
+ * createLoginContext - allow code to instantiate a
+ * <code>LoginContext</code>.
+ * </pre>
+ *
+ * <p> <code>javax.security.auth.Policy</code> has been
+ * deprecated in favor of <code>java.security.Policy</code>.
+ * Therefore, the following target names have also been deprecated:
+ *
+ * <pre>
+ * getPolicy - allow the caller to retrieve the system-wide
+ * Subject-based access control policy.
+ *
+ * setPolicy - allow the caller to set the system-wide
+ * Subject-based access control policy.
+ *
+ * refreshPolicy - allow the caller to refresh the system-wide
+ * Subject-based access control policy.
+ * </pre>
+ *
+ * @version 1.61, 05/05/07
+ */
+public final class AuthPermission extends
+java.security.BasicPermission {
+
+ private static final long serialVersionUID = 5806031445061587174L;
+
+ /**
+ * Creates a new AuthPermission with the specified name.
+ * The name is the symbolic name of the AuthPermission.
+ *
+ * <p>
+ *
+ * @param name the name of the AuthPermission
+ *
+ * @throws NullPointerException if <code>name</code> is <code>null</code>.
+ * @throws IllegalArgumentException if <code>name</code> is empty.
+ */
+ public AuthPermission(String name) {
+ // for backwards compatibility --
+ // createLoginContext is deprecated in favor of createLoginContext.*
+ super("createLoginContext".equals(name) ?
+ "createLoginContext.*" : name);
+ }
+
+ /**
+ * Creates a new AuthPermission object with the specified name.
+ * The name is the symbolic name of the AuthPermission, and the
+ * actions String is currently unused and should be null.
+ *
+ * <p>
+ *
+ * @param name the name of the AuthPermission <p>
+ *
+ * @param actions should be null.
+ *
+ * @throws NullPointerException if <code>name</code> is <code>null</code>.
+ * @throws IllegalArgumentException if <code>name</code> is empty.
+ */
+ public AuthPermission(String name, String actions) {
+ // for backwards compatibility --
+ // createLoginContext is deprecated in favor of createLoginContext.*
+ super("createLoginContext".equals(name) ?
+ "createLoginContext.*" : name, actions);
+ }
+}
Added: trunk/core/src/openjdk/javax/javax/security/auth/DestroyFailedException.java
===================================================================
--- trunk/core/src/openjdk/javax/javax/security/auth/DestroyFailedException.java (rev 0)
+++ trunk/core/src/openjdk/javax/javax/security/auth/DestroyFailedException.java 2007-11-18 16:23:27 UTC (rev 3598)
@@ -0,0 +1,61 @@
+/*
+ * Copyright 1999-2003 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package javax.security.auth;
+
+/**
+ * Signals that a <code>destroy</code> operation failed.
+ *
+ * <p> This exception is thrown by credentials implementing
+ * the <code>Destroyable</code> interface when the <code>destroy</code>
+ * method fails.
+ *
+ * @version 1.15, 05/05/07
+ */
+public class DestroyFailedException extends Exception {
+
+ private static final long serialVersionUID = -7790152857282749162L;
+
+ /**
+ * Constructs a DestroyFailedException with no detail message. A detail
+ * message is a String that describes this particular exception.
+ */
+ public DestroyFailedException() {
+ super();
+ }
+
+ /**
+ * Constructs a DestroyFailedException with the specified detail
+ * message. A detail message is a String that describes this particular
+ * exception.
+ *
+ * <p>
+ *
+ * @param msg the detail message.
+ */
+ public DestroyFailedException(String msg) {
+ super(msg);
+ }
+}
Added: trunk/core/src/openjdk/javax/javax/security/auth/Destroyable.java
===================================================================
--- trunk/core/src/openjdk/javax/javax/security/auth/Destroyable.java (rev 0)
+++ trunk/core/src/openjdk/javax/javax/security/auth/Destroyable.java 2007-11-18 16:23:27 UTC (rev 3598)
@@ -0,0 +1,63 @@
+/*
+ * Copyright 1999 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package javax.security.auth;
+
+/**
+ * Objects such as credentials may optionally implement this interface
+ * to provide the capability to destroy its contents.
+ *
+ * @version 1.18, 05/05/07
+ * @see javax.security.auth.Subject
+ */
+public interface Destroyable {
+
+ /**
+ * Destroy this <code>Object</code>.
+ *
+ * <p> Sensitive information associated with this <code>Object</code>
+ * is destroyed or cleared. Subsequent calls to certain methods
+ * on this <code>Object</code> will result in an
+ * <code>IllegalStateException</code> being thrown.
+ *
+ * <p>
+ *
+ * @exception DestroyFailedException if the destroy operation fails. <p>
+ *
+ * @exception SecurityException if the caller does not have permission
+ * to destroy this <code>Object</code>.
+ */
+ void destroy() throws DestroyFailedException;
+
+ /**
+ * Determine if this <code>Object</code> has been destroyed.
+ *
+ * <p>
+ *
+ * @return true if this <code>Object</code> has been destroyed,
+ * false otherwise.
+ */
+ boolean isDestroyed();
+}
Added: trunk/core/src/openjdk/javax/javax/security/auth/Policy.java
===================================================================
--- trunk/core/src/openjdk/javax/javax/security/auth/Policy.java (rev 0)
+++ trunk/core/src/openjdk/javax/javax/security/auth/Policy.java 2007-11-18 16:23:27 UTC (rev 3598)
@@ -0,0 +1,313 @@
+/*
+ * Copyright 1998-2006 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package javax.security.auth;
+
+/**
+ * <p> This is an abstract class for representing the system policy for
+ * Subject-based authorization. A subclass implementation
+ * of this class provides a means to specify a Subject-based
+ * access control <code>Policy</code>.
+ *
+ * <p> A <code>Policy</code> object can be queried for the set of
+ * Permissions granted to code running as a
+ * <code>Principal</code> in the following manner:
+ *
+ * <pre>
+ * policy = Policy.getPolicy();
+ * PermissionCollection perms = policy.getPermissions(subject,
+ * codeSource);
+ * </pre>
+ *
+ * The <code>Policy</code> object consults the local policy and returns
+ * and appropriate <code>Permissions</code> object with the
+ * Permissions granted to the Principals associated with the
+ * provided <i>subject</i>, and granted to the code specified
+ * by the provided <i>codeSource</i>.
+ *
+ * <p> A <code>Policy</code> contains the following information.
+ * Note that this example only represents the syntax for the default
+ * <code>Policy</code> implementation. Subclass implementations of this class
+ * may implement alternative syntaxes and may retrieve the
+ * <code>Policy</code> from any source such as files, databases,
+ * or servers.
+ *
+ * <p> Each entry in the <code>Policy</code> is represented as
+ * a <b><i>grant</i></b> entry. Each <b><i>grant</i></b> entry
+ * specifies a codebase, code signers, and Principals triplet,
+ * as well as the Permissions granted to that triplet.
+ *
+ * <pre>
+ * grant CodeBase ["URL"], Signedby ["signers"],
+ * Principal [Principal_Class] "Principal_Name" {
+ * Permission Permission_Class ["Target_Name"]
+ * [, "Permission_Actions"]
+ * [, signedBy "SignerName"];
+ * };
+ * </pre>
+ *
+ * The CodeBase and Signedby components of the triplet name/value pairs
+ * are optional. If they are not present, then any any codebase will match,
+ * and any signer (including unsigned code) will match.
+ * For Example,
+ *
+ * <pre>
+ * grant CodeBase "foo.com", Signedby "foo",
+ * Principal com.sun.security.auth.SolarisPrincipal "duke" {
+ * permission java.io.FilePermission "/home/duke", "read, write";
+ * };
+ * </pre>
+ *
+ * This <b><i>grant</i></b> entry specifies that code from "foo.com",
+ * signed by "foo', and running as a <code>SolarisPrincipal</code> with the
+ * name, duke, has one <code>Permission</code>. This <code>Permission</code>
+ * permits the executing code to read and write files in the directory,
+ * "/home/duke".
+ *
+ * <p> To "run" as a particular <code>Principal</code>,
+ * code invokes the <code>Subject.doAs(subject, ...)</code> method.
+ * After invoking that method, the code runs as all the Principals
+ * associated with the specified <code>Subject</code>.
+ * Note that this <code>Policy</code> (and the Permissions
+ * granted in this <code>Policy</code>) only become effective
+ * after the call to <code>Subject.doAs</code> has occurred.
+ *
+ * <p> Multiple Principals may be listed within one <b><i>grant</i></b> entry.
+ * All the Principals in the grant entry must be associated with
+ * the <code>Subject</code> provided to <code>Subject.doAs</code>
+ * for that <code>Subject</code> to be granted the specified Permissions.
+ *
+ * <pre>
+ * grant Principal com.sun.security.auth.SolarisPrincipal "duke",
+ * Principal com.sun.security.auth.SolarisNumericUserPrincipal "0" {
+ * permission java.io.FilePermission "/home/duke", "read, write";
+ * permission java.net.SocketPermission "duke.com", "connect";
+ * };
+ * </pre>
+ *
+ * This entry grants any code running as both "duke" and "0"
+ * permission to read and write files in duke's home directory,
+ * as well as permission to make socket connections to "duke.com".
+ *
+ * <p> Note that non Principal-based grant entries are not permitted
+ * in this <code>Policy</code>. Therefore, grant entries such as:
+ *
+ * <pre>
+ * grant CodeBase "foo.com", Signedby "foo" {
+ * permission java.io.FilePermission "/tmp/scratch", "read, write";
+ * };
+ * </pre>
+ *
+ * are rejected. Such permission must be listed in the
+ * <code>java.security.Policy</code>.
+ *
+ * <p> The default <code>Policy</code> implementation can be changed by
+ * setting the value of the "auth.policy.provider" security property
+ * (in the Java security properties file) to the fully qualified name of
+ * the desired <code>Policy</code> implementation class.
+ * The Java security properties file is located in the file named
+ * <JAVA_HOME>/lib/security/java.security.
+ * <JAVA_HOME> refers to the value of the java.home system property,
+ * and specifies the directory where the JRE is installed.
+ *
+ * @deprecated as of JDK version 1.4 -- Replaced by java.security.Policy.
+ * java.security.Policy has a method:
+ * <pre>
+ * public PermissionCollection getPermissions
+ * (java.security.ProtectionDomain pd)
+ *
+ * </pre>
+ * and ProtectionDomain has a constructor:
+ * <pre>
+ * public ProtectionDomain
+ * (CodeSource cs,
+ * PermissionCollection permissions,
+ * ClassLoader loader,
+ * Principal[] principals)
+ * </pre>
+ *
+ * These two APIs provide callers the means to query the
+ * Policy for Principal-based Permission entries.
+ *
+ *
+ * @version 1.59, 05/05/07
+ */
+@Deprecated
+public abstract class Policy {
+
+ private static Policy policy;
+ private static ClassLoader contextClassLoader;
+
+ static {
+ contextClassLoader = java.security.AccessController.doPrivileged
+ (new java.security.PrivilegedAction<ClassLoader>() {
+ public ClassLoader run() {
+ return Thread.currentThread().getContextClassLoader();
+ }
+ });
+ };
+
+ /**
+ * Sole constructor. (For invocation by subclass constructors, typically
+ * implicit.)
+ */
+ protected Policy() { }
+
+ /**
+ * Returns the installed Policy object.
+ * This method first calls
+ * <code>SecurityManager.checkPermission</code> with the
+ * <code>AuthPermission("getPolicy")</code> permission
+ * to ensure the caller has permission to get the Policy object.
+ *
+ * <p>
+ *
+ * @return the installed Policy. The return value cannot be
+ * <code>null</code>.
+ *
+ * @exception java.lang.SecurityException if the current thread does not
+ * have permission to get the Policy object.
+ *
+ * @see #setPolicy
+ */
+ public static Policy getPolicy() {
+ java.lang.SecurityManager sm = System.getSecurityManager();
+ if (sm != null) sm.checkPermission(new AuthPermission("getPolicy"));
+ return getPolicyNoCheck();
+ }
+
+ /**
+ * Returns the installed Policy object, skipping the security check.
+ *
+ * @return the installed Policy.
+ *
+ */
+ static Policy getPolicyNoCheck() {
+ if (policy == null) {
+
+ synchronized(Policy.class) {
+
+ if (policy == null) {
+ String policy_class = null;
+ policy_class = java.security.AccessController.doPrivileged
+ (new java.security.PrivilegedAction<String>() {
+ public String run() {
+ return java.security.Security.getProperty
+ ("auth.policy.provider");
+ }
+ });
+ if (policy_class == null) {
+ policy_class = "com.sun.security.auth.PolicyFile";
+ }
+
+ try {
+ final String finalClass = policy_class;
+ policy = java.security.AccessController.doPrivileged
+ (new java.security.PrivilegedExceptionAction<Policy>() {
+ public Policy run() throws ClassNotFoundException,
+ InstantiationException,
+ IllegalAccessException {
+ return (Policy) Class.forName
+ (finalClass,
+ true,
+ contextClassLoader).newInstance();
+ }
+ });
+ } catch (Exception e) {
+ throw new SecurityException
+ (sun.security.util.ResourcesMgr.getString
+ ("unable to instantiate Subject-based policy"));
+ }
+ }
+ }
+ }
+ return policy;
+ }
+
+
+ /**
+ * Sets the system-wide Policy object. This method first calls
+ * <code>SecurityManager.checkPermission</code> with the
+ * <code>AuthPermission("setPolicy")</code>
+ * permission to ensure the caller has permission to set the Policy.
+ *
+ * <p>
+ *
+ * @param policy the new system Policy object.
+ *
+ * @exception java.lang.SecurityException if the current thread does not
+ * have permission to set the Policy.
+ *
+ * @see #getPolicy
+ */
+ public static void setPolicy(Policy policy) {
+ java.lang.SecurityManager sm = System.getSecurityManager();
+ if (sm != null) sm.checkPermission(new AuthPermission("setPolicy"));
+ Policy.policy = policy;
+ }
+
+ /**
+ * Retrieve the Permissions granted to the Principals associated with
+ * the specified <code>CodeSource</code>.
+ *
+ * <p>
+ *
+ * @param subject the <code>Subject</code>
+ * whose associated Principals,
+ * in conjunction with the provided
+ * <code>CodeSource</code>, determines the Permissions
+ * returned by this method. This parameter
+ * may be <code>null</code>. <p>
+ *
+ * @param cs the code specified by its <code>CodeSource</code>
+ * that determines, in conjunction with the provided
+ * <code>Subject</code>, the Permissions
+ * returned by this method. This parameter may be
+ * <code>null</code>.
+ *
+ * @return the Collection of Permissions granted to all the
+ * <code>Subject</code> and code specified in
+ * the provided <i>subject</i> and <i>cs</i>
+ * parameters.
+ */
+ public abstract java.security.PermissionCollection getPermissions
+ (Subject subject,
+ java.security.CodeSource cs);
+
+ /**
+ * Refresh and reload the Policy.
+ *
+ * <p>This method causes this object to refresh/reload its current
+ * Policy. This is implementation-dependent.
+ * For example, if the Policy object is stored in
+ * a file, calling <code>refresh</code> will cause the file to be re-read.
+ *
+ * <p>
+ *
+ * @exception SecurityException if the caller does not have permission
+ * to refresh the Policy.
+ */
+ public abstract void refresh();
+}
Added: trunk/core/src/openjdk/javax/javax/security/auth/PrivateCredentialPermission.java
===================================================================
--- trunk/core/src/openjdk/javax/javax/security/auth/PrivateCredentialPermission.java (rev 0)
+++ trunk/core/src/openjdk/javax/javax/security/auth/PrivateCredentialPermission.java 2007-11-18 16:23:27 UTC (rev 3598)
@@ -0,0 +1,566 @@
+/*
+ * Copyright 1999-2006 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package javax.security.auth;
+
+import java.util.*;
+import java.text.MessageFormat;
+import java.security.Permission;
+import java.security.PermissionCollection;
+import java.security.Principal;
+import sun.security.util.ResourcesMgr;
+
+/**
+ * This class is used to protect access to private Credentials
+ * belonging to a particular <code>Subject</code>. The <code>Subject</code>
+ * is represented by a Set of Principals.
+ *
+ * <p> The target name of this <code>Permission</code> specifies
+ * a Credential class name, and a Set of Principals.
+ * The only valid value for this Permission's actions is, "read".
+ * The target name must abide by the following syntax:
+ *
+ * <pre>
+ * CredentialClass {PrincipalClass "PrincipalName"}*
+ * </pre>
+ *
+ * For example, the following permission grants access to the
+ * com.sun.PrivateCredential owned by Subjects which have
+ * a com.sun.Principal with the name, "duke". Note that although
+ * this example, as well as all the examples below, do not contain
+ * Codebase, SignedBy, or Principal information in the grant statement
+ * (for simplicity reasons), actual policy configurations should
+ * specify that information when appropriate.
+ *
+ * <pre>
+ *
+ * grant {
+ * permission javax.security.auth.PrivateCredentialPermission
+ * "com.sun.PrivateCredential com.sun.Principal \"duke\"",
+ * "read";
+ * };
+ * </pre>
+ *
+ * If CredentialClass is "*", then access is granted to
+ * all private Credentials belonging to the specified
+ * <code>Subject</code>.
+ * If "PrincipalName" is "*", then access is granted to the
+ * specified Credential owned by any <code>Subject</code> that has the
+ * specified <code>Principal</code> (the actual PrincipalName doesn't matter).
+ * For example, the following grants access to the
+ * a.b.Credential owned by any <code>Subject</code> that has
+ * an a.b.Principal.
+ *
+ * <pre>
+ * grant {
+ * permission javax.security.auth.PrivateCredentialPermission
+ * "a.b.Credential a.b.Principal "*"",
+ * "read";
+ * };
+ * </pre>
+ *
+ * If both the PrincipalClass and "PrincipalName" are "*",
+ * then access is granted to the specified Credential owned by
+ * any <code>Subject</code>.
+ *
+ * <p> In addition, the PrincipalClass/PrincipalName pairing may be repeated:
+ *
+ * <pre>
+ * grant {
+ * permission javax.security.auth.PrivateCredentialPermission
+ * "a.b.Credential a.b.Principal "duke" c.d.Principal "dukette"",
+ * "read";
+ * };
+ * </pre>
+ *
+ * The above grants access to the private Credential, "a.b.Credential",
+ * belonging to a <code>Subject</code> with at least two associated Principals:
+ * "a.b.Principal" with the name, "duke", and "c.d.Principal", with the name,
+ * "dukette".
+ *
+ * @version 1.39, 05/05/07
+ */
+public final class PrivateCredentialPermission extends Permission {
+
+ private static final long serialVersionUID = 5284372143517237068L;
+
+ private static final CredOwner[] EMPTY_PRINCIPALS = new CredOwner[0];
+
+ /**
+ * @serial
+ */
+ private String credentialClass;
+
+ /**
+ * @serial The Principals associated with this permission.
+ * The set contains elements of type,
+ * <code>PrivateCredentialPermission.CredOwner</code>.
+ */
+ private Set principals; // ignored - kept around for compatibility
+ private transient CredOwner[] credOwners;
+
+ /**
+ * @serial
+ */
+ private boolean testing = false;
+
+ /**
+ * Create a new <code>PrivateCredentialPermission</code>
+ * with the specified <code>credentialClass</code> and Principals.
+ */
+ PrivateCredentialPermission(String credentialClass,
+ Set<Principal> principals) {
+
+ super(credentialClass);
+ this.credentialClass = credentialClass;
+
+ synchronized(principals) {
+ if (principals.size() == 0) {
+ this.credOwners = EMPTY_PRINCIPALS;
+ } else {
+ this.credOwners = new CredOwner[principals.size()];
+ int index = 0;
+ Iterator<Principal> i = principals.iterator();
+ while (i.hasNext()) {
+ Principal p = i.next();
+ this.credOwners[index++] = new CredOwner
+ (p.getClass().getName(),
+ p.getName());
+ }
+ }
+ }
+ }
+
+ /**
+ * Creates a new <code>PrivateCredentialPermission</code>
+ * with the specified <code>name</code>. The <code>name</code>
+ * specifies both a Credential class and a <code>Principal</code> Set.
+ *
+ * <p>
+ *
+ * @param name the name specifying the Credential class and
+ * <code>Principal</code> Set. <p>
+ *
+ * @param actions the actions specifying that the Credential can be read.
+ *
+ * @throws IllegalArgumentException if <code>name</code> does not conform
+ * to the correct syntax or if <code>actions</code> 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);
+ }
+
+ /**
+ * Returns the Class name of the Credential associated with this
+ * <code>PrivateCredentialPermission</code>.
+ *
+ * <p>
+ *
+ * @return the Class name of the Credential associated with this
+ * <code>PrivateCredentialPermission</code>.
+ */
+ public String getCredentialClass() {
+ return credentialClass;
+ }
+
+ /**
+ * Returns the <code>Principal</code> classes and names
+ * associated with this <code>PrivateCredentialPermission</code>.
+ * The information is returned as a two-dimensional array (array[x][y]).
+ * The 'x' value corresponds to the number of <code>Principal</code>
+ * class and name pairs. When (y==0), it corresponds to
+ * the <code>Principal</code> class value, and when (y==1),
+ * it corresponds to the <code>Principal</code> name value.
+ * For example, array[0][0] corresponds to the class name of
+ * the first <code>Principal</code> in the array. array[0][1]
+ * corresponds to the <code>Principal</code> name of the
+ * first <code>Principal</code> in the array.
+ *
+ * <p>
+ *
+ * @return the <code>Principal</code> class and names associated
+ * with this <code>PrivateCredentialPermission</code>.
+ */
+ public String[][] getPrincipals() {
+
+ if (credOwners == null || credOwners.length == 0) {
+ return new String[0][0];
+ }
+
+ String[][] pArray = new String[credOwners.length][2];
+ for (int i = 0; i < credOwners.length; i++) {
+ pArray[i][0] = credOwners[i].principalClass;
+ pArray[i][1] = credOwners[i].principalName;
+ }
+ return pArray;
+ }
+
+ /**
+ * Checks if this <code>PrivateCredentialPermission</code> implies
+ * the specified <code>Permission</code>.
+ *
+ * <p>
+ *
+ * This method returns true if:
+ * <p><ul>
+ * <li> <i>p</i> is an instanceof PrivateCredentialPermission and <p>
+ * <li> the target name for <i>p</i> is implied by this object's
+ * target name. For example:
+ * <pre>
+ * [* P1 "duke"] implies [a.b.Credential P1 "duke"].
+ * [C1 P1 "duke"] implies [C1 P1 "duke" P2 "dukette"].
+ * [C1 P2 "dukette"] implies [C1 P1 "duke" P2 "dukette"].
+ * </pre>
+ * </ul>
+ *
+ * <p>
+ *
+ * @param p the <code>Permission</code> to check against.
+ *
+ * @return true if this <code>PrivateCredentialPermission</code> implies
+ * the specified <code>Permission</code>, false if not.
+ */
+ public boolean implies(Permission p) {
+
+ if (p == null || !(p instanceof PrivateCredentialPermission))
+ return false;
+
+ PrivateCredentialPermission that = (PrivateCredentialPermission)p;
+
+ if (!impliesCredentialClass(credentialClass, that.credentialClass))
+ return false;
+
+ return impliesPrincipalSet(credOwners, that.credOwners);
+ }
+
+ /**
+ * Checks two <code>PrivateCredentialPermission</code> objects for
+ * equality. Checks that <i>obj</i> is a
+ * <code>PrivateCredentialPermission</code>,
+ * and has the same credential class as this object,
+ * as well as the same Principals as this object.
+ * The order of the Principals in the respective Permission's
+ * target names is not relevant.
+ *
+ * <p>
+ *
+ * @param obj the object we are testing for equality with this object.
+ *
+ * @return true if obj is a <code>PrivateCredentialPermission</code>,
+ * has the same credential class as this object,
+ * and has the same Principals as this object.
+ */
+ public boolean equals(Object obj) {
+ if (obj == this)
+ return true;
+
+ if (! (obj instanceof PrivateCredentialPermission))
+ return false;
+
+ PrivateCredentialPermission that = (PrivateCredentialPermission)obj;
+
+ return (this.implies(that) && that.implies(this));
+ }
+
+ /**
+ * Returns the hash code value for this object.
+ *
+ * @return a hash code value for this object.
+ */
+ public int hashCode() {
+ return this.credentialClass.hashCode();
+ }
+
+ /**
+ * Returns the "canonical string representation" of the actions.
+ * This method always returns the String, "read".
+ *
+ * <p>
+ *
+ * @return the actions (always returns "read").
+ */
+ public String getActions() {
+ return "read";
+ }
+
+ /**
+ * Return a homogeneous collection of PrivateCredentialPermissions
+ * in a <code>PermissionCollection</code>.
+ * No such <code>PermissionCollection</code> is defined,
+ * so this method always returns <code>null</code>.
+ *
+ * <p>
+ *
+ * @return null in all cases.
+ */
+ public PermissionCollection newPermissionCollection() {
+ return null;
+ }
+
+ private void init(String name) {
+
+ if (name == null || name.trim().length() == 0) {
+ throw new IllegalArgumentException("invalid empty name");
+ }
+
+ ArrayList<CredOwner> pList = new ArrayList<CredOwner>();
+ StringTokenizer tokenizer = new StringTokenizer(name, " ", true);
+ String principalClass = null;
+ String principalName = null;
+
+ if (testing)
+ System.out.println("whole name = " + name);
+
+ // get the Credential Class
+ credentialClass = tokenizer.nextToken();
+ if (testing)
+ System.out.println("Credential Class = " + credentialClass);
+
+ if (tokenizer.hasMoreTokens() == false) {
+ MessageFormat form = new MessageFormat(ResourcesMgr.getString
+ ("permission name [name] syntax invalid: "));
+ Object[] source = {name};
+ throw new IllegalArgumentException
+ (form.format(source) + ResourcesMgr.getString
+ ("Credential Class not followed by a " +
+ "Principal Class and Name"));
+ }
+
+ while (tokenizer.hasMoreTokens()) {
+
+ // skip delimiter
+ tokenizer.nextToken();
+
+ // get the Principal Class
+ principalClass = tokenizer.nextToken();
+ if (testing)
+ System.out.println(" Principal Class = " + principalClass);
+
+ if (tokenizer.hasMoreTokens() == false) {
+ MessageFormat form = new MessageFormat(ResourcesMgr.getString
+ ("permission name [name] syntax invalid: "));
+ Object[] source = {name};
+ throw new IllegalArgumentException
+ (form.format(source) + ResourcesMgr.getString
+ ("Principal Class not followed by a Principal Name"));
+ }
+
+ // skip delimiter
+ tokenizer.nextToken();
+
+ // get the Principal Name
+ principalName = tokenizer.nextToken();
+
+ if (!principalName.startsWith("\"")) {
+ MessageFormat form = new MessageFormat(ResourcesMgr.getString
+ ("permission name [name] syntax invalid: "));
+ Object[] source = {name};
+ throw new IllegalArgumentException
+ (form.format(source) + ResourcesMgr.getString
+ ("Principal Name must be surrounded by quotes"));
+ }
+
+ if (!principalName.endsWith("\"")) {
+
+ // we have a name with spaces in it --
+ // keep parsing until we find the end quote,
+ // and keep the spaces in the name
+
+ while (tokenizer.hasMoreTokens()) {
+ principalName = principalName + tokenizer.nextToken();
+ if (principalName.endsWith("\""))
+ break;
+ }
+
+ if (!principalName.endsWith("\"")) {
+ MessageFormat form = new MessageFormat
+ (ResourcesMgr.getString
+ ("permission name [name] syntax invalid: "));
+ Object[] source = {name};
+ throw new IllegalArgumentException
+ (form.format(source) + ResourcesMgr.getString
+ ("Principal Name missing end quote"));
+ }
+ }
+
+ if (testing)
+ System.out.println("\tprincipalName = '" + principalName + "'");
+
+ principalName = principalName.substring
+ (1, principalName.length() - 1);
+
+ if (principalClass.equals("*") &&
+ !principalName.equals("*")) {
+ throw new IllegalArgumentException(ResourcesMgr.getString
+ ("PrivateCredentialPermission Principal Class " +
+ "can not be a wildcard (*) value if Principal Name " +
+ "is not a wildcard (*) value"));
+ }
+
+ if (testing)
+ System.out.println("\tprincipalName = '" + principalName + "'");
+
+ pList.add(new CredOwner(principalClass, principalName));
+ }
+
+ this.credOwners = new CredOwner[pList.size()];
+ pList.toArray((CredOwner[])this.credOwners);
+ }
+
+ private boolean impliesCredentialClass(String thisC, String thatC) {
+
+ // this should never happen
+ if (thisC == null || thatC == null)
+ return false;
+
+ if (testing)
+ System.out.println("credential class comparison: " +
+ thisC + "/" + thatC);
+
+ if (thisC.equals("*"))
+ return true;
+
+ /**
+ * XXX let's not enable this for now --
+ * if people want it, we'll enable it later
+ */
+ /*
+ if (thisC.endsWith("*")) {
+ String cClass = thisC.substring(0, thisC.length() - 2);
+ return thatC.startsWith(cClass);
+ }
+ */
+
+ return thisC.equals(thatC);
+ }
+
+ private boolean impliesPrincipalSet(CredOwner[] thisP, CredOwner[] thatP) {
+
+ // this should never happen
+ if (thisP == null || thatP == null)
+ return false;
+
+ if (thatP.length == 0)
+ return true;
+
+ if (thisP.length == 0)
+ return false;
+
+ for (int i = 0; i < thisP.length; i++) {
+ boolean foundMatch = false;
+ for (int j = 0; j < thatP.length; j++) {
+ if (thisP[i].implies(thatP[j])) {
+ foundMatch = true;
+ break;
+ }
+ }
+ if (!foundMatch) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /**
+ * Reads this object from a stream (i.e., deserializes it)
+ */
+ private void readObject(java.io.ObjectInputStream s) throws
+ java.io.IOException,
+ ClassNotFoundException {
+
+ s.defaultReadObject();
+
+ // perform new initialization from the permission name
+
+ if (getName().indexOf(" ") == -1 && getName().indexOf("\"") == -1) {
+
+ // name only has a credential class specified
+ credentialClass = getName();
+ credOwners = EMPTY_PRINCIPALS;
+
+ } else {
+
+ // perform regular initialization
+ init(getName());
+ }
+ }
+
+ /**
+ * @serial include
+ */
+ static class CredOwner implements java.io.Serializable {
+
+ private static final long serialVersionUID = -5607449830436408266L;
+
+ /**
+ * @serial
+ */
+ String principalClass;
+ /**
+ * @serial
+ */
+ String principalName;
+
+ CredOwner(String principalClass, String principalName) {
+ this.principalClass = principalClass;
+ this.principalName = principalName;
+ }
+
+ public boolean implies(Object obj) {
+ if (obj == null || !(obj instanceof CredOwner))
+ return false;
+
+ CredOwner that = (CredOwner)obj;
+
+ if (principalClass.equals("*") ||
+ principalClass.equals(that.principalClass)) {
+
+ if (principalName.equals("*") ||
+ principalName.equals(that.principalName)) {
+ return true;
+ }
+ }
+
+ /**
+ * XXX no code yet to support a.b.*
+ */
+
+ return false;
+ }
+
+ public String toString() {
+ MessageFormat form = new MessageFormat(ResourcesMgr.getString
+ ("CredOwner:\n\tPrincipal Class = class\n\t" +
+ "Principal Name = name"));
+ Object[] source = {principalClass, principalName};
+ return (form.format(source));
+ }
+ }
+}
Added: trunk/core/src/openjdk/javax/javax/security/auth/RefreshFailedException.java
===================================================================
--- trunk/core/src/openjdk/javax/javax/security/auth/RefreshFailedException.java (rev 0)
+++ trunk/core/src/openjdk/javax/javax/security/auth/RefreshFailedException.java 2007-11-18 16:23:27 UTC (rev 3598)
@@ -0,0 +1,61 @@
+/*
+ * Copyright 1999-2003 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package javax.security.auth;
+
+/**
+ * Signals that a <code>refresh</code> operation failed.
+ *
+ * <p> This exception is thrown by credentials implementing
+ * the <code>Refreshable</code> interface when the <code>refresh</code>
+ * method fails.
+ *
+ * @version 1.15, 05/05/07
+ */
+public class RefreshFailedException extends Exception {
+
+ private static final long serialVersionUID = 5058444488565265840L;
+
+ /**
+ * Constructs a RefreshFailedException with no detail message. A detail
+ * message is a String that describes this particular exception.
+ */
+ public RefreshFailedException() {
+ super();
+ }
+
+ /**
+ * Constructs a RefreshFailedException with the specified detail
+ * message. A detail message is a String that describes this particular
+ * exception.
+ *
+ * <p>
+ *
+ * @param msg the detail message.
+ */
+ public RefreshFailedException(String msg) {
+ super(msg);
+ }
+}
Added: trunk/core/src/openjdk/javax/javax/security/auth/Refreshable.java
===================================================================
--- trunk/core/src/openjdk/javax/javax/security/auth/Refreshable.java (rev 0)
+++ trunk/core/src/openjdk/javax/javax/security/auth/Refreshable.java 2007-11-18 16:23:27 UTC (rev 3598)
@@ -0,0 +1,63 @@
+/*
+ * Copyright 1999 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package javax.security.auth;
+
+/**
+ * Objects such as credentials may optionally implement this
+ * interface to provide the capability to refresh itself.
+ * For example, a credential with a particular time-restricted lifespan
+ * may implement this interface to allow callers to refresh the time period
+ * for which it is valid.
+ *
+ * @version 1.16, 05/05/07
+ * @see javax.security.auth.Subject
+ */
+public interface Refreshable {
+
+ /**
+ * Determine if this <code>Object</code> is current.
+ *
+ * <p>
+ *
+ * @return true if this <code>Object</code> is currently current,
+ * false otherwise.
+ */
+ boolean isCurrent();
+
+ /**
+ * Update or extend the validity period for this
+ * <code>Object</code>.
+ *
+ * <p>
+ *
+ * @exception SecurityException if the caller does not have permission
+ * to update or extend the validity period for this
+ * <code>Object</code>. <p>
+ *
+ * @exception RefreshFailedException if the refresh attempt failed.
+ */
+ void refresh() throws RefreshFailedException;
+}
Added: trunk/core/src/openjdk/javax/javax/security/auth/Subject.java
===================================================================
--- trunk/core/src/openjdk/javax/javax/security/auth/Subject.java (rev 0)
+++ trunk/core/src/openjdk/javax/javax/security/auth/Subject.java 2007-11-18 16:23:27 UTC (rev 3598)
@@ -0,0 +1,1406 @@
+/*
+ * Copyright 1998-2006 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package javax.security.auth;
+
+import java.util.*;
+import java.io.*;
+import java.lang.reflect.*;
+import java.text.MessageFormat;
+import java.security.AccessController;
+import java.security.AccessControlContext;
+import java.security.DomainCombiner;
+import java.security.Permission;
+import java.security.PermissionCollection;
+import java.security.Principal;
+import java.security.PrivilegedAction;
+import java.security.PrivilegedExceptionAction;
+import java.security.PrivilegedActionException;
+import java.security.ProtectionDomain;
+import sun.security.util.ResourcesMgr;
+import sun.security.util.SecurityConstants;
+
+/**
+ * <p> A <code>Subject</code> represents a grouping of related information
+ * for a single entity, such as a person.
+ * Such information includes the Subject's identities as well as
+ * its security-related attributes
+ * (passwords and cryptographic keys, for example).
+ *
+ * <p> Subjects may potentially have multiple identities.
+ * Each identity is represented as a <code>Principal</code>
+ * within the <code>Subject</code>. Principals simply bind names to a
+ * <code>Subject</code>. For example, a <code>Subject</code> that happens
+ * to be a person, Alice, might have two Principals:
+ * one which binds "Alice Bar", the name on her driver license,
+ * to the <code>Subject</code>, and another which binds,
+ * "999-99-9999", the number on her student identification card,
+ * to the <code>Subject</code>. Both Principals refer to the same
+ * <code>Subject</code> even though each has a different name.
+ *
+ * <p> A <code>Subject</code> may also own security-related attributes,
+ * which are referred to as credentials.
+ * Sensitive credentials that require special protection, such as
+ * private cryptographic keys, are stored within a private credential
+ * <code>Set</code>. Credentials intended to be shared, such as
+ * public key certificates or Kerberos server tickets are stored
+ * within a public credential <code>Set</code>. Different permissions
+ * are required to access and modify the different credential Sets.
+ *
+ * <p> To retrieve all the Principals associated with a <code>Subject</code>,
+ * invoke the <code>getPrincipals</code> method. To retrieve
+ * all the public or private credentials belonging to a <code>Subject</code>,
+ * invoke the <code>getPublicCredentials</code> method or
+ * <code>getPrivateCredentials</code> method, respectively.
+ * To modify the returned <code>Set</code> of Principals and credentials,
+ * use the methods defined in the <code>Set</code> class.
+ * For example:
+ * <pre>
+ * Subject subject;
+ * Principal principal;
+ * Object credential;
+ *
+ * // add a Principal and credential to the Subject
+ * subject.getPrincipals().add(principal);
+ * subject.getPublicCredentials().add(credential);
+ * </pre>
+ *
+ * <p> This <code>Subject</code> class implements <code>Serializable</code>.
+ * While the Principals associated with the <code>Subject</code> are serialized,
+ * the credentials associated with the <code>Subject</code> are not.
+ * Note that the <code>java.security.Principal</code> class
+ * does not implement <code>Serializable</code>. Therefore all concrete
+ * <code>Principal</code> implementations associated with Subjects
+ * must implement <code>Serializable</code>.
+ *
+ * @version 1.134, 05/05/07
+ * @see java.security.Principal
+ * @see java.security.DomainCombiner
+ */
+public final class Subject implements java.io.Serializable {
+
+ private static final long serialVersionUID = -8308522755600156056L;
+
+ /**
+ * A <code>Set</code> that provides a view of all of this
+ * Subject's Principals
+ *
+ * <p>
+ *
+ * @serial Each element in this set is a
+ * <code>java.security.Principal</code>.
+ * The set is a <code>Subject.SecureSet</code>.
+ */
+ Set<Principal> principals;
+
+ /**
+ * Sets that provide a view of all of this
+ * Subject's Credentials
+ */
+ transient Set<Object> pubCredentials;
+ transient Set<Object> privCredentials;
+
+ /**
+ * Whether this Subject is read-only
+ *
+ * @serial
+ */
+ private volatile boolean readOnly = false;
+
+ private static final int PRINCIPAL_SET = 1;
+ private static final int PUB_CREDENTIAL_SET = 2;
+ private static final int PRIV_CREDENTIAL_SET = 3;
+
+ /**
+ * Create an instance of a <code>Subject</code>
+ * with an empty <code>Set</code> of Principals and empty
+ * Sets of public and private credentials.
+ *
+ * <p> The newly constructed Sets check whether this <code>Subject</code>
+ * has been set read-only before permitting subsequent modifications.
+ * The newly created Sets also prevent illegal modifications
+ * by ensuring that callers have sufficient permissions.
+ *
+ * <p> To modify the Principals Set, the caller must have
+ * <code>AuthPermission("modifyPrincipals")</code>.
+ * To modify the public credential Set, the caller must have
+ * <code>AuthPermission("modifyPublicCredentials")</code>.
+ * To modify the private credential Set, the caller must have
+ * <code>AuthPermission("modifyPrivateCredentials")</code>.
+ */
+ public Subject() {
+
+ this.principals = Collections.synchronizedSet
+ (new SecureSet<Principal>(this, PRINCIPAL_SET));
+ this.pubCredentials = Collections.synchronizedSet
+ (new SecureSet<Object>(this, PUB_CREDENTIAL_SET));
+ this.privCredentials = Collections.synchronizedSet
+ (new SecureSet<Object>(this, PRIV_CREDENTIAL_SET));
+ }
+
+ /**
+ * Create an instance of a <code>Subject</code> with
+ * Principals and credentials.
+ *
+ * <p> The Principals and credentials from the specified Sets
+ * are copied into newly constructed Sets.
+ * These newly created Sets check whether this <code>Subject</code>
+ * has been set read-only before permitting subsequent modifications.
+ * The newly created Sets also prevent illegal modifications
+ * by ensuring that callers have sufficient permissions.
+ *
+ * <p> To modify the Principals Set, the caller must have
+ * <code>AuthPermission("modifyPrincipals")</code>.
+ * To modify the public credential Set, the caller must have
+ * <code>AuthPermission("modifyPublicCredentials")</code>.
+ * To modify the private credential Set, the caller must have
+ * <code>AuthPermission("modifyPrivateCredentials")</code>.
+ * <p>
+ *
+ * @param readOnly true if the <code>Subject</code> is to be read-only,
+ * and false otherwise. <p>
+ *
+ * @param principals the <code>Set</code> of Principals
+ * to be associated with this <code>Subject</code>. <p>
+ *
+ * @param pubCredentials the <code>Set</code> of public credentials
+ * to be associated with this <code>Subject</code>. <p>
+ *
+ * @param privCredentials the <code>Set</code> of private credentials
+ * to be associated with this <code>Subject</code>.
+ *
+ * @exception NullPointerException if the specified
+ * <code>principals</code>, <code>pubCredentials</code>,
+ * or <code>privCredentials</code> are <code>null</code>.
+ */
+ public Subject(boolean readOnly, Set<? extends Principal> principals,
+ Set<?> pubCredentials, Set<?> privCredentials)
+ {
+
+ if (principals == null ||
+ pubCredentials == null ||
+ privCredentials == null)
+ throw new NullPointerException
+ (ResourcesMgr.getString("invalid null input(s)"));
+
+ this.principals = Collections.synchronizedSet(new SecureSet<Principal>
+ (this, PRINCIPAL_SET, principals));
+ this.pubCredentials = Collections.synchronizedSet(new SecureSet<Object>
+ (this, PUB_CREDENTIAL_SET, pubCredentials));
+ this.privCredentials = Collections.synchronizedSet(new SecureSet<Object>
+ (this, PRIV_CREDENTIAL_SET, privCredentials));
+ this.readOnly = readOnly;
+ }
+
+ /**
+ * Set this <code>Subject</code> to be read-only.
+ *
+ * <p> Modifications (additions and removals) to this Subject's
+ * <code>Principal</code> <code>Set</code> and
+ * credential Sets will be disallowed.
+ * The <code>destroy</code> operati...
[truncated message content] |