ConfigFilepublic class ConfigFile extends AuthConfig This is a default file-based AuthConfig implementation. |
Fields Summary |
---|
private int | epoch | private String | parserClassName | private ConfigParser | parser | static final String | CLIENT | static final String | SERVER | private static final String | DEFAULT_HANDLER_CLASS | private static final String | DEFAULT_PARSER_CLASS | private static final Debug | debug |
Constructors Summary |
---|
ConfigFile()
String propertyValue = System.getProperty("configfile.parser");
if (propertyValue == null) {
parserClassName = DEFAULT_PARSER_CLASS;
} else {
parserClassName = propertyValue;
}
this.epoch = 1;
parser = ConfigFile.loadParser(parserClassName);
|
Methods Summary |
---|
private static java.lang.Object | createModule(com.sun.enterprise.security.jauth.ConfigFile$Entry entry, javax.security.auth.callback.CallbackHandler handler)Instantiate+initialize module class
try {
// instantiate module using no-arg constructor
Object newModule = entry.newInstance();
// initialize module
Object[] initArgs = { entry.getRequestPolicy(),
entry.getResponsePolicy(),
handler,
entry.getOptions() };
try {
Method initMethod = newModule.getClass().getMethod(AuthContext.INIT,
AuthPolicy.class, AuthPolicy.class, CallbackHandler.class,
Map.class);
initMethod.invoke(newModule, initArgs);
// return the new module
return newModule;
} catch(Exception ex) {
throw new SecurityException("could not invoke " +
AuthContext.INIT +
" method in module: " +
newModule.getClass().getName() + " " + ex, ex);
}
} catch (Exception e) {
if (e instanceof AuthException) {
throw (AuthException)e;
}
AuthException ae = new AuthException();
ae.initCause(e);
throw ae;
}
| public ClientAuthContext | getClientAuthContext(java.lang.String intercept, java.lang.String id, AuthPolicy requestPolicy, AuthPolicy responsePolicy, javax.security.auth.callback.CallbackHandler handler)Get a default ClientAuthContext.
ConfigFile.Entry[] entries = getEntries(intercept,
id,
requestPolicy,
responsePolicy,
CLIENT);
if (entries == null || entries.length == 0) {
return null;
}
// instantiate and initialize modules up front as well
if (handler == null) {
handler = ConfigFile.loadDefaultCallbackHandler();
} else if (handler instanceof DependentCallbackHandler) {
handler = new DelegatingHandler(handler);
}
for (int i = 0; i < entries.length; i++) {
entries[i].module = ConfigFile.createModule(entries[i], handler);
}
return new ConfigClient(entries);
| private com.sun.enterprise.security.jauth.ConfigFile$Entry[] | getEntries(java.lang.String intercept, java.lang.String id, AuthPolicy requestPolicy, AuthPolicy responsePolicy, java.lang.String type)
// get the parsed module config and DD information
HashMap configMap;
synchronized (parser) {
configMap = parser.getConfigMap();
}
if (configMap == null) {
return null;
}
// get the module config info for this intercept
InterceptEntry intEntry = (InterceptEntry)configMap.get(intercept);
if (intEntry == null || intEntry.idMap == null) {
if (debug != null) {
debug.println("module config has no IDs configured for [" +
intercept +
"]");
}
return null;
}
// look up the DD's provider ID in the module config
IDEntry idEntry = null;
if (id == null || (idEntry = (IDEntry)intEntry.idMap.get(id)) == null) {
// either the DD did not specify a provider ID,
// or the DD-specified provider ID was not found
// in the module config.
//
// in either case, look for a default ID in the module config
if (debug != null) {
debug.println("DD did not specify ID, " +
"or DD-specified ID for [" +
intercept +
"] not found in config -- " +
"attempting to look for default ID");
}
String defaultID;
if (CLIENT.equals(type)) {
defaultID = intEntry.defaultClientID;
} else {
defaultID = intEntry.defaultServerID;
}
idEntry = (IDEntry)intEntry.idMap.get(defaultID);
if (idEntry == null) {
// did not find a default provider ID
if (debug != null) {
debug.println("no default config ID for [" +
intercept +
"]");
}
return null;
}
}
// we found the DD provider ID in the module config
// or we found a default module config
// check provider-type
if (idEntry.type.indexOf(type) < 0) {
if (debug != null) {
debug.println("request type [" +
type +
"] does not match config type [" +
idEntry.type +
"]");
}
return null;
}
// check whether a policy is set
AuthPolicy reqP = (requestPolicy != null || responsePolicy != null) ?
requestPolicy :
idEntry.requestPolicy; //default;
AuthPolicy respP = (requestPolicy != null || responsePolicy != null) ?
responsePolicy :
idEntry.responsePolicy; //default;
// optimization: if policy was not set, return null
if (reqP == null && respP == null) {
if (debug != null) {
debug.println("no policy applies");
}
return null;
}
// return the configured modules with the correct policies
ConfigFile.Entry[] entries = new Entry[idEntry.modules.size()];
for (int i = 0; i < entries.length; i++) {
AppConfigurationEntry aEntry =
(AppConfigurationEntry)idEntry.modules.get(i);
entries[i] = new ConfigFile.Entry(reqP,
respP,
aEntry.getLoginModuleName(),
aEntry.getControlFlag(),
aEntry.getOptions());
}
if (debug != null) {
debug.println("getEntries found " +
entries.length +
" entries for: " +
intercept +
" -- "
+ id);
for (int i = 0; i < entries.length; i++) {
debug.println("Entry " + (i+1) + ":" +
"\n module class: " + entries[i].getLoginModuleName() +
"\n flag: " + entries[i].getControlFlag() +
"\n options: " + entries[i].getOptions() +
"\n request policy: " + entries[i].requestPolicy +
"\n response policy: " + entries[i].responsePolicy);
}
}
return entries;
| public ServerAuthContext | getServerAuthContext(java.lang.String intercept, java.lang.String id, AuthPolicy requestPolicy, AuthPolicy responsePolicy, javax.security.auth.callback.CallbackHandler handler)Get a default ServerAuthContext.
ConfigFile.Entry[] entries = getEntries(intercept,
id,
requestPolicy,
responsePolicy,
SERVER);
if (entries == null || entries.length == 0) {
return null;
}
// instantiate and initialize modules up front as well
if (handler == null) {
handler = ConfigFile.loadDefaultCallbackHandler();
} else if (handler instanceof DependentCallbackHandler) {
handler = new DelegatingHandler(handler);
}
for (int i = 0; i < entries.length; i++) {
entries[i].module = ConfigFile.createModule(entries[i], handler);
}
return new ConfigServer(entries);
| private static javax.security.auth.callback.CallbackHandler | loadDefaultCallbackHandler()get the default callback handler
// get the default handler class
try {
final ClassLoader finalLoader = AuthConfig.getClassLoader();
return (CallbackHandler)
java.security.AccessController.doPrivileged
(new java.security.PrivilegedExceptionAction() {
public Object run() throws Exception {
String className = DEFAULT_HANDLER_CLASS;
Class c = Class.forName(className,
true,
finalLoader);
return c.newInstance();
}
});
} catch (java.security.PrivilegedActionException pae) {
AuthException aex = new AuthException(pae.getException().toString());
aex.initCause(pae.getException());
throw aex;
}
| private static ConfigParser | loadParser(java.lang.String className)get a custom config file parser
XXX custom file that can be used in place of [domain|sun-acc].xml
try {
final String finalClassName = className;
final ClassLoader finalLoader = AuthConfig.getClassLoader();
return (ConfigParser)java.security.AccessController.doPrivileged
(new java.security.PrivilegedExceptionAction() {
public Object run() throws Exception {
Class c = Class.forName(finalClassName,true,finalLoader);
return c.newInstance();
}
});
} catch (java.security.PrivilegedActionException pae) {
IOException iex = new IOException(pae.getException().toString());
iex.initCause(pae.getException());
throw iex;
}
| public void | refresh()
synchronized (parser) {
ConfigParser nextParser;
int next = this.epoch + 1;
try {
nextParser = ConfigFile.loadParser(parserClassName);
} catch (IOException ioe) {
throw new AuthException(ioe.toString());
}
this.epoch = (next == 0 ? 1 : next);
parser = nextParser;
}
|
|