KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jmanage > webui > Startup


1 /**
2  * Copyright 2004-2005 jManage.org
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.jmanage.webui;
17
18 import org.mortbay.jetty.Server;
19 import org.jmanage.core.util.CoreUtils;
20 import org.jmanage.core.util.PasswordField;
21 import org.jmanage.core.util.JManageProperties;
22 import org.jmanage.core.crypto.Crypto;
23 import org.jmanage.core.auth.UserManager;
24 import org.jmanage.core.auth.AuthConstants;
25 import org.jmanage.core.auth.User;
26 import org.jmanage.core.auth.ACLStore;
27 import org.jmanage.core.services.ServiceFactory;
28 import org.jmanage.core.alert.AlertEngine;
29 import org.jmanage.core.config.ApplicationTypes;
30
31 import java.util.Arrays JavaDoc;
32 import java.io.File JavaDoc;
33
34 /**
35  * The Web-UI startup class.
36  *
37  * date: Jun 11, 2004
38  * @author Rakesh Kalra
39  */

40 public class Startup {
41
42     public static void main(String JavaDoc[] args) throws Exception JavaDoc{
43
44         /* create logs dir */
45         new File JavaDoc(CoreUtils.getLogDir()).mkdirs();
46
47         UserManager userManager = UserManager.getInstance();
48         User user = null;
49         char[] password = null;
50         int invalidAttempts = 0;
51
52         if(args.length == 1){
53             password = args[0].toCharArray();
54             user = userManager.verifyUsernamePassword(
55                     AuthConstants.USER_ADMIN, password);
56             /* invalid password was tried */
57             if(user == null){
58                 invalidAttempts ++;
59             }
60         }
61
62         while(user == null){
63             if(invalidAttempts > 0){
64                 System.out.println("Invalid Admin Password.");
65             }
66             /* get the password */
67             password = PasswordField.getPassword("Enter password:");
68             /* the password should match for the admin user */
69             user = userManager.verifyUsernamePassword(
70                     AuthConstants.USER_ADMIN, password);
71             invalidAttempts ++;
72             if(invalidAttempts >= 3){
73                 break;
74             }
75         }
76
77         /* exit if the admin password is still invalid */
78         if(user == null){
79             System.out.println("Number of invalid attempts exceeded. Exiting !");
80             return;
81         }
82
83         /* set admin password as the stop key */
84         final JettyStopKey stopKey = new JettyStopKey(new String JavaDoc(password));
85         System.setProperty("STOP.KEY", stopKey.toString());
86         /* set stop.port */
87         System.setProperty("STOP.PORT", JManageProperties.getStopPort());
88
89         /* initialize ServiceFactory */
90         ServiceFactory.init(ServiceFactory.MODE_LOCAL);
91         /* initialize crypto */
92         Crypto.init(password);
93         /* clear the password */
94         Arrays.fill(password, ' ');
95         /* load ACLs */
96         ACLStore.getInstance();
97         /* load application types */
98         ApplicationTypes.init();
99         /* start the AlertEngine */
100         AlertEngine.getInstance().start();
101         /* start the application */
102         start();
103     }
104
105     private static void start() throws Exception JavaDoc {
106         Server server =
107                 new Server(CoreUtils.getConfigDir() +
108                 File.separator + "jetty-config.xml");
109         ServerMonitor.monitor();
110         server.start();
111     }
112 }
113
Popular Tags