src/java.base/share/classes/java/security/Identity.java
author chegar
Thu, 17 Oct 2019 20:54:25 +0100
branchdatagramsocketimpl-branch
changeset 58679 9c3209ff7550
parent 58678 9cf78a70fa4f
parent 58242 94bb65cb37d3
permissions -rw-r--r--
datagramsocketimpl-branch: merge with default
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
57950
4612a3cfb927 8229999: Apply java.io.Serial annotations to security types in java.base
darcy
parents: 51759
diff changeset
     2
 * Copyright (c) 1996, 2019, 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
45434
4582657c7260 8181082: class-level since tag issues in java.base & java.datatransfer module
mli
parents: 43541
diff changeset
    54
 * @since 1.1
47742
28096878fae5 8175091: Mark the deprecated java.security.{Certificate,Identity,IdentityScope,Signer} APIs with forRemoval=true
mullan
parents: 47216
diff changeset
    55
 * @deprecated This class is deprecated and subject to removal in a future
28096878fae5 8175091: Mark the deprecated java.security.{Certificate,Identity,IdentityScope,Signer} APIs with forRemoval=true
mullan
parents: 47216
diff changeset
    56
 *     version of Java SE. It has been replaced by
28096878fae5 8175091: Mark the deprecated java.security.{Certificate,Identity,IdentityScope,Signer} APIs with forRemoval=true
mullan
parents: 47216
diff changeset
    57
 *     {@code java.security.KeyStore}, the {@code java.security.cert} package,
28096878fae5 8175091: Mark the deprecated java.security.{Certificate,Identity,IdentityScope,Signer} APIs with forRemoval=true
mullan
parents: 47216
diff changeset
    58
 *     and {@code java.security.Principal}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 */
47742
28096878fae5 8175091: Mark the deprecated java.security.{Certificate,Identity,IdentityScope,Signer} APIs with forRemoval=true
mullan
parents: 47216
diff changeset
    60
@Deprecated(since="1.2", forRemoval=true)
28096878fae5 8175091: Mark the deprecated java.security.{Certificate,Identity,IdentityScope,Signer} APIs with forRemoval=true
mullan
parents: 47216
diff changeset
    61
@SuppressWarnings("removal")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
public abstract class Identity implements Principal, Serializable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    /** use serialVersionUID from JDK 1.1.x for interoperability */
57950
4612a3cfb927 8229999: Apply java.io.Serial annotations to security types in java.base
darcy
parents: 51759
diff changeset
    65
    @java.io.Serial
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    private static final long serialVersionUID = 3609922007826600659L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     * The name for this identity.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    private String name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * The public key for this identity.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    private PublicKey publicKey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * Generic, descriptive information about the identity.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    String info = "No further information available.";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * The scope of the identity.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    IdentityScope scope;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * The certificates for this identity.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    Vector<Certificate> certificates;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * Constructor for serialization only.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    protected Identity() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        this("restoring...");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * Constructs an identity with the specified name and scope.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * @param name the identity name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * @param scope the scope of the identity.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     *
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 57950
diff changeset
   116
     * @throws    KeyManagementException if there is already an identity
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * with the same name in the scope.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    public Identity(String name, IdentityScope scope) throws
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    KeyManagementException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        this(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        if (scope != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
            scope.addIdentity(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        this.scope = scope;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * Constructs an identity with the specified name and no scope.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * @param name the identity name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    public Identity(String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        this.name = name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * Returns this identity's name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * @return the name of this identity.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    public final String getName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        return name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * Returns this identity's scope.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * @return the scope of this identity.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    public final IdentityScope getScope() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        return scope;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * Returns this identity's public key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * @return the public key for this identity.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * @see #setPublicKey
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    public PublicKey getPublicKey() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        return publicKey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * Sets this identity's public key. The old key and all of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * identity's certificates are removed by this operation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     *
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
   170
     * <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
   171
     * method is called with {@code "setIdentityPublicKey"}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * as its argument to see if it's ok to set the public key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * @param key the public key for this identity.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     *
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 57950
diff changeset
   176
     * @throws    KeyManagementException if another identity in the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * identity's scope has the same public key, or if another exception occurs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     *
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 57950
diff changeset
   179
     * @throws     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
   180
     * {@code checkSecurityAccess} method doesn't allow
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * setting the public key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * @see #getPublicKey
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * @see SecurityManager#checkSecurityAccess
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    /* Should we throw an exception if this is already set? */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    public void setPublicKey(PublicKey key) throws KeyManagementException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        check("setIdentityPublicKey");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        this.publicKey = key;
30033
b9c86c17164a 8078468: Update security libraries to use diamond with anonymous classes
darcy
parents: 25859
diff changeset
   191
        certificates = new Vector<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * Specifies a general information string for this identity.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     *
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
   197
     * <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
   198
     * method is called with {@code "setIdentityInfo"}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * as its argument to see if it's ok to specify the information string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * @param info the information string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     *
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 57950
diff changeset
   203
     * @throws     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
   204
     * {@code checkSecurityAccess} method doesn't allow
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * setting the information string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * @see #getInfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * @see SecurityManager#checkSecurityAccess
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    public void setInfo(String info) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        check("setIdentityInfo");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        this.info = info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * Returns general information previously specified for this identity.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * @return general information about this identity.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * @see #setInfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    public String getInfo() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        return info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * Adds a certificate for this identity. If the identity has a public
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * key, the public key in the certificate must be the same, and if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * the identity does not have a public key, the identity's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * public key is set to be that specified in the certificate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     *
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
   232
     * <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
   233
     * method is called with {@code "addIdentityCertificate"}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * as its argument to see if it's ok to add a certificate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * @param certificate the certificate to be added.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     *
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 57950
diff changeset
   238
     * @throws    KeyManagementException if the certificate is not valid,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * if the public key in the certificate being added conflicts with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * this identity's public key, or if another exception occurs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     *
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 57950
diff changeset
   242
     * @throws     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
   243
     * {@code checkSecurityAccess} method doesn't allow
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     * adding a certificate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     * @see SecurityManager#checkSecurityAccess
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    public void addCertificate(Certificate certificate)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    throws KeyManagementException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        check("addIdentityCertificate");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        if (certificates == null) {
30033
b9c86c17164a 8078468: Update security libraries to use diamond with anonymous classes
darcy
parents: 25859
diff changeset
   254
            certificates = new Vector<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        if (publicKey != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
            if (!keyEquals(publicKey, certificate.getPublicKey())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
                throw new KeyManagementException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
                    "public key different from cert public key");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
            publicKey = certificate.getPublicKey();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        certificates.addElement(certificate);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
31695
4d10942c9a7b 8074865: General crypto resilience changes
valeriep
parents: 30033
diff changeset
   267
    private boolean keyEquals(PublicKey aKey, PublicKey anotherKey) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        String aKeyFormat = aKey.getFormat();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        String anotherKeyFormat = anotherKey.getFormat();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        if ((aKeyFormat == null) ^ (anotherKeyFormat == null))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        if (aKeyFormat != null && anotherKeyFormat != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
            if (!aKeyFormat.equalsIgnoreCase(anotherKeyFormat))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        return java.util.Arrays.equals(aKey.getEncoded(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
                                     anotherKey.getEncoded());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     * Removes a certificate from this identity.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     *
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
   283
     * <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
   284
     * method is called with {@code "removeIdentityCertificate"}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     * as its argument to see if it's ok to remove a certificate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     * @param certificate the certificate to be removed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     *
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 57950
diff changeset
   289
     * @throws    KeyManagementException if the certificate is
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     * missing, or if another exception occurs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     *
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 57950
diff changeset
   292
     * @throws     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
   293
     * {@code checkSecurityAccess} method doesn't allow
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     * removing a certificate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     * @see SecurityManager#checkSecurityAccess
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    public void removeCertificate(Certificate certificate)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    throws KeyManagementException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        check("removeIdentityCertificate");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        if (certificates != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
            certificates.removeElement(certificate);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     * Returns a copy of all the certificates for this identity.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * @return a copy of all the certificates for this identity.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    public Certificate[] certificates() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        if (certificates == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
            return new Certificate[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        int len = certificates.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        Certificate[] certs = new Certificate[len];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        certificates.copyInto(certs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        return certs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     * Tests for equality between the specified object and this identity.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     * This first tests to see if the entities actually refer to the same
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     * object, in which case it returns true. Next, it checks to see if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     * the entities have the same name and the same scope. If they do,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     * the method returns true. Otherwise, it calls
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     * {@link #identityEquals(Identity) identityEquals}, which subclasses should
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     * override.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     * @param identity the object to test for equality with this identity.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     * @return true if the objects are considered equal, false otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     * @see #identityEquals
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
    public final boolean equals(Object identity) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        if (identity == this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        if (identity instanceof Identity) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
            Identity i = (Identity)identity;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
            if (this.fullName().equals(i.fullName())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
                return identityEquals(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     * Tests for equality between the specified identity and this identity.
51759
ac6e9a2ebc04 8210786: Typo s/overriden/overridden/ in several places
igerasim
parents: 47742
diff changeset
   355
     * This method should be overridden by subclasses to test for equality.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
     * The default behavior is to return true if the names and public keys
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
     * are equal.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     * @param identity the identity to test for equality with this identity.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     * @return true if the identities are considered equal, false
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     * otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     * @see #equals
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
    protected boolean identityEquals(Identity identity) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
        if (!name.equalsIgnoreCase(identity.name))
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
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        if (publicKey != null && identity.publicKey != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
            if (!publicKey.equals(identity.publicKey))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
     * Returns a parsable name for identity: identityName.scopeName
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
    String fullName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        String parsable = name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        if (scope != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
            parsable += "." + scope.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        return parsable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     * Returns a short string describing this identity, telling its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
     * name and its scope (if any).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     *
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
   396
     * <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
   397
     * method is called with {@code "printIdentity"}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
     * as its argument to see if it's ok to return the string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
     * @return information about this identity, such as its name and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
     * name of its scope (if any).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     *
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 57950
diff changeset
   403
     * @throws     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
   404
     * {@code checkSecurityAccess} method doesn't allow
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     * returning a string describing this identity.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
     * @see SecurityManager#checkSecurityAccess
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
        check("printIdentity");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
        String printable = name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        if (scope != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
            printable += "[" + scope.getName() + "]";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
        return printable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     * Returns a string representation of this identity, with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     * 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
   421
     * {@code toString} method without any arguments.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
     *
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
   423
     * <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
   424
     * method is called with {@code "printIdentity"}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
     * as its argument to see if it's ok to return the string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
     * @param detailed whether or not to provide detailed information.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
     *
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
   429
     * @return information about this identity. If {@code detailed}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
     * 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
   431
     * provided by the {@code toString} method without any arguments.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
     *
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 57950
diff changeset
   433
     * @throws     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
   434
     * {@code checkSecurityAccess} method doesn't allow
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
     * returning a string describing this identity.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
     * @see #toString
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
     * @see SecurityManager#checkSecurityAccess
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
    public String toString(boolean detailed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
        String out = toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
        if (detailed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
            out += "\n";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
            out += printKeys();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
            out += "\n" + printCertificates();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
            if (info != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
                out += "\n\t" + info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
                out += "\n\tno additional information available.";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
        return out;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
    String printKeys() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
        String key = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
        if (publicKey != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
            key = "\tpublic key initialized";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
            key = "\tno public key";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
        return key;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
    String printCertificates() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        String out = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
        if (certificates == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
            return "\tno certificates";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
            out += "\tcertificates: \n";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
            int i = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
            for (Certificate cert : certificates) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
                out += "\tcertificate " + i++ +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
                    "\tfor  : " + cert.getPrincipal() + "\n";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
                out += "\t\t\tfrom : " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
                    cert.getGuarantor() + "\n";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
        return out;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
     * Returns a hashcode for this identity.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
     * @return a hashcode for this identity.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
    public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
        return name.hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
    private static void check(String directive) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
        SecurityManager security = System.getSecurityManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
        if (security != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
            security.checkSecurityAccess(directive);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
}