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