jdk/src/share/classes/com/sun/security/auth/login/ConfigFile.java
author mullan
Wed, 26 Dec 2012 10:07:00 -0500
changeset 14923 189882d66a51
parent 14775 2ed01c760aea
child 19385 a7b34a4b1fcb
permissions -rw-r--r--
8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile Reviewed-by: alanb, mchung, weijun
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
14775
2ed01c760aea 8004064: Downgrade normative references to ${java.home}/lib/security/java.security
mullan
parents: 9035
diff changeset
     2
 * Copyright (c) 2000, 2012, 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: 715
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: 715
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: 715
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
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 com.sun.security.auth.login;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import javax.security.auth.login.AppConfigurationEntry;
14923
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 14775
diff changeset
    29
import javax.security.auth.login.Configuration;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.net.URI;
14923
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 14775
diff changeset
    31
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 14775
diff changeset
    32
// NOTE: As of JDK 8, this class instantiates
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 14775
diff changeset
    33
// sun.security.provider.ConfigSpiFile and forwards all methods to that
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 14775
diff changeset
    34
// implementation. All implementation fixes and enhancements should be made to
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 14775
diff changeset
    35
// sun.security.provider.ConfigSpiFile and not this class.
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 14775
diff changeset
    36
// See JDK-8005117 for more information.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * This class represents a default implementation for
14923
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 14775
diff changeset
    40
 * {@code javax.security.auth.login.Configuration}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * <p> This object stores the runtime login configuration representation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * and is the amalgamation of multiple static login
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * configurations that resides in files.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * The algorithm for locating the login configuration file(s) and reading their
14923
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 14775
diff changeset
    46
 * information into this {@code Configuration} object is:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * <ol>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * <li>
14775
2ed01c760aea 8004064: Downgrade normative references to ${java.home}/lib/security/java.security
mullan
parents: 9035
diff changeset
    50
 *   Loop through the security properties,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 *   <i>login.config.url.1</i>, <i>login.config.url.2</i>, ...,
14775
2ed01c760aea 8004064: Downgrade normative references to ${java.home}/lib/security/java.security
mullan
parents: 9035
diff changeset
    52
 *   <i>login.config.url.X</i>.
14923
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 14775
diff changeset
    53
 *   Each property value specifies a {@code URL} pointing to a
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 *   login configuration file to be loaded.  Read in and load
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 *   each configuration.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * <li>
14923
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 14775
diff changeset
    58
 *   The {@code java.lang.System} property
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 *   <i>java.security.auth.login.config</i>
14923
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 14775
diff changeset
    60
 *   may also be set to a {@code URL} pointing to another
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 *   login configuration file
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 *   (which is the case when a user uses the -D switch at runtime).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 *   If this property is defined, and its use is allowed by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 *   security property file (the Security property,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 *   <i>policy.allowSystemProperty</i> is set to <i>true</i>),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 *   also load that login configuration.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * <li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 *   If the <i>java.security.auth.login.config</i> property is defined using
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 *   "==" (rather than "="), then ignore all other specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 *   login configurations and only load this configuration.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * <li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 *   If no system or security properties were set, try to read from the file,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 *   ${user.home}/.java.login.config, where ${user.home} is the value
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 *   represented by the "user.home" System property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * </ol>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * <p> The configuration syntax supported by this implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * is exactly that syntax specified in the
14923
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 14775
diff changeset
    81
 * {@code javax.security.auth.login.Configuration} class.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 * @see javax.security.auth.login.LoginContext
14775
2ed01c760aea 8004064: Downgrade normative references to ${java.home}/lib/security/java.security
mullan
parents: 9035
diff changeset
    84
 * @see java.security.Security security properties
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 */
14923
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 14775
diff changeset
    86
public class ConfigFile extends Configuration {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
14923
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 14775
diff changeset
    88
    private sun.security.provider.ConfigSpiFile configFile;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    /**
14923
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 14775
diff changeset
    91
     * Create a new {@code Configuration} object.
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 14775
diff changeset
    92
     *
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 14775
diff changeset
    93
     * @throws SecurityException if the {@code Configuration} can not be
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 14775
diff changeset
    94
     *                           initialized
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    public ConfigFile() {
14923
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 14775
diff changeset
    97
        configFile = new sun.security.provider.ConfigSpiFile();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    /**
14923
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 14775
diff changeset
   101
     * Create a new {@code Configuration} object from the specified {@code URI}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     *
14923
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 14775
diff changeset
   103
     * @param uri the {@code URI}
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 14775
diff changeset
   104
     * @throws SecurityException if the {@code Configuration} can not be
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 14775
diff changeset
   105
     *                           initialized
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 14775
diff changeset
   106
     * @throws NullPointerException if {@code uri} is null
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     */
14923
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 14775
diff changeset
   108
    public ConfigFile(URI uri) {
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 14775
diff changeset
   109
        configFile = new sun.security.provider.ConfigSpiFile(uri);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    /**
14923
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 14775
diff changeset
   113
     * Retrieve an entry from the {@code Configuration} using an application
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 14775
diff changeset
   114
     * name as an index.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     *
14923
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 14775
diff changeset
   116
     * @param applicationName the name used to index the {@code Configuration}
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 14775
diff changeset
   117
     * @return an array of {@code AppConfigurationEntry} which correspond to
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 14775
diff changeset
   118
     *         the stacked configuration of {@code LoginModule}s for this
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 14775
diff changeset
   119
     *         application, or null if this application has no configured
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 14775
diff changeset
   120
     *         {@code LoginModule}s.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     */
14923
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 14775
diff changeset
   122
    @Override
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 14775
diff changeset
   123
    public AppConfigurationEntry[] getAppConfigurationEntry
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 14775
diff changeset
   124
        (String applicationName) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
14923
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 14775
diff changeset
   126
        return configFile.engineGetAppConfigurationEntry(applicationName);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
14923
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 14775
diff changeset
   129
    /**
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 14775
diff changeset
   130
     * Refresh and reload the {@code Configuration} by re-reading all of the
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 14775
diff changeset
   131
     * login configurations.
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 14775
diff changeset
   132
     *
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 14775
diff changeset
   133
     * @throws SecurityException if the caller does not have permission
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 14775
diff changeset
   134
     *                           to refresh the {@code Configuration}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     */
14923
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 14775
diff changeset
   136
    @Override
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 14775
diff changeset
   137
    public synchronized void refresh() {
189882d66a51 8005117: Eliminate dependency from ConfigSpiFile to com.sun.security.auth.login.ConfigFile
mullan
parents: 14775
diff changeset
   138
        configFile.engineRefresh();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
}