Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/projectapollo/demo/General/MysqlAdmin/Login/LoginBroker.java


1   package org.projectapollo.demo.General.MysqlAdmin.Login;
2   
3   import apollo.*;
4   
5   import java.util.zip.*;
6   import java.io.*;
7   
8   import apollo.Log.*;
9   
10  import apollo.Template.*;
11  import apollo.Storable.*;
12  import apollo.Session.*;
13  
14  import org.projectapollo.demo.Storable.*;
15  
16  import java.util.*;
17  
18  
19  
20  public class LoginBroker extends PageBroker {
21    private Vector AS;
22    
23    AcceptClause displayEntry;
24    AcceptClause mysqlAdminLogin;
25    public LoginBroker(ManagerTracker MT, String fquid, PageBroker PB) throws TemplatePageException {
26      super(MT,fquid,PB);
27      MT.getPM().registerTemplatePage(FQUID, new TemplatePage(MT,this, false));
28  
29      AS = new Vector();
30      displayEntry= new AcceptClause("DisplayEntry");
31      mysqlAdminLogin= new AcceptClause("MysqlAdmin Login");
32      mysqlAdminLogin.addAcceptClause(AcceptClause.STRING, "MysqlAdminLogin", AcceptClause.REQUIRED);
33      mysqlAdminLogin.addAcceptClause(AcceptClause.STRING, "Hostname", AcceptClause.REQUIRED);
34      mysqlAdminLogin.addAcceptClause(AcceptClause.STRING, "Password", AcceptClause.REQUIRED);
35      mysqlAdminLogin.addAcceptClause(AcceptClause.STRING, "UserID", AcceptClause.REQUIRED);
36      mysqlAdminLogin.addAcceptClause(AcceptClause.STRING, "Database", AcceptClause.REQUIRED);
37  
38      AS.addElement(mysqlAdminLogin);
39      AS.addElement(displayEntry);
40    }
41    
42    public HTTPResponse render(TransactionTracker TT, HTTPRequest req, WebSession thisSession) throws ApolloException {
43      EntryAssertionManager EAM = new EntryAssertionManager(MT, AS);
44      EAM.evaluate(req);
45  
46      User user = (User)thisSession.getValue("User");
47  
48      Hashtable RT = new Hashtable();
49      if (EAM.isAccept(mysqlAdminLogin)) {
50        //Ok, now try to establish a database connection
51        try {
52          if (EAM.getString("Hostname").toLowerCase().trim().equals("localhost") || EAM.getString("Hostname").toLowerCase().trim().equals("127.0.0.1")) {
53            // This really doesn't amount to much security, but it will do.  There's nothing running
54            // on the demo server anyway
55            if (!EAM.getString("Database").equals("test")) {
56              throw new Exception("Cannot connect to database other then test on localhost");
57            }
58          }
59          SerializableJDBCConnection sc = new SerializableJDBCConnection("org.gjt.mm.mysql.Driver","jdbc:mysql://"+req.getValue("Hostname")+":"+req.getValue("Port")+"/"+req.getValue("Database")+"?user="+req.getValue("UserID")+"&password="+req.getValue("Password"));
60          
61          //        Class.forName("org.gjt.mm.mysql.Driver").newInstance(); 
62          //    Connection c = DriverManager.getConnection("jdbc:mysql://"+req.getValue("Hostname")+":"+req.getValue("Port")+"/"+req.getValue("Database")+"?user="+req.getValue("Username")+"&password="+req.getValue("Password"));
63          //        SerializableJDBCConnection sc = new SerializableJDBCConnection(c);
64          thisSession.setValue("DBConnection", sc);
65          thisSession.setValue("DatabaseName", req.getValue("Database"));
66          thisSession.setValue("Hostname", req.getValue("Hostname"));
67          thisSession.setValue("ServletPath", req.getServletPath());
68          thisSession.setServletPath(req.getServletPath());
69        } catch (Exception e) {
70          Hashtable hashReplacement = new Hashtable();
71             hashReplacement.put("Error",e.getMessage());
72           return MT.getPM().getPage(FQUID).render(hashReplacement,thisSession);
73        }
74        return MT.getPM().handleRequest(TT,"MAMainMenu",req,thisSession);
75      } else {
76        return MT.getPM().getPage(FQUID).render(RT,thisSession);
77      }
78    }//  end render
79    
80  }
81  
82