1 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 ; 32 import java.io.File ; 33 34 40 public class Startup { 41 42 public static void main(String [] args) throws Exception { 43 44 45 new File (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 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 67 password = PasswordField.getPassword("Enter password:"); 68 69 user = userManager.verifyUsernamePassword( 70 AuthConstants.USER_ADMIN, password); 71 invalidAttempts ++; 72 if(invalidAttempts >= 3){ 73 break; 74 } 75 } 76 77 78 if(user == null){ 79 System.out.println("Number of invalid attempts exceeded. Exiting !"); 80 return; 81 } 82 83 84 final JettyStopKey stopKey = new JettyStopKey(new String (password)); 85 System.setProperty("STOP.KEY", stopKey.toString()); 86 87 System.setProperty("STOP.PORT", JManageProperties.getStopPort()); 88 89 90 ServiceFactory.init(ServiceFactory.MODE_LOCAL); 91 92 Crypto.init(password); 93 94 Arrays.fill(password, ' '); 95 96 ACLStore.getInstance(); 97 98 ApplicationTypes.init(); 99 100 AlertEngine.getInstance().start(); 101 102 start(); 103 } 104 105 private static void start() throws Exception { 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 |