OSDN Git Service

2006-06-09 Thomas Fitzsimmons <fitzsim@redhat.com>
[pf3gnuchains/gcc-fork.git] / libjava / classpath / tools / gnu / classpath / tools / keytool / IdentityDBCmd.java
1 /* IdentityDBCmd.java -- The identitydb command handler of the keytool
2    Copyright (C) 2006 Free Software Foundation, Inc.
3
4 This file is part of GNU Classpath.
5
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
10
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING.  If not, write to the
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 02110-1301 USA.
20
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library.  Thus, the terms and
23 conditions of the GNU General Public License cover the whole
24 combination.
25
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module.  An independent module is a module which is not derived from
33 or based on this library.  If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so.  If you do not wish to do so, delete this
36 exception statement from your version. */
37
38
39 package gnu.classpath.tools.keytool;
40
41 import gnu.classpath.tools.getopt.ClasspathToolParser;
42 import gnu.classpath.tools.getopt.Option;
43 import gnu.classpath.tools.getopt.OptionException;
44 import gnu.classpath.tools.getopt.OptionGroup;
45 import gnu.classpath.tools.getopt.Parser;
46
47 import java.util.logging.Logger;
48
49 /**
50  * <b>NOT IMPLEMENTED YET</b>
51  * <p>
52  * The <b>-identitydb</b> keytool command handler is used to read the JDK 1.1.x-
53  * style identity database and add its entries to the key store. If a key store
54  * does not exist, it is created.
55  * <p>
56  * Possible options for this command are:
57  * <p>
58  * <dl>
59  *      <dt>-file FILE_NAME</dt>
60  *      <dd>The fully qualified path of the identity file to import. If this
61  *      option is omitted, the tool will process STDIN.
62  *      <p></dd>
63  *      
64  *      <dt>-storetype STORE_TYPE</dt>
65  *      <dd>Use this option to specify the type of the key store to use. The
66  *      default value, if this option is omitted, is that of the property
67  *      <code>keystore.type</code> in the security properties file, which is
68  *      obtained by invoking the {@link java.security.KeyStore#getDefaultType()}
69  *      static method.
70  *      <p></dd>
71  *      
72  *      <dt>-keystore URL</dt>
73  *      <dd>Use this option to specify the location of the key store to use.
74  *      The default value is a file {@link java.net.URL} referencing the file
75  *      named <code>.keystore</code> located in the path returned by the call to
76  *      {@link java.lang.System#getProperty(String)} using <code>user.home</code>
77  *      as argument.
78  *      <p>
79  *      If a URL was specified, but was found to be malformed --e.g. missing
80  *      protocol element-- the tool will attempt to use the URL value as a file-
81  *      name (with absolute or relative path-name) of a key store --as if the
82  *      protocol was <code>file:</code>.
83  *      <p></dd>
84  *      
85  *      <dt>-storepass PASSWORD</dt>
86  *      <dd>Use this option to specify the password protecting the key store. If
87  *      this option is omitted from the command line, you will be prompted to
88  *      provide a password.
89  *      <p></dd>
90  *      
91  *      <dt>-provider PROVIDER_CLASS_NAME</dt>
92  *      <dd>A fully qualified class name of a Security Provider to add to the
93  *      current list of Security Providers already installed in the JVM in-use.
94  *      If a provider class is specified with this option, and was successfully
95  *      added to the runtime --i.e. it was not already installed-- then the tool
96  *      will attempt to removed this Security Provider before exiting.
97  *      <p></dd>
98  *      
99  *      <dt>-v</dt>
100  *      <dd>Use this option to enable more verbose output.</dd>
101  * </dl>
102  */
103 class IdentityDBCmd extends Command
104 {
105   private static final Logger log = Logger.getLogger(IdentityDBCmd.class.getName());
106   protected String _idbFileName;
107   protected String _ksType;
108   protected String _ksURL;
109   protected String _ksPassword;
110   protected String _providerClassName;
111
112   // default 0-arguments constructor
113
114   // public setters -----------------------------------------------------------
115
116   /** @param pathName the fully qualified path name of the file to process. */
117   public void setFile(String pathName)
118   {
119     this._idbFileName = pathName;
120   }
121
122   /** @param type the key-store type to use. */
123   public void setStoretype(String type)
124   {
125     this._ksType = type;
126   }
127
128   /** @param url the key-store URL to use. */
129   public void setKeystore(String url)
130   {
131     this._ksURL = url;
132   }
133
134   /** @param password the key-store password to use. */
135   public void setStorepass(String password)
136   {
137     this._ksPassword = password;
138   }
139
140   /** @param className a security provider fully qualified class name to use. */
141   public void setProvider(String className)
142   {
143     this._providerClassName = className;
144   }
145
146   // life-cycle methods -------------------------------------------------------
147
148   void setup() throws Exception
149   {
150     setInputStreamParam(_idbFileName);
151     setKeyStoreParams(_providerClassName, _ksType, _ksPassword, _ksURL);
152
153     log.finer("-identitydb handler will use the following options:"); //$NON-NLS-1$
154     log.finer("  -file=" + _idbFileName); //$NON-NLS-1$
155     log.finer("  -storetype=" + storeType); //$NON-NLS-1$
156     log.finer("  -keystore=" + storeURL); //$NON-NLS-1$
157     log.finer("  -provider=" + provider); //$NON-NLS-1$
158     log.finer("  -v=" + verbose); //$NON-NLS-1$
159   }
160
161   // own methods --------------------------------------------------------------
162
163   Parser getParser()
164   {
165     log.entering(this.getClass().getName(), "getParser"); //$NON-NLS-1$
166
167     Parser result = new ClasspathToolParser(Main.IDENTITYDB_CMD, true);
168     result.setHeader(Messages.getString("IdentityDBCmd.7")); //$NON-NLS-1$
169     result.setFooter(Messages.getString("IdentityDBCmd.8")); //$NON-NLS-1$
170     OptionGroup options = new OptionGroup(Messages.getString("IdentityDBCmd.9")); //$NON-NLS-1$
171     options.add(new Option(Main.FILE_OPT,
172                            Messages.getString("IdentityDBCmd.10"), //$NON-NLS-1$
173                            Messages.getString("IdentityDBCmd.11")) //$NON-NLS-1$
174     {
175       public void parsed(String argument) throws OptionException
176       {
177         _idbFileName = argument;
178       }
179     });
180     options.add(new Option(Main.STORETYPE_OPT,
181                            Messages.getString("IdentityDBCmd.12"), //$NON-NLS-1$
182                            Messages.getString("IdentityDBCmd.13")) //$NON-NLS-1$
183     {
184       public void parsed(String argument) throws OptionException
185       {
186         _ksType = argument;
187       }
188     });
189     options.add(new Option(Main.KEYSTORE_OPT,
190                            Messages.getString("IdentityDBCmd.14"), //$NON-NLS-1$
191                            Messages.getString("IdentityDBCmd.15")) //$NON-NLS-1$
192     {
193       public void parsed(String argument) throws OptionException
194       {
195         _ksURL = argument;
196       }
197     });
198     options.add(new Option(Main.STOREPASS_OPT,
199                            Messages.getString("IdentityDBCmd.16"), //$NON-NLS-1$
200                            Messages.getString("IdentityDBCmd.17")) //$NON-NLS-1$
201     {
202       public void parsed(String argument) throws OptionException
203       {
204         _ksPassword = argument;
205       }
206     });
207     options.add(new Option(Main.PROVIDER_OPT,
208                            Messages.getString("IdentityDBCmd.18"), //$NON-NLS-1$
209                            Messages.getString("IdentityDBCmd.19")) //$NON-NLS-1$
210     {
211       public void parsed(String argument) throws OptionException
212       {
213         _providerClassName = argument;
214       }
215     });
216     options.add(new Option(Main.VERBOSE_OPT,
217                            Messages.getString("IdentityDBCmd.20")) //$NON-NLS-1$
218     {
219       public void parsed(String argument) throws OptionException
220       {
221         verbose = true;
222       }
223     });
224     result.add(options);
225
226     log.exiting(this.getClass().getName(), "getParser", result); //$NON-NLS-1$
227     return result;
228   }
229 }