use of edu.uiuc.ncsa.security.core.exceptions.MyConfigurationException in project OA4MP by ncsa.
the class CopyTool method getEnv.
protected ServiceEnvironmentImpl getEnv(String cfgFileOption, String cfgNameOption) {
if (getCommandLine().getOptionValue(SOURCE_CONFIG_NAME_OPTION).equals(getCommandLine().getOptionValue(TARGET_CONFIG_NAME_OPTION))) {
throw new MyConfigurationException("Error! You have specified that source and target as the same.");
}
String fileName = getCommandLine().getOptionValue(cfgFileOption);
if (fileName == null) {
fileName = getCommandLine().getOptionValue(SOURCE_CONFIG_FILE_OPTION);
}
String configName = getCommandLine().getOptionValue(cfgNameOption);
sayv("loading configuration \"" + (configName == null ? "(none)" : configName) + "\" from file " + fileName);
ConfigurationNode node = ConfigUtil.findConfiguration(fileName, getCommandLine().getOptionValue(cfgNameOption), OA4MPConfigTags.COMPONENT);
// override the logging in the configuration file, since that might be remote.
ConfigurationLoader loader = null;
setConfigurationNode(node);
try {
loader = getLoader();
} catch (Exception e) {
throw new GeneralException("Error: Could not get loader", e);
}
// new CILogonConfigurationLoader(node, getMyLogger());
ServiceEnvironmentImpl env = (ServiceEnvironmentImpl) loader.load();
return env;
}
use of edu.uiuc.ncsa.security.core.exceptions.MyConfigurationException in project OA4MP by ncsa.
the class AbstractClientBootstrapper method getConfigurationLoader.
@Override
public ConfigurationLoader getConfigurationLoader(ServletContext servletContext) throws Exception {
MyLoggingFacade logger = new MyLoggingFacade(getClass().getSimpleName());
logger.info("Starting to load configuration");
try {
ConfigurationLoader x = getConfigurationLoader(ServletConfigUtil.findConfigurationNode(servletContext, getOa4mpConfigFileKey(), getOa4mpConfigNameKey(), ClientXMLTags.COMPONENT));
logger.info("Loaded configuration named " + servletContext.getInitParameter(getOa4mpConfigNameKey()) + " from file " + servletContext.getInitParameter(getOa4mpConfigFileKey()));
return x;
} catch (MyConfigurationException ce) {
logger.info("Did not find a configuration via the servlet context:" + ce.getMessage());
}
logger.info("No configuration found in servlet context. Trying default locations");
// That didn't work, so try to look for it in a few other places.
String configName = servletContext.getInitParameter(getOa4mpConfigNameKey());
ConfigurationLoader loader = loadFromDefaultLocations(logger, configName);
if (loader != null) {
return loader;
}
MyConfigurationException cx = new MyConfigurationException("Error: No configuration found anyplace. OA4MP client startup aborted!");
logger.error(cx);
throw cx;
}
use of edu.uiuc.ncsa.security.core.exceptions.MyConfigurationException in project OA4MP by ncsa.
the class ClientLoader method checkPublicKey.
protected PublicKey checkPublicKey() throws IOException {
String publicKeyFileName = getCfgValue(ClientXMLTags.PUBLIC_KEY);
if (trivial(publicKeyFileName)) {
throw new MyConfigurationException("Error: There is no public key specified.");
}
File publicKeyFile = new File(publicKeyFileName);
if (!publicKeyFile.exists()) {
throw new MyConfigurationException("Error: The specified public key file \"" + publicKeyFileName + "\" does not exist");
}
if (!publicKeyFile.isFile()) {
throw new MyConfigurationException("Error: The specified public key file \"" + publicKeyFileName + "\" is not actually a file");
}
if (!publicKeyFile.canRead()) {
throw new MyConfigurationException("Error: The specified public key file \"" + publicKeyFileName + "\" is not readable. Check the permissions.");
}
return KeyUtil.fromX509PEM(new FileReader(publicKeyFile));
}
use of edu.uiuc.ncsa.security.core.exceptions.MyConfigurationException in project OA4MP by ncsa.
the class FSCAStoreTest method testPermissions.
public void testPermissions() throws Exception {
File storeDirectory = File.createTempFile("fs-store", "-tmp");
File indexDirectory = File.createTempFile("fs-index", "-tmp");
storeDirectory.setWritable(false);
indexDirectory.setWritable(false);
assert !storeDirectory.canWrite();
FSClientApprovalStore x = null;
final ClientApprovalProvider caProvider = new ClientApprovalProvider();
try {
// Make sure that if someone creates a bad one, it blows up in the constructor.
x = new FSClientApprovalStore(null, null, null, null) {
@Override
public Object put(Object key, Object value) {
return null;
}
};
assert false : "Could make a new object without being properly configured";
} catch (MyConfigurationException xx) {
assert true;
}
x = new DSFSClientApprovalStore(storeDirectory, indexDirectory, caProvider, new ClientApproverConverter(caProvider));
try {
// should bomb here.
x.create();
assert false;
} catch (FilePermissionsException xx) {
assert true;
}
// so make a new entry and then have retrieving it fail.
storeDirectory.setWritable(true);
indexDirectory.setWritable(true);
ClientApproval ca = (ClientApproval) x.create();
// fail for store directory un readable
storeDirectory.setReadable(false);
try {
x.get(ca.getIdentifier());
assert false;
} catch (FilePermissionsException xx) {
assert true;
}
}
use of edu.uiuc.ncsa.security.core.exceptions.MyConfigurationException in project OA4MP by ncsa.
the class TestUtils method findConfigNode.
/**
* Loads a given configuration from a specified (on the command line) file.
* Generally you should stick all of your configurations for a test run in a single
* file then use this to pull off the ones you need, by name. If you do not specify a name
* this will try to get a configuration with the name specified at the command line.
*
* @param configName
* @return
*/
public static ConfigurationNode findConfigNode(String configName) {
try {
String fileName = System.getProperty(getBootstrapper().getOa4mpConfigFileKey());
if (fileName == null) {
throw new MyConfigurationException("Error: No configuration file specified");
}
XMLConfiguration cfg = null;
if (fileName.length() != 0) {
// A properties file is supplied. Use that.
try {
cfg = Configurations.getConfiguration(new File(fileName));
} catch (MyConfigurationException cx) {
cx.printStackTrace();
// plan B, maybe it's in the deployment itself? try to get as a resource
URL url = TestUtils.class.getResource(fileName);
if (url == null) {
throw new MyConfigurationException("Error:No configuration found. for \"" + fileName + "\"");
}
cfg = Configurations.getConfiguration(url);
}
} else {
throw new MyConfigurationException("Error:No configuration file found.");
}
ConfigurationNode cn = null;
if (configName == null) {
// try to find a specified configuration.
String cfgName = System.getProperty(getBootstrapper().getOa4mpConfigNameKey());
if (cfgName == null) {
System.out.println("no name for a configuration given");
cn = cfg.configurationAt(COMPONENT).getRootNode();
} else {
System.out.println("getting named configuration \"" + cfgName + "\"");
cn = Configurations.getConfig(cfg, COMPONENT, cfgName);
}
} else {
cn = Configurations.getConfig(cfg, COMPONENT, configName);
}
return cn;
} catch (Exception x) {
throw new MyConfigurationException("Error loading configuration", x);
}
}
Aggregations