/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* This class represents a default implementation for
* <code>javax.security.auth.login.Configuration</code>.
*
* <p> This object stores the runtime login configuration representation,
* and is the amalgamation of multiple static login
* configurations that resides in files.
* The algorithm for locating the login configuration file(s) and reading their
* information into this <code>Configuration</code> object is:
*
* <ol>
* <li>
* Loop through the <code>java.security.Security</code> properties,
* <i>login.config.url.1</i>, <i>login.config.url.2</i>, ...,
* <i>login.config.url.X</i>. These properties are set
* in the Java security properties file, which is located in the file named
* <JAVA_HOME>/lib/security/java.security.
* <JAVA_HOME> refers to the value of the java.home system property,
* and specifies the directory where the JRE is installed.
* Each property value specifies a <code>URL</code> pointing to a
* login configuration file to be loaded. Read in and load
* each configuration.
*
* <li>
* The <code>java.lang.System</code> property
* <i>java.security.auth.login.config</i>
* may also be set to a <code>URL</code> pointing to another
* login configuration file
* (which is the case when a user uses the -D switch at runtime).
* If this property is defined, and its use is allowed by the
* security property file (the Security property,
* <i>policy.allowSystemProperty</i> is set to <i>true</i>),
* also load that login configuration.
*
* <li>
* If the <i>java.security.auth.login.config</i> property is defined using
* "==" (rather than "="), then ignore all other specified
* login configurations and only load this configuration.
*
* <li>
* If no system or security properties were set, try to read from the file,
* ${user.home}/.java.login.config, where ${user.home} is the value
* represented by the "user.home" System property.
* </ol>
*
* <p> The configuration syntax supported by this implementation
* is exactly that syntax specified in the
* <code>javax.security.auth.login.Configuration</code> class.
*
* @see javax.security.auth.login.LoginContext
*/
private int lookahead;
private int linenum;
private boolean expandProp = true;
/**
* Create a new <code>Configuration</code> object.
*/
public ConfigFile() {
try {
} catch (IOException ioe) {
throw (SecurityException)
}
}
/**
* Create a new <code>Configuration</code> object from the specified URI.
*
* @param uri Create a new Configuration object from this URI.
*/
// only load config from the specified URI
try {
} catch (MalformedURLException mue) {
throw (SecurityException)
} catch (IOException ioe) {
throw (SecurityException)
}
}
/**
* Read and initialize the entire login Configuration.
*
* <p>
*
* @exception IOException if the Configuration can not be initialized. <p>
* @exception SecurityException if the caller does not have permission
* to initialize the Configuration.
*/
boolean initialized = false;
expandProp = false;
}
// new configuration
new HashMap<>();
/**
* If the caller specified a URI via Configuration.getInstance,
* we only read from that URI
*/
if (debugConfig != null) {
}
return;
}
/**
* Caller did not specify URI via Configuration.getInstance.
* Read from URLs listed in the java.security properties file.
*/
("policy.allowSystemProperty");
if (extra_config != null) {
boolean overrideAll = false;
overrideAll = true;
}
try {
"sun.security.util.AuthResources"));
}
try {
if (configFile.exists()) {
} else {
("extra.config.No.such.file.or.directory.",
"sun.security.util.AuthResources"));
}
}
if (debugConfig != null) {
}
initialized = true;
if (overrideAll) {
if (debugConfig != null) {
}
return;
}
}
}
int n = 1;
("login.config.url."+n)) != null) {
try {
if (debugConfig != null) {
}
initialized = true;
"sun.security.util.AuthResources"));
}
n++;
}
// get the config from the user's home directory
if (debugConfig != null) {
"from ~/.java.login.config");
}
// No longer throws an exception when there's no config file
// at all. Returns an empty Configuration instead.
}
}
}
throws IOException {
try {
} catch (FileNotFoundException fnfe) {
if (debugConfig != null) {
}
("Configuration.Error.No.such.file.or.directory",
"sun.security.util.AuthResources"));
} finally {
}
}
}
/**
* Retrieve an entry from the Configuration using an application name
* as an index.
*
* <p>
*
* @param applicationName the name used to index the Configuration.
* @return an array of AppConfigurationEntries which correspond to
* the stacked configuration of LoginModules for this
* application, or null if this application has no configured
* LoginModules.
*/
synchronized (configuration) {
}
return null;
e.getControlFlag(),
e.getOptions());
}
return entries;
}
/**
* Refresh and reload the Configuration by re-reading all of the
* login configurations.
*
* <p>
*
* @exception SecurityException if the caller does not have permission
* to refresh the Configuration.
*/
public synchronized void refresh() {
try {
throw (SecurityException) new SecurityException
}
return null;
}
});
}
throws IOException {
int linenum = 1;
if (!(reader instanceof BufferedReader))
st.lowerCaseMode(false);
st.slashSlashComments(true);
st.slashStarComments(true);
st.eolIsSignificant(true);
}
}
private void parseLoginEntry(
throws IOException {
// application name
if (debugParser != null) {
}
match("{");
// get the modules
while (peek("}") == false) {
// get the module class name
// controlFlag (required, optional, etc)
else {
("Configuration.Error.Invalid.control.flag.flag",
"sun.security.util.AuthResources"));
}
// get the args
while (peek(";") == false) {
match("=");
try {
}
}
// create the new element
if (debugParser != null) {
while (i.hasNext()) {
key +
"=" +
}
}
options);
}
match("}");
match(";");
// add this configuration entry
("Configuration.Error.Can.not.specify.multiple.entries.for.appName",
"sun.security.util.AuthResources"));
}
}
switch(lookahead) {
case StreamTokenizer.TT_EOF:
("Configuration.Error.expected.expect.read.end.of.file.",
"sun.security.util.AuthResources"));
case '"':
case StreamTokenizer.TT_WORD:
} else {
("Configuration.Error.Line.line.expected.expect.found.value.",
"sun.security.util.AuthResources"));
}
break;
case '{':
} else {
("Configuration.Error.Line.line.expected.expect.",
"sun.security.util.AuthResources"));
}
break;
case ';':
} else {
("Configuration.Error.Line.line.expected.expect.",
"sun.security.util.AuthResources"));
}
break;
case '}':
} else {
("Configuration.Error.Line.line.expected.expect.",
"sun.security.util.AuthResources"));
}
break;
case '=':
} else {
("Configuration.Error.Line.line.expected.expect.",
"sun.security.util.AuthResources"));
}
break;
default:
("Configuration.Error.Line.line.expected.expect.found.value.",
"sun.security.util.AuthResources"));
}
return value;
}
boolean found = false;
switch (lookahead) {
case ',':
found = true;
break;
case ';':
found = true;
break;
case '{':
found = true;
break;
case '}':
found = true;
break;
default:
}
return found;
}
int tok;
linenum++;
}
return tok;
}
/*
* Fast path reading from file urls in order to avoid calling
* FileURLConnection.connect() which can be quite slow the first time
* it is called. We really should clean up FileURLConnection so that
* this is not a problem but in the meantime this fix helps reduce
* start up time noticeably for the new launcher. -- DAC
*/
// Compatibility notes:
//
// Code changed from
// String path = url.getFile().replace('/', File.separatorChar);
// return new FileInputStream(path);
//
// The original implementation would search for "/tmp/a%20b"
// when url is "file:///tmp/a%20b". This is incorrect. The
// current codes fix this bug and searches for "/tmp/a b".
// For compatibility reasons, when the file "/tmp/a b" does
// not exist, the file named "/tmp/a%20b" will be tried.
//
// This also means that if both file exists, the behavior of
// this method is changed, and the current codes choose the
// correct one.
try {
return url.openStream();
} catch (Exception e) {
}
if (debugConfig != null) {
", try " + file);
}
return new FileInputStream(file);
}
} else {
return url.openStream();
}
}
return value;
}
if (expandProp) {
("Configuration.Error.Line.line.system.property.value.expanded.to.empty.value",
"sun.security.util.AuthResources"));
}
return s;
} else {
return value;
}
}
}