1 19 package org.openbravo.erpCommon.security; 20 21 import javax.servlet.*; 22 import javax.servlet.http.*; 23 import java.net.*; 24 import org.openbravo.database.ConnectionProvider; 25 import org.openbravo.erpCommon.utility.SequenceIdData; 26 27 import org.apache.log4j.Logger ; 28 29 public class SessionLogin { 30 static Logger log4j = Logger.getLogger(SessionLogin.class); 31 protected String sessionID; 32 protected String client; 33 protected String org; 34 protected String isactive = "Y"; 35 protected String user; 36 protected String websession; 37 protected String remoteAddr; 38 protected String remoteHost; 39 protected String processed = "N"; 40 41 public SessionLogin(String ad_client_id, String ad_org_id, String ad_user_id) throws ServletException { 42 if (ad_client_id==null || ad_client_id.equals("")) throw new ServletException("SessionLogin load - client is null"); 43 else if (ad_org_id==null || ad_org_id.equals("")) throw new ServletException("SessionLogin load - organization is null"); 44 else if (ad_user_id==null || ad_user_id.equals("")) throw new ServletException("SessionLogin load - user is null"); 45 setClient(ad_client_id); 46 setOrg(ad_org_id); 47 setUser(ad_user_id); 48 defaultParameters(); 49 } 50 51 public SessionLogin(HttpServletRequest request, String ad_client_id, String ad_org_id, String ad_user_id) throws ServletException { 52 if (ad_client_id==null || ad_client_id.equals("")) throw new ServletException("SessionLogin load - client is null"); 53 else if (ad_org_id==null || ad_org_id.equals("")) throw new ServletException("SessionLogin load - organization is null"); 54 else if (ad_user_id==null || ad_user_id.equals("")) throw new ServletException("SessionLogin load - user is null"); 55 setClient(ad_client_id); 56 setOrg(ad_org_id); 57 setUser(ad_user_id); 58 defaultParameters(request); 59 } 60 61 public void defaultParameters() { 62 try { 63 InetAddress lh = InetAddress.getLocalHost(); 64 setRemoteAddr(lh.getHostAddress()); 65 setRemoteHost(lh.getHostName()); 66 } catch (UnknownHostException e) { 67 log4j.error("SessionLogin.defaultParameters() - No local host. " + e); 68 } 69 if (log4j.isDebugEnabled()) log4j.debug("SessionLogin.defaultParameters() - Remote Address: " + getRemoteAddr() + " - Remote Host: " + getRemoteHost()); 70 } 71 72 public void defaultParameters(HttpServletRequest request) { 73 setRemoteAddr(request.getRemoteAddr()); 74 setRemoteHost(request.getRemoteHost()); 75 if (log4j.isDebugEnabled()) log4j.debug("SessionLogin.defaultParameters(request) - Remote Address: " + getRemoteAddr() + " - Remote Host: " + getRemoteHost()); 76 } 77 78 public int save(ConnectionProvider conn) throws ServletException { 79 if (getSessionID().equals("")) { 80 String key = SequenceIdData.getSequence(conn, "AD_Session", getClient()); 81 if (key==null || key.equals("")) throw new ServletException("SessionLogin.save() - key creation failed"); 82 setSessionID(key); 83 return SessionLoginData.insert(conn, getSessionID(), getClient(), getOrg(), getIsActive(), getUser(), getWebSession(), getRemoteAddr(), getRemoteHost(), getProcessed()); 84 } else return SessionLoginData.update(conn, getIsActive(), getUser(), getWebSession(), getRemoteAddr(), getRemoteHost(), getProcessed(), getSessionID()); 85 } 86 87 public void setSessionID(String newValue) { 88 this.sessionID = (newValue==null)?"":newValue; 89 } 90 91 public String getSessionID() { 92 return ((this.sessionID==null)?"":this.sessionID); 93 } 94 95 public void setClient(String newValue) { 96 this.client = (newValue==null)?"":newValue; 97 } 98 99 public String getClient() { 100 return ((this.client==null)?"":this.client); 101 } 102 103 public void setOrg(String newValue) { 104 this.org = (newValue==null)?"":newValue; 105 } 106 107 public String getOrg() { 108 return ((this.org==null)?"":this.org); 109 } 110 111 public void setIsActive(String newValue) { 112 this.isactive = (newValue==null)?"Y":newValue; 113 } 114 115 public String getIsActive() { 116 return (this.isactive); 117 } 118 119 public void setUser(String newValue) { 120 this.user = (newValue==null)?"":newValue; 121 } 122 123 public String getUser() { 124 return ((this.user==null)?"":this.user); 125 } 126 127 public void setWebSession(String newValue) { 128 this.websession = (newValue==null)?"":newValue; 129 } 130 131 public String getWebSession() { 132 return ((this.websession==null)?"":this.websession); 133 } 134 135 public void setRemoteAddr(String newValue) { 136 this.remoteAddr = (newValue==null)?"":newValue; 137 } 138 139 public String getRemoteAddr() { 140 return ((this.remoteAddr==null)?"":this.remoteAddr); 141 } 142 143 public void setRemoteHost(String newValue) { 144 this.remoteHost = (newValue==null)?"":newValue; 145 } 146 147 public String getRemoteHost() { 148 return ((this.remoteHost==null)?"":this.remoteHost); 149 } 150 151 public void setProcessed(String newValue) { 152 this.processed = (newValue==null)?"":newValue; 153 } 154 155 public String getProcessed() { 156 return ((this.processed==null)?"":this.processed); 157 } 158 } 159 | Popular Tags |