src/java.base/share/classes/sun/security/provider/ConfigFile.java
author weijun
Wed, 01 Aug 2018 13:35:08 +0800
changeset 51272 9d92ff04a29c
parent 47216 71c04702a3d5
child 53018 8bf9268df0e2
permissions -rw-r--r--
8208602: Cannot read PEM X.509 cert if there is whitespace after the header or footer Reviewed-by: xuelei
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: 19385
diff changeset
     2
 * Copyright (c) 2000, 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
14923
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 5506
diff changeset
    28
import java.io.*;
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 5506
diff changeset
    29
import java.net.MalformedURLException;
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 5506
diff changeset
    30
import java.net.URI;
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 5506
diff changeset
    31
import java.net.URL;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.security.AccessController;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.security.PrivilegedAction;
14923
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 5506
diff changeset
    34
import java.security.PrivilegedActionException;
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 5506
diff changeset
    35
import java.security.PrivilegedExceptionAction;
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 5506
diff changeset
    36
import java.security.Security;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.security.URIParameter;
14923
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 5506
diff changeset
    38
import java.text.MessageFormat;
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 5506
diff changeset
    39
import java.util.*;
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 5506
diff changeset
    40
import javax.security.auth.AuthPermission;
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 5506
diff changeset
    41
import javax.security.auth.login.AppConfigurationEntry;
19385
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
    42
import javax.security.auth.login.AppConfigurationEntry.LoginModuleControlFlag;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import javax.security.auth.login.Configuration;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import javax.security.auth.login.ConfigurationSpi;
14923
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 5506
diff changeset
    45
import sun.security.util.Debug;
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 5506
diff changeset
    46
import sun.security.util.PropertyExpander;
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 5506
diff changeset
    47
import sun.security.util.ResourcesMgr;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
/**
14923
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 5506
diff changeset
    50
 * This class represents a default implementation for
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 5506
diff changeset
    51
 * {@code javax.security.auth.login.Configuration}.
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 5506
diff changeset
    52
 *
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 5506
diff changeset
    53
 * <p> This object stores the runtime login configuration representation,
19385
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
    54
 * and is the amalgamation of multiple static login configurations that
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
    55
 * resides in files. The algorithm for locating the login configuration
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
    56
 * file(s) and reading their information into this {@code Configuration}
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
    57
 * object is:
14923
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 5506
diff changeset
    58
 *
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 5506
diff changeset
    59
 * <ol>
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 5506
diff changeset
    60
 * <li>
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 5506
diff changeset
    61
 *   Loop through the security properties,
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 5506
diff changeset
    62
 *   <i>login.config.url.1</i>, <i>login.config.url.2</i>, ...,
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 5506
diff changeset
    63
 *   <i>login.config.url.X</i>.
19385
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
    64
 *   Each property value specifies a {@code URL} pointing to a
14923
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 5506
diff changeset
    65
 *   login configuration file to be loaded.  Read in and load
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 5506
diff changeset
    66
 *   each configuration.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 *
14923
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 5506
diff changeset
    68
 * <li>
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 5506
diff changeset
    69
 *   The {@code java.lang.System} property
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 5506
diff changeset
    70
 *   <i>java.security.auth.login.config</i>
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 5506
diff changeset
    71
 *   may also be set to a {@code URL} pointing to another
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 5506
diff changeset
    72
 *   login configuration file
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 5506
diff changeset
    73
 *   (which is the case when a user uses the -D switch at runtime).
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 5506
diff changeset
    74
 *   If this property is defined, and its use is allowed by the
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 5506
diff changeset
    75
 *   security property file (the Security property,
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 5506
diff changeset
    76
 *   <i>policy.allowSystemProperty</i> is set to <i>true</i>),
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 5506
diff changeset
    77
 *   also load that login configuration.
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 5506
diff changeset
    78
 *
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 5506
diff changeset
    79
 * <li>
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 5506
diff changeset
    80
 *   If the <i>java.security.auth.login.config</i> property is defined using
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 5506
diff changeset
    81
 *   "==" (rather than "="), then ignore all other specified
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 5506
diff changeset
    82
 *   login configurations and only load this configuration.
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 5506
diff changeset
    83
 *
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 5506
diff changeset
    84
 * <li>
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 5506
diff changeset
    85
 *   If no system or security properties were set, try to read from the file,
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 5506
diff changeset
    86
 *   ${user.home}/.java.login.config, where ${user.home} is the value
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 5506
diff changeset
    87
 *   represented by the "user.home" System property.
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 5506
diff changeset
    88
 * </ol>
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 5506
diff changeset
    89
 *
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 5506
diff changeset
    90
 * <p> The configuration syntax supported by this implementation
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 5506
diff changeset
    91
 * is exactly that syntax specified in the
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 5506
diff changeset
    92
 * {@code javax.security.auth.login.Configuration} class.
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 5506
diff changeset
    93
 *
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 5506
diff changeset
    94
 * @see javax.security.auth.login.LoginContext
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 5506
diff changeset
    95
 * @see java.security.Security security properties
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 */
19385
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
    97
public final class ConfigFile extends Configuration {
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
    98
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
    99
    private final Spi spi;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
19385
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   101
    public ConfigFile() {
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   102
        spi = new Spi();
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   103
    }
14923
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 5506
diff changeset
   104
19385
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   105
    @Override
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   106
    public AppConfigurationEntry[] getAppConfigurationEntry(String appName) {
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   107
        return spi.engineGetAppConfigurationEntry(appName);
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   108
    }
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   109
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   110
    @Override
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   111
    public synchronized void refresh() {
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   112
        spi.engineRefresh();
14923
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 5506
diff changeset
   113
    }
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 5506
diff changeset
   114
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 25859
diff changeset
   115
    public static final class Spi extends ConfigurationSpi {
19385
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   116
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   117
        private URL url;
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   118
        private boolean expandProp = true;
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   119
        private Map<String, List<AppConfigurationEntry>> configuration;
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   120
        private int linenum;
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   121
        private StreamTokenizer st;
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   122
        private int lookahead;
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   123
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   124
        private static Debug debugConfig = Debug.getInstance("configfile");
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   125
        private static Debug debugParser = Debug.getInstance("configparser");
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   126
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   127
        /**
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   128
         * Creates a new {@code ConfigurationSpi} object.
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   129
         *
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   130
         * @throws SecurityException if the {@code ConfigurationSpi} can not be
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   131
         *                           initialized
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   132
         */
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   133
        public Spi() {
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   134
            try {
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   135
                init();
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   136
            } catch (IOException ioe) {
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   137
                throw new SecurityException(ioe);
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   138
            }
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   139
        }
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   140
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   141
        /**
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   142
         * Creates a new {@code ConfigurationSpi} object from the specified
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   143
         * {@code URI}.
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   144
         *
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   145
         * @param uri the {@code URI}
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   146
         * @throws SecurityException if the {@code ConfigurationSpi} can not be
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   147
         *                           initialized
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   148
         * @throws NullPointerException if {@code uri} is null
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   149
         */
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   150
        public Spi(URI uri) {
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   151
            // only load config from the specified URI
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   152
            try {
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   153
                url = uri.toURL();
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   154
                init();
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   155
            } catch (IOException ioe) {
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   156
                throw new SecurityException(ioe);
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   157
            }
14923
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 5506
diff changeset
   158
        }
19385
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   159
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   160
        public Spi(final Configuration.Parameters params) throws IOException {
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   161
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   162
            // call in a doPrivileged
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   163
            //
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   164
            // we have already passed the Configuration.getInstance
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   165
            // security check.  also this class is not freely accessible
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   166
            // (it is in the "sun" package).
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   167
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   168
            try {
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   169
                AccessController.doPrivileged(new PrivilegedExceptionAction<Void>() {
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   170
                    public Void run() throws IOException {
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   171
                        if (params == null) {
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   172
                            init();
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   173
                        } else {
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   174
                            if (!(params instanceof URIParameter)) {
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   175
                                throw new IllegalArgumentException
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   176
                                        ("Unrecognized parameter: " + params);
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   177
                            }
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   178
                            URIParameter uriParam = (URIParameter)params;
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   179
                            url = uriParam.getURI().toURL();
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   180
                            init();
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   181
                        }
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   182
                        return null;
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   183
                    }
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   184
                });
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   185
            } catch (PrivilegedActionException pae) {
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   186
                throw (IOException)pae.getException();
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   187
            }
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   188
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   189
            // if init() throws some other RuntimeException,
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   190
            // let it percolate up naturally.
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   191
        }
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   192
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   193
        /**
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   194
         * Read and initialize the entire login Configuration from the
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   195
         * configured URL.
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   196
         *
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   197
         * @throws IOException if the Configuration can not be initialized
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   198
         * @throws SecurityException if the caller does not have permission
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   199
         *                           to initialize the Configuration
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   200
         */
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   201
        private void init() throws IOException {
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   202
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   203
            boolean initialized = false;
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   204
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   205
            // For policy.expandProperties, check if either a security or system
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   206
            // property is set to false (old code erroneously checked the system
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   207
            // prop so we must check both to preserve compatibility).
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   208
            String expand = Security.getProperty("policy.expandProperties");
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   209
            if (expand == null) {
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   210
                expand = System.getProperty("policy.expandProperties");
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   211
            }
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   212
            if ("false".equals(expand)) {
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   213
                expandProp = false;
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   214
            }
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   215
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   216
            // new configuration
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   217
            Map<String, List<AppConfigurationEntry>> newConfig = new HashMap<>();
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   218
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   219
            if (url != null) {
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   220
                /**
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   221
                 * If the caller specified a URI via Configuration.getInstance,
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   222
                 * we only read from that URI
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   223
                 */
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   224
                if (debugConfig != null) {
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   225
                    debugConfig.println("reading " + url);
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   226
                }
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   227
                init(url, newConfig);
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   228
                configuration = newConfig;
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   229
                return;
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   230
            }
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   231
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   232
            /**
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   233
             * Caller did not specify URI via Configuration.getInstance.
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   234
             * Read from URLs listed in the java.security properties file.
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   235
             */
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   236
            String allowSys = Security.getProperty("policy.allowSystemProperty");
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   237
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   238
            if ("true".equalsIgnoreCase(allowSys)) {
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   239
                String extra_config = System.getProperty
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   240
                                      ("java.security.auth.login.config");
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   241
                if (extra_config != null) {
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   242
                    boolean overrideAll = false;
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   243
                    if (extra_config.startsWith("=")) {
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   244
                        overrideAll = true;
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   245
                        extra_config = extra_config.substring(1);
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   246
                    }
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   247
                    try {
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   248
                        extra_config = PropertyExpander.expand(extra_config);
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   249
                    } catch (PropertyExpander.ExpandException peee) {
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   250
                        throw ioException("Unable.to.properly.expand.config",
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   251
                                          extra_config);
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   252
                    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
19385
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   254
                    URL configURL = null;
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   255
                    try {
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   256
                        configURL = new URL(extra_config);
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   257
                    } catch (MalformedURLException mue) {
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   258
                        File configFile = new File(extra_config);
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   259
                        if (configFile.exists()) {
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   260
                            configURL = configFile.toURI().toURL();
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   261
                        } else {
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   262
                            throw ioException(
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   263
                                "extra.config.No.such.file.or.directory.",
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   264
                                extra_config);
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   265
                        }
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   266
                    }
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   267
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   268
                    if (debugConfig != null) {
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   269
                        debugConfig.println("reading "+configURL);
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   270
                    }
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   271
                    init(configURL, newConfig);
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   272
                    initialized = true;
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   273
                    if (overrideAll) {
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   274
                        if (debugConfig != null) {
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   275
                            debugConfig.println("overriding other policies!");
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   276
                        }
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   277
                        configuration = newConfig;
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   278
                        return;
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   279
                    }
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   280
                }
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   281
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
19385
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   283
            int n = 1;
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   284
            String config_url;
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   285
            while ((config_url = Security.getProperty
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   286
                                     ("login.config.url."+n)) != null) {
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   287
                try {
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   288
                    config_url = PropertyExpander.expand
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   289
                        (config_url).replace(File.separatorChar, '/');
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   290
                    if (debugConfig != null) {
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   291
                        debugConfig.println("\tReading config: " + config_url);
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   292
                    }
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   293
                    init(new URL(config_url), newConfig);
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   294
                    initialized = true;
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   295
                } catch (PropertyExpander.ExpandException peee) {
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   296
                    throw ioException("Unable.to.properly.expand.config",
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   297
                                      config_url);
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   298
                }
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   299
                n++;
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   300
            }
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   301
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   302
            if (initialized == false && n == 1 && config_url == null) {
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   303
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   304
                // get the config from the user's home directory
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   305
                if (debugConfig != null) {
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   306
                    debugConfig.println("\tReading Policy " +
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   307
                                "from ~/.java.login.config");
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   308
                }
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   309
                config_url = System.getProperty("user.home");
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   310
                String userConfigFile = config_url + File.separatorChar +
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   311
                                        ".java.login.config";
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   312
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   313
                // No longer throws an exception when there's no config file
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   314
                // at all. Returns an empty Configuration instead.
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   315
                if (new File(userConfigFile).exists()) {
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   316
                    init(new File(userConfigFile).toURI().toURL(), newConfig);
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   317
                }
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   318
            }
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   319
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   320
            configuration = newConfig;
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   321
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
19385
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   323
        private void init(URL config,
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   324
                          Map<String, List<AppConfigurationEntry>> newConfig)
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   325
                          throws IOException {
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   326
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   327
            try (InputStreamReader isr
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   328
                    = new InputStreamReader(getInputStream(config), "UTF-8")) {
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   329
                readConfig(isr, newConfig);
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   330
            } catch (FileNotFoundException fnfe) {
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   331
                if (debugConfig != null) {
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   332
                    debugConfig.println(fnfe.toString());
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   333
                }
43243
a48dab17a356 8173024: Replace direct use of AuthResources resource bundle from jdk.security.auth
mchung
parents: 32649
diff changeset
   334
                throw new IOException(ResourcesMgr.getAuthResourceString
a48dab17a356 8173024: Replace direct use of AuthResources resource bundle from jdk.security.auth
mchung
parents: 32649
diff changeset
   335
                    ("Configuration.Error.No.such.file.or.directory"));
19385
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   336
            }
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   337
        }
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   338
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   339
        /**
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   340
         * Retrieve an entry from the Configuration using an application name
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   341
         * as an index.
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   342
         *
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   343
         * @param applicationName the name used to index the Configuration.
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   344
         * @return an array of AppConfigurationEntries which correspond to
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   345
         *         the stacked configuration of LoginModules for this
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   346
         *         application, or null if this application has no configured
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   347
         *         LoginModules.
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   348
         */
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   349
        @Override
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   350
        public AppConfigurationEntry[] engineGetAppConfigurationEntry
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   351
            (String applicationName) {
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   352
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   353
            List<AppConfigurationEntry> list = null;
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   354
            synchronized (configuration) {
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   355
                list = configuration.get(applicationName);
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   356
            }
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   357
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   358
            if (list == null || list.size() == 0) {
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   359
                return null;
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   360
            }
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   361
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   362
            AppConfigurationEntry[] entries =
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   363
                                    new AppConfigurationEntry[list.size()];
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   364
            Iterator<AppConfigurationEntry> iterator = list.iterator();
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   365
            for (int i = 0; iterator.hasNext(); i++) {
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   366
                AppConfigurationEntry e = iterator.next();
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   367
                entries[i] = new AppConfigurationEntry(e.getLoginModuleName(),
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   368
                                                       e.getControlFlag(),
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   369
                                                       e.getOptions());
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   370
            }
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   371
            return entries;
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   372
        }
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   373
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   374
        /**
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   375
         * Refresh and reload the Configuration by re-reading all of the
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   376
         * login configurations.
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   377
         *
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   378
         * @throws SecurityException if the caller does not have permission
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   379
         *                           to refresh the Configuration.
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   380
         */
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   381
        @Override
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   382
        public synchronized void engineRefresh() {
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   383
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   384
            SecurityManager sm = System.getSecurityManager();
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   385
            if (sm != null) {
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   386
                sm.checkPermission(
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   387
                    new AuthPermission("refreshLoginConfiguration"));
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   388
            }
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   389
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   390
            AccessController.doPrivileged(new PrivilegedAction<Void>() {
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   391
                public Void run() {
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   392
                    try {
14923
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 5506
diff changeset
   393
                        init();
19385
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   394
                    } catch (IOException ioe) {
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   395
                        throw new SecurityException(ioe.getLocalizedMessage(),
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   396
                                                    ioe);
14923
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 5506
diff changeset
   397
                    }
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 5506
diff changeset
   398
                    return null;
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 5506
diff changeset
   399
                }
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 5506
diff changeset
   400
            });
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 5506
diff changeset
   401
        }
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 5506
diff changeset
   402
19385
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   403
        private void readConfig(Reader reader,
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   404
            Map<String, List<AppConfigurationEntry>> newConfig)
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   405
            throws IOException {
14923
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 5506
diff changeset
   406
19385
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   407
            linenum = 1;
14923
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 5506
diff changeset
   408
19385
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   409
            if (!(reader instanceof BufferedReader)) {
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   410
                reader = new BufferedReader(reader);
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   411
            }
14923
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 5506
diff changeset
   412
19385
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   413
            st = new StreamTokenizer(reader);
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   414
            st.quoteChar('"');
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   415
            st.wordChars('$', '$');
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   416
            st.wordChars('_', '_');
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   417
            st.wordChars('-', '-');
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   418
            st.wordChars('*', '*');
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   419
            st.lowerCaseMode(false);
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   420
            st.slashSlashComments(true);
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   421
            st.slashStarComments(true);
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   422
            st.eolIsSignificant(true);
14923
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 5506
diff changeset
   423
19385
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   424
            lookahead = nextToken();
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   425
            while (lookahead != StreamTokenizer.TT_EOF) {
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   426
                parseLoginEntry(newConfig);
14923
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 5506
diff changeset
   427
            }
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 5506
diff changeset
   428
        }
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 5506
diff changeset
   429
19385
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   430
        private void parseLoginEntry(
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   431
            Map<String, List<AppConfigurationEntry>> newConfig)
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   432
            throws IOException {
14923
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 5506
diff changeset
   433
19385
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   434
            List<AppConfigurationEntry> configEntries = new LinkedList<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
19385
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   436
            // application name
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   437
            String appName = st.sval;
14923
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 5506
diff changeset
   438
            lookahead = nextToken();
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 5506
diff changeset
   439
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 5506
diff changeset
   440
            if (debugParser != null) {
19385
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   441
                debugParser.println("\tReading next config entry: " + appName);
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   442
            }
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   443
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   444
            match("{");
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   445
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   446
            // get the modules
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   447
            while (peek("}") == false) {
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   448
                // get the module class name
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   449
                String moduleClass = match("module class name");
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   450
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   451
                // controlFlag (required, optional, etc)
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   452
                LoginModuleControlFlag controlFlag;
25402
0c24d9aa8fb9 7065233: To interpret case-insensitive string locale independently
juh
parents: 19385
diff changeset
   453
                String sflag = match("controlFlag").toUpperCase(Locale.ENGLISH);
19385
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   454
                switch (sflag) {
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   455
                    case "REQUIRED":
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   456
                        controlFlag = LoginModuleControlFlag.REQUIRED;
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   457
                        break;
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   458
                    case "REQUISITE":
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   459
                        controlFlag = LoginModuleControlFlag.REQUISITE;
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   460
                        break;
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   461
                    case "SUFFICIENT":
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   462
                        controlFlag = LoginModuleControlFlag.SUFFICIENT;
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   463
                        break;
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   464
                    case "OPTIONAL":
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   465
                        controlFlag = LoginModuleControlFlag.OPTIONAL;
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   466
                        break;
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   467
                    default:
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   468
                        throw ioException(
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   469
                            "Configuration.Error.Invalid.control.flag.flag",
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   470
                            sflag);
14923
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 5506
diff changeset
   471
                }
19385
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   472
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   473
                // get the args
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   474
                Map<String, String> options = new HashMap<>();
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   475
                while (peek(";") == false) {
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   476
                    String key = match("option key");
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   477
                    match("=");
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   478
                    try {
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   479
                        options.put(key, expand(match("option value")));
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   480
                    } catch (PropertyExpander.ExpandException peee) {
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   481
                        throw new IOException(peee.getLocalizedMessage());
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   482
                    }
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   483
                }
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   484
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   485
                lookahead = nextToken();
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   486
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   487
                // create the new element
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   488
                if (debugParser != null) {
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   489
                    debugParser.println("\t\t" + moduleClass + ", " + sflag);
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   490
                    for (String key : options.keySet()) {
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   491
                        debugParser.println("\t\t\t" + key +
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   492
                                            "=" + options.get(key));
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   493
                    }
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   494
                }
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   495
                configEntries.add(new AppConfigurationEntry(moduleClass,
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   496
                                                            controlFlag,
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   497
                                                            options));
14923
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 5506
diff changeset
   498
            }
19385
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   499
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   500
            match("}");
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   501
            match(";");
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   502
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   503
            // add this configuration entry
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   504
            if (newConfig.containsKey(appName)) {
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   505
                throw ioException(
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   506
                    "Configuration.Error.Can.not.specify.multiple.entries.for.appName",
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   507
                    appName);
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   508
            }
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   509
            newConfig.put(appName, configEntries);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
19385
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   512
        private String match(String expect) throws IOException {
14923
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 5506
diff changeset
   513
19385
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   514
            String value = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
19385
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   516
            switch(lookahead) {
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   517
            case StreamTokenizer.TT_EOF:
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   518
                throw ioException(
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   519
                    "Configuration.Error.expected.expect.read.end.of.file.",
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   520
                    expect);
14923
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 5506
diff changeset
   521
19385
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   522
            case '"':
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   523
            case StreamTokenizer.TT_WORD:
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   524
                if (expect.equalsIgnoreCase("module class name") ||
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   525
                    expect.equalsIgnoreCase("controlFlag") ||
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   526
                    expect.equalsIgnoreCase("option key") ||
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   527
                    expect.equalsIgnoreCase("option value")) {
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   528
                    value = st.sval;
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   529
                    lookahead = nextToken();
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   530
                } else {
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   531
                    throw ioException(
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   532
                        "Configuration.Error.Line.line.expected.expect.found.value.",
25522
10d789df41bb 8049892: Replace uses of 'new Integer()' with appropriate alternative across core classes
prr
parents: 25402
diff changeset
   533
                        linenum, expect, st.sval);
19385
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   534
                }
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   535
                break;
14923
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 5506
diff changeset
   536
19385
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   537
            case '{':
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   538
                if (expect.equalsIgnoreCase("{")) {
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   539
                    lookahead = nextToken();
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   540
                } else {
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   541
                    throw ioException(
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   542
                        "Configuration.Error.Line.line.expected.expect.",
25522
10d789df41bb 8049892: Replace uses of 'new Integer()' with appropriate alternative across core classes
prr
parents: 25402
diff changeset
   543
                        linenum, expect, st.sval);
19385
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   544
                }
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   545
                break;
14923
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 5506
diff changeset
   546
19385
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   547
            case ';':
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   548
                if (expect.equalsIgnoreCase(";")) {
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   549
                    lookahead = nextToken();
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   550
                } else {
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   551
                    throw ioException(
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   552
                        "Configuration.Error.Line.line.expected.expect.",
25522
10d789df41bb 8049892: Replace uses of 'new Integer()' with appropriate alternative across core classes
prr
parents: 25402
diff changeset
   553
                        linenum, expect, st.sval);
19385
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   554
                }
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   555
                break;
14923
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 5506
diff changeset
   556
19385
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   557
            case '}':
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   558
                if (expect.equalsIgnoreCase("}")) {
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   559
                    lookahead = nextToken();
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   560
                } else {
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   561
                    throw ioException(
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   562
                        "Configuration.Error.Line.line.expected.expect.",
25522
10d789df41bb 8049892: Replace uses of 'new Integer()' with appropriate alternative across core classes
prr
parents: 25402
diff changeset
   563
                        linenum, expect, st.sval);
19385
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   564
                }
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   565
                break;
14923
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 5506
diff changeset
   566
19385
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   567
            case '=':
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   568
                if (expect.equalsIgnoreCase("=")) {
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   569
                    lookahead = nextToken();
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   570
                } else {
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   571
                    throw ioException(
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   572
                        "Configuration.Error.Line.line.expected.expect.",
25522
10d789df41bb 8049892: Replace uses of 'new Integer()' with appropriate alternative across core classes
prr
parents: 25402
diff changeset
   573
                        linenum, expect, st.sval);
14923
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 5506
diff changeset
   574
                }
19385
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   575
                break;
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   576
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   577
            default:
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   578
                throw ioException(
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   579
                    "Configuration.Error.Line.line.expected.expect.found.value.",
25522
10d789df41bb 8049892: Replace uses of 'new Integer()' with appropriate alternative across core classes
prr
parents: 25402
diff changeset
   580
                    linenum, expect, st.sval);
14923
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 5506
diff changeset
   581
            }
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 5506
diff changeset
   582
            return value;
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 5506
diff changeset
   583
        }
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 5506
diff changeset
   584
19385
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   585
        private boolean peek(String expect) {
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   586
            switch (lookahead) {
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   587
                case ',':
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   588
                    return expect.equalsIgnoreCase(",");
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   589
                case ';':
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   590
                    return expect.equalsIgnoreCase(";");
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   591
                case '{':
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   592
                    return expect.equalsIgnoreCase("{");
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   593
                case '}':
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   594
                    return expect.equalsIgnoreCase("}");
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   595
                default:
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   596
                    return false;
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   597
            }
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   598
        }
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   599
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   600
        private int nextToken() throws IOException {
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   601
            int tok;
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   602
            while ((tok = st.nextToken()) == StreamTokenizer.TT_EOL) {
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   603
                linenum++;
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   604
            }
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   605
            return tok;
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   606
        }
14923
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 5506
diff changeset
   607
19385
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   608
        private InputStream getInputStream(URL url) throws IOException {
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   609
            if ("file".equalsIgnoreCase(url.getProtocol())) {
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   610
                // Compatibility notes:
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   611
                //
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   612
                // Code changed from
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   613
                //   String path = url.getFile().replace('/', File.separatorChar);
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   614
                //   return new FileInputStream(path);
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   615
                //
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   616
                // The original implementation would search for "/tmp/a%20b"
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   617
                // when url is "file:///tmp/a%20b". This is incorrect. The
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   618
                // current codes fix this bug and searches for "/tmp/a b".
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   619
                // For compatibility reasons, when the file "/tmp/a b" does
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   620
                // not exist, the file named "/tmp/a%20b" will be tried.
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   621
                //
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   622
                // This also means that if both file exists, the behavior of
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   623
                // this method is changed, and the current codes choose the
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   624
                // correct one.
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   625
                try {
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   626
                    return url.openStream();
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   627
                } catch (Exception e) {
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   628
                    String file = url.getPath();
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   629
                    if (url.getHost().length() > 0) {  // For Windows UNC
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   630
                        file = "//" + url.getHost() + file;
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   631
                    }
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   632
                    if (debugConfig != null) {
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   633
                        debugConfig.println("cannot read " + url +
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   634
                                            ", try " + file);
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   635
                    }
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   636
                    return new FileInputStream(file);
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   637
                }
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   638
            } else {
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   639
                return url.openStream();
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   640
            }
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   641
        }
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   642
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   643
        private String expand(String value)
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   644
            throws PropertyExpander.ExpandException, IOException {
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   645
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   646
            if (value.isEmpty()) {
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   647
                return value;
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   648
            }
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   649
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   650
            if (!expandProp) {
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   651
                return value;
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   652
            }
14923
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 5506
diff changeset
   653
            String s = PropertyExpander.expand(value);
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 5506
diff changeset
   654
            if (s == null || s.length() == 0) {
19385
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   655
                throw ioException(
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   656
                    "Configuration.Error.Line.line.system.property.value.expanded.to.empty.value",
25522
10d789df41bb 8049892: Replace uses of 'new Integer()' with appropriate alternative across core classes
prr
parents: 25402
diff changeset
   657
                    linenum, value);
14923
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 5506
diff changeset
   658
            }
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 5506
diff changeset
   659
            return s;
19385
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   660
        }
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   661
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   662
        private IOException ioException(String resourceKey, Object... args) {
43243
a48dab17a356 8173024: Replace direct use of AuthResources resource bundle from jdk.security.auth
mchung
parents: 32649
diff changeset
   663
            MessageFormat form = new MessageFormat(
a48dab17a356 8173024: Replace direct use of AuthResources resource bundle from jdk.security.auth
mchung
parents: 32649
diff changeset
   664
                ResourcesMgr.getAuthResourceString(resourceKey));
19385
a7b34a4b1fcb 8016848: javax_security/auth/login tests fail in compact 1 and 2 profiles
mullan
parents: 15649
diff changeset
   665
            return new IOException(form.format(args));
14923
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 5506
diff changeset
   666
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
}