KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > cli > commands > ChangeAdminPasswordCommand


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package com.sun.enterprise.cli.commands;
25
26 import com.sun.enterprise.cli.framework.*;
27
28 /**
29    This class gets called when change-admin-password command is invoked.
30    This class will overwrite validOptions in GenericCommand to validate
31    the userpassword option. If the userpassword and passwordfile options
32    are not entered in the command line and interactive is true, then
33    CLI will prompt the user for the password.
34  */

35 public class ChangeAdminPasswordCommand extends GenericCommand
36 {
37     private static final String JavaDoc ADMIN_PASSWORD = "adminpassword";
38     private static final String JavaDoc PASSWORD = "password";
39     private static final String JavaDoc INTERACTIVE = "interactive";
40     private static final String JavaDoc OLD_ADMIN_PASSWORD = "oldadminpassword";
41     private static final String JavaDoc NEW_ADMIN_PASSWORD = "newadminpassword";
42     private String JavaDoc sPassword;
43     
44     private String JavaDoc getOldAdminPassword()
45         throws CommandValidationException, CommandException
46     {
47         return getPassword(OLD_ADMIN_PASSWORD,
48             "OldAdminPasswordPrompt", null,
49             false, false, false, false, null, null,
50             true, false, true, false);
51     }
52
53     
54     private String JavaDoc getNewAdminPassword()
55         throws CommandValidationException, CommandException
56     {
57         return getPassword(NEW_ADMIN_PASSWORD,
58             "NewAdminPasswordPrompt", "NewAdminPasswordConfirmationPrompt",
59             false, false, false, false, null, null,
60             true, true, true, false);
61     }
62
63     
64     /**
65        This method prompts the user for the old and new adminpassword.
66      */

67     public boolean validateOptions() throws CommandValidationException
68     {
69         super.validateOptions();
70         
71         try {
72             /**
73              * set interactive to true so that passwords can be prompted.
74              **/

75             setOption(INTERACTIVE, "true");
76             //sPassword = getPassword("old " + ADMIN_PASSWORD, true, false, false, false, null, null, true, false, false, false);
77
sPassword = getOldAdminPassword();
78             setOption(PASSWORD, sPassword);
79             //final String adminPassword = getPassword("new " + ADMIN_PASSWORD, true, false, false, false, null, null, true, true, false, false);
80
final String JavaDoc adminPassword = getNewAdminPassword();
81             setOption(ADMIN_PASSWORD, adminPassword);
82         }
83         catch (CommandException ce) {
84             throw new CommandValidationException(ce.getLocalizedMessage());
85         }
86         
87         return true;
88     }
89
90         /**
91          * This is a polymorphic method that overwrites the one in S1ASCommand
92          * class.
93          * The reason for doing this is so that when GenericCommand class
94          * calls getPassword() in runCommand() routine, the warning message
95          * does not get displayed.
96          **/

97     public String JavaDoc getPassword() throws CommandValidationException, CommandException
98     {
99         return sPassword;
100     }
101     
102 }
103
Popular Tags