jdk/src/java.base/share/classes/sun/security/provider/PolicyParser.java
author chegar
Wed, 03 Dec 2014 14:22:58 +0000
changeset 27565 729f9700483a
parent 25859 3317bb8137f4
child 30374 2abaf49910ea
permissions -rw-r--r--
8049367: Modular Run-Time Images Reviewed-by: chegar, dfuchs, ihse, joehw, mullan, psandoz, wetmore Contributed-by: alan.bateman@oracle.com, alex.buckley@oracle.com, bradford.wetmore@oracle.com, chris.hegarty@oracle.com, erik.joelsson@oracle.com, james.laskey@oracle.com, jonathan.gibbons@oracle.com, karen.kinnear@oracle.com, magnus.ihse.bursie@oracle.com, mandy.chung@oracle.com, mark.reinhold@oracle.com, paul.sandoz@oracle.com, sundararajan.athijegannathan@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
25402
0c24d9aa8fb9 7065233: To interpret case-insensitive string locale independently
juh
parents: 15664
diff changeset
     2
 * Copyright (c) 1997, 2014, 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 sun.security.provider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.lang.RuntimePermission;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.net.SocketPermission;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.net.URL;
15013
4a17ca431caf 7019834: Eliminate dependency from PolicyFile to com.sun.security.auth.PrincipalComparator
mullan
parents: 7179
diff changeset
    32
import java.security.GeneralSecurityException;
4a17ca431caf 7019834: Eliminate dependency from PolicyFile to com.sun.security.auth.PrincipalComparator
mullan
parents: 7179
diff changeset
    33
import java.security.Principal;
4a17ca431caf 7019834: Eliminate dependency from PolicyFile to com.sun.security.auth.PrincipalComparator
mullan
parents: 7179
diff changeset
    34
import java.text.MessageFormat;
15664
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
    35
import java.util.*;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import javax.security.auth.x500.X500Principal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import sun.security.util.Debug;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import sun.security.util.PropertyExpander;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import sun.security.util.ResourcesMgr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * The policy for a Java runtime (specifying
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * which permissions are available for code from various principals)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * is represented as a separate
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * persistent configuration.  The configuration may be stored as a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * flat ASCII file, as a serialized binary file of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * the Policy class, or as a database. <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * <p>The Java runtime creates one global Policy object, which is used to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * represent the static policy configuration file.  It is consulted by
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * a ProtectionDomain when the protection domain initializes its set of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * permissions. <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * <p>The Policy <code>init</code> method parses the policy
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * configuration file, and then
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * populates the Policy object.  The Policy object is agnostic in that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * it is not involved in making policy decisions.  It is merely the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * Java runtime representation of the persistent policy configuration
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * file. <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * <p>When a protection domain needs to initialize its set of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * permissions, it executes code such as the following
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * to ask the global Policy object to populate a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * Permissions object with the appropriate permissions:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 *  policy = Policy.getPolicy();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 *  Permissions perms = policy.getPermissions(protectiondomain)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 *
15013
4a17ca431caf 7019834: Eliminate dependency from PolicyFile to com.sun.security.auth.PrincipalComparator
mullan
parents: 7179
diff changeset
    71
 * <p>The protection domain contains a CodeSource
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * object, which encapsulates its codebase (URL) and public key attributes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * It also contains the principals associated with the domain.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * The Policy object evaluates the global policy in light of who the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * principal is and what the code source is and returns an appropriate
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * Permissions object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * @author Roland Schemers
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * @author Ram Marti
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
public class PolicyParser {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    private Vector<GrantEntry> grantEntries;
15664
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
    87
    private Map<String, DomainEntry> domainEntries;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    // Convenience variables for parsing
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    private static final Debug debug = Debug.getInstance("parser",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
                                                "\t[Policy Parser]");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    private StreamTokenizer st;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    private int lookahead;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    private boolean expandProp = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    private String keyStoreUrlString = null; // unexpanded
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    private String keyStoreType = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    private String keyStoreProvider = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    private String storePassURL = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    private String expand(String value)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        throws PropertyExpander.ExpandException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        return expand(value, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    private String expand(String value, boolean encodeURL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        throws PropertyExpander.ExpandException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        if (!expandProp) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
            return value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
            return PropertyExpander.expand(value, encodeURL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * Creates a PolicyParser object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    public PolicyParser() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        grantEntries = new Vector<GrantEntry>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    public PolicyParser(boolean expandProp) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        this();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        this.expandProp = expandProp;
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
     * Reads a policy configuration into the Policy object using a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * Reader object. <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * @param policy the policy Reader object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * @exception ParsingException if the policy configuration contains
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     *          a syntax error.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * @exception IOException if an error occurs while reading the policy
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     *          configuration.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    public void read(Reader policy)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        throws ParsingException, IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        if (!(policy instanceof BufferedReader)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            policy = new BufferedReader(policy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
         * Configure the stream tokenizer:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
         *      Recognize strings between "..."
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
         *      Don't convert words to lowercase
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
         *      Recognize both C-style and C++-style comments
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
         *      Treat end-of-line as white space, not as a token
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        st   = new StreamTokenizer(policy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        st.resetSyntax();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        st.wordChars('a', 'z');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        st.wordChars('A', 'Z');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        st.wordChars('.', '.');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        st.wordChars('0', '9');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        st.wordChars('_', '_');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        st.wordChars('$', '$');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        st.wordChars(128 + 32, 255);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        st.whitespaceChars(0, ' ');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        st.commentChar('/');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        st.quoteChar('\'');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        st.quoteChar('"');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        st.lowerCaseMode(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        st.ordinaryChar('/');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        st.slashSlashComments(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        st.slashStarComments(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
         * The main parsing loop.  The loop is executed once
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
         * for each entry in the config file.      The entries
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
         * are delimited by semicolons.   Once we've read in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
         * the information for an entry, go ahead and try to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
         * add it to the policy vector.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        lookahead = st.nextToken();
15664
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
   186
        GrantEntry ge = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        while (lookahead != StreamTokenizer.TT_EOF) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            if (peek("grant")) {
15664
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
   189
                ge = parseGrantEntry();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                // could be null if we couldn't expand a property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
                if (ge != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
                    add(ge);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            } else if (peek("keystore") && keyStoreUrlString==null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
                // only one keystore entry per policy file, others will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
                // ignored
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
                parseKeyStoreEntry();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
            } else if (peek("keystorePasswordURL") && storePassURL==null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
                // only one keystore passwordURL per policy file, others will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                // ignored
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                parseStorePassURL();
15664
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
   201
            } else if (ge == null && keyStoreUrlString == null &&
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
   202
                storePassURL == null && peek("domain")) {
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
   203
                if (domainEntries == null) {
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
   204
                    domainEntries = new TreeMap<>();
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
   205
                }
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
   206
                DomainEntry de = parseDomainEntry();
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
   207
                if (de != null) {
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
   208
                    String domainName = de.getName();
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
   209
                    if (!domainEntries.containsKey(domainName)) {
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
   210
                        domainEntries.put(domainName, de);
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
   211
                    } else {
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
   212
                        MessageFormat form =
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
   213
                            new MessageFormat(ResourcesMgr.getString(
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
   214
                                "duplicate.keystore.domain.name"));
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
   215
                        Object[] source = {domainName};
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
   216
                        throw new ParsingException(form.format(source));
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
   217
                    }
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
   218
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                // error?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
            match(";");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        if (keyStoreUrlString == null && storePassURL != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            throw new ParsingException(ResourcesMgr.getString
7179
4afb81e50183 6987827: security/util/Resources.java needs improvement
weijun
parents: 5506
diff changeset
   227
                ("keystorePasswordURL.can.not.be.specified.without.also.specifying.keystore"));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    public void add(GrantEntry ge)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        grantEntries.addElement(ge);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    public void replace(GrantEntry origGe, GrantEntry newGe)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        grantEntries.setElementAt(newGe, grantEntries.indexOf(origGe));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    public boolean remove(GrantEntry ge)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        return grantEntries.removeElement(ge);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * Returns the (possibly expanded) keystore location, or null if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     * expansion fails.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    public String getKeyStoreUrl() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
            if (keyStoreUrlString!=null && keyStoreUrlString.length()!=0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
                return expand(keyStoreUrlString, true).replace
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
                                                (File.separatorChar, '/');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        } catch (PropertyExpander.ExpandException peee) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
            if (debug != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
                debug.println(peee.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    public void setKeyStoreUrl(String url) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        keyStoreUrlString = url;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    public String getKeyStoreType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        return keyStoreType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    public void setKeyStoreType(String type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        keyStoreType = type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    public String getKeyStoreProvider() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        return keyStoreProvider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    public void setKeyStoreProvider(String provider) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        keyStoreProvider = provider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    public String getStorePassURL() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
            if (storePassURL!=null && storePassURL.length()!=0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
                return expand(storePassURL, true).replace
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
                                                (File.separatorChar, '/');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        } catch (PropertyExpander.ExpandException peee) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
            if (debug != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
                debug.println(peee.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    public void setStorePassURL(String storePassURL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        this.storePassURL = storePassURL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     * Enumerate all the entries in the global policy object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     * This method is used by policy admin tools.   The tools
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     * should use the Enumeration methods on the returned object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     * to fetch the elements sequentially.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
    public Enumeration<GrantEntry> grantElements(){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        return grantEntries.elements();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
15664
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
   314
    public Collection<DomainEntry> getDomainEntries() {
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
   315
        return domainEntries.values();
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
   316
    }
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
   317
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     * write out the policy
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
    public void write(Writer policy)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        PrintWriter out = new PrintWriter(new BufferedWriter(policy));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        Enumeration<GrantEntry> enum_ = grantElements();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        out.println("/* AUTOMATICALLY GENERATED ON "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
                    (new java.util.Date()) + "*/");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        out.println("/* DO NOT EDIT */");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        out.println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        // write the (unexpanded) keystore entry as the first entry of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        // policy file
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
        if (keyStoreUrlString != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
            writeKeyStoreEntry(out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        if (storePassURL != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
            writeStorePassURL(out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        // write "grant" entries
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        while (enum_.hasMoreElements()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
            GrantEntry ge = enum_.nextElement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
            ge.write(out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
            out.println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        out.flush();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     * parses a keystore entry
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
    private void parseKeyStoreEntry() throws ParsingException, IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        match("keystore");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        keyStoreUrlString = match("quoted string");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        // parse keystore type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        if (!peek(",")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
            return; // default type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
        match(",");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
        if (peek("\"")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
            keyStoreType = match("quoted string");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
            throw new ParsingException(st.lineno(),
7179
4afb81e50183 6987827: security/util/Resources.java needs improvement
weijun
parents: 5506
diff changeset
   368
                        ResourcesMgr.getString("expected.keystore.type"));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
        // parse keystore provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
        if (!peek(",")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
            return; // provider optional
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        match(",");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        if (peek("\"")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
            keyStoreProvider = match("quoted string");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
            throw new ParsingException(st.lineno(),
7179
4afb81e50183 6987827: security/util/Resources.java needs improvement
weijun
parents: 5506
diff changeset
   381
                        ResourcesMgr.getString("expected.keystore.provider"));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
    private void parseStorePassURL() throws ParsingException, IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        match("keyStorePasswordURL");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        storePassURL = match("quoted string");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     * writes the (unexpanded) keystore entry
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
    private void writeKeyStoreEntry(PrintWriter out) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        out.print("keystore \"");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
        out.print(keyStoreUrlString);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        out.print('"');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        if (keyStoreType != null && keyStoreType.length() > 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
            out.print(", \"" + keyStoreType + "\"");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        if (keyStoreProvider != null && keyStoreProvider.length() > 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
            out.print(", \"" + keyStoreProvider + "\"");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        out.println(";");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        out.println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
    private void writeStorePassURL(PrintWriter out) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
        out.print("keystorePasswordURL \"");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
        out.print(storePassURL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        out.print('"');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        out.println(";");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
        out.println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     * parse a Grant entry
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
    private GrantEntry parseGrantEntry()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
        throws ParsingException, IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
        GrantEntry e = new GrantEntry();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
        LinkedList<PrincipalEntry> principals = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
        boolean ignoreEntry = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
        match("grant");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        while(!peek("{")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
            if (peekAndMatch("Codebase")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
                if (e.codeBase != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
                    throw new ParsingException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
                            st.lineno(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
                            ResourcesMgr.getString
7179
4afb81e50183 6987827: security/util/Resources.java needs improvement
weijun
parents: 5506
diff changeset
   432
                                ("multiple.Codebase.expressions"));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
                e.codeBase = match("quoted string");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
                peekAndMatch(",");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
            } else if (peekAndMatch("SignedBy")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
                if (e.signedBy != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
                    throw new ParsingException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
                            st.lineno(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
                            ResourcesMgr.getString(
7179
4afb81e50183 6987827: security/util/Resources.java needs improvement
weijun
parents: 5506
diff changeset
   440
                                "multiple.SignedBy.expressions"));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
                e.signedBy = match("quoted string");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
                // verify syntax of the aliases
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
                StringTokenizer aliases = new StringTokenizer(e.signedBy,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
                                                              ",", true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
                int actr = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
                int cctr = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
                while (aliases.hasMoreTokens()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
                    String alias = aliases.nextToken().trim();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
                    if (alias.equals(","))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
                        cctr++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
                    else if (alias.length() > 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
                        actr++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
                if (actr <= cctr)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
                    throw new ParsingException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
                            st.lineno(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
                            ResourcesMgr.getString(
7179
4afb81e50183 6987827: security/util/Resources.java needs improvement
weijun
parents: 5506
diff changeset
   459
                                "SignedBy.has.empty.alias"));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
                peekAndMatch(",");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
            } else if (peekAndMatch("Principal")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
                if (principals == null) {
15013
4a17ca431caf 7019834: Eliminate dependency from PolicyFile to com.sun.security.auth.PrincipalComparator
mullan
parents: 7179
diff changeset
   464
                    principals = new LinkedList<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
                String principalClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
                String principalName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
                if (peek("\"")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
                    // both the principalClass and principalName
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
                    // will be replaced later
15013
4a17ca431caf 7019834: Eliminate dependency from PolicyFile to com.sun.security.auth.PrincipalComparator
mullan
parents: 7179
diff changeset
   473
                    principalClass = PrincipalEntry.REPLACE_NAME;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
                    principalName = match("principal type");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
                    // check for principalClass wildcard
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
                    if (peek("*")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
                        match("*");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
                        principalClass = PrincipalEntry.WILDCARD_CLASS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
                        principalClass = match("principal type");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
                    // check for principalName wildcard
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
                    if (peek("*")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
                        match("*");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
                        principalName = PrincipalEntry.WILDCARD_NAME;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
                        principalName = match("quoted string");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
                    // disallow WILDCARD_CLASS && actual name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
                    if (principalClass.equals(PrincipalEntry.WILDCARD_CLASS) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
                        !principalName.equals(PrincipalEntry.WILDCARD_NAME)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
                        if (debug != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
                                debug.println("disallowing principal that " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
                                    "has WILDCARD class but no WILDCARD name");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
                        throw new ParsingException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
                                (st.lineno(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
                                 ResourcesMgr.getString
7179
4afb81e50183 6987827: security/util/Resources.java needs improvement
weijun
parents: 5506
diff changeset
   502
                                    ("can.not.specify.Principal.with.a.wildcard.class.without.a.wildcard.name"));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
                    principalName = expand(principalName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
                    if (principalClass.equals
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
                                ("javax.security.auth.x500.X500Principal") &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
                        !principalName.equals(PrincipalEntry.WILDCARD_NAME)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
                        // 4702543:  X500 names with an EmailAddress
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
                        // were encoded incorrectly.  construct a new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
                        // X500Principal with correct encoding.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
                        X500Principal p = new X500Principal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
                                ((new X500Principal(principalName)).toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
                        principalName = p.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
                    principals.add
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
                        (new PrincipalEntry(principalClass, principalName));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
                } catch (PropertyExpander.ExpandException peee) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
                    // ignore the entire policy entry
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
                    // but continue parsing all the info
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
                    // so we can get to the next entry
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
                    if (debug != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
                        debug.println("principal name expansion failed: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
                                        principalName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
                    ignoreEntry = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
                peekAndMatch(",");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
                throw new ParsingException(st.lineno(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
                                  ResourcesMgr.getString(
7179
4afb81e50183 6987827: security/util/Resources.java needs improvement
weijun
parents: 5506
diff changeset
   539
                                      "expected.codeBase.or.SignedBy.or.Principal"));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
        if (principals != null) e.principals = principals;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
        match("{");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
        while(!peek("}")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
            if (peek("Permission")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
                    PermissionEntry pe = parsePermissionEntry();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
                    e.add(pe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
                } catch (PropertyExpander.ExpandException peee) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
                    // ignore. The add never happened
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
                    if (debug != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
                        debug.println(peee.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
                    skipEntry();  // BugId 4219343
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
                match(";");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
                throw new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
                    ParsingException(st.lineno(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
                                     ResourcesMgr.getString(
7179
4afb81e50183 6987827: security/util/Resources.java needs improvement
weijun
parents: 5506
diff changeset
   563
                                        "expected.permission.entry"));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
        match("}");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
            if (e.signedBy != null) e.signedBy = expand(e.signedBy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
            if (e.codeBase != null) {
27565
729f9700483a 8049367: Modular Run-Time Images
chegar
parents: 25859
diff changeset
   571
                e.codeBase = expand(e.codeBase, true).replace
729f9700483a 8049367: Modular Run-Time Images
chegar
parents: 25859
diff changeset
   572
                                    (File.separatorChar, '/');
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
        } catch (PropertyExpander.ExpandException peee) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
            if (debug != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
                debug.println(peee.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
        return (ignoreEntry == true) ? null : e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
     * parse a Permission entry
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
    private PermissionEntry parsePermissionEntry()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
        throws ParsingException, IOException, PropertyExpander.ExpandException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
        PermissionEntry e = new PermissionEntry();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
        // Permission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
        match("Permission");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
        e.permission = match("permission type");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
        if (peek("\"")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
            // Permission name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
            e.name = expand(match("quoted string"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
        if (!peek(",")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
            return e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
        match(",");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
        if (peek("\"")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
                e.action = expand(match("quoted string"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
                if (!peek(",")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
                    return e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
                match(",");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
        if (peekAndMatch("SignedBy")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
            e.signedBy = expand(match("quoted string"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
        return e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
15664
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
   620
    /**
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
   621
     * parse a domain entry
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
   622
     */
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
   623
    private DomainEntry parseDomainEntry()
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
   624
        throws ParsingException, IOException
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
   625
    {
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
   626
        boolean ignoreEntry = false;
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
   627
        DomainEntry domainEntry;
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
   628
        String name = null;
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
   629
        Map<String, String> properties = new HashMap<>();
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
   630
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
   631
        match("domain");
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
   632
        name = match("domain name");
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
   633
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
   634
        while(!peek("{")) {
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
   635
            // get the domain properties
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
   636
            properties = parseProperties("{");
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
   637
        }
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
   638
        match("{");
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
   639
        domainEntry = new DomainEntry(name, properties);
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
   640
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
   641
        while(!peek("}")) {
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
   642
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
   643
            match("keystore");
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
   644
            name = match("keystore name");
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
   645
            // get the keystore properties
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
   646
            if (!peek("}")) {
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
   647
                properties = parseProperties(";");
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
   648
            }
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
   649
            match(";");
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
   650
            domainEntry.add(new KeyStoreEntry(name, properties));
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
   651
        }
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
   652
        match("}");
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
   653
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
   654
        return (ignoreEntry == true) ? null : domainEntry;
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
   655
    }
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
   656
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
   657
    /*
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
   658
     * Return a collection of domain properties or keystore properties.
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
   659
     */
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
   660
    private Map<String, String> parseProperties(String terminator)
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
   661
        throws ParsingException, IOException {
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
   662
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
   663
        Map<String, String> properties = new HashMap<>();
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
   664
        String key;
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
   665
        String value;
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
   666
        while (!peek(terminator)) {
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
   667
            key = match("property name");
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
   668
            match("=");
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
   669
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
   670
            try {
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
   671
                value = expand(match("quoted string"));
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
   672
            } catch (PropertyExpander.ExpandException peee) {
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
   673
                throw new IOException(peee.getLocalizedMessage());
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
   674
            }
25402
0c24d9aa8fb9 7065233: To interpret case-insensitive string locale independently
juh
parents: 15664
diff changeset
   675
            properties.put(key.toLowerCase(Locale.ENGLISH), value);
15664
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
   676
        }
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
   677
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
   678
        return properties;
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
   679
    }
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
   680
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
    private boolean peekAndMatch(String expect)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
        throws ParsingException, IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
        if (peek(expect)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
            match(expect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
    private boolean peek(String expect) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
        boolean found = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
        switch (lookahead) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
        case StreamTokenizer.TT_WORD:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
            if (expect.equalsIgnoreCase(st.sval))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
                found = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
        case ',':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
            if (expect.equalsIgnoreCase(","))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
                found = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
        case '{':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
            if (expect.equalsIgnoreCase("{"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
                found = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
        case '}':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
            if (expect.equalsIgnoreCase("}"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
                found = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
        case '"':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
            if (expect.equalsIgnoreCase("\""))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
                found = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
        case '*':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
            if (expect.equalsIgnoreCase("*"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
                found = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
            break;
15664
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
   721
        case ';':
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
   722
            if (expect.equalsIgnoreCase(";"))
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
   723
                found = true;
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
   724
            break;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
        return found;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
    private String match(String expect)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
        throws ParsingException, IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
        String value = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
        switch (lookahead) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
        case StreamTokenizer.TT_NUMBER:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
            throw new ParsingException(st.lineno(), expect,
7179
4afb81e50183 6987827: security/util/Resources.java needs improvement
weijun
parents: 5506
diff changeset
   739
                                       ResourcesMgr.getString("number.") +
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
                                       String.valueOf(st.nval));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
        case StreamTokenizer.TT_EOF:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
            MessageFormat form = new MessageFormat(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
                    ResourcesMgr.getString
7179
4afb81e50183 6987827: security/util/Resources.java needs improvement
weijun
parents: 5506
diff changeset
   744
                            ("expected.expect.read.end.of.file."));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
            Object[] source = {expect};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
            throw new ParsingException(form.format(source));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
        case StreamTokenizer.TT_WORD:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
            if (expect.equalsIgnoreCase(st.sval)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
                lookahead = st.nextToken();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
            } else if (expect.equalsIgnoreCase("permission type")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
                value = st.sval;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
                lookahead = st.nextToken();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
            } else if (expect.equalsIgnoreCase("principal type")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
                value = st.sval;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
                lookahead = st.nextToken();
15664
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
   756
            } else if (expect.equalsIgnoreCase("domain name") ||
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
   757
                       expect.equalsIgnoreCase("keystore name") ||
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
   758
                       expect.equalsIgnoreCase("property name")) {
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
   759
                value = st.sval;
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
   760
                lookahead = st.nextToken();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
                 throw new ParsingException(st.lineno(), expect,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
                                            st.sval);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
        case '"':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
            if (expect.equalsIgnoreCase("quoted string")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
                value = st.sval;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
                lookahead = st.nextToken();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
            } else if (expect.equalsIgnoreCase("permission type")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
                value = st.sval;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
                lookahead = st.nextToken();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
            } else if (expect.equalsIgnoreCase("principal type")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
                value = st.sval;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
                lookahead = st.nextToken();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
                throw new ParsingException(st.lineno(), expect, st.sval);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
        case ',':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
            if (expect.equalsIgnoreCase(","))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
                lookahead = st.nextToken();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
                throw new ParsingException(st.lineno(), expect, ",");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
        case '{':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
            if (expect.equalsIgnoreCase("{"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
                lookahead = st.nextToken();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
                throw new ParsingException(st.lineno(), expect, "{");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
        case '}':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
            if (expect.equalsIgnoreCase("}"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
                lookahead = st.nextToken();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
                throw new ParsingException(st.lineno(), expect, "}");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
        case ';':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
            if (expect.equalsIgnoreCase(";"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
                lookahead = st.nextToken();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
                throw new ParsingException(st.lineno(), expect, ";");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
        case '*':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
            if (expect.equalsIgnoreCase("*"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
                lookahead = st.nextToken();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
                throw new ParsingException(st.lineno(), expect, "*");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
            break;
15664
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
   810
        case '=':
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
   811
            if (expect.equalsIgnoreCase("="))
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
   812
                lookahead = st.nextToken();
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
   813
            else
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
   814
                throw new ParsingException(st.lineno(), expect, "=");
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
   815
            break;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
            throw new ParsingException(st.lineno(), expect,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
                               new String(new char[] {(char)lookahead}));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
        return value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
     * skip all tokens for this entry leaving the delimiter ";"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
     * in the stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
    private void skipEntry() throws ParsingException, IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
        while(lookahead != ';') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
            switch (lookahead) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
            case StreamTokenizer.TT_NUMBER:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
                throw new ParsingException(st.lineno(), ";",
7179
4afb81e50183 6987827: security/util/Resources.java needs improvement
weijun
parents: 5506
diff changeset
   832
                                          ResourcesMgr.getString("number.") +
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
                                          String.valueOf(st.nval));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
            case StreamTokenizer.TT_EOF:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
                throw new ParsingException(ResourcesMgr.getString
7179
4afb81e50183 6987827: security/util/Resources.java needs improvement
weijun
parents: 5506
diff changeset
   836
                        ("expected.read.end.of.file."));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
                lookahead = st.nextToken();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
     * Each grant entry in the policy configuration file is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
     * represented by a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
     * GrantEntry object.  <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
     * For example, the entry
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
     *      grant signedBy "Duke" {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
     *          permission java.io.FilePermission "/tmp", "read,write";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
     *      };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
     * is represented internally
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
     * pe = new PermissionEntry("java.io.FilePermission",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
     *                           "/tmp", "read,write");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
     * ge = new GrantEntry("Duke", null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
     * ge.add(pe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
     * @author Roland Schemers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
     * version 1.19, 05/21/98
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
    public static class GrantEntry {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
        public String signedBy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
        public String codeBase;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
        public LinkedList<PrincipalEntry> principals;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
        public Vector<PermissionEntry> permissionEntries;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
        public GrantEntry() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
            principals = new LinkedList<PrincipalEntry>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
            permissionEntries = new Vector<PermissionEntry>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
        public GrantEntry(String signedBy, String codeBase) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
            this.codeBase = codeBase;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
            this.signedBy = signedBy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
            principals = new LinkedList<PrincipalEntry>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
            permissionEntries = new Vector<PermissionEntry>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
        public void add(PermissionEntry pe)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
            permissionEntries.addElement(pe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
        public boolean remove(PrincipalEntry pe)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
            return principals.remove(pe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
        public boolean remove(PermissionEntry pe)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
            return permissionEntries.removeElement(pe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
        public boolean contains(PrincipalEntry pe)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
            return principals.contains(pe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
        public boolean contains(PermissionEntry pe)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
            return permissionEntries.contains(pe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
         * Enumerate all the permission entries in this GrantEntry.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
        public Enumeration<PermissionEntry> permissionElements(){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
            return permissionEntries.elements();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
        public void write(PrintWriter out) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
            out.print("grant");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
            if (signedBy != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
                out.print(" signedBy \"");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
                out.print(signedBy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
                out.print('"');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
                if (codeBase != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
                    out.print(", ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
            if (codeBase != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
                out.print(" codeBase \"");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
                out.print(codeBase);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
                out.print('"');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
                if (principals != null && principals.size() > 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
                    out.print(",\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
            if (principals != null && principals.size() > 0) {
15013
4a17ca431caf 7019834: Eliminate dependency from PolicyFile to com.sun.security.auth.PrincipalComparator
mullan
parents: 7179
diff changeset
   942
                Iterator<PrincipalEntry> pli = principals.iterator();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
                while (pli.hasNext()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
                    out.print("      ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
                    PrincipalEntry pe = pli.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
                    pe.write(out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
                    if (pli.hasNext())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
                        out.print(",\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
            out.println(" {");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
            Enumeration<PermissionEntry> enum_ = permissionEntries.elements();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
            while (enum_.hasMoreElements()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
                PermissionEntry pe = enum_.nextElement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
                out.write("  ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
                pe.write(out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
            out.println("};");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
        public Object clone() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
            GrantEntry ge = new GrantEntry();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
            ge.codeBase = this.codeBase;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
            ge.signedBy = this.signedBy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
            ge.principals = new LinkedList<PrincipalEntry>(this.principals);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
            ge.permissionEntries =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
                        new Vector<PermissionEntry>(this.permissionEntries);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
            return ge;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
     * Principal info (class and name) in a grant entry
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
     */
15013
4a17ca431caf 7019834: Eliminate dependency from PolicyFile to com.sun.security.auth.PrincipalComparator
mullan
parents: 7179
diff changeset
   975
    public static class PrincipalEntry implements Principal {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
        public static final String WILDCARD_CLASS = "WILDCARD_PRINCIPAL_CLASS";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
        public static final String WILDCARD_NAME = "WILDCARD_PRINCIPAL_NAME";
15013
4a17ca431caf 7019834: Eliminate dependency from PolicyFile to com.sun.security.auth.PrincipalComparator
mullan
parents: 7179
diff changeset
   979
        public static final String REPLACE_NAME = "PolicyParser.REPLACE_NAME";
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
        String principalClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
        String principalName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
        /**
15013
4a17ca431caf 7019834: Eliminate dependency from PolicyFile to com.sun.security.auth.PrincipalComparator
mullan
parents: 7179
diff changeset
   985
         * A PrincipalEntry consists of the Principal class and Principal name.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
         *
15013
4a17ca431caf 7019834: Eliminate dependency from PolicyFile to com.sun.security.auth.PrincipalComparator
mullan
parents: 7179
diff changeset
   987
         * @param principalClass the Principal class
4a17ca431caf 7019834: Eliminate dependency from PolicyFile to com.sun.security.auth.PrincipalComparator
mullan
parents: 7179
diff changeset
   988
         * @param principalName the Principal name
4a17ca431caf 7019834: Eliminate dependency from PolicyFile to com.sun.security.auth.PrincipalComparator
mullan
parents: 7179
diff changeset
   989
         * @throws NullPointerException if principalClass or principalName
4a17ca431caf 7019834: Eliminate dependency from PolicyFile to com.sun.security.auth.PrincipalComparator
mullan
parents: 7179
diff changeset
   990
         *                              are null
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
        public PrincipalEntry(String principalClass, String principalName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
            if (principalClass == null || principalName == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
                throw new NullPointerException(ResourcesMgr.getString(
7179
4afb81e50183 6987827: security/util/Resources.java needs improvement
weijun
parents: 5506
diff changeset
   995
                                  "null.principalClass.or.principalName"));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
            this.principalClass = principalClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
            this.principalName = principalName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
15013
4a17ca431caf 7019834: Eliminate dependency from PolicyFile to com.sun.security.auth.PrincipalComparator
mullan
parents: 7179
diff changeset
  1000
        boolean isWildcardName() {
4a17ca431caf 7019834: Eliminate dependency from PolicyFile to com.sun.security.auth.PrincipalComparator
mullan
parents: 7179
diff changeset
  1001
            return principalName.equals(WILDCARD_NAME);
4a17ca431caf 7019834: Eliminate dependency from PolicyFile to com.sun.security.auth.PrincipalComparator
mullan
parents: 7179
diff changeset
  1002
        }
4a17ca431caf 7019834: Eliminate dependency from PolicyFile to com.sun.security.auth.PrincipalComparator
mullan
parents: 7179
diff changeset
  1003
4a17ca431caf 7019834: Eliminate dependency from PolicyFile to com.sun.security.auth.PrincipalComparator
mullan
parents: 7179
diff changeset
  1004
        boolean isWildcardClass() {
4a17ca431caf 7019834: Eliminate dependency from PolicyFile to com.sun.security.auth.PrincipalComparator
mullan
parents: 7179
diff changeset
  1005
            return principalClass.equals(WILDCARD_CLASS);
4a17ca431caf 7019834: Eliminate dependency from PolicyFile to com.sun.security.auth.PrincipalComparator
mullan
parents: 7179
diff changeset
  1006
        }
4a17ca431caf 7019834: Eliminate dependency from PolicyFile to com.sun.security.auth.PrincipalComparator
mullan
parents: 7179
diff changeset
  1007
4a17ca431caf 7019834: Eliminate dependency from PolicyFile to com.sun.security.auth.PrincipalComparator
mullan
parents: 7179
diff changeset
  1008
        boolean isReplaceName() {
4a17ca431caf 7019834: Eliminate dependency from PolicyFile to com.sun.security.auth.PrincipalComparator
mullan
parents: 7179
diff changeset
  1009
            return principalClass.equals(REPLACE_NAME);
4a17ca431caf 7019834: Eliminate dependency from PolicyFile to com.sun.security.auth.PrincipalComparator
mullan
parents: 7179
diff changeset
  1010
        }
4a17ca431caf 7019834: Eliminate dependency from PolicyFile to com.sun.security.auth.PrincipalComparator
mullan
parents: 7179
diff changeset
  1011
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
        public String getPrincipalClass() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
            return principalClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
        public String getPrincipalName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
            return principalName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
        public String getDisplayClass() {
15013
4a17ca431caf 7019834: Eliminate dependency from PolicyFile to com.sun.security.auth.PrincipalComparator
mullan
parents: 7179
diff changeset
  1021
            if (isWildcardClass()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
                return "*";
15013
4a17ca431caf 7019834: Eliminate dependency from PolicyFile to com.sun.security.auth.PrincipalComparator
mullan
parents: 7179
diff changeset
  1023
            } else if (isReplaceName()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
                return "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
            else return principalClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
        public String getDisplayName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
            return getDisplayName(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
        public String getDisplayName(boolean addQuote) {
15013
4a17ca431caf 7019834: Eliminate dependency from PolicyFile to com.sun.security.auth.PrincipalComparator
mullan
parents: 7179
diff changeset
  1034
            if (isWildcardName()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
                return "*";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
                if (addQuote) return "\"" + principalName + "\"";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
                else return principalName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
15013
4a17ca431caf 7019834: Eliminate dependency from PolicyFile to com.sun.security.auth.PrincipalComparator
mullan
parents: 7179
diff changeset
  1043
        @Override
4a17ca431caf 7019834: Eliminate dependency from PolicyFile to com.sun.security.auth.PrincipalComparator
mullan
parents: 7179
diff changeset
  1044
        public String getName() {
4a17ca431caf 7019834: Eliminate dependency from PolicyFile to com.sun.security.auth.PrincipalComparator
mullan
parents: 7179
diff changeset
  1045
            return principalName;
4a17ca431caf 7019834: Eliminate dependency from PolicyFile to com.sun.security.auth.PrincipalComparator
mullan
parents: 7179
diff changeset
  1046
        }
4a17ca431caf 7019834: Eliminate dependency from PolicyFile to com.sun.security.auth.PrincipalComparator
mullan
parents: 7179
diff changeset
  1047
4a17ca431caf 7019834: Eliminate dependency from PolicyFile to com.sun.security.auth.PrincipalComparator
mullan
parents: 7179
diff changeset
  1048
        @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
        public String toString() {
15013
4a17ca431caf 7019834: Eliminate dependency from PolicyFile to com.sun.security.auth.PrincipalComparator
mullan
parents: 7179
diff changeset
  1050
            if (!isReplaceName()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
                return getDisplayClass() + "/" + getDisplayName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
                return getDisplayName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
         * Test for equality between the specified object and this object.
15013
4a17ca431caf 7019834: Eliminate dependency from PolicyFile to com.sun.security.auth.PrincipalComparator
mullan
parents: 7179
diff changeset
  1059
         * Two PrincipalEntries are equal if their class and name values
4a17ca431caf 7019834: Eliminate dependency from PolicyFile to com.sun.security.auth.PrincipalComparator
mullan
parents: 7179
diff changeset
  1060
         * are equal.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
         *
15013
4a17ca431caf 7019834: Eliminate dependency from PolicyFile to com.sun.security.auth.PrincipalComparator
mullan
parents: 7179
diff changeset
  1062
         * @param obj the object to test for equality with this object
4a17ca431caf 7019834: Eliminate dependency from PolicyFile to com.sun.security.auth.PrincipalComparator
mullan
parents: 7179
diff changeset
  1063
         * @return true if the objects are equal, false otherwise
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
         */
15013
4a17ca431caf 7019834: Eliminate dependency from PolicyFile to com.sun.security.auth.PrincipalComparator
mullan
parents: 7179
diff changeset
  1065
        @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
        public boolean equals(Object obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
            if (this == obj)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
            if (!(obj instanceof PrincipalEntry))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
            PrincipalEntry that = (PrincipalEntry)obj;
15013
4a17ca431caf 7019834: Eliminate dependency from PolicyFile to com.sun.security.auth.PrincipalComparator
mullan
parents: 7179
diff changeset
  1074
            return (principalClass.equals(that.principalClass) &&
4a17ca431caf 7019834: Eliminate dependency from PolicyFile to com.sun.security.auth.PrincipalComparator
mullan
parents: 7179
diff changeset
  1075
                    principalName.equals(that.principalName));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
        /**
15013
4a17ca431caf 7019834: Eliminate dependency from PolicyFile to com.sun.security.auth.PrincipalComparator
mullan
parents: 7179
diff changeset
  1079
         * Return a hashcode for this PrincipalEntry.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
         *
15013
4a17ca431caf 7019834: Eliminate dependency from PolicyFile to com.sun.security.auth.PrincipalComparator
mullan
parents: 7179
diff changeset
  1081
         * @return a hashcode for this PrincipalEntry
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
         */
15013
4a17ca431caf 7019834: Eliminate dependency from PolicyFile to com.sun.security.auth.PrincipalComparator
mullan
parents: 7179
diff changeset
  1083
        @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
        public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
            return principalClass.hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
        }
15013
4a17ca431caf 7019834: Eliminate dependency from PolicyFile to com.sun.security.auth.PrincipalComparator
mullan
parents: 7179
diff changeset
  1087
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
        public void write(PrintWriter out) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
            out.print("principal " + getDisplayClass() + " " +
15013
4a17ca431caf 7019834: Eliminate dependency from PolicyFile to com.sun.security.auth.PrincipalComparator
mullan
parents: 7179
diff changeset
  1090
                      getDisplayName(true));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
     * Each permission entry in the policy configuration file is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
     * represented by a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
     * PermissionEntry object.  <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
     * For example, the entry
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
     *          permission java.io.FilePermission "/tmp", "read,write";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
     * is represented internally
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
     * pe = new PermissionEntry("java.io.FilePermission",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
     *                           "/tmp", "read,write");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
     * @author Roland Schemers
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
     * version 1.19, 05/21/98
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
    public static class PermissionEntry {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
        public String permission;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
        public String name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
        public String action;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
        public String signedBy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
        public PermissionEntry() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
        public PermissionEntry(String permission,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
                        String name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
                        String action) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
            this.permission = permission;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
            this.name = name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
            this.action = action;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
         * Calculates a hash code value for the object.  Objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
         * which are equal will also have the same hashcode.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
         */
15013
4a17ca431caf 7019834: Eliminate dependency from PolicyFile to com.sun.security.auth.PrincipalComparator
mullan
parents: 7179
diff changeset
  1138
        @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
        public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
            int retval = permission.hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
            if (name != null) retval ^= name.hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
            if (action != null) retval ^= action.hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
            return retval;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
15013
4a17ca431caf 7019834: Eliminate dependency from PolicyFile to com.sun.security.auth.PrincipalComparator
mullan
parents: 7179
diff changeset
  1146
        @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
        public boolean equals(Object obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
            if (obj == this)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
            if (! (obj instanceof PermissionEntry))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
            PermissionEntry that = (PermissionEntry) obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
            if (this.permission == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
                if (that.permission != null) return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
                if (!this.permission.equals(that.permission)) return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
            if (this.name == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
                if (that.name != null) return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
                if (!this.name.equals(that.name)) return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
            if (this.action == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
                if (that.action != null) return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
                if (!this.action.equals(that.action)) return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
            if (this.signedBy == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
                if (that.signedBy != null) return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
                if (!this.signedBy.equals(that.signedBy)) return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
            // everything matched -- the 2 objects are equal
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
        public void write(PrintWriter out) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
            out.print("permission ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
            out.print(permission);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
            if (name != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
                out.print(" \"");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
                // ATTENTION: regex with double escaping,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
                // the normal forms look like:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
                // $name =~ s/\\/\\\\/g; and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
                // $name =~ s/\"/\\\"/g;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
                // and then in a java string, it's escaped again
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
                out.print(name.replaceAll("\\\\", "\\\\\\\\").replaceAll("\\\"", "\\\\\\\""));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
                out.print('"');
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
            if (action != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
                out.print(", \"");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
                out.print(action);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
                out.print('"');
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
            if (signedBy != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
                out.print(", signedBy \"");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
                out.print(signedBy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
                out.print('"');
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
            out.println(";");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
15664
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
  1213
    /**
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
  1214
     * Each domain entry in the keystore domain configuration file is
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
  1215
     * represented by a DomainEntry object.
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
  1216
     */
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
  1217
    static class DomainEntry {
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
  1218
        private final String name;
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
  1219
        private final Map<String, String> properties;
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
  1220
        private final Map<String, KeyStoreEntry> entries;
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
  1221
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
  1222
        DomainEntry(String name, Map<String, String> properties) {
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
  1223
            this.name = name;
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
  1224
            this.properties = properties;
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
  1225
            entries = new HashMap<>();
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
  1226
        }
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
  1227
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
  1228
        String getName() {
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
  1229
            return name;
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
  1230
        }
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
  1231
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
  1232
        Map<String, String> getProperties() {
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
  1233
            return properties;
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
  1234
        }
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
  1235
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
  1236
        Collection<KeyStoreEntry> getEntries() {
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
  1237
            return entries.values();
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
  1238
        }
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
  1239
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
  1240
        void add(KeyStoreEntry entry) throws ParsingException {
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
  1241
            String keystoreName = entry.getName();
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
  1242
            if (!entries.containsKey(keystoreName)) {
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
  1243
                entries.put(keystoreName, entry);
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
  1244
            } else {
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
  1245
                MessageFormat form = new MessageFormat(ResourcesMgr.getString(
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
  1246
                    "duplicate.keystore.name"));
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
  1247
                Object[] source = {keystoreName};
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
  1248
                throw new ParsingException(form.format(source));
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
  1249
            }
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
  1250
        }
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
  1251
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
  1252
        @Override
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
  1253
        public String toString() {
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
  1254
            StringBuilder s =
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
  1255
                new StringBuilder("\ndomain ").append(name);
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
  1256
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
  1257
            if (properties != null) {
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
  1258
                for (Map.Entry<String, String> property :
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
  1259
                    properties.entrySet()) {
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
  1260
                    s.append("\n        ").append(property.getKey()).append('=')
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
  1261
                        .append(property.getValue());
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
  1262
                }
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
  1263
            }
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
  1264
            s.append(" {\n");
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
  1265
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
  1266
            if (entries != null) {
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
  1267
                for (KeyStoreEntry entry : entries.values()) {
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
  1268
                    s.append(entry).append("\n");
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
  1269
                }
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
  1270
            }
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
  1271
            s.append("}");
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
  1272
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
  1273
            return s.toString();
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
  1274
        }
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
  1275
    }
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
  1276
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
  1277
    /**
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
  1278
     * Each keystore entry in the keystore domain configuration file is
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
  1279
     * represented by a KeyStoreEntry object.
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
  1280
     */
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
  1281
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
  1282
    static class KeyStoreEntry {
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
  1283
        private final String name;
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
  1284
        private final Map<String, String> properties;
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
  1285
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
  1286
        KeyStoreEntry(String name, Map<String, String> properties) {
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
  1287
            this.name = name;
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
  1288
            this.properties = properties;
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
  1289
        }
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
  1290
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
  1291
        String getName() {
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
  1292
            return name;
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
  1293
        }
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
  1294
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
  1295
        Map<String, String>  getProperties() {
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
  1296
            return properties;
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
  1297
        }
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
  1298
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
  1299
        @Override
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
  1300
        public String toString() {
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
  1301
            StringBuilder s = new StringBuilder("\n    keystore ").append(name);
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
  1302
            if (properties != null) {
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
  1303
                for (Map.Entry<String, String> property :
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
  1304
                    properties.entrySet()) {
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
  1305
                    s.append("\n        ").append(property.getKey()).append('=')
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
  1306
                        .append(property.getValue());
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
  1307
                }
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
  1308
            }
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
  1309
            s.append(";");
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
  1310
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
  1311
            return s.toString();
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
  1312
        }
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
  1313
    }
e33b115f1981 8007755: Support the logical grouping of keystores
vinnie
parents: 15013
diff changeset
  1314
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
    public static class ParsingException extends GeneralSecurityException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
        private static final long serialVersionUID = -4330692689482574072L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
        private String i18nMessage;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
         * Constructs a ParsingException with the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
         * detail message. A detail message is a String that describes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
         * this particular exception, which may, for example, specify which
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
         * algorithm is not available.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
         * @param msg the detail message.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
        public ParsingException(String msg) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
            super(msg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
            i18nMessage = msg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
        public ParsingException(int line, String msg) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
            super("line " + line + ": " + msg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
            MessageFormat form = new MessageFormat
7179
4afb81e50183 6987827: security/util/Resources.java needs improvement
weijun
parents: 5506
diff changeset
  1337
                (ResourcesMgr.getString("line.number.msg"));
25522
10d789df41bb 8049892: Replace uses of 'new Integer()' with appropriate alternative across core classes
prr
parents: 25402
diff changeset
  1338
            Object[] source = {line, msg};
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1339
            i18nMessage = form.format(source);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1341
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1342
        public ParsingException(int line, String expect, String actual) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1343
            super("line " + line + ": expected [" + expect +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1344
                "], found [" + actual + "]");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1345
            MessageFormat form = new MessageFormat(ResourcesMgr.getString
7179
4afb81e50183 6987827: security/util/Resources.java needs improvement
weijun
parents: 5506
diff changeset
  1346
                ("line.number.expected.expect.found.actual."));
25522
10d789df41bb 8049892: Replace uses of 'new Integer()' with appropriate alternative across core classes
prr
parents: 25402
diff changeset
  1347
            Object[] source = {line, expect, actual};
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1348
            i18nMessage = form.format(source);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1349
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1350
15013
4a17ca431caf 7019834: Eliminate dependency from PolicyFile to com.sun.security.auth.PrincipalComparator
mullan
parents: 7179
diff changeset
  1351
        @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1352
        public String getLocalizedMessage() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1353
            return i18nMessage;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1354
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1355
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1356
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1357
    public static void main(String arg[]) throws Exception {
15013
4a17ca431caf 7019834: Eliminate dependency from PolicyFile to com.sun.security.auth.PrincipalComparator
mullan
parents: 7179
diff changeset
  1358
        try (FileReader fr = new FileReader(arg[0]);
4a17ca431caf 7019834: Eliminate dependency from PolicyFile to com.sun.security.auth.PrincipalComparator
mullan
parents: 7179
diff changeset
  1359
             FileWriter fw = new FileWriter(arg[1])) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1360
            PolicyParser pp = new PolicyParser(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1361
            pp.read(fr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1362
            pp.write(fw);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1363
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1364
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1365
}