Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/java/security/IdentityScope.java
38829 views
/*1* Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package java.security;2627import java.io.Serializable;28import java.util.Enumeration;29import java.util.Properties;3031/**32* <p>This class represents a scope for identities. It is an Identity33* itself, and therefore has a name and can have a scope. It can also34* optionally have a public key and associated certificates.35*36* <p>An IdentityScope can contain Identity objects of all kinds, including37* Signers. All types of Identity objects can be retrieved, added, and38* removed using the same methods. Note that it is possible, and in fact39* expected, that different types of identity scopes will40* apply different policies for their various operations on the41* various types of Identities.42*43* <p>There is a one-to-one mapping between keys and identities, and44* there can only be one copy of one key per scope. For example, suppose45* <b>Acme Software, Inc</b> is a software publisher known to a user.46* Suppose it is an Identity, that is, it has a public key, and a set of47* associated certificates. It is named in the scope using the name48* "Acme Software". No other named Identity in the scope has the same49* public key. Of course, none has the same name as well.50*51* @see Identity52* @see Signer53* @see Principal54* @see Key55*56* @author Benjamin Renaud57*58* @deprecated This class is no longer used. Its functionality has been59* replaced by {@code java.security.KeyStore}, the60* {@code java.security.cert} package, and61* {@code java.security.Principal}.62*/63@Deprecated64public abstract65class IdentityScope extends Identity {6667private static final long serialVersionUID = -2337346281189773310L;6869/* The system's scope */70private static IdentityScope scope;7172// initialize the system scope73private static void initializeSystemScope() {7475String classname = AccessController.doPrivileged(76new PrivilegedAction<String>() {77public String run() {78return Security.getProperty("system.scope");79}80});8182if (classname == null) {83return;8485} else {8687try {88Class.forName(classname);89} catch (ClassNotFoundException e) {90System.err.println("unable to establish a system scope from " +91classname);92e.printStackTrace();93}94}95}9697/**98* This constructor is used for serialization only and should not99* be used by subclasses.100*/101protected IdentityScope() {102this("restoring...");103}104105/**106* Constructs a new identity scope with the specified name.107*108* @param name the scope name.109*/110public IdentityScope(String name) {111super(name);112}113114/**115* Constructs a new identity scope with the specified name and scope.116*117* @param name the scope name.118* @param scope the scope for the new identity scope.119*120* @exception KeyManagementException if there is already an identity121* with the same name in the scope.122*/123public IdentityScope(String name, IdentityScope scope)124throws KeyManagementException {125super(name, scope);126}127128/**129* Returns the system's identity scope.130*131* @return the system's identity scope, or {@code null} if none has been132* set.133*134* @see #setSystemScope135*/136public static IdentityScope getSystemScope() {137if (scope == null) {138initializeSystemScope();139}140return scope;141}142143144/**145* Sets the system's identity scope.146*147* <p>First, if there is a security manager, its148* {@code checkSecurityAccess}149* method is called with {@code "setSystemScope"}150* as its argument to see if it's ok to set the identity scope.151*152* @param scope the scope to set.153*154* @exception SecurityException if a security manager exists and its155* {@code checkSecurityAccess} method doesn't allow156* setting the identity scope.157*158* @see #getSystemScope159* @see SecurityManager#checkSecurityAccess160*/161protected static void setSystemScope(IdentityScope scope) {162check("setSystemScope");163IdentityScope.scope = scope;164}165166/**167* Returns the number of identities within this identity scope.168*169* @return the number of identities within this identity scope.170*/171public abstract int size();172173/**174* Returns the identity in this scope with the specified name (if any).175*176* @param name the name of the identity to be retrieved.177*178* @return the identity named {@code name}, or null if there are179* no identities named {@code name} in this scope.180*/181public abstract Identity getIdentity(String name);182183/**184* Retrieves the identity whose name is the same as that of the185* specified principal. (Note: Identity implements Principal.)186*187* @param principal the principal corresponding to the identity188* to be retrieved.189*190* @return the identity whose name is the same as that of the191* principal, or null if there are no identities of the same name192* in this scope.193*/194public Identity getIdentity(Principal principal) {195return getIdentity(principal.getName());196}197198/**199* Retrieves the identity with the specified public key.200*201* @param key the public key for the identity to be returned.202*203* @return the identity with the given key, or null if there are204* no identities in this scope with that key.205*/206public abstract Identity getIdentity(PublicKey key);207208/**209* Adds an identity to this identity scope.210*211* @param identity the identity to be added.212*213* @exception KeyManagementException if the identity is not214* valid, a name conflict occurs, another identity has the same215* public key as the identity being added, or another exception216* occurs. */217public abstract void addIdentity(Identity identity)218throws KeyManagementException;219220/**221* Removes an identity from this identity scope.222*223* @param identity the identity to be removed.224*225* @exception KeyManagementException if the identity is missing,226* or another exception occurs.227*/228public abstract void removeIdentity(Identity identity)229throws KeyManagementException;230231/**232* Returns an enumeration of all identities in this identity scope.233*234* @return an enumeration of all identities in this identity scope.235*/236public abstract Enumeration<Identity> identities();237238/**239* Returns a string representation of this identity scope, including240* its name, its scope name, and the number of identities in this241* identity scope.242*243* @return a string representation of this identity scope.244*/245public String toString() {246return super.toString() + "[" + size() + "]";247}248249private static void check(String directive) {250SecurityManager security = System.getSecurityManager();251if (security != null) {252security.checkSecurityAccess(directive);253}254}255256}257258259