1 17 18 package org.apache.geronimo.deployment.cli; 19 20 import org.apache.geronimo.common.DeploymentException; 21 import org.apache.geronimo.util.SimpleEncryption; 22 23 import java.io.PrintWriter ; 24 import java.io.File ; 25 import java.io.InputStream ; 26 import java.io.FileInputStream ; 27 import java.io.BufferedInputStream ; 28 import java.io.OutputStream ; 29 import java.io.BufferedOutputStream ; 30 import java.io.FileOutputStream ; 31 import java.io.IOException ; 32 import java.util.Properties ; 33 34 39 public class CommandLogin extends AbstractCommand { 40 public CommandLogin() { 41 super("login", "1. Common Commands", "", 42 "Saves the username and password for this connection to the "+ 43 "file .geronimo-deployer in the current user's home directory. " + 44 "Future connections to the same server will try to use this "+ 45 "saved authentication information instead of prompting where " + 46 "possible. This information is saved separately per connection " + 47 "URL, so you can specify --url or --host and/or --port on the command " + 48 "line to save a login to a different server.\n" + 49 "WARNING: while the login information is not saved in " + 50 "clear text, it is not secure either. If you want to " + 51 "save the authentication securely, you should change the " + 52 ".geronimo-deployer file in your home directory so that nobody " + 53 "else can read or write it."); 54 } 55 56 public CommandLogin(String command, String group, String helpArgumentList, String helpText) { 57 super(command, group, helpArgumentList, helpText); 58 } 59 60 public void execute(PrintWriter out, ServerConnection connection, String [] args) throws DeploymentException { 61 try { 62 File authFile = new File (System.getProperty("user.home"), ".geronimo-deployer"); 63 if(!authFile.exists()) { 64 if(!authFile.createNewFile()) { 65 throw new DeploymentException("Unable to create "+authFile.getAbsolutePath()+" to hold saved logins"); 66 } 67 } 68 if(!authFile.canRead() || !authFile.canWrite()) { 69 throw new DeploymentException("Saved login file "+authFile.getAbsolutePath()+" is not readable or not writable"); 70 } 71 Properties props = new Properties (); 72 InputStream in = new BufferedInputStream (new FileInputStream (authFile)); 73 props.load(in); 74 in.close(); 75 props.setProperty("login."+connection.getServerURI(), "{Standard}"+SimpleEncryption.encrypt(connection.getAuthentication())); 76 OutputStream save = new BufferedOutputStream (new FileOutputStream (authFile)); 77 props.store(save, "Saved authentication information to connect to Geronimo servers"); 78 save.flush(); 79 save.close(); 80 System.out.print(DeployUtils.reformat("Saved login for: "+connection.getServerURI(), 4, 72)); 81 } catch (IOException e) { 82 throw new DeploymentException("Unable to save authentication to login file", e); 83 } 84 } 85 } 86 | Popular Tags |