KickJava   Java API By Example, From Geeks To Geeks.

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


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 /*
25  * $Id: ChangeMasterPasswordCommand.java,v 1.3 2005/12/25 03:46:20 tcfujii Exp $
26  */

27
28 package com.sun.enterprise.cli.commands;
29
30 import com.sun.enterprise.cli.framework.CommandValidationException;
31 import com.sun.enterprise.cli.framework.CommandException;
32 import com.sun.enterprise.cli.framework.CLILogger;
33
34
35 import com.sun.enterprise.admin.servermgmt.DomainConfig;
36 import com.sun.enterprise.admin.servermgmt.RepositoryManager;
37 import com.sun.enterprise.admin.servermgmt.DomainsManager;
38 import com.sun.enterprise.admin.servermgmt.DomainException;
39
40
41 /**
42  * This is a local command that creates a new domain
43  * @version $Revision: 1.3 $
44  */

45 public class ChangeMasterPasswordCommand extends BaseLifeCycleCommand
46 {
47     private String JavaDoc newMasterPassword = null;
48     private String JavaDoc masterPassword = null;
49
50     /** Creates new CreateDomainCommand */
51     public ChangeMasterPasswordCommand()
52     {
53     }
54
55     /**
56      * An abstract method that validates the options
57      * on the specification in the xml properties file
58      * @return true if successfull
59      */

60     public boolean validateOptions() throws CommandValidationException
61     {
62         super.validateOptions();
63
64         //verify adminpassword is greater than 8 characters
65
if (!isPasswordValid(newMasterPassword)) {
66             throw new CommandValidationException(getLocalizedString("PasswordLimit",
67                 new Object JavaDoc[]{NEW_MASTER_PASSWORD}));
68         }
69                 
70         return true;
71     }
72
73     public void changeMasterPassword(String JavaDoc domainName)
74         throws DomainException, CommandValidationException, CommandException
75     {
76         //WARNING!!! The code below is duplicated in admin-cli-ee ChangeMasterPasswordCommand.java.
77
//I tried to share the code but ran into issues.
78
DomainConfig config = getDomainConfig(domainName);
79         DomainsManager mgr = getFeatureFactory().getDomainsManager();
80         //domain validation upfront (i.e. before we prompt)
81
mgr.validateDomain(config, true);
82         
83         masterPassword = getMasterPassword(new RepositoryManager(), config);
84         //getPassword(optionName, allowedOnCommandLine, readPrefsFile, readPasswordOptionFromPrefs,
85
//readMasterPasswordFile, mgr, config,
86
//promptUser, confirm, validate)
87
config.put(DomainConfig.K_MASTER_PASSWORD, masterPassword);
88         mgr.validateMasterPassword(config);
89         
90         newMasterPassword = getNewMasterPassword();
91         validateOptions();
92         Boolean JavaDoc saveMasterPassword = getSaveMasterPassword(null);
93         config.put(DomainConfig.K_NEW_MASTER_PASSWORD, newMasterPassword);
94         config.put(DomainConfig.K_SAVE_MASTER_PASSWORD, saveMasterPassword);
95         mgr.changeMasterPassword(config);
96         //END WARNING!!!
97
}
98    
99     /**
100      * An abstract method that executes the command
101      * @throws CommandException
102      */

103     public void runCommand()
104         throws CommandException, CommandValidationException
105     {
106         String JavaDoc domainName = null;
107         try {
108             setLoggerLevel();
109             domainName = getDomainName();
110             changeMasterPassword(domainName);
111             CLILogger.getInstance().printDetailMessage(getLocalizedString("DomainPasswordChanged",
112                 new Object JavaDoc[] {domainName}));
113         } catch (Exception JavaDoc e) {
114             CLILogger.getInstance().printDetailMessage(e.getLocalizedMessage());
115             throw new CommandException(getLocalizedString("ExceptionChangingPassword",
116                                                           new Object JavaDoc[] {domainName}), e);
117         }
118     }
119 }
Popular Tags