jdk/src/java.security.jgss/share/classes/javax/security/auth/kerberos/DelegationPermission.java
author asmotrak
Thu, 25 Jun 2015 20:20:41 +0800
changeset 31265 2eabccc392ed
parent 31080 00a25f4c4d44
child 32424 2d9d66d0519f
permissions -rw-r--r--
8129575: Equal DelegationPermission instances may return different hash codes Reviewed-by: mullan, weijun
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
31080
00a25f4c4d44 8056179: Store permissions in concurrent collections in PermissionCollection subclasses
mullan
parents: 29492
diff changeset
     2
 * Copyright (c) 2000, 2015, 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 javax.security.auth.kerberos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
31080
00a25f4c4d44 8056179: Store permissions in concurrent collections in PermissionCollection subclasses
mullan
parents: 29492
diff changeset
    28
import java.io.IOException;
00a25f4c4d44 8056179: Store permissions in concurrent collections in PermissionCollection subclasses
mullan
parents: 29492
diff changeset
    29
import java.io.ObjectInputStream;
00a25f4c4d44 8056179: Store permissions in concurrent collections in PermissionCollection subclasses
mullan
parents: 29492
diff changeset
    30
import java.io.ObjectOutputStream;
00a25f4c4d44 8056179: Store permissions in concurrent collections in PermissionCollection subclasses
mullan
parents: 29492
diff changeset
    31
import java.io.ObjectStreamField;
00a25f4c4d44 8056179: Store permissions in concurrent collections in PermissionCollection subclasses
mullan
parents: 29492
diff changeset
    32
import java.security.BasicPermission;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.security.Permission;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.security.PermissionCollection;
31080
00a25f4c4d44 8056179: Store permissions in concurrent collections in PermissionCollection subclasses
mullan
parents: 29492
diff changeset
    35
import java.util.*;
00a25f4c4d44 8056179: Store permissions in concurrent collections in PermissionCollection subclasses
mullan
parents: 29492
diff changeset
    36
import java.util.concurrent.ConcurrentHashMap;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * This class is used to restrict the usage of the Kerberos
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * delegation model, ie: forwardable and proxiable tickets.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * <p>
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 14342
diff changeset
    42
 * The target name of this {@code Permission} specifies a pair of
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * kerberos service principals. The first is the subordinate service principal
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * being entrusted to use the TGT. The second service principal designates
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * the target service the subordinate service principal is to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * interact with on behalf of the initiating KerberosPrincipal. This
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * latter service principal is specified to restrict the use of a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * proxiable ticket.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * For example, to specify the "host" service use of a forwardable TGT the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * target permission is specified as follows:
21955
abc02575919c 8029475: Fix more doclint issues in javax.security
darcy
parents: 18830
diff changeset
    52
 *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 *  DelegationPermission("\"host/foo.example.com@EXAMPLE.COM\" \"krbtgt/EXAMPLE.COM@EXAMPLE.COM\"");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * To give the "backup" service a proxiable nfs service ticket the target permission
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * might be specified:
21955
abc02575919c 8029475: Fix more doclint issues in javax.security
darcy
parents: 18830
diff changeset
    59
 *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 *  DelegationPermission("\"backup/bar.example.com@EXAMPLE.COM\" \"nfs/home.EXAMPLE.COM@EXAMPLE.COM\"");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
public final class DelegationPermission extends BasicPermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    implements java.io.Serializable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    private static final long serialVersionUID = 883133252142523922L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    private transient String subordinate, service;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    /**
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 14342
diff changeset
    75
     * Create a new {@code DelegationPermission}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * with the specified subordinate and target principals.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * @param principals the name of the subordinate and target principals
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     *
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 14342
diff changeset
    80
     * @throws NullPointerException if {@code principals} is {@code null}.
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 14342
diff changeset
    81
     * @throws IllegalArgumentException if {@code principals} is empty.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    public DelegationPermission(String principals) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        super(principals);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        init(principals);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    /**
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 14342
diff changeset
    89
     * Create a new {@code DelegationPermission}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * with the specified subordinate and target principals.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * @param principals the name of the subordinate and target principals
29492
a4bf9a570035 8028266: Tidy warnings cleanup for packages java.security/javax.security
avstepan
parents: 25859
diff changeset
    93
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * @param actions should be null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     *
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 14342
diff changeset
    96
     * @throws NullPointerException if {@code principals} is {@code null}.
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 14342
diff changeset
    97
     * @throws IllegalArgumentException if {@code principals} is empty.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    public DelegationPermission(String principals, String actions) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        super(principals, actions);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        init(principals);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * Initialize the DelegationPermission object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    private void init(String target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        StringTokenizer t = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        if (!target.startsWith("\"")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
            throw new IllegalArgumentException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
                ("service principal [" + target +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
                 "] syntax invalid: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
                 "improperly quoted");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
            t = new StringTokenizer(target, "\"", false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
            subordinate = t.nextToken();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
            if (t.countTokens() == 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
                t.nextToken();  // bypass whitespace
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
                service = t.nextToken();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
            } else if (t.countTokens() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
                throw new IllegalArgumentException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
                    ("service principal [" + t.nextToken() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
                     "] syntax invalid: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
                     "improperly quoted");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * Checks if this Kerberos delegation permission object "implies" the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * specified permission.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * <P>
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 14342
diff changeset
   135
     * If none of the above are true, {@code implies} returns false.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * @param p the permission to check against.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * @return true if the specified permission is implied by this object,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * false if not.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     */
31080
00a25f4c4d44 8056179: Store permissions in concurrent collections in PermissionCollection subclasses
mullan
parents: 29492
diff changeset
   141
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    public boolean implies(Permission p) {
31265
2eabccc392ed 8129575: Equal DelegationPermission instances may return different hash codes
asmotrak
parents: 31080
diff changeset
   143
        return equals(p);
2
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
     * Checks two DelegationPermission objects for equality.
29492
a4bf9a570035 8028266: Tidy warnings cleanup for packages java.security/javax.security
avstepan
parents: 25859
diff changeset
   148
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * @param obj the object to test for equality with this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     *
29492
a4bf9a570035 8028266: Tidy warnings cleanup for packages java.security/javax.security
avstepan
parents: 25859
diff changeset
   151
     * @return true if {@code obj} is a DelegationPermission, and
31265
2eabccc392ed 8129575: Equal DelegationPermission instances may return different hash codes
asmotrak
parents: 31080
diff changeset
   152
     *  has the same subordinate and service principal as this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     *  DelegationPermission object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     */
31080
00a25f4c4d44 8056179: Store permissions in concurrent collections in PermissionCollection subclasses
mullan
parents: 29492
diff changeset
   155
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    public boolean equals(Object obj) {
31265
2eabccc392ed 8129575: Equal DelegationPermission instances may return different hash codes
asmotrak
parents: 31080
diff changeset
   157
        if (obj == this) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
            return true;
31265
2eabccc392ed 8129575: Equal DelegationPermission instances may return different hash codes
asmotrak
parents: 31080
diff changeset
   159
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
31265
2eabccc392ed 8129575: Equal DelegationPermission instances may return different hash codes
asmotrak
parents: 31080
diff changeset
   161
        if (!(obj instanceof DelegationPermission)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
            return false;
31265
2eabccc392ed 8129575: Equal DelegationPermission instances may return different hash codes
asmotrak
parents: 31080
diff changeset
   163
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        DelegationPermission that = (DelegationPermission) obj;
31265
2eabccc392ed 8129575: Equal DelegationPermission instances may return different hash codes
asmotrak
parents: 31080
diff changeset
   166
2eabccc392ed 8129575: Equal DelegationPermission instances may return different hash codes
asmotrak
parents: 31080
diff changeset
   167
        return this.subordinate.equals(that.subordinate) &&
2eabccc392ed 8129575: Equal DelegationPermission instances may return different hash codes
asmotrak
parents: 31080
diff changeset
   168
                this.service.equals(that.service);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * Returns the hash code value for this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * @return a hash code value for this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     */
31080
00a25f4c4d44 8056179: Store permissions in concurrent collections in PermissionCollection subclasses
mullan
parents: 29492
diff changeset
   176
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    public int hashCode() {
31265
2eabccc392ed 8129575: Equal DelegationPermission instances may return different hash codes
asmotrak
parents: 31080
diff changeset
   178
        return 17 * subordinate.hashCode() + 31 * service.hashCode();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * Returns a PermissionCollection object for storing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * DelegationPermission objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * <br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * DelegationPermission objects must be stored in a manner that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * allows them to be inserted into the collection in any order, but
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * that also enables the PermissionCollection implies method to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * be implemented in an efficient (and consistent) manner.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * @return a new PermissionCollection object suitable for storing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * DelegationPermissions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     */
31080
00a25f4c4d44 8056179: Store permissions in concurrent collections in PermissionCollection subclasses
mullan
parents: 29492
diff changeset
   193
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    public PermissionCollection newPermissionCollection() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        return new KrbDelegationPermissionCollection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * WriteObject is called to save the state of the DelegationPermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * to a stream. The actions are serialized, and the superclass
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * takes care of the name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    private synchronized void writeObject(java.io.ObjectOutputStream s)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        s.defaultWriteObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * readObject is called to restore the state of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * DelegationPermission from a stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    private synchronized void readObject(java.io.ObjectInputStream s)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
         throws IOException, ClassNotFoundException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        // Read in the action, then initialize the rest
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        s.defaultReadObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        init(getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
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
final class KrbDelegationPermissionCollection extends PermissionCollection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    implements java.io.Serializable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    // Not serialized; see serialization section at end of class.
31080
00a25f4c4d44 8056179: Store permissions in concurrent collections in PermissionCollection subclasses
mullan
parents: 29492
diff changeset
   228
    private transient ConcurrentHashMap<Permission, Boolean> perms;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    public KrbDelegationPermissionCollection() {
31080
00a25f4c4d44 8056179: Store permissions in concurrent collections in PermissionCollection subclasses
mullan
parents: 29492
diff changeset
   231
        perms = new ConcurrentHashMap<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * Check and see if this collection of permissions implies the permissions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * expressed in "permission".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     *
14014
da3648e13e67 8000269: Cleanup javadoc warnings
alanb
parents: 10709
diff changeset
   238
     * @param permission the Permission object to compare
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * @return true if "permission" is a proper subset of a permission in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * the collection, false if not.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     */
31080
00a25f4c4d44 8056179: Store permissions in concurrent collections in PermissionCollection subclasses
mullan
parents: 29492
diff changeset
   243
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    public boolean implies(Permission permission) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        if (! (permission instanceof DelegationPermission))
31080
00a25f4c4d44 8056179: Store permissions in concurrent collections in PermissionCollection subclasses
mullan
parents: 29492
diff changeset
   246
            return false;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
31080
00a25f4c4d44 8056179: Store permissions in concurrent collections in PermissionCollection subclasses
mullan
parents: 29492
diff changeset
   248
        // if map contains key, then it automatically implies it
00a25f4c4d44 8056179: Store permissions in concurrent collections in PermissionCollection subclasses
mullan
parents: 29492
diff changeset
   249
        return perms.containsKey(permission);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     * Adds a permission to the DelegationPermissions. The key for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * the hash is the name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * @param permission the Permission object to add.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * @exception IllegalArgumentException - if the permission is not a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     *                                       DelegationPermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * @exception SecurityException - if this PermissionCollection object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     *                                has been marked readonly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     */
31080
00a25f4c4d44 8056179: Store permissions in concurrent collections in PermissionCollection subclasses
mullan
parents: 29492
diff changeset
   264
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    public void add(Permission permission) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        if (! (permission instanceof DelegationPermission))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
            throw new IllegalArgumentException("invalid permission: "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
                                               permission);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        if (isReadOnly())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
            throw new SecurityException("attempt to add a Permission to a readonly PermissionCollection");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
31080
00a25f4c4d44 8056179: Store permissions in concurrent collections in PermissionCollection subclasses
mullan
parents: 29492
diff changeset
   272
        perms.put(permission, Boolean.TRUE);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * Returns an enumeration of all the DelegationPermission objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * in the container.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     * @return an enumeration of all the DelegationPermission objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     */
31080
00a25f4c4d44 8056179: Store permissions in concurrent collections in PermissionCollection subclasses
mullan
parents: 29492
diff changeset
   281
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    public Enumeration<Permission> elements() {
31080
00a25f4c4d44 8056179: Store permissions in concurrent collections in PermissionCollection subclasses
mullan
parents: 29492
diff changeset
   283
        return perms.keys();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    private static final long serialVersionUID = -3383936936589966948L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    // Need to maintain serialization interoperability with earlier releases,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    // which had the serializable field:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    //    private Vector permissions;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     * @serialField permissions java.util.Vector
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     *     A list of DelegationPermission objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    private static final ObjectStreamField[] serialPersistentFields = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        new ObjectStreamField("permissions", Vector.class),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     * @serialData "permissions" field (a Vector containing the DelegationPermissions).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     * Writes the contents of the perms field out as a Vector for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     * serialization compatibility with earlier releases.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
    private void writeObject(ObjectOutputStream out) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        // Don't call out.defaultWriteObject()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        // Write out Vector
31080
00a25f4c4d44 8056179: Store permissions in concurrent collections in PermissionCollection subclasses
mullan
parents: 29492
diff changeset
   310
        Vector<Permission> permissions = new Vector<>(perms.keySet());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        ObjectOutputStream.PutField pfields = out.putFields();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        pfields.put("permissions", permissions);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        out.writeFields();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     * Reads in a Vector of DelegationPermissions and saves them in the perms field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     */
10709
d865c9f21240 7092375: Security Libraries don't build with javac -Werror
xuelei
parents: 9035
diff changeset
   320
    @SuppressWarnings("unchecked")
14014
da3648e13e67 8000269: Cleanup javadoc warnings
alanb
parents: 10709
diff changeset
   321
    private void readObject(ObjectInputStream in)
da3648e13e67 8000269: Cleanup javadoc warnings
alanb
parents: 10709
diff changeset
   322
        throws IOException, ClassNotFoundException
da3648e13e67 8000269: Cleanup javadoc warnings
alanb
parents: 10709
diff changeset
   323
    {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        // Don't call defaultReadObject()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        // Read in serialized fields
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        ObjectInputStream.GetField gfields = in.readFields();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        // Get the one we want
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        Vector<Permission> permissions =
31080
00a25f4c4d44 8056179: Store permissions in concurrent collections in PermissionCollection subclasses
mullan
parents: 29492
diff changeset
   331
            (Vector<Permission>)gfields.get("permissions", null);
00a25f4c4d44 8056179: Store permissions in concurrent collections in PermissionCollection subclasses
mullan
parents: 29492
diff changeset
   332
        perms = new ConcurrentHashMap<>(permissions.size());
00a25f4c4d44 8056179: Store permissions in concurrent collections in PermissionCollection subclasses
mullan
parents: 29492
diff changeset
   333
        for (Permission perm : permissions) {
00a25f4c4d44 8056179: Store permissions in concurrent collections in PermissionCollection subclasses
mullan
parents: 29492
diff changeset
   334
            perms.put(perm, Boolean.TRUE);
00a25f4c4d44 8056179: Store permissions in concurrent collections in PermissionCollection subclasses
mullan
parents: 29492
diff changeset
   335
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
}