public void initialize(Subject subject,
CallbackHandler callbackHandler,
Map sharedState,
Map options) {
this.subject = subject;
this.handler = callbackHandler;
for (Object key : options.keySet()) {
Option option = Option.findByName((String) key);
if (option != null) {
String value = (String) options.get(key);
optionsMap.put(option, value.trim());
} else {
log.warning("Ignoring option: {0}. Not supported.", key);
}
}
userSelect = optionsMap.get(Option.USER_SELECT);
groupSelect = optionsMap.get(Option.GROUP_SELECT);
digest = optionsMap.get(Option.DIGEST);
encoding = optionsMap.get(Option.ENCODING);
if (!StringUtilities.checkNullBlankString(digest)) {
// Check if the digest algorithm is available
try {
MessageDigest.getInstance(digest);
} catch (NoSuchAlgorithmException e) {
initError(e, "Digest algorithm %s is not available.", digest);
}
if (encoding != null && !"hex".equalsIgnoreCase(encoding) && !"base64".equalsIgnoreCase(encoding)) {
initError(null, "Digest Encoding %s is not supported.", encoding);
}
}
if (optionsMap.containsKey(Option.DATABASE_POOL_NAME)) {
String dataSourceName = optionsMap.get(Option.DATABASE_POOL_NAME);
ContainerSystem containerSystem = SystemInstance.get().getComponent(ContainerSystem.class);
try {
dataSource = (DataSource) containerSystem.getJNDIContext().lookup("openejb/Resource/" + dataSourceName);
} catch (NamingException e) {
initError(e, "Data source %s not found.", dataSourceName);
}
} else if (optionsMap.containsKey(Option.CONNECTION_URL)) {
connectionURL = optionsMap.get(Option.CONNECTION_URL);
String user = optionsMap.get(Option.USER);
String password = optionsMap.get(Option.PASSWORD);
String driverName = optionsMap.get(Option.DRIVER);
properties = new Properties();
if (user != null) {
properties.put("user", user);
}
if (password != null) {
properties.put("password", password);
}
if (driverName != null) {
ClassLoader cl = getClass().getClassLoader();
try {
driver = (Driver) cl.loadClass(driverName).newInstance();
} catch (ClassNotFoundException e) {
initError(e, "Driver class %s is not available. Perhaps you need to add it as a dependency in your deployment plan?", driverName);
} catch (Exception e) {
initError(e, "Unable to load, instantiate, register driver %s: %s", driverName, e.getMessage());
}
}
} else {
initError(null, "Neither %s nor %s was specified", Option.DATABASE_POOL_NAME.name, Option.CONNECTION_URL.name);
}
}
|