KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openbravo > base > secureApp > LoginUtils


1 /*
2  ************************************************************************************
3  * Copyright (C) 2001-2006 Openbravo S.L.
4  * Licensed under the Apache Software License version 2.0
5  * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
6  * Unless required by applicable law or agreed to in writing, software distributed
7  * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
8  * CONDITIONS OF ANY KIND, either express or implied. See the License for the
9  * specific language governing permissions and limitations under the License.
10  ************************************************************************************
11 */

12 package org.openbravo.base.secureApp;
13
14 import javax.servlet.ServletException JavaDoc;
15 import javax.servlet.http.HttpServletRequest JavaDoc;
16 import org.openbravo.erpCommon.ad_combos.ClientComboData;
17 import org.openbravo.erpCommon.ad_combos.OrganizationComboData;
18 import org.openbravo.erpCommon.ad_combos.RoleComboData;
19 import org.openbravo.erpCommon.ad_combos.WarehouseComboData;
20 import org.openbravo.erpCommon.reference.PreferencesData;
21 import org.openbravo.erpCommon.utility.Utility;
22 import org.apache.log4j.Logger;
23 import org.openbravo.database.ConnectionProvider;
24
25 public class LoginUtils {
26     
27     public static Logger log4j = Logger.getLogger(LoginUtils.class);
28     
29     /** Creates a new instance of LoginUtils */
30     private LoginUtils() {
31     }
32     
33     public static boolean fillSessionArguments(ConnectionProvider conn, VariablesSecureApp vars, String JavaDoc strUserAuth, String JavaDoc strLanguage, String JavaDoc strRol, String JavaDoc strCliente, String JavaDoc strOrg, String JavaDoc strAlmacen) throws ServletException JavaDoc {
34
35          // Check session options
36
if (!RoleComboData.isUserRole(conn, strUserAuth, strRol)) {
37             log4j.error("Login role is not in user roles list");
38             log4j.error("User: " + strUserAuth);
39             log4j.error("Role: " + strRol);
40             return false;
41         }
42         if (!ClientComboData.isRoleClient(conn, strRol, strCliente)) {
43             log4j.error("Login client is not in role clients list");
44             return false;
45         }
46         if (!OrganizationComboData.isRoleOrg(conn, strRol, strOrg)) {
47           log4j.error("Login organization is not in role organizations list");
48           return false;
49         }
50         if (!strAlmacen.equals("") && !WarehouseComboData.isRoleClientWarehouse(conn, strRol, strCliente, strAlmacen)) {
51           log4j.error("Login warehouse is not in role warehouses list");
52           return false;
53         }
54
55         // Set session vars
56
vars.setSessionValue("#AD_User_ID", strUserAuth);
57         vars.setSessionValue("#SalesRep_ID", strUserAuth);
58         vars.setSessionValue("#AD_Language", strLanguage);
59         vars.setSessionValue("#AD_Role_ID", strRol);
60         vars.setSessionValue("#AD_Client_ID", strCliente);
61         vars.setSessionValue("#AD_Org_ID", strOrg);
62         vars.setSessionValue("#M_Warehouse_ID", strAlmacen);
63
64         vars.setSessionValue("#StdPrecision", "2");
65
66         try {
67           SeguridadData[] data = SeguridadData.select(conn, strRol, strUserAuth);
68           if (data==null || data.length==0) return false;
69           vars.setSessionValue("#User_Level", data[0].userlevel);
70           vars.setSessionValue("#User_Client", data[0].clientlist);
71           vars.setSessionValue("#User_Org", data[0].orglist);
72           vars.setSessionValue("#Approval_C_Currency_ID", data[0].cCurrencyId);
73           vars.setSessionValue("#Approval_Amt", data[0].amtapproval);
74           vars.setSessionValue("#Client_Value", data[0].value);
75           vars.setSessionValue("#Client_SMTP", data[0].smtphost);
76           data=null;
77           AttributeData[] attr = AttributeData.select(conn, Utility.getContext(conn, vars, "#User_Client", "LoginHandler"), Utility.getContext(conn, vars, "#User_Org", "LoginHandler"));
78           if (attr!=null && attr.length>0) {
79             vars.setSessionValue("$C_AcctSchema_ID", attr[0].value);
80             vars.setSessionValue("$C_Currency_ID", attr[0].attribute);
81             vars.setSessionValue("#StdPrecision", AttributeData.selectStdPrecision(conn, attr[0].attribute, Utility.getContext(conn, vars, "#User_Client", "LoginHandler"), Utility.getContext(conn, vars, "#User_Org", "LoginHandler")));
82             vars.setSessionValue("$HasAlias", attr[0].hasalias);
83             for (int i=0;i<attr.length;i++) vars.setSessionValue("$Element_" + attr[i].elementtype, "Y");
84           }
85           attr=null;
86           PreferencesData[] prefs = PreferencesData.select(conn, Utility.getContext(conn, vars, "#User_Client", "LoginHandler"), Utility.getContext(conn, vars, "#User_Org", "LoginHandler"), strUserAuth);
87
88           if (prefs!=null && prefs.length>0) {
89             for (int i=0;i<prefs.length;i++) {
90               vars.setSessionValue("P|" + (prefs[i].adWindowId.equals("")?"":(prefs[i].adWindowId + "|")) + prefs[i].attribute, prefs[i].value);
91             }
92           }
93           prefs=null;
94
95           attr = AttributeData.selectIsSOTrx(conn);
96           if (attr!=null && attr.length>0) {
97             for (int i=0;i<attr.length;i++) vars.setSessionValue(attr[i].adWindowId + "|isSOTrx", attr[i].value);
98           }
99           attr=null;
100
101           DefaultSessionValuesData[] ds = DefaultSessionValuesData.select(conn);
102           if (ds!=null && ds.length>0) {
103             for (int i=0;i<ds.length;i++) {
104               String JavaDoc value = DefaultValuesData.select(conn, ds[i].columnname, ds[i].tablename, Utility.getContext(conn, vars, "#User_Client", "LoginHandler"), Utility.getContext(conn, vars, "#User_Org", "LoginHandler"));
105               if (ds[i].tablename.equals("C_DocType")) vars.setSessionValue("#C_DocTypeTarget_ID", value);
106               vars.setSessionValue("#" + ds[i].columnname, value);
107             }
108           }
109           vars.setSessionValue("#Date", Utility.getContext(conn, vars, "#Date", "LoginHandler"));
110           vars.setSessionValue("#ShowTrl", Utility.getPreference(vars, "ShowTrl", ""));
111           vars.setSessionValue("#ShowAcct", Utility.getPreference(vars, "ShowAcct", ""));
112           SystemPreferencesData[] dataSystem = SystemPreferencesData.select(conn);
113           if (dataSystem!=null && dataSystem.length>0) {
114             vars.setSessionValue("#RecordRange", dataSystem[0].tadRecordrange);
115             vars.setSessionValue("#RecordRangeInfo", dataSystem[0].tadRecordrangeInfo);
116             vars.setSessionValue("#Transactional$Range", dataSystem[0].tadTransactionalrange);
117             vars.setSessionValue("#Theme", dataSystem[0].tadTheme);
118           }
119
120         } catch (ServletException JavaDoc e) {
121           log4j.warn("Error while loading session arguments: " + e);
122           return false;
123         }
124         return true;
125     }
126 }
127
Popular Tags