01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */package org.apache.geronimo.deployment.cli;
17:
18: import java.io.BufferedInputStream;
19: import java.io.BufferedOutputStream;
20: import java.io.File;
21: import java.io.FileInputStream;
22: import java.io.FileOutputStream;
23: import java.io.IOException;
24: import java.io.InputStream;
25: import java.io.OutputStream;
26: import java.util.Properties;
27:
28: import org.apache.geronimo.cli.deployer.CommandArgs;
29: import org.apache.geronimo.common.DeploymentException;
30: import org.apache.geronimo.crypto.EncryptionManager;
31: import jline.ConsoleReader;
32:
33: /**
34: * The CLI deployer logic to start.
35: *
36: * @version $Rev: 617588 $ $Date: 2008-02-01 10:20:07 -0800 (Fri, 01 Feb 2008) $
37: */
38: public class CommandLogin extends AbstractCommand {
39:
40: public void execute(ConsoleReader consoleReader,
41: ServerConnection connection, CommandArgs commandArgs)
42: throws DeploymentException {
43: try {
44: File authFile = new File(System.getProperty("user.home"),
45: ".geronimo-deployer");
46: if (!authFile.exists()) {
47: if (!authFile.createNewFile()) {
48: throw new DeploymentException("Unable to create "
49: + authFile.getAbsolutePath()
50: + " to hold saved logins");
51: }
52: }
53: if (!authFile.canRead() || !authFile.canWrite()) {
54: throw new DeploymentException("Saved login file "
55: + authFile.getAbsolutePath()
56: + " is not readable or not writable");
57: }
58: Properties props = new Properties();
59: InputStream authIn = new BufferedInputStream(
60: new FileInputStream(authFile));
61: props.load(authIn);
62: authIn.close();
63: props.setProperty("login." + connection.getServerURI(),
64: EncryptionManager.encrypt(connection
65: .getAuthentication()));
66: OutputStream save = new BufferedOutputStream(
67: new FileOutputStream(authFile));
68: props
69: .store(save,
70: "Saved authentication information to connect to Geronimo servers");
71: save.flush();
72: save.close();
73: consoleReader.printString(DeployUtils.reformat(
74: "Saved login for: " + connection.getServerURI(), 4,
75: 72));
76: consoleReader.printNewline();
77: } catch (IOException e) {
78: throw new DeploymentException(
79: "Unable to save authentication to login file", e);
80: }
81: }
82: }
|