KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ejbca > core > model > ra > raadmin > GlobalConfiguration


1 /*************************************************************************
2  * *
3  * EJBCA: The OpenSource Certificate Authority *
4  * *
5  * This software is free software; you can redistribute it and/or *
6  * modify it under the terms of the GNU Lesser General Public *
7  * License as published by the Free Software Foundation; either *
8  * version 2.1 of the License, or any later version. *
9  * *
10  * See terms of license at gnu.org. *
11  * *
12  *************************************************************************/

13  
14 package org.ejbca.core.model.ra.raadmin;
15
16
17
18 import org.ejbca.core.model.UpgradeableDataHashMap;
19
20
21 /**
22  * This is a class containing global configuration parameters.
23  *
24  * @version $Id: GlobalConfiguration.java,v 1.8.2.1 2007/01/24 08:47:42 anatom Exp $
25  */

26 public class GlobalConfiguration extends UpgradeableDataHashMap implements java.io.Serializable JavaDoc {
27
28     // Default Values
29
public static final float LATEST_VERSION = 1;
30     
31     public static final String JavaDoc EJBCA_VERSION = "@ejbca.version@";
32
33     /**
34      * Setting to indicate if the secret information stored on hard tokens (i.e initial PIN/PUK codes) should
35      * be displayed for the administrators. If false only non-sensitive information is displayed.
36      */

37     public static final boolean HARDTOKEN_DIPLAYSENSITIVEINFO = "@hardtoken.diplaysensitiveinfo@".equalsIgnoreCase("true");
38     
39     public static final String JavaDoc PREFEREDINTERNALRESOURCES = "@intresources.preferredlanguage@".trim();
40     public static final String JavaDoc SECONDARYINTERNALRESOURCES = "@intresources.secondarylanguage@".trim();
41
42     // Entries to choose from in userpreference part, defines the size of data to be displayed on one page.
43
private final String JavaDoc[] DEFAULTPOSSIBLEENTRIESPERPAGE = {"10" , "25" , "50" , "100"};
44     // Entries to choose from in view log part, defines the size of data to be displayed on one page.
45
private final String JavaDoc[] DEFAULTPOSSIBLELOGENTRIESPERPAGE = {"10" , "25" , "50" , "100", "200", "400"};
46
47     // Path added to baseurl used as default vaule in CRLDistributionPointURI field in Certificate Profile definitions.
48
private static final String JavaDoc DEFAULTCRLDISTURIPATH = "publicweb/webdist/certdist?cmd=crl&issuer=";
49     
50     // Path added to baseurl used as default vaule in CRLDistributionPointURI field in Certificate Profile definitions.
51
private static final String JavaDoc DEFAULTCRLDISTURIPATHDN = "CN=TestCA,O=AnaTom,C=SE";
52
53
54     // Path added to baseurl used as default vaule in OCSP Service Locator URI field in Certificate Profile definitions.
55
private static final String JavaDoc DEFAULTOCSPSERVICELOCATORURIPATH = "publicweb/status/ocsp";
56
57     // Default name of headbanner in web interface.
58
private static final String JavaDoc DEFAULTHEADBANNER = "head_banner.jsp";
59     // Default name of footbanner page in web interface.
60
private static final String JavaDoc DEFAULTFOOTBANNER = "foot_banner.jsp";
61
62     // Title of ra admin web interface.
63
private static final String JavaDoc DEFAULTEJBCATITLE = "@EJBCA@ Administration";
64
65     // Language codes. Observe the order is important
66
public static final int EN = 0;
67     public static final int SE = 1;
68
69     // Public constants.
70
public static final String JavaDoc HEADERFRAME = "topFrame"; // Name of header browser frame
71
public static final String JavaDoc MENUFRAME = "leftFrame"; // Name of menu browser frame
72
public static final String JavaDoc MAINFRAME = "mainFrame"; // Name of main browser frame
73

74
75     /** Creates a new instance of Globaldatauration */
76     public GlobalConfiguration() {
77        super();
78
79        setEjbcaTitle(DEFAULTEJBCATITLE);
80        setEnableEndEntityProfileLimitations(true);
81        setEnableAuthenticatedUsersOnly(false);
82        setEnableKeyRecovery(false);
83        setIssueHardwareTokens(false);
84     }
85     
86     
87     /** Initializes a new global datauration with data used in ra web interface. */
88     public void initialize(String JavaDoc adminpath, String JavaDoc availablelanguages, String JavaDoc availablethemes,
89                            String JavaDoc publicport, String JavaDoc privateport, String JavaDoc publicprotocol, String JavaDoc privateprotocol){
90        
91        String JavaDoc tempadminpath = adminpath.trim();
92
93        
94        if(tempadminpath == null)
95          tempadminpath = "";
96        if(!tempadminpath.endsWith("/") && !tempadminpath.equals("")){
97          tempadminpath = tempadminpath + "/"; // Add ending '/'
98
}
99        if(tempadminpath.startsWith("/")){
100          tempadminpath =tempadminpath.substring(1); // Remove starting '/'
101
}
102
103        
104        
105        data.put(ADMINPATH,tempadminpath);
106        data.put(AVAILABLELANGUAGES,availablelanguages.trim());
107        data.put(AVAILABLETHEMES,availablethemes.trim());
108        data.put(PUBLICPORT,publicport.trim());
109        data.put(PRIVATEPORT,privateport.trim());
110        data.put(PUBLICPROTOCOL,publicprotocol.trim());
111        data.put(PRIVATEPROTOCOL,privateprotocol.trim());
112
113        data.put(AUTHORIZATION_PATH,tempadminpath+"administratorprivileges");
114        data.put(BANNERS_PATH,"banners");
115        data.put(CA_PATH, tempadminpath+"ca");
116        data.put(CONFIG_PATH,tempadminpath+"sysconfig");
117        data.put(HELP_PATH,"help");
118        data.put(IMAGES_PATH,"images");
119        data.put(LANGUAGE_PATH,"languages");
120        data.put(LOG_PATH,tempadminpath+"log");
121        data.put(RA_PATH,tempadminpath+"ra");
122        data.put(THEME_PATH,"themes");
123        data.put(HARDTOKEN_PATH,tempadminpath+"hardtoken");
124
125        data.put(LANGUAGEFILENAME,"languagefile");
126        data.put(MAINFILENAME,"main.jsp");
127        data.put(INDEXFILENAME,"index.jsp");
128        data.put(MENUFILENAME,"adminmenu.jsp");
129        data.put(ERRORPAGE,"errorpage.jsp");
130
131        setHeadBanner(DEFAULTHEADBANNER);
132        setFootBanner(DEFAULTFOOTBANNER);
133
134     }
135
136     /** Checks if global datauration have been initialized. */
137     public boolean isInitialized(){
138       return data.get(AVAILABLELANGUAGES)!=null;
139     }
140
141     /** Method used by the Admin GUI. */
142     public String JavaDoc getBaseUrl(String JavaDoc requestServerName) {
143         return (String JavaDoc) data.get(GlobalConfiguration.PRIVATEPROTOCOL) + "://" +
144                     requestServerName + "/" +
145                    (String JavaDoc) data.get(GlobalConfiguration.APPLICATIONPATH);
146    }
147     
148     public String JavaDoc getBaseUrl() {
149         return (String JavaDoc) data.get(GlobalConfiguration.PRIVATEPROTOCOL) + "://" +
150                    (String JavaDoc) data.get(GlobalConfiguration.COMPUTERNAME) + ":" +
151                    (String JavaDoc) data.get(GlobalConfiguration.PRIVATEPORT) + "/" +
152                    (String JavaDoc) data.get(GlobalConfiguration.APPLICATIONPATH);
153    }
154         
155     
156     
157     public void setComputerName(String JavaDoc computername){
158         data.put(COMPUTERNAME, computername);
159     }
160     
161     public void setApplicationPath(String JavaDoc applicationpath){
162      // Add trailing '/' if it doesn't exists.
163
if(!applicationpath.endsWith("/")){
164          data.put(APPLICATIONPATH,applicationpath + "/");
165        }
166        else{
167          data.put(APPLICATIONPATH,applicationpath);
168        }
169      }
170     
171     
172
173     public String JavaDoc getAdminWebPath(){return (String JavaDoc) data.get(ADMINPATH);}
174
175     public String JavaDoc getStandardCRLDistributionPointURI(){
176         String JavaDoc retval = getBaseUrl();
177         retval =retval.replaceFirst((String JavaDoc) data.get(PRIVATEPROTOCOL), (String JavaDoc) data.get(PUBLICPROTOCOL));
178         retval =retval.replaceFirst((String JavaDoc) data.get(PRIVATEPORT), (String JavaDoc) data.get(PUBLICPORT));
179         retval+= DEFAULTCRLDISTURIPATH + DEFAULTCRLDISTURIPATHDN;
180         return retval;
181     }
182     
183     public String JavaDoc getStandardCRLDistributionPointURINoDN(){
184         String JavaDoc retval = getBaseUrl();
185         retval =retval.replaceFirst((String JavaDoc) data.get(PRIVATEPROTOCOL), (String JavaDoc) data.get(PUBLICPROTOCOL));
186         retval =retval.replaceFirst((String JavaDoc) data.get(PRIVATEPORT), (String JavaDoc) data.get(PUBLICPORT));
187         retval+= DEFAULTCRLDISTURIPATH;
188         return retval;
189     }
190         
191     public String JavaDoc getStandardOCSPServiceLocatorURI(){
192         String JavaDoc retval = getBaseUrl();
193         retval =retval.replaceFirst((String JavaDoc) data.get(PRIVATEPROTOCOL), (String JavaDoc) data.get(PUBLICPROTOCOL));
194         retval =retval.replaceFirst((String JavaDoc) data.get(PRIVATEPORT), (String JavaDoc) data.get(PUBLICPORT));
195         retval+= DEFAULTOCSPSERVICELOCATORURIPATH;
196         return retval;
197     }
198
199      /** Checks the themes paht for css files and returns an array of filenames
200      * without the ".css" ending. */

201     public String JavaDoc[] getAvailableThemes() {
202        String JavaDoc[] availablethemes;
203        availablethemes = getAvailableThemesAsString().split(",");
204        if(availablethemes != null){
205          for(int i = 0; i < availablethemes.length; i++){
206            availablethemes[i] = availablethemes[i].trim();
207            if(availablethemes[i].endsWith(".css")){
208              availablethemes[i] = availablethemes[i].substring(0,availablethemes[i].length()-4);
209            }
210          }
211        }
212        return availablethemes;
213     }
214
215     /** Returns the default avaiable theme used by administrator preferences. */
216     public String JavaDoc getDefaultAvailableTheme(){
217       return getAvailableThemes()[0];
218     }
219     
220
221     
222     // Methods for manipulating the headbanner filename.
223
public String JavaDoc getHeadBanner() {return (String JavaDoc) data.get(HEADBANNER);}
224     public String JavaDoc getHeadBannerFilename(){
225       String JavaDoc returnval = (String JavaDoc) data.get(HEADBANNER);
226       return returnval.substring(returnval.lastIndexOf('/')+1);
227     }
228     public void setHeadBanner(String JavaDoc head){
229       data.put(HEADBANNER, ((String JavaDoc) data.get(ADMINPATH)) + ((String JavaDoc) data.get(BANNERS_PATH)) + "/" + head);
230     }
231
232
233     // Methods for manipulating the headbanner filename.
234
public String JavaDoc getFootBanner() {return (String JavaDoc) data.get(FOOTBANNER);}
235     public String JavaDoc getFootBannerFilename(){
236       String JavaDoc returnval = (String JavaDoc) data.get(FOOTBANNER);
237       return returnval.substring(returnval.lastIndexOf('/')+1);
238     }
239     public void setFootBanner(String JavaDoc foot){
240       data.put(FOOTBANNER, "/" + ((String JavaDoc) data.get(BANNERS_PATH)) + "/" +foot);
241     }
242
243     // Methods for manipulating the title.
244
public String JavaDoc getEjbcaTitle() {return (String JavaDoc) data.get(TITLE);}
245     public void setEjbcaTitle(String JavaDoc ejbcatitle) {data.put(TITLE,ejbcatitle);}
246
247
248     public String JavaDoc getAuthorizationPath() {return (String JavaDoc) data.get(AUTHORIZATION_PATH);}
249     public String JavaDoc getBannersPath() {return (String JavaDoc) data.get(BANNERS_PATH);}
250     public String JavaDoc getCaPath() {return (String JavaDoc) data.get(CA_PATH);}
251     public String JavaDoc getConfigPath() {return (String JavaDoc) data.get(CONFIG_PATH);}
252     public String JavaDoc getHelpPath() {return (String JavaDoc) data.get(HELP_PATH);}
253     public String JavaDoc getImagesPath() {return (String JavaDoc) data.get(IMAGES_PATH);}
254     public String JavaDoc getLanguagePath() {return (String JavaDoc) data.get(LANGUAGE_PATH);}
255     public String JavaDoc getLogPath() {return (String JavaDoc) data.get(LOG_PATH);}
256     public String JavaDoc getRaPath() {return (String JavaDoc) data.get(RA_PATH);}
257     public String JavaDoc getThemePath() {return (String JavaDoc) data.get(THEME_PATH);}
258     public String JavaDoc getHardTokenPath() {return (String JavaDoc) data.get(HARDTOKEN_PATH);}
259
260     public String JavaDoc getLanguageFilename(){return (String JavaDoc) data.get(LANGUAGEFILENAME);}
261     public String JavaDoc getMainFilename(){return (String JavaDoc) data.get(MAINFILENAME);}
262     public String JavaDoc getIndexFilename(){return (String JavaDoc) data.get(INDEXFILENAME);}
263     public String JavaDoc getMenuFilename(){return (String JavaDoc) data.get(MENUFILENAME);}
264     public String JavaDoc getErrorPage(){return (String JavaDoc) data.get(ERRORPAGE);}
265
266     public String JavaDoc[] getPossibleEntiresPerPage(){return DEFAULTPOSSIBLEENTRIESPERPAGE;}
267     public String JavaDoc[] getPossibleLogEntiresPerPage(){return DEFAULTPOSSIBLELOGENTRIESPERPAGE;}
268
269     public String JavaDoc getAvailableLanguagesAsString(){return (String JavaDoc) data.get(AVAILABLELANGUAGES);}
270     public String JavaDoc getAvailableThemesAsString(){return (String JavaDoc) data.get(AVAILABLETHEMES);}
271
272     public boolean getEnableEndEntityProfileLimitations(){return ((Boolean JavaDoc) data.get(ENABLEEEPROFILELIMITATIONS)).booleanValue();}
273     public void setEnableEndEntityProfileLimitations(boolean value){ data.put(ENABLEEEPROFILELIMITATIONS, Boolean.valueOf(value));}
274
275     public boolean getEnableAuthenticatedUsersOnly(){return ((Boolean JavaDoc) data.get(ENABLEAUTHENTICATEDUSERSONLY)).booleanValue();}
276     public void setEnableAuthenticatedUsersOnly(boolean value){ data.put(ENABLEAUTHENTICATEDUSERSONLY, Boolean.valueOf(value));}
277
278     public boolean getEnableKeyRecovery(){return ((Boolean JavaDoc) data.get(ENABLEKEYRECOVERY)).booleanValue();}
279     public void setEnableKeyRecovery(boolean value){ data.put(ENABLEKEYRECOVERY, Boolean.valueOf(value));}
280
281     public boolean getIssueHardwareTokens(){return ((Boolean JavaDoc) data.get(ISSUEHARDWARETOKENS)).booleanValue();}
282     public void setIssueHardwareTokens(boolean value){ data.put(ISSUEHARDWARETOKENS, Boolean.valueOf(value));}
283
284    /**
285     * @return the number of required approvals to access sensitive hard token data (default 0)
286     */

287     public int getNumberOfApprovalsToViewPUK(){
288         Object JavaDoc num = data.get(NUMBEROFAPPROVALSTOVIEWPUK);
289         if(num == null){
290             return 0;
291         }
292         
293         return ((Integer JavaDoc) num).intValue();
294     }
295     
296     public void setNumberOfApprovalsToViewPUK(int numberOfHardTokenApprovals){
297         data.put(NUMBEROFAPPROVALSTOVIEWPUK, new Integer JavaDoc(numberOfHardTokenApprovals));
298     }
299     
300     /**
301      * @return true of email notification of requested approvals should be sent (default false)
302      */

303      public boolean getUseApprovalNotifications(){
304         Object JavaDoc value = data.get(USEAPPROVALNOTIFICATIONS);
305          if(value == null){
306             return false;
307          }
308         
309         return ((Boolean JavaDoc) value).booleanValue();
310      }
311      
312      public void setUseApprovalNotifications(boolean useApprovalNotifications){
313         data.put(USEAPPROVALNOTIFICATIONS, Boolean.valueOf(useApprovalNotifications));
314      }
315     
316      /**
317       * Returns the email address to the administrators that should recieve notification emails
318       * should be an alias to all approval administrators default "" never null
319       */

320       public String JavaDoc getApprovalAdminEmailAddress(){
321         Object JavaDoc value = data.get(APPROVALADMINEMAILADDRESS);
322           if(value == null){
323             return "";
324           }
325         
326         return (String JavaDoc) value;
327       }
328
329       public void setApprovalAdminEmailAddress(String JavaDoc approvalAdminEmailAddress){
330         data.put(APPROVALADMINEMAILADDRESS, approvalAdminEmailAddress);
331       }
332       
333       /**
334        * Returns the email address used in the from field of approval notification emails
335        */

336        public String JavaDoc getApprovalNotificationFromAddress(){
337         Object JavaDoc value = data.get(APPROVALNOTIFICATIONFROMADDR);
338            if(value == null){
339             return "";
340            }
341         
342         return (String JavaDoc) value;
343        }
344  
345        public void setApprovalNotificationFromAddress(String JavaDoc approvalNotificationFromAddress){
346         data.put(APPROVALNOTIFICATIONFROMADDR, approvalNotificationFromAddress);
347        }
348       
349
350     /** Implemtation of UpgradableDataHashMap function getLatestVersion */
351     public float getLatestVersion(){
352        return LATEST_VERSION;
353     }
354
355     /** Implemtation of UpgradableDataHashMap function upgrade. */
356
357     public void upgrade(){
358         if(Float.compare(LATEST_VERSION, getVersion()) != 0) {
359             // New version of the class, upgrade
360
if(data.get(HARDTOKEN_PATH) == null){
361                 data.put(HARDTOKEN_PATH, ((String JavaDoc) data.get(ADMINPATH) + "hardtoken"));
362             }
363             
364             data.put(VERSION, new Float JavaDoc(LATEST_VERSION));
365         }
366     }
367
368     // Private fields.
369

370     // Private constants
371
//private static final String BASEURL = "baseurl";
372
private static final String JavaDoc COMPUTERNAME = "computername";
373     private static final String JavaDoc APPLICATIONPATH = "applicationpath";
374     private static final String JavaDoc ADMINPATH = "raadminpath";
375     private static final String JavaDoc AVAILABLELANGUAGES = "availablelanguages";
376     private static final String JavaDoc AVAILABLETHEMES = "availablethemes";
377     private static final String JavaDoc PUBLICPORT = "publicport";
378     private static final String JavaDoc PRIVATEPORT = "privateport";
379     private static final String JavaDoc PUBLICPROTOCOL = "publicprotocol";
380     private static final String JavaDoc PRIVATEPROTOCOL = "privateprotocol";
381
382
383       // Title
384
private static final String JavaDoc TITLE = "title";
385       // Banner files.
386
private static final String JavaDoc HEADBANNER = "headbanner";
387     private static final String JavaDoc FOOTBANNER = "footbanner";
388       // Other configuration.
389
private static final String JavaDoc ENABLEEEPROFILELIMITATIONS = "endentityprofilelimitations";
390     private static final String JavaDoc ENABLEAUTHENTICATEDUSERSONLY = "authenticatedusersonly";
391     private static final String JavaDoc ENABLEKEYRECOVERY = "enablekeyrecovery";
392     private static final String JavaDoc ISSUEHARDWARETOKENS = "issuehardwaretokens";
393     
394     private static final String JavaDoc NUMBEROFAPPROVALSTOVIEWPUK = "numberofapprovalstoviewpuk";
395     private static final String JavaDoc USEAPPROVALNOTIFICATIONS = "useapprovalnotifications";
396     private static final String JavaDoc APPROVALADMINEMAILADDRESS = "approvaladminemailaddress";
397     private static final String JavaDoc APPROVALNOTIFICATIONFROMADDR = "approvalnotificationfromaddr";
398        
399
400     
401       // Paths
402
private static final String JavaDoc AUTHORIZATION_PATH = "authorization_path";
403     private static final String JavaDoc BANNERS_PATH = "banners_path";
404     private static final String JavaDoc CA_PATH = "ca_path";
405     private static final String JavaDoc CONFIG_PATH = "data_path";
406     private static final String JavaDoc HELP_PATH = "help_path";
407     private static final String JavaDoc IMAGES_PATH = "images_path";
408     private static final String JavaDoc LANGUAGE_PATH = "language_path";
409     private static final String JavaDoc LOG_PATH = "log_path";
410     private static final String JavaDoc RA_PATH = "ra_path";
411     private static final String JavaDoc THEME_PATH = "theme_path";
412     private static final String JavaDoc HARDTOKEN_PATH = "hardtoken_path";
413
414     private static final String JavaDoc LANGUAGEFILENAME = "languagefilename";
415     private static final String JavaDoc MAINFILENAME = "mainfilename";
416     private static final String JavaDoc INDEXFILENAME = "indexfilename";
417     private static final String JavaDoc MENUFILENAME = "menufilename";
418     private static final String JavaDoc ERRORPAGE = "errorpage";
419
420 }
421
Popular Tags