src/java.base/share/classes/javax/security/auth/PrivateCredentialPermission.java
author chegar
Thu, 17 Oct 2019 20:54:25 +0100
branchdatagramsocketimpl-branch
changeset 58679 9c3209ff7550
parent 58678 9cf78a70fa4f
parent 58519 6e017b301287
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: 53018
diff changeset
     2
 * Copyright (c) 1999, 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 javax.security.auth;
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.text.MessageFormat;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.security.Permission;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.security.PermissionCollection;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.security.Principal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import sun.security.util.ResourcesMgr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * This class is used to protect access to private Credentials
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 10709
diff changeset
    37
 * belonging to a particular {@code Subject}.  The {@code Subject}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * is represented by a Set of Principals.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 *
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 10709
diff changeset
    40
 * <p> The target name of this {@code Permission} specifies
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * a Credential class name, and a Set of Principals.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * The only valid value for this Permission's actions is, "read".
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * The target name must abide by the following syntax:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 *      CredentialClass {PrincipalClass "PrincipalName"}*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * For example, the following permission grants access to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * com.sun.PrivateCredential owned by Subjects which have
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * a com.sun.Principal with the name, "duke".  Note that although
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * this example, as well as all the examples below, do not contain
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * Codebase, SignedBy, or Principal information in the grant statement
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * (for simplicity reasons), actual policy configurations should
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * specify that information when appropriate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 *    grant {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 *      permission javax.security.auth.PrivateCredentialPermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 *              "com.sun.PrivateCredential com.sun.Principal \"duke\"",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 *              "read";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 *    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * If CredentialClass is "*", then access is granted to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * all private Credentials belonging to the specified
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 10709
diff changeset
    68
 * {@code Subject}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * If "PrincipalName" is "*", then access is granted to the
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 10709
diff changeset
    70
 * specified Credential owned by any {@code Subject} that has the
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 10709
diff changeset
    71
 * specified {@code Principal} (the actual PrincipalName doesn't matter).
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * For example, the following grants access to the
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 10709
diff changeset
    73
 * a.b.Credential owned by any {@code Subject} that has
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * an a.b.Principal.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 *    grant {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 *      permission javax.security.auth.PrivateCredentialPermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 *              "a.b.Credential a.b.Principal "*"",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 *              "read";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 *    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 * If both the PrincipalClass and "PrincipalName" are "*",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 * then access is granted to the specified Credential owned by
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 10709
diff changeset
    86
 * any {@code Subject}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 * <p> In addition, the PrincipalClass/PrincipalName pairing may be repeated:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 *    grant {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 *      permission javax.security.auth.PrivateCredentialPermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 *              "a.b.Credential a.b.Principal "duke" c.d.Principal "dukette"",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 *              "read";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
 *    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
 * The above grants access to the private Credential, "a.b.Credential",
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 10709
diff changeset
    99
 * belonging to a {@code Subject} with at least two associated Principals:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
 * "a.b.Principal" with the name, "duke", and "c.d.Principal", with the name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
 * "dukette".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
 *
45434
4582657c7260 8181082: class-level since tag issues in java.base & java.datatransfer module
mli
parents: 29492
diff changeset
   103
 * @since 1.4
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
public final class PrivateCredentialPermission extends Permission {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
57950
4612a3cfb927 8229999: Apply java.io.Serial annotations to security types in java.base
darcy
parents: 53018
diff changeset
   107
    @java.io.Serial
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    private static final long serialVersionUID = 5284372143517237068L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    private static final CredOwner[] EMPTY_PRINCIPALS = new CredOwner[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    private String credentialClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * @serial The Principals associated with this permission.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     *          The set contains elements of type,
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 10709
diff changeset
   120
     *          {@code PrivateCredentialPermission.CredOwner}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     */
58519
6e017b301287 8231262: Suppress warnings on non-serializable instance fields in security libs serializable classes
darcy
parents: 57950
diff changeset
   122
    @SuppressWarnings("serial") // Not statically typed as Serializable
10709
d865c9f21240 7092375: Security Libraries don't build with javac -Werror
xuelei
parents: 9035
diff changeset
   123
    private Set<Principal> principals;  // ignored - kept around for compatibility
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    private transient CredOwner[] credOwners;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    private boolean testing = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    /**
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 10709
diff changeset
   132
     * Create a new {@code PrivateCredentialPermission}
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 10709
diff changeset
   133
     * with the specified {@code credentialClass} and Principals.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    PrivateCredentialPermission(String credentialClass,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
                        Set<Principal> principals) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        super(credentialClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        this.credentialClass = credentialClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        synchronized(principals) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
            if (principals.size() == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
                this.credOwners = EMPTY_PRINCIPALS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
                this.credOwners = new CredOwner[principals.size()];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
                int index = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
                Iterator<Principal> i = principals.iterator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
                while (i.hasNext()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
                    Principal p = i.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
                    this.credOwners[index++] = new CredOwner
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
                                                (p.getClass().getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
                                                p.getName());
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
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    /**
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 10709
diff changeset
   159
     * Creates a new {@code PrivateCredentialPermission}
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 10709
diff changeset
   160
     * with the specified {@code name}.  The {@code name}
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 10709
diff changeset
   161
     * specifies both a Credential class and a {@code Principal} Set.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * @param name the name specifying the Credential class and
29492
a4bf9a570035 8028266: Tidy warnings cleanup for packages java.security/javax.security
avstepan
parents: 25859
diff changeset
   164
     *          {@code Principal} Set.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * @param actions the actions specifying that the Credential can be read.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     *
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 10709
diff changeset
   168
     * @throws IllegalArgumentException if {@code name} does not conform
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 10709
diff changeset
   169
     *          to the correct syntax or if {@code actions} is not "read".
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    public PrivateCredentialPermission(String name, String actions) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        super(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        if (!"read".equalsIgnoreCase(actions))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
            throw new IllegalArgumentException
7179
4afb81e50183 6987827: security/util/Resources.java needs improvement
weijun
parents: 5506
diff changeset
   176
                (ResourcesMgr.getString("actions.can.only.be.read."));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        init(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * Returns the Class name of the Credential associated with this
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 10709
diff changeset
   182
     * {@code PrivateCredentialPermission}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * @return the Class name of the Credential associated with this
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 10709
diff changeset
   185
     *          {@code PrivateCredentialPermission}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    public String getCredentialClass() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        return credentialClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    /**
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 10709
diff changeset
   192
     * Returns the {@code Principal} classes and names
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 10709
diff changeset
   193
     * associated with this {@code PrivateCredentialPermission}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * The information is returned as a two-dimensional array (array[x][y]).
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 10709
diff changeset
   195
     * The 'x' value corresponds to the number of {@code Principal}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * class and name pairs.  When (y==0), it corresponds to
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 10709
diff changeset
   197
     * the {@code Principal} class value, and when (y==1),
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 10709
diff changeset
   198
     * it corresponds to the {@code Principal} name value.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * For example, array[0][0] corresponds to the class name of
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 10709
diff changeset
   200
     * the first {@code Principal} in the array.  array[0][1]
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 10709
diff changeset
   201
     * corresponds to the {@code Principal} name of the
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 10709
diff changeset
   202
     * first {@code Principal} in the array.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     *
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 10709
diff changeset
   204
     * @return the {@code Principal} class and names associated
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 10709
diff changeset
   205
     *          with this {@code PrivateCredentialPermission}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    public String[][] getPrincipals() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        if (credOwners == null || credOwners.length == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
            return new String[0][0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        String[][] pArray = new String[credOwners.length][2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        for (int i = 0; i < credOwners.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
            pArray[i][0] = credOwners[i].principalClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
            pArray[i][1] = credOwners[i].principalName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        return pArray;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    /**
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 10709
diff changeset
   222
     * Checks if this {@code PrivateCredentialPermission} implies
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 10709
diff changeset
   223
     * the specified {@code Permission}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * This method returns true if:
21955
abc02575919c 8029475: Fix more doclint issues in javax.security
darcy
parents: 18830
diff changeset
   228
     * <ul>
29492
a4bf9a570035 8028266: Tidy warnings cleanup for packages java.security/javax.security
avstepan
parents: 25859
diff changeset
   229
     * <li> {@code p} is an instanceof PrivateCredentialPermission and
a4bf9a570035 8028266: Tidy warnings cleanup for packages java.security/javax.security
avstepan
parents: 25859
diff changeset
   230
     * <li> the target name for {@code p} is implied by this object's
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     *          target name.  For example:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     *  [* P1 "duke"] implies [a.b.Credential P1 "duke"].
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     *  [C1 P1 "duke"] implies [C1 P1 "duke" P2 "dukette"].
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     *  [C1 P2 "dukette"] implies [C1 P1 "duke" P2 "dukette"].
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     *
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 10709
diff changeset
   239
     * @param p the {@code Permission} to check against.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     *
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 10709
diff changeset
   241
     * @return true if this {@code PrivateCredentialPermission} implies
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 10709
diff changeset
   242
     * the specified {@code Permission}, false if not.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    public boolean implies(Permission p) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        if (p == null || !(p instanceof PrivateCredentialPermission))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        PrivateCredentialPermission that = (PrivateCredentialPermission)p;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        if (!impliesCredentialClass(credentialClass, that.credentialClass))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        return impliesPrincipalSet(credOwners, that.credOwners);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    /**
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 10709
diff changeset
   258
     * Checks two {@code PrivateCredentialPermission} objects for
29492
a4bf9a570035 8028266: Tidy warnings cleanup for packages java.security/javax.security
avstepan
parents: 25859
diff changeset
   259
     * equality.  Checks that {@code obj} is a
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 10709
diff changeset
   260
     * {@code PrivateCredentialPermission},
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * and has the same credential class as this object,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * as well as the same Principals as this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * The order of the Principals in the respective Permission's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * target names is not relevant.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * @param obj the object we are testing for equality with this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     *
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 10709
diff changeset
   268
     * @return true if obj is a {@code PrivateCredentialPermission},
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     *          has the same credential class as this object,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     *          and has the same Principals as this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    public boolean equals(Object obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        if (obj == this)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        if (! (obj instanceof PrivateCredentialPermission))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        PrivateCredentialPermission that = (PrivateCredentialPermission)obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        return (this.implies(that) && that.implies(this));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     * Returns the hash code value for this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     * @return a hash code value for this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        return this.credentialClass.hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     * Returns the "canonical string representation" of the actions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     * This method always returns the String, "read".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     * @return the actions (always returns "read").
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    public String getActions() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        return "read";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     * Return a homogeneous collection of PrivateCredentialPermissions
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 10709
diff changeset
   305
     * in a {@code PermissionCollection}.
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 10709
diff changeset
   306
     * No such {@code PermissionCollection} is defined,
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 10709
diff changeset
   307
     * so this method always returns {@code null}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * @return null in all cases.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    public PermissionCollection newPermissionCollection() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    private void init(String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
53018
8bf9268df0e2 8215281: Use String.isEmpty() when applicable in java.base
redestad
parents: 47216
diff changeset
   317
        if (name == null || name.trim().isEmpty()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
            throw new IllegalArgumentException("invalid empty name");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
7970
af1579474d16 7008728: diamond conversion of basic security, permissions, authentication
smarks
parents: 7179
diff changeset
   321
        ArrayList<CredOwner> pList = new ArrayList<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        StringTokenizer tokenizer = new StringTokenizer(name, " ", true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        String principalClass = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        String principalName = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        if (testing)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
            System.out.println("whole name = " + name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        // get the Credential Class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        credentialClass = tokenizer.nextToken();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        if (testing)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
            System.out.println("Credential Class = " + credentialClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        if (tokenizer.hasMoreTokens() == false) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
            MessageFormat form = new MessageFormat(ResourcesMgr.getString
7179
4afb81e50183 6987827: security/util/Resources.java needs improvement
weijun
parents: 5506
diff changeset
   336
                ("permission.name.name.syntax.invalid."));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
            Object[] source = {name};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
            throw new IllegalArgumentException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
                (form.format(source) + ResourcesMgr.getString
7179
4afb81e50183 6987827: security/util/Resources.java needs improvement
weijun
parents: 5506
diff changeset
   340
                        ("Credential.Class.not.followed.by.a.Principal.Class.and.Name"));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        while (tokenizer.hasMoreTokens()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
            // skip delimiter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
            tokenizer.nextToken();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
            // get the Principal Class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
            principalClass = tokenizer.nextToken();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
            if (testing)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
                System.out.println("    Principal Class = " + principalClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
            if (tokenizer.hasMoreTokens() == false) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
                MessageFormat form = new MessageFormat(ResourcesMgr.getString
7179
4afb81e50183 6987827: security/util/Resources.java needs improvement
weijun
parents: 5506
diff changeset
   355
                        ("permission.name.name.syntax.invalid."));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
                Object[] source = {name};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
                throw new IllegalArgumentException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
                        (form.format(source) + ResourcesMgr.getString
7179
4afb81e50183 6987827: security/util/Resources.java needs improvement
weijun
parents: 5506
diff changeset
   359
                        ("Principal.Class.not.followed.by.a.Principal.Name"));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
            // skip delimiter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
            tokenizer.nextToken();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
            // get the Principal Name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
            principalName = tokenizer.nextToken();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
            if (!principalName.startsWith("\"")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
                MessageFormat form = new MessageFormat(ResourcesMgr.getString
7179
4afb81e50183 6987827: security/util/Resources.java needs improvement
weijun
parents: 5506
diff changeset
   370
                        ("permission.name.name.syntax.invalid."));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
                Object[] source = {name};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
                throw new IllegalArgumentException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
                        (form.format(source) + ResourcesMgr.getString
7179
4afb81e50183 6987827: security/util/Resources.java needs improvement
weijun
parents: 5506
diff changeset
   374
                        ("Principal.Name.must.be.surrounded.by.quotes"));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
            if (!principalName.endsWith("\"")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
                // we have a name with spaces in it --
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
                // keep parsing until we find the end quote,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
                // and keep the spaces in the name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
                while (tokenizer.hasMoreTokens()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
                    principalName = principalName + tokenizer.nextToken();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
                    if (principalName.endsWith("\""))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
                if (!principalName.endsWith("\"")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
                    MessageFormat form = new MessageFormat
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
                        (ResourcesMgr.getString
7179
4afb81e50183 6987827: security/util/Resources.java needs improvement
weijun
parents: 5506
diff changeset
   392
                        ("permission.name.name.syntax.invalid."));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
                    Object[] source = {name};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
                    throw new IllegalArgumentException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
                        (form.format(source) + ResourcesMgr.getString
7179
4afb81e50183 6987827: security/util/Resources.java needs improvement
weijun
parents: 5506
diff changeset
   396
                                ("Principal.Name.missing.end.quote"));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
            if (testing)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
                System.out.println("\tprincipalName = '" + principalName + "'");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
            principalName = principalName.substring
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
                                        (1, principalName.length() - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
            if (principalClass.equals("*") &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
                !principalName.equals("*")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
                    throw new IllegalArgumentException(ResourcesMgr.getString
7179
4afb81e50183 6987827: security/util/Resources.java needs improvement
weijun
parents: 5506
diff changeset
   409
                        ("PrivateCredentialPermission.Principal.Class.can.not.be.a.wildcard.value.if.Principal.Name.is.not.a.wildcard.value"));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
            if (testing)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
                System.out.println("\tprincipalName = '" + principalName + "'");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
            pList.add(new CredOwner(principalClass, principalName));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
        this.credOwners = new CredOwner[pList.size()];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
        pList.toArray(this.credOwners);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
    private boolean impliesCredentialClass(String thisC, String thatC) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
        // this should never happen
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        if (thisC == null || thatC == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
        if (testing)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
            System.out.println("credential class comparison: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
                                thisC + "/" + thatC);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        if (thisC.equals("*"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
         * XXX let's not enable this for now --
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
         *      if people want it, we'll enable it later
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
        if (thisC.endsWith("*")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
            String cClass = thisC.substring(0, thisC.length() - 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
            return thatC.startsWith(cClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
        */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
        return thisC.equals(thatC);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
    private boolean impliesPrincipalSet(CredOwner[] thisP, CredOwner[] thatP) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        // this should never happen
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
        if (thisP == null || thatP == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
        if (thatP.length == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
        if (thisP.length == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
        for (int i = 0; i < thisP.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
            boolean foundMatch = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
            for (int j = 0; j < thatP.length; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
                if (thisP[i].implies(thatP[j])) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
                    foundMatch = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
            if (!foundMatch) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
     * Reads this object from a stream (i.e., deserializes it)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
     */
57950
4612a3cfb927 8229999: Apply java.io.Serial annotations to security types in java.base
darcy
parents: 53018
diff changeset
   479
    @java.io.Serial
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
    private void readObject(java.io.ObjectInputStream s) throws
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
                                        java.io.IOException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
                                        ClassNotFoundException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
        s.defaultReadObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
        // perform new initialization from the permission name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
24685
215fa91e1b4c 8044461: Cleanup new Boolean and single character strings
rriggs
parents: 21955
diff changeset
   488
        if (getName().indexOf(' ') == -1 && getName().indexOf('"') == -1) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
            // name only has a credential class specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
            credentialClass = getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
            credOwners = EMPTY_PRINCIPALS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
            // perform regular initialization
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
            init(getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
     * @serial include
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
    static class CredOwner implements java.io.Serializable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
57950
4612a3cfb927 8229999: Apply java.io.Serial annotations to security types in java.base
darcy
parents: 53018
diff changeset
   506
        @java.io.Serial
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
        private static final long serialVersionUID = -5607449830436408266L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
         * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
        String principalClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
         * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
        String principalName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
        CredOwner(String principalClass, String principalName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
            this.principalClass = principalClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
            this.principalName = principalName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
        public boolean implies(Object obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
            if (obj == null || !(obj instanceof CredOwner))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
            CredOwner that = (CredOwner)obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
            if (principalClass.equals("*") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
                principalClass.equals(that.principalClass)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
                if (principalName.equals("*") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
                    principalName.equals(that.principalName)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
                    return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
             * XXX no code yet to support a.b.*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
        public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
            MessageFormat form = new MessageFormat(ResourcesMgr.getString
7179
4afb81e50183 6987827: security/util/Resources.java needs improvement
weijun
parents: 5506
diff changeset
   547
                ("CredOwner.Principal.Class.class.Principal.Name.name"));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
            Object[] source = {principalClass, principalName};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
            return (form.format(source));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
}