jdk/src/share/classes/javax/security/auth/login/Configuration.java
author ohair
Wed, 06 Apr 2011 22:06:11 -0700
changeset 9035 1255eb81cc2f
parent 8152 94e5966bdf22
child 14775 2ed01c760aea
permissions -rw-r--r--
7033660: Update copyright year to 2011 on any files changed in 2011 Reviewed-by: dholmes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
9035
1255eb81cc2f 7033660: Update copyright year to 2011 on any files changed in 2011
ohair
parents: 8152
diff changeset
     2
 * Copyright (c) 1998, 2011, 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: 2943
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: 2943
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: 2943
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2943
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2943
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package javax.security.auth.login;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import javax.security.auth.AuthPermission;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.net.URI;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.security.AccessController;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.security.PrivilegedAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.security.PrivilegedExceptionAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.security.PrivilegedActionException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.security.NoSuchAlgorithmException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.security.NoSuchProviderException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.security.Provider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.security.Security;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.security.SecurityPermission;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import sun.security.jca.GetInstance;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * A Configuration object is responsible for specifying which LoginModules
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * should be used for a particular application, and in what order the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * LoginModules should be invoked.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * <p> A login configuration contains the following information.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * Note that this example only represents the default syntax for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * <code>Configuration</code>.  Subclass implementations of this class
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * may implement alternative syntaxes and may retrieve the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * <code>Configuration</code> from any source such as files, databases,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * or servers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 *      Name {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 *            ModuleClass  Flag    ModuleOptions;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 *            ModuleClass  Flag    ModuleOptions;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 *            ModuleClass  Flag    ModuleOptions;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 *      };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 *      Name {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 *            ModuleClass  Flag    ModuleOptions;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 *            ModuleClass  Flag    ModuleOptions;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 *      };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 *      other {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 *            ModuleClass  Flag    ModuleOptions;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 *            ModuleClass  Flag    ModuleOptions;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 *      };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * <p> Each entry in the <code>Configuration</code> is indexed via an
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * application name, <i>Name</i>, and contains a list of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * LoginModules configured for that application.  Each <code>LoginModule</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * is specified via its fully qualified class name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * Authentication proceeds down the module list in the exact order specified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * If an application does not have specific entry,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * it defaults to the specific entry for "<i>other</i>".
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 * <p> The <i>Flag</i> value controls the overall behavior as authentication
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * proceeds down the stack.  The following represents a description of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 * valid values for <i>Flag</i> and their respective semantics:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 *      1) Required     - The <code>LoginModule</code> is required to succeed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 *                      If it succeeds or fails, authentication still continues
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 *                      to proceed down the <code>LoginModule</code> list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 *      2) Requisite    - The <code>LoginModule</code> is required to succeed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 *                      If it succeeds, authentication continues down the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 *                      <code>LoginModule</code> list.  If it fails,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 *                      control immediately returns to the application
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 *                      (authentication does not proceed down the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
 *                      <code>LoginModule</code> list).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
 *      3) Sufficient   - The <code>LoginModule</code> is not required to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
 *                      succeed.  If it does succeed, control immediately
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
 *                      returns to the application (authentication does not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
 *                      proceed down the <code>LoginModule</code> list).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
 *                      If it fails, authentication continues down the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
 *                      <code>LoginModule</code> list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
 *      4) Optional     - The <code>LoginModule</code> is not required to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
 *                      succeed.  If it succeeds or fails,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
 *                      authentication still continues to proceed down the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
 *                      <code>LoginModule</code> list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
 * <p> The overall authentication succeeds only if all <i>Required</i> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
 * <i>Requisite</i> LoginModules succeed.  If a <i>Sufficient</i>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
 * <code>LoginModule</code> is configured and succeeds,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
 * then only the <i>Required</i> and <i>Requisite</i> LoginModules prior to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
 * that <i>Sufficient</i> <code>LoginModule</code> need to have succeeded for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
 * the overall authentication to succeed. If no <i>Required</i> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
 * <i>Requisite</i> LoginModules are configured for an application,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
 * then at least one <i>Sufficient</i> or <i>Optional</i>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
 * <code>LoginModule</code> must succeed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
 * <p> <i>ModuleOptions</i> is a space separated list of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
 * <code>LoginModule</code>-specific values which are passed directly to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
 * the underlying LoginModules.  Options are defined by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
 * <code>LoginModule</code> itself, and control the behavior within it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
 * For example, a <code>LoginModule</code> may define options to support
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
 * debugging/testing capabilities.  The correct way to specify options in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
 * <code>Configuration</code> is by using the following key-value pairing:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
 * <i>debug="true"</i>.  The key and value should be separated by an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
 * 'equals' symbol, and the value should be surrounded by double quotes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
 * If a String in the form, ${system.property}, occurs in the value,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
 * it will be expanded to the value of the system property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
 * Note that there is no limit to the number of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
 * options a <code>LoginModule</code> may define.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
 * <p> The following represents an example <code>Configuration</code> entry
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
 * based on the syntax above:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
 * Login {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
 *   com.sun.security.auth.module.UnixLoginModule required;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
 *   com.sun.security.auth.module.Krb5LoginModule optional
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
 *                   useTicketCache="true"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
 *                   ticketCache="${user.home}${/}tickets";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
 * };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
 * <p> This <code>Configuration</code> specifies that an application named,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
 * "Login", requires users to first authenticate to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
 * <i>com.sun.security.auth.module.UnixLoginModule</i>, which is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
 * required to succeed.  Even if the <i>UnixLoginModule</i>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
 * authentication fails, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
 * <i>com.sun.security.auth.module.Krb5LoginModule</i>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
 * still gets invoked.  This helps hide the source of failure.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
 * Since the <i>Krb5LoginModule</i> is <i>Optional</i>, the overall
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
 * authentication succeeds only if the <i>UnixLoginModule</i>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
 * (<i>Required</i>) succeeds.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
 * <p> Also note that the LoginModule-specific options,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
 * <i>useTicketCache="true"</i> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
 * <i>ticketCache=${user.home}${/}tickets"</i>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
 * are passed to the <i>Krb5LoginModule</i>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
 * These options instruct the <i>Krb5LoginModule</i> to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
 * use the ticket cache at the specified location.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
 * The system properties, <i>user.home</i> and <i>/</i>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
 * (file.separator), are expanded to their respective values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
 * <p> There is only one Configuration object installed in the runtime at any
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
 * given time.  A Configuration object can be installed by calling the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
 * <code>setConfiguration</code> method.  The installed Configuration object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
 * can be obtained by calling the <code>getConfiguration</code> method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
 * <p> If no Configuration object has been installed in the runtime, a call to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
 * <code>getConfiguration</code> installs an instance of the default
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
 * Configuration implementation (a default subclass implementation of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
 * abstract class).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
 * The default Configuration implementation can be changed by setting the value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
 * of the "login.configuration.provider" security property (in the Java
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
 * security properties file) to the fully qualified name of the desired
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
 * Configuration subclass implementation.  The Java security properties file
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
 * is located in the file named &lt;JAVA_HOME&gt;/lib/security/java.security.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
 * &lt;JAVA_HOME&gt; refers to the value of the java.home system property,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
 * and specifies the directory where the JRE is installed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
 * <p> Application code can directly subclass Configuration to provide a custom
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
 * implementation.  In addition, an instance of a Configuration object can be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
 * constructed by invoking one of the <code>getInstance</code> factory methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
 * with a standard type.  The default policy type is "JavaLoginConfig".
8152
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   187
 * See the Configuration section in the <a href=
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   188
 * "{@docRoot}/../technotes/guides/security/StandardNames.html#Configuration">
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   189
 * Java Cryptography Architecture Standard Algorithm Name Documentation</a>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
 * for a list of standard Configuration types.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
 * @see javax.security.auth.login.LoginContext
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
public abstract class Configuration {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    private static Configuration configuration;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    private static ClassLoader contextClassLoader;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        contextClassLoader = AccessController.doPrivileged
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                (new PrivilegedAction<ClassLoader>() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
                public ClassLoader run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
                    return Thread.currentThread().getContextClassLoader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    private static void checkPermission(String type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        SecurityManager sm = System.getSecurityManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        if (sm != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
            sm.checkPermission(new AuthPermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                                ("createLoginConfiguration." + type));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * Sole constructor.  (For invocation by subclass constructors, typically
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * implicit.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    protected Configuration() { }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * Get the installed login Configuration.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * @return the login Configuration.  If a Configuration object was set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     *          via the <code>Configuration.setConfiguration</code> method,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     *          then that object is returned.  Otherwise, a default
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     *          Configuration object is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * @exception SecurityException if the caller does not have permission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     *                          to retrieve the Configuration.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * @see #setConfiguration
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     */
2943
0418028311a2 6845161: Bottleneck in Configuration.getConfiguration synchronized call
mullan
parents: 2
diff changeset
   237
    public static Configuration getConfiguration() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        SecurityManager sm = System.getSecurityManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        if (sm != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            sm.checkPermission(new AuthPermission("getLoginConfiguration"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
2943
0418028311a2 6845161: Bottleneck in Configuration.getConfiguration synchronized call
mullan
parents: 2
diff changeset
   243
        synchronized (Configuration.class) {
0418028311a2 6845161: Bottleneck in Configuration.getConfiguration synchronized call
mullan
parents: 2
diff changeset
   244
            if (configuration == null) {
0418028311a2 6845161: Bottleneck in Configuration.getConfiguration synchronized call
mullan
parents: 2
diff changeset
   245
                String config_class = null;
0418028311a2 6845161: Bottleneck in Configuration.getConfiguration synchronized call
mullan
parents: 2
diff changeset
   246
                config_class = AccessController.doPrivileged
0418028311a2 6845161: Bottleneck in Configuration.getConfiguration synchronized call
mullan
parents: 2
diff changeset
   247
                    (new PrivilegedAction<String>() {
0418028311a2 6845161: Bottleneck in Configuration.getConfiguration synchronized call
mullan
parents: 2
diff changeset
   248
                    public String run() {
0418028311a2 6845161: Bottleneck in Configuration.getConfiguration synchronized call
mullan
parents: 2
diff changeset
   249
                        return java.security.Security.getProperty
0418028311a2 6845161: Bottleneck in Configuration.getConfiguration synchronized call
mullan
parents: 2
diff changeset
   250
                                    ("login.configuration.provider");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
                });
2943
0418028311a2 6845161: Bottleneck in Configuration.getConfiguration synchronized call
mullan
parents: 2
diff changeset
   253
                if (config_class == null) {
0418028311a2 6845161: Bottleneck in Configuration.getConfiguration synchronized call
mullan
parents: 2
diff changeset
   254
                    config_class = "com.sun.security.auth.login.ConfigFile";
0418028311a2 6845161: Bottleneck in Configuration.getConfiguration synchronized call
mullan
parents: 2
diff changeset
   255
                }
0418028311a2 6845161: Bottleneck in Configuration.getConfiguration synchronized call
mullan
parents: 2
diff changeset
   256
0418028311a2 6845161: Bottleneck in Configuration.getConfiguration synchronized call
mullan
parents: 2
diff changeset
   257
                try {
0418028311a2 6845161: Bottleneck in Configuration.getConfiguration synchronized call
mullan
parents: 2
diff changeset
   258
                    final String finalClass = config_class;
0418028311a2 6845161: Bottleneck in Configuration.getConfiguration synchronized call
mullan
parents: 2
diff changeset
   259
                    configuration = AccessController.doPrivileged
0418028311a2 6845161: Bottleneck in Configuration.getConfiguration synchronized call
mullan
parents: 2
diff changeset
   260
                        (new PrivilegedExceptionAction<Configuration>() {
0418028311a2 6845161: Bottleneck in Configuration.getConfiguration synchronized call
mullan
parents: 2
diff changeset
   261
                        public Configuration run() throws ClassNotFoundException,
0418028311a2 6845161: Bottleneck in Configuration.getConfiguration synchronized call
mullan
parents: 2
diff changeset
   262
                                            InstantiationException,
0418028311a2 6845161: Bottleneck in Configuration.getConfiguration synchronized call
mullan
parents: 2
diff changeset
   263
                                            IllegalAccessException {
0418028311a2 6845161: Bottleneck in Configuration.getConfiguration synchronized call
mullan
parents: 2
diff changeset
   264
                            return (Configuration)Class.forName
0418028311a2 6845161: Bottleneck in Configuration.getConfiguration synchronized call
mullan
parents: 2
diff changeset
   265
                                    (finalClass,
0418028311a2 6845161: Bottleneck in Configuration.getConfiguration synchronized call
mullan
parents: 2
diff changeset
   266
                                    true,
0418028311a2 6845161: Bottleneck in Configuration.getConfiguration synchronized call
mullan
parents: 2
diff changeset
   267
                                    contextClassLoader).newInstance();
0418028311a2 6845161: Bottleneck in Configuration.getConfiguration synchronized call
mullan
parents: 2
diff changeset
   268
                        }
0418028311a2 6845161: Bottleneck in Configuration.getConfiguration synchronized call
mullan
parents: 2
diff changeset
   269
                    });
0418028311a2 6845161: Bottleneck in Configuration.getConfiguration synchronized call
mullan
parents: 2
diff changeset
   270
                } catch (PrivilegedActionException e) {
0418028311a2 6845161: Bottleneck in Configuration.getConfiguration synchronized call
mullan
parents: 2
diff changeset
   271
                    Exception ee = e.getException();
0418028311a2 6845161: Bottleneck in Configuration.getConfiguration synchronized call
mullan
parents: 2
diff changeset
   272
                    if (ee instanceof InstantiationException) {
0418028311a2 6845161: Bottleneck in Configuration.getConfiguration synchronized call
mullan
parents: 2
diff changeset
   273
                        throw (SecurityException) new
0418028311a2 6845161: Bottleneck in Configuration.getConfiguration synchronized call
mullan
parents: 2
diff changeset
   274
                            SecurityException
0418028311a2 6845161: Bottleneck in Configuration.getConfiguration synchronized call
mullan
parents: 2
diff changeset
   275
                                    ("Configuration error:" +
0418028311a2 6845161: Bottleneck in Configuration.getConfiguration synchronized call
mullan
parents: 2
diff changeset
   276
                                     ee.getCause().getMessage() +
0418028311a2 6845161: Bottleneck in Configuration.getConfiguration synchronized call
mullan
parents: 2
diff changeset
   277
                                     "\n").initCause(ee.getCause());
0418028311a2 6845161: Bottleneck in Configuration.getConfiguration synchronized call
mullan
parents: 2
diff changeset
   278
                    } else {
0418028311a2 6845161: Bottleneck in Configuration.getConfiguration synchronized call
mullan
parents: 2
diff changeset
   279
                        throw (SecurityException) new
0418028311a2 6845161: Bottleneck in Configuration.getConfiguration synchronized call
mullan
parents: 2
diff changeset
   280
                            SecurityException
0418028311a2 6845161: Bottleneck in Configuration.getConfiguration synchronized call
mullan
parents: 2
diff changeset
   281
                                    ("Configuration error: " +
0418028311a2 6845161: Bottleneck in Configuration.getConfiguration synchronized call
mullan
parents: 2
diff changeset
   282
                                     ee.toString() +
0418028311a2 6845161: Bottleneck in Configuration.getConfiguration synchronized call
mullan
parents: 2
diff changeset
   283
                                     "\n").initCause(ee);
0418028311a2 6845161: Bottleneck in Configuration.getConfiguration synchronized call
mullan
parents: 2
diff changeset
   284
                    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
            }
2943
0418028311a2 6845161: Bottleneck in Configuration.getConfiguration synchronized call
mullan
parents: 2
diff changeset
   287
            return configuration;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     * Set the login <code>Configuration</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     * @param configuration the new <code>Configuration</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     * @exception SecurityException if the current thread does not have
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     *                  Permission to set the <code>Configuration</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     * @see #getConfiguration
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    public static void setConfiguration(Configuration configuration) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        SecurityManager sm = System.getSecurityManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        if (sm != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
            sm.checkPermission(new AuthPermission("setLoginConfiguration"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        Configuration.configuration = configuration;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     * Returns a Configuration object of the specified type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     * <p> This method traverses the list of registered security providers,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     * starting with the most preferred Provider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     * A new Configuration object encapsulating the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     * ConfigurationSpi implementation from the first
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     * Provider that supports the specified type is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     * <p> Note that the list of registered providers may be retrieved via
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     * the {@link Security#getProviders() Security.getProviders()} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     *
8152
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   322
     * @param type the specified Configuration type.  See the Configuration
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   323
     *    section in the <a href=
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   324
     *    "{@docRoot}/../technotes/guides/security/StandardNames.html#Configuration">
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   325
     *    Java Cryptography Architecture Standard Algorithm Name
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   326
     *    Documentation</a> for a list of standard Configuration types.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     * @param params parameters for the Configuration, which may be null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     * @return the new Configuration object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     * @exception SecurityException if the caller does not have permission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     *          to get a Configuration instance for the specified type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     * @exception NullPointerException if the specified type is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     * @exception IllegalArgumentException if the specified parameters
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     *          are not understood by the ConfigurationSpi implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     *          from the selected Provider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     * @exception NoSuchAlgorithmException if no Provider supports a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     *          ConfigurationSpi implementation for the specified type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     * @see Provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
    public static Configuration getInstance(String type,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
                                Configuration.Parameters params)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
                throws NoSuchAlgorithmException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        checkPermission(type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
            GetInstance.Instance instance = GetInstance.getInstance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
                                                        ("Configuration",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
                                                        ConfigurationSpi.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
                                                        type,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
                                                        params);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
            return new ConfigDelegate((ConfigurationSpi)instance.impl,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
                                                        instance.provider,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
                                                        type,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
                                                        params);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
        } catch (NoSuchAlgorithmException nsae) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
            return handleException (nsae);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     * Returns a Configuration object of the specified type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     * <p> A new Configuration object encapsulating the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     * ConfigurationSpi implementation from the specified provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     * is returned.   The specified provider must be registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     * in the provider list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     * <p> Note that the list of registered providers may be retrieved via
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
     * the {@link Security#getProviders() Security.getProviders()} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     *
8152
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   378
     * @param type the specified Configuration type.  See the Configuration
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   379
     *    section in the <a href=
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   380
     *    "{@docRoot}/../technotes/guides/security/StandardNames.html#Configuration">
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   381
     *    Java Cryptography Architecture Standard Algorithm Name
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   382
     *    Documentation</a> for a list of standard Configuration types.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
     * @param params parameters for the Configuration, which may be null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
     * @param provider the provider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     * @return the new Configuration object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     * @exception SecurityException if the caller does not have permission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     *          to get a Configuration instance for the specified type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     * @exception NullPointerException if the specified type is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     * @exception IllegalArgumentException if the specified provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     *          is null or empty,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
     *          or if the specified parameters are not understood by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
     *          the ConfigurationSpi implementation from the specified provider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
     * @exception NoSuchProviderException if the specified provider is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
     *          registered in the security provider list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
     * @exception NoSuchAlgorithmException if the specified provider does not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
     *          support a ConfigurationSpi implementation for the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     *          type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
     * @see Provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
    public static Configuration getInstance(String type,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
                                Configuration.Parameters params,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
                                String provider)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
                throws NoSuchProviderException, NoSuchAlgorithmException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
        if (provider == null || provider.length() == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
            throw new IllegalArgumentException("missing provider");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
        checkPermission(type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
            GetInstance.Instance instance = GetInstance.getInstance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
                                                        ("Configuration",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
                                                        ConfigurationSpi.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
                                                        type,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
                                                        params,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
                                                        provider);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
            return new ConfigDelegate((ConfigurationSpi)instance.impl,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
                                                        instance.provider,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
                                                        type,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
                                                        params);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        } catch (NoSuchAlgorithmException nsae) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
            return handleException (nsae);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
     * Returns a Configuration object of the specified type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
     * <p> A new Configuration object encapsulating the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
     * ConfigurationSpi implementation from the specified Provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
     * object is returned.  Note that the specified Provider object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
     * does not have to be registered in the provider list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
     *
8152
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   444
     * @param type the specified Configuration type.  See the Configuration
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   445
     *    section in the <a href=
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   446
     *    "{@docRoot}/../technotes/guides/security/StandardNames.html#Configuration">
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   447
     *    Java Cryptography Architecture Standard Algorithm Name
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   448
     *    Documentation</a> for a list of standard Configuration types.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
     * @param params parameters for the Configuration, which may be null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
     * @param provider the Provider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
     * @return the new Configuration object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
     * @exception SecurityException if the caller does not have permission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
     *          to get a Configuration instance for the specified type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
     * @exception NullPointerException if the specified type is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
     * @exception IllegalArgumentException if the specified Provider is null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
     *          or if the specified parameters are not understood by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
     *          the ConfigurationSpi implementation from the specified Provider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
     * @exception NoSuchAlgorithmException if the specified Provider does not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
     *          support a ConfigurationSpi implementation for the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
     *          type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
     * @see Provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
    public static Configuration getInstance(String type,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
                                Configuration.Parameters params,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
                                Provider provider)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
                throws NoSuchAlgorithmException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        if (provider == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
            throw new IllegalArgumentException("missing provider");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
        checkPermission(type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
            GetInstance.Instance instance = GetInstance.getInstance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
                                                        ("Configuration",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
                                                        ConfigurationSpi.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
                                                        type,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
                                                        params,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
                                                        provider);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
            return new ConfigDelegate((ConfigurationSpi)instance.impl,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
                                                        instance.provider,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
                                                        type,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
                                                        params);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
        } catch (NoSuchAlgorithmException nsae) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
            return handleException (nsae);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
    private static Configuration handleException(NoSuchAlgorithmException nsae)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
                throws NoSuchAlgorithmException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
        Throwable cause = nsae.getCause();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
        if (cause instanceof IllegalArgumentException) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
            throw (IllegalArgumentException)cause;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
        throw nsae;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
     * Return the Provider of this Configuration.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
     * <p> This Configuration instance will only have a Provider if it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
     * was obtained via a call to <code>Configuration.getInstance</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
     * Otherwise this method returns null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
     * @return the Provider of this Configuration, or null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
    public Provider getProvider() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
     * Return the type of this Configuration.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
     * <p> This Configuration instance will only have a type if it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
     * was obtained via a call to <code>Configuration.getInstance</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
     * Otherwise this method returns null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
     * @return the type of this Configuration, or null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
    public String getType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
     * Return Configuration parameters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
     * <p> This Configuration instance will only have parameters if it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
     * was obtained via a call to <code>Configuration.getInstance</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
     * Otherwise this method returns null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
     * @return Configuration parameters, or null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
    public Configuration.Parameters getParameters() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
     * Retrieve the AppConfigurationEntries for the specified <i>name</i>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
     * from this Configuration.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
     * @param name the name used to index the Configuration.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
     * @return an array of AppConfigurationEntries for the specified <i>name</i>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
     *          from this Configuration, or null if there are no entries
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
     *          for the specified <i>name</i>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
    public abstract AppConfigurationEntry[] getAppConfigurationEntry
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
                                                        (String name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
     * Refresh and reload the Configuration.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
     * <p> This method causes this Configuration object to refresh/reload its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
     * contents in an implementation-dependent manner.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
     * For example, if this Configuration object stores its entries in a file,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
     * calling <code>refresh</code> may cause the file to be re-read.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
     * <p> The default implementation of this method does nothing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
     * This method should be overridden if a refresh operation is supported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
     * by the implementation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
     * @exception SecurityException if the caller does not have permission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
     *                          to refresh its Configuration.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
    public void refresh() { }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
     * This subclass is returned by the getInstance calls.  All Configuration
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
     * calls are delegated to the underlying ConfigurationSpi.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
    private static class ConfigDelegate extends Configuration {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
        private ConfigurationSpi spi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
        private Provider p;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
        private String type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
        private Configuration.Parameters params;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
        private ConfigDelegate(ConfigurationSpi spi, Provider p,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
                        String type, Configuration.Parameters params) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
            this.spi = spi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
            this.p = p;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
            this.type = type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
            this.params = params;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
        public String getType() { return type; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
        public Configuration.Parameters getParameters() { return params; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
        public Provider getProvider() { return p; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
        public AppConfigurationEntry[] getAppConfigurationEntry(String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
            return spi.engineGetAppConfigurationEntry(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
        public void refresh() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
            spi.engineRefresh();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
     * This represents a marker interface for Configuration parameters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
    public static interface Parameters { }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
}