String getServerURI() {
return auth.uri;
}
private void tryToConnect(String argURI, String driver, String user, String password, boolean secure) throws DeploymentException {
DeploymentFactoryManager mgr = DeploymentFactoryManager.getInstance();
if (driver != null) {
loadDriver(driver, mgr);
} else {
mgr.registerDeploymentFactory(geronimoDeploymentFactory);
}
String useURI = argURI == null ? getDefaultURI(secure) : argURI;
if (user == null && password == null) {
InputStream in;
// First check for .geronimo-deployer on class path (e.g. packaged in deployer.jar)
in = ServerConnection.class.getResourceAsStream("/.geronimo-deployer");
// If not there, check in home directory
if (in == null) {
File authFile = new File(System.getProperty("user.home"), ".geronimo-deployer");
if (authFile.exists() && authFile.canRead()) {
try {
in = new BufferedInputStream(new FileInputStream(authFile));
} catch (FileNotFoundException e) {
// ignore
}
}
}
if (in != null) {
try {
Properties props = new Properties();
props.load(in);
String encrypted = props.getProperty("login." + useURI);
if (encrypted != null) {
if (encrypted.startsWith("{Plain}")) {
int pos = encrypted.indexOf("/");
user = encrypted.substring(7, pos);
password = encrypted.substring(pos + 1);
} else {
Object o = EncryptionManager.decrypt(encrypted);
if (o == encrypted) {
System.out.print(DeployUtils.reformat("Unknown encryption used in saved login file", 4, 72));
} else {
SavedAuthentication auth = (SavedAuthentication) o;
if (auth.uri.equals(useURI)) {
user = auth.user;
password = new String(auth.password);
}
}
}
}
} catch (IOException e) {
System.out.print(DeployUtils.reformat("Unable to read authentication from saved login file: " + e.getMessage(), 4, 72));
} finally {
try {
in.close();
} catch (IOException e) {
// ingore
}
}
}
}
if (user == null || password == null) {
try {
InputPrompt prompt = new InputPrompt(in, out);
if (user == null) {
user = prompt.getInput("Username: ");
}
if (password == null) {
password = prompt.getPassword("Password: ");
}
} catch (IOException e) {
throw new DeploymentException("Unable to prompt for login", e);
}
}
try {
manager = mgr.getDeploymentManager(useURI, user, password);
auth = new SavedAuthentication(useURI, user, password == null ? null : password.toCharArray());
} catch (AuthenticationFailedException e) {
// server's there, you just can't talk to it
throw new DeploymentException("Login Failed");
} catch (DeploymentManagerCreationException e) {