KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openbravo > erpCommon > security > SessionLogin


1 /*
2  *************************************************************************
3  * The contents of this file are subject to the Openbravo Public License
4  * Version 1.0 (the "License"), being the Mozilla Public License
5  * Version 1.1 with a permitted attribution clause; you may not use this
6  * file except in compliance with the License. You may obtain a copy of
7  * the License at http://www.openbravo.com/legal/license.html
8  * Software distributed under the License is distributed on an "AS IS"
9  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
10  * License for the specific language governing rights and limitations
11  * under the License.
12  * The Original Code is Openbravo ERP.
13  * The Initial Developer of the Original Code is Openbravo SL
14  * All portions are Copyright (C) 2001-2006 Openbravo SL
15  * All Rights Reserved.
16  * Contributor(s): ______________________________________.
17  ************************************************************************
18 */

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 JavaDoc sessionID;
32   protected String JavaDoc client;
33   protected String JavaDoc org;
34   protected String JavaDoc isactive = "Y";
35   protected String JavaDoc user;
36   protected String JavaDoc websession;
37   protected String JavaDoc remoteAddr;
38   protected String JavaDoc remoteHost;
39   protected String JavaDoc processed = "N";
40
41   public SessionLogin(String JavaDoc ad_client_id, String JavaDoc ad_org_id, String JavaDoc 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 JavaDoc ad_client_id, String JavaDoc ad_org_id, String JavaDoc 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 JavaDoc 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 JavaDoc newValue) {
88     this.sessionID = (newValue==null)?"":newValue;
89   }
90
91   public String JavaDoc getSessionID() {
92     return ((this.sessionID==null)?"":this.sessionID);
93   }
94
95   public void setClient(String JavaDoc newValue) {
96     this.client = (newValue==null)?"":newValue;
97   }
98
99   public String JavaDoc getClient() {
100     return ((this.client==null)?"":this.client);
101   }
102
103   public void setOrg(String JavaDoc newValue) {
104     this.org = (newValue==null)?"":newValue;
105   }
106
107   public String JavaDoc getOrg() {
108     return ((this.org==null)?"":this.org);
109   }
110
111   public void setIsActive(String JavaDoc newValue) {
112     this.isactive = (newValue==null)?"Y":newValue;
113   }
114
115   public String JavaDoc getIsActive() {
116     return (this.isactive);
117   }
118
119   public void setUser(String JavaDoc newValue) {
120     this.user = (newValue==null)?"":newValue;
121   }
122
123   public String JavaDoc getUser() {
124     return ((this.user==null)?"":this.user);
125   }
126
127   public void setWebSession(String JavaDoc newValue) {
128     this.websession = (newValue==null)?"":newValue;
129   }
130
131   public String JavaDoc getWebSession() {
132     return ((this.websession==null)?"":this.websession);
133   }
134
135   public void setRemoteAddr(String JavaDoc newValue) {
136     this.remoteAddr = (newValue==null)?"":newValue;
137   }
138
139   public String JavaDoc getRemoteAddr() {
140     return ((this.remoteAddr==null)?"":this.remoteAddr);
141   }
142
143   public void setRemoteHost(String JavaDoc newValue) {
144     this.remoteHost = (newValue==null)?"":newValue;
145   }
146
147   public String JavaDoc getRemoteHost() {
148     return ((this.remoteHost==null)?"":this.remoteHost);
149   }
150
151   public void setProcessed(String JavaDoc newValue) {
152     this.processed = (newValue==null)?"":newValue;
153   }
154
155   public String JavaDoc getProcessed() {
156     return ((this.processed==null)?"":this.processed);
157   }
158 }
159
Popular Tags