author | mullan |
Wed, 26 Dec 2012 10:07:00 -0500 | |
changeset 14923 | 189882d66a51 |
parent 14775 | 2ed01c760aea |
child 19385 | a7b34a4b1fcb |
permissions | -rw-r--r-- |
2 | 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 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
package com.sun.security.auth.login; |
|
27 |
||
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 | 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 | 37 |
|
38 |
/** |
|
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 | 41 |
* |
42 |
* <p> This object stores the runtime login configuration representation, |
|
43 |
* and is the amalgamation of multiple static login |
|
44 |
* configurations that resides in files. |
|
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 | 47 |
* |
48 |
* <ol> |
|
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 | 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 | 54 |
* login configuration file to be loaded. Read in and load |
55 |
* each configuration. |
|
56 |
* |
|
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 | 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 | 61 |
* login configuration file |
62 |
* (which is the case when a user uses the -D switch at runtime). |
|
63 |
* If this property is defined, and its use is allowed by the |
|
64 |
* security property file (the Security property, |
|
65 |
* <i>policy.allowSystemProperty</i> is set to <i>true</i>), |
|
66 |
* also load that login configuration. |
|
67 |
* |
|
68 |
* <li> |
|
69 |
* If the <i>java.security.auth.login.config</i> property is defined using |
|
70 |
* "==" (rather than "="), then ignore all other specified |
|
71 |
* login configurations and only load this configuration. |
|
72 |
* |
|
73 |
* <li> |
|
74 |
* If no system or security properties were set, try to read from the file, |
|
75 |
* ${user.home}/.java.login.config, where ${user.home} is the value |
|
76 |
* represented by the "user.home" System property. |
|
77 |
* </ol> |
|
78 |
* |
|
79 |
* <p> The configuration syntax supported by this implementation |
|
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 | 82 |
* |
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 | 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 | 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 | 89 |
|
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 | 95 |
*/ |
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 | 98 |
} |
99 |
||
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 | 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 | 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 | 110 |
} |
111 |
||
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 | 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 | 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 | 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 | 127 |
} |
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 | 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 | 139 |
} |
140 |
} |