0N/A/*
3261N/A * Copyright (c) 1996, 2010, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage java.security;
0N/A
0N/Aimport java.io.Serializable;
0N/Aimport java.util.Enumeration;
0N/Aimport java.util.Properties;
0N/A
0N/A/**
0N/A * <p>This class represents a scope for identities. It is an Identity
0N/A * itself, and therefore has a name and can have a scope. It can also
0N/A * optionally have a public key and associated certificates.
0N/A *
0N/A * <p>An IdentityScope can contain Identity objects of all kinds, including
0N/A * Signers. All types of Identity objects can be retrieved, added, and
0N/A * removed using the same methods. Note that it is possible, and in fact
0N/A * expected, that different types of identity scopes will
0N/A * apply different policies for their various operations on the
0N/A * various types of Identities.
0N/A *
0N/A * <p>There is a one-to-one mapping between keys and identities, and
0N/A * there can only be one copy of one key per scope. For example, suppose
0N/A * <b>Acme Software, Inc</b> is a software publisher known to a user.
0N/A * Suppose it is an Identity, that is, it has a public key, and a set of
0N/A * associated certificates. It is named in the scope using the name
0N/A * "Acme Software". No other named Identity in the scope has the same
0N/A * public key. Of course, none has the same name as well.
0N/A *
0N/A * @see Identity
0N/A * @see Signer
0N/A * @see Principal
0N/A * @see Key
0N/A *
0N/A * @author Benjamin Renaud
0N/A *
0N/A * @deprecated This class is no longer used. Its functionality has been
0N/A * replaced by <code>java.security.KeyStore</code>, the
0N/A * <code>java.security.cert</code> package, and
0N/A * <code>java.security.Principal</code>.
0N/A */
0N/A@Deprecated
0N/Apublic abstract
0N/Aclass IdentityScope extends Identity {
0N/A
0N/A private static final long serialVersionUID = -2337346281189773310L;
0N/A
0N/A /* The system's scope */
0N/A private static IdentityScope scope;
0N/A
0N/A // initialize the system scope
0N/A private static void initializeSystemScope() {
0N/A
0N/A String classname = AccessController.doPrivileged(
0N/A new PrivilegedAction<String>() {
0N/A public String run() {
0N/A return Security.getProperty("system.scope");
0N/A }
0N/A });
0N/A
0N/A if (classname == null) {
0N/A return;
0N/A
0N/A } else {
0N/A
0N/A try {
0N/A Class.forName(classname);
0N/A } catch (ClassNotFoundException e) {
0N/A //Security.error("unable to establish a system scope from " +
0N/A // classname);
0N/A e.printStackTrace();
0N/A }
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * This constructor is used for serialization only and should not
0N/A * be used by subclasses.
0N/A */
0N/A protected IdentityScope() {
0N/A this("restoring...");
0N/A }
0N/A
0N/A /**
0N/A * Constructs a new identity scope with the specified name.
0N/A *
0N/A * @param name the scope name.
0N/A */
0N/A public IdentityScope(String name) {
0N/A super(name);
0N/A }
0N/A
0N/A /**
0N/A * Constructs a new identity scope with the specified name and scope.
0N/A *
0N/A * @param name the scope name.
0N/A * @param scope the scope for the new identity scope.
0N/A *
0N/A * @exception KeyManagementException if there is already an identity
0N/A * with the same name in the scope.
0N/A */
0N/A public IdentityScope(String name, IdentityScope scope)
0N/A throws KeyManagementException {
0N/A super(name, scope);
0N/A }
0N/A
0N/A /**
0N/A * Returns the system's identity scope.
0N/A *
2195N/A * @return the system's identity scope, or {@code null} if none has been
2195N/A * set.
0N/A *
0N/A * @see #setSystemScope
0N/A */
0N/A public static IdentityScope getSystemScope() {
0N/A if (scope == null) {
0N/A initializeSystemScope();
0N/A }
0N/A return scope;
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Sets the system's identity scope.
0N/A *
0N/A * <p>First, if there is a security manager, its
0N/A * <code>checkSecurityAccess</code>
0N/A * method is called with <code>"setSystemScope"</code>
0N/A * as its argument to see if it's ok to set the identity scope.
0N/A *
0N/A * @param scope the scope to set.
0N/A *
0N/A * @exception SecurityException if a security manager exists and its
0N/A * <code>checkSecurityAccess</code> method doesn't allow
0N/A * setting the identity scope.
0N/A *
0N/A * @see #getSystemScope
0N/A * @see SecurityManager#checkSecurityAccess
0N/A */
0N/A protected static void setSystemScope(IdentityScope scope) {
0N/A check("setSystemScope");
0N/A IdentityScope.scope = scope;
0N/A }
0N/A
0N/A /**
0N/A * Returns the number of identities within this identity scope.
0N/A *
0N/A * @return the number of identities within this identity scope.
0N/A */
0N/A public abstract int size();
0N/A
0N/A /**
0N/A * Returns the identity in this scope with the specified name (if any).
0N/A *
0N/A * @param name the name of the identity to be retrieved.
0N/A *
0N/A * @return the identity named <code>name</code>, or null if there are
0N/A * no identities named <code>name</code> in this scope.
0N/A */
0N/A public abstract Identity getIdentity(String name);
0N/A
0N/A /**
0N/A * Retrieves the identity whose name is the same as that of the
0N/A * specified principal. (Note: Identity implements Principal.)
0N/A *
0N/A * @param principal the principal corresponding to the identity
0N/A * to be retrieved.
0N/A *
0N/A * @return the identity whose name is the same as that of the
0N/A * principal, or null if there are no identities of the same name
0N/A * in this scope.
0N/A */
0N/A public Identity getIdentity(Principal principal) {
0N/A return getIdentity(principal.getName());
0N/A }
0N/A
0N/A /**
0N/A * Retrieves the identity with the specified public key.
0N/A *
0N/A * @param key the public key for the identity to be returned.
0N/A *
0N/A * @return the identity with the given key, or null if there are
0N/A * no identities in this scope with that key.
0N/A */
0N/A public abstract Identity getIdentity(PublicKey key);
0N/A
0N/A /**
0N/A * Adds an identity to this identity scope.
0N/A *
0N/A * @param identity the identity to be added.
0N/A *
0N/A * @exception KeyManagementException if the identity is not
0N/A * valid, a name conflict occurs, another identity has the same
0N/A * public key as the identity being added, or another exception
0N/A * occurs. */
0N/A public abstract void addIdentity(Identity identity)
0N/A throws KeyManagementException;
0N/A
0N/A /**
0N/A * Removes an identity from this identity scope.
0N/A *
0N/A * @param identity the identity to be removed.
0N/A *
0N/A * @exception KeyManagementException if the identity is missing,
0N/A * or another exception occurs.
0N/A */
0N/A public abstract void removeIdentity(Identity identity)
0N/A throws KeyManagementException;
0N/A
0N/A /**
0N/A * Returns an enumeration of all identities in this identity scope.
0N/A *
0N/A * @return an enumeration of all identities in this identity scope.
0N/A */
0N/A public abstract Enumeration<Identity> identities();
0N/A
0N/A /**
0N/A * Returns a string representation of this identity scope, including
0N/A * its name, its scope name, and the number of identities in this
0N/A * identity scope.
0N/A *
0N/A * @return a string representation of this identity scope.
0N/A */
0N/A public String toString() {
0N/A return super.toString() + "[" + size() + "]";
0N/A }
0N/A
0N/A private static void check(String directive) {
0N/A SecurityManager security = System.getSecurityManager();
0N/A if (security != null) {
0N/A security.checkSecurityAccess(directive);
0N/A }
0N/A }
0N/A
0N/A}