1 package edu.rice.rubis.beans.servlets; 2 3 import javax.naming.Context ; 4 import javax.rmi.PortableRemoteObject ; 5 import javax.servlet.http.HttpServlet ; 6 7 import edu.rice.rubis.beans.User; 8 import edu.rice.rubis.beans.UserHome; 9 10 15 public class Auth extends HttpServlet 16 { 17 18 private Context servletContext; 19 private ServletPrinter sp; 20 21 27 public Auth(Context context, ServletPrinter printer) 28 { 29 servletContext = context; 30 sp = printer; 31 } 32 33 40 public int authenticate(String name, String password) 41 { 42 int userId = -1; 43 44 UserHome userHome = null; 46 try 47 { 48 userHome = 49 (UserHome) PortableRemoteObject.narrow( 50 servletContext.lookup("UserHome"), 51 UserHome.class); 52 } 53 catch (Exception e) 54 { 55 sp.printHTML("Cannot lookup User: " + e + "<br>"); 56 return userId; 57 } 58 try 60 { 61 User user = userHome.findByNickName(name); 62 String pwd = user.getPassword(); 63 if (pwd.compareTo(password) == 0) 64 { 65 userId = user.getId().intValue(); 66 } 67 } 68 catch (Exception e) 69 { 70 sp.printHTML( 71 " User " 72 + name 73 + " does not exist in the database!<br>(got exception: " 74 + e 75 + ")<br>"); 76 return userId; 77 } 78 return userId; 79 } 80 81 } 82 | Popular Tags |