jdk/src/java.base/share/classes/java/security/Identity.java
author darcy
Thu, 23 Apr 2015 18:51:18 -0700
changeset 30033 b9c86c17164a
parent 25859 3317bb8137f4
child 31695 4d10942c9a7b
permissions -rw-r--r--
8078468: Update security libraries to use diamond with anonymous classes Reviewed-by: weijun
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
     2
 * Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package java.security;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.Serializable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * <p>This class represents identities: real-world objects such as people,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * companies or organizations whose identities can be authenticated using
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * their public keys. Identities may also be more abstract (or concrete)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * constructs, such as daemon threads or smart cards.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * <p>All Identity objects have a name and a public key. Names are
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * immutable. Identities may also be scoped. That is, if an Identity is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * specified to have a particular scope, then the name and public
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * key of the Identity are unique within that scope.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * <p>An Identity also has a set of certificates (all certifying its own
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * public key). The Principal names specified in these certificates need
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * not be the same, only the key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * <p>An Identity can be subclassed, to include postal and email addresses,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * telephone numbers, images of faces and logos, and so on.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * @see IdentityScope
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * @see Signer
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * @see Principal
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * @author Benjamin Renaud
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * @deprecated This class is no longer used. Its functionality has been
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
    55
 * replaced by {@code java.security.KeyStore}, the
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
    56
 * {@code java.security.cert} package, and
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
    57
 * {@code java.security.Principal}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
@Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
public abstract class Identity implements Principal, Serializable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    /** use serialVersionUID from JDK 1.1.x for interoperability */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    private static final long serialVersionUID = 3609922007826600659L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     * The name for this identity.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    private String name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * The public key for this identity.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    private PublicKey publicKey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * Generic, descriptive information about the identity.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    String info = "No further information available.";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * The scope of the identity.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    IdentityScope scope;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * The certificates for this identity.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    Vector<Certificate> certificates;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * Constructor for serialization only.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    protected Identity() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        this("restoring...");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * Constructs an identity with the specified name and scope.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * @param name the identity name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * @param scope the scope of the identity.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * @exception KeyManagementException if there is already an identity
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * with the same name in the scope.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    public Identity(String name, IdentityScope scope) throws
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    KeyManagementException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        this(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        if (scope != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
            scope.addIdentity(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        this.scope = scope;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * Constructs an identity with the specified name and no scope.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * @param name the identity name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    public Identity(String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        this.name = name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * Returns this identity's name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * @return the name of this identity.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    public final String getName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        return name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * Returns this identity's scope.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * @return the scope of this identity.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    public final IdentityScope getScope() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        return scope;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * Returns this identity's public key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * @return the public key for this identity.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * @see #setPublicKey
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    public PublicKey getPublicKey() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        return publicKey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * Sets this identity's public key. The old key and all of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * identity's certificates are removed by this operation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     *
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
   167
     * <p>First, if there is a security manager, its {@code checkSecurityAccess}
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
   168
     * method is called with {@code "setIdentityPublicKey"}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * as its argument to see if it's ok to set the public key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * @param key the public key for this identity.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * @exception KeyManagementException if another identity in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * identity's scope has the same public key, or if another exception occurs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * @exception  SecurityException  if a security manager exists and its
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
   177
     * {@code checkSecurityAccess} method doesn't allow
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * setting the public key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * @see #getPublicKey
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * @see SecurityManager#checkSecurityAccess
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    /* Should we throw an exception if this is already set? */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    public void setPublicKey(PublicKey key) throws KeyManagementException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        check("setIdentityPublicKey");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        this.publicKey = key;
30033
b9c86c17164a 8078468: Update security libraries to use diamond with anonymous classes
darcy
parents: 25859
diff changeset
   188
        certificates = new Vector<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * Specifies a general information string for this identity.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     *
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
   194
     * <p>First, if there is a security manager, its {@code checkSecurityAccess}
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
   195
     * method is called with {@code "setIdentityInfo"}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * as its argument to see if it's ok to specify the information string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * @param info the information string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * @exception  SecurityException  if a security manager exists and its
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
   201
     * {@code checkSecurityAccess} method doesn't allow
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * setting the information string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * @see #getInfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * @see SecurityManager#checkSecurityAccess
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    public void setInfo(String info) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        check("setIdentityInfo");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        this.info = info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * Returns general information previously specified for this identity.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * @return general information about this identity.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * @see #setInfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    public String getInfo() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        return info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * Adds a certificate for this identity. If the identity has a public
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * key, the public key in the certificate must be the same, and if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * the identity does not have a public key, the identity's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * public key is set to be that specified in the certificate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     *
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
   229
     * <p>First, if there is a security manager, its {@code checkSecurityAccess}
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
   230
     * method is called with {@code "addIdentityCertificate"}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * as its argument to see if it's ok to add a certificate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * @param certificate the certificate to be added.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * @exception KeyManagementException if the certificate is not valid,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * if the public key in the certificate being added conflicts with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * this identity's public key, or if another exception occurs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * @exception  SecurityException  if a security manager exists and its
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
   240
     * {@code checkSecurityAccess} method doesn't allow
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * adding a certificate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * @see SecurityManager#checkSecurityAccess
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    public void addCertificate(Certificate certificate)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    throws KeyManagementException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        check("addIdentityCertificate");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        if (certificates == null) {
30033
b9c86c17164a 8078468: Update security libraries to use diamond with anonymous classes
darcy
parents: 25859
diff changeset
   251
            certificates = new Vector<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        if (publicKey != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
            if (!keyEquals(publicKey, certificate.getPublicKey())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
                throw new KeyManagementException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
                    "public key different from cert public key");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
            publicKey = certificate.getPublicKey();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        certificates.addElement(certificate);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    private boolean keyEquals(Key aKey, Key anotherKey) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        String aKeyFormat = aKey.getFormat();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        String anotherKeyFormat = anotherKey.getFormat();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        if ((aKeyFormat == null) ^ (anotherKeyFormat == null))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        if (aKeyFormat != null && anotherKeyFormat != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
            if (!aKeyFormat.equalsIgnoreCase(anotherKeyFormat))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        return java.util.Arrays.equals(aKey.getEncoded(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
                                     anotherKey.getEncoded());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     * Removes a certificate from this identity.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     *
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
   280
     * <p>First, if there is a security manager, its {@code checkSecurityAccess}
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
   281
     * method is called with {@code "removeIdentityCertificate"}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     * as its argument to see if it's ok to remove a certificate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     * @param certificate the certificate to be removed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     * @exception KeyManagementException if the certificate is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     * missing, or if another exception occurs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     * @exception  SecurityException  if a security manager exists and its
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
   290
     * {@code checkSecurityAccess} method doesn't allow
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     * removing a certificate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     * @see SecurityManager#checkSecurityAccess
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    public void removeCertificate(Certificate certificate)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    throws KeyManagementException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        check("removeIdentityCertificate");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        if (certificates != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
            certificates.removeElement(certificate);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     * Returns a copy of all the certificates for this identity.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     * @return a copy of all the certificates for this identity.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
    public Certificate[] certificates() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        if (certificates == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
            return new Certificate[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        int len = certificates.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        Certificate[] certs = new Certificate[len];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        certificates.copyInto(certs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        return certs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     * Tests for equality between the specified object and this identity.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     * This first tests to see if the entities actually refer to the same
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     * object, in which case it returns true. Next, it checks to see if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     * the entities have the same name and the same scope. If they do,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     * the method returns true. Otherwise, it calls
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     * {@link #identityEquals(Identity) identityEquals}, which subclasses should
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     * override.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     * @param identity the object to test for equality with this identity.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     * @return true if the objects are considered equal, false otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     * @see #identityEquals
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
    public final boolean equals(Object identity) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
        if (identity == this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        if (identity instanceof Identity) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
            Identity i = (Identity)identity;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
            if (this.fullName().equals(i.fullName())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
                return identityEquals(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     * Tests for equality between the specified identity and this identity.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     * This method should be overriden by subclasses to test for equality.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     * The default behavior is to return true if the names and public keys
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     * are equal.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
     * @param identity the identity to test for equality with this identity.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     * @return true if the identities are considered equal, false
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     * otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     * @see #equals
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
    protected boolean identityEquals(Identity identity) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
        if (!name.equalsIgnoreCase(identity.name))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
        if ((publicKey == null) ^ (identity.publicKey == null))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
        if (publicKey != null && identity.publicKey != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
            if (!publicKey.equals(identity.publicKey))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
     * Returns a parsable name for identity: identityName.scopeName
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
    String fullName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        String parsable = name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
        if (scope != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
            parsable += "." + scope.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        return parsable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     * Returns a short string describing this identity, telling its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     * name and its scope (if any).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
     *
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
   393
     * <p>First, if there is a security manager, its {@code checkSecurityAccess}
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
   394
     * method is called with {@code "printIdentity"}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     * as its argument to see if it's ok to return the string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
     * @return information about this identity, such as its name and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
     * name of its scope (if any).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
     * @exception  SecurityException  if a security manager exists and its
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
   401
     * {@code checkSecurityAccess} method doesn't allow
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     * returning a string describing this identity.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
     * @see SecurityManager#checkSecurityAccess
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
        check("printIdentity");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        String printable = name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        if (scope != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
            printable += "[" + scope.getName() + "]";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        return printable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     * Returns a string representation of this identity, with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
     * optionally more details than that provided by the
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
   418
     * {@code toString} method without any arguments.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     *
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
   420
     * <p>First, if there is a security manager, its {@code checkSecurityAccess}
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
   421
     * method is called with {@code "printIdentity"}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
     * as its argument to see if it's ok to return the string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
     * @param detailed whether or not to provide detailed information.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
     *
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
   426
     * @return information about this identity. If {@code detailed}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
     * is true, then this method returns more information than that
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
   428
     * provided by the {@code toString} method without any arguments.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
     * @exception  SecurityException  if a security manager exists and its
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
   431
     * {@code checkSecurityAccess} method doesn't allow
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
     * returning a string describing this identity.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
     * @see #toString
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
     * @see SecurityManager#checkSecurityAccess
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
    public String toString(boolean detailed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
        String out = toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
        if (detailed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
            out += "\n";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
            out += printKeys();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
            out += "\n" + printCertificates();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
            if (info != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
                out += "\n\t" + info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
                out += "\n\tno additional information available.";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
        return out;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
    String printKeys() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
        String key = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
        if (publicKey != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
            key = "\tpublic key initialized";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
            key = "\tno public key";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
        return key;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
    String printCertificates() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
        String out = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
        if (certificates == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
            return "\tno certificates";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
            out += "\tcertificates: \n";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
            int i = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
            for (Certificate cert : certificates) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
                out += "\tcertificate " + i++ +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
                    "\tfor  : " + cert.getPrincipal() + "\n";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
                out += "\t\t\tfrom : " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
                    cert.getGuarantor() + "\n";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        return out;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
     * Returns a hashcode for this identity.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
     * @return a hashcode for this identity.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
    public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
        return name.hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
    private static void check(String directive) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
        SecurityManager security = System.getSecurityManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
        if (security != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
            security.checkSecurityAccess(directive);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
}