ofbiz-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j..@apache.org
Subject svn commit: r527736 - in /ofbiz/trunk/framework: common/src/org/ofbiz/common/login/LoginServices.java webapp/build.xml webapp/src/org/ofbiz/webapp/control/LoginWorker.java
Date Thu, 12 Apr 2007 00:14:38 GMT
Author: jaz
Date: Wed Apr 11 17:14:37 2007
New Revision: 527736

URL: http://svn.apache.org/viewvc?view=rev&rev=527736
Log:
fixed auto-login from x509 cert

Modified:
    ofbiz/trunk/framework/common/src/org/ofbiz/common/login/LoginServices.java
    ofbiz/trunk/framework/webapp/build.xml
    ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/LoginWorker.java

Modified: ofbiz/trunk/framework/common/src/org/ofbiz/common/login/LoginServices.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/common/src/org/ofbiz/common/login/LoginServices.java?view=diff&rev=527736&r1=527735&r2=527736
==============================================================================
--- ofbiz/trunk/framework/common/src/org/ofbiz/common/login/LoginServices.java (original)
+++ ofbiz/trunk/framework/common/src/org/ofbiz/common/login/LoginServices.java Wed Apr 11
17:14:37 2007
@@ -169,21 +169,8 @@
 
                             if (!isServiceAuth) {
                                 // get the UserLoginSession if this is not a service auth
+                                Map userLoginSessionMap = getUserLoginSession(userLogin);
                                 GenericValue userLoginSession = null;
-                                Map userLoginSessionMap = null;
-                                try {
-                                    userLoginSession = userLogin.getRelatedOne("UserLoginSession");
-                                    if (userLoginSession != null) {
-                                        Object deserObj = XmlSerializer.deserialize(userLoginSession.getString("sessionData"),
delegator);
-                                        //don't check, just cast, if it fails it will get
caught and reported below; if (deserObj instanceof Map)
-                                        userLoginSessionMap = (Map) deserObj;
-                                    }
-                                } catch (GenericEntityException ge) {
-                                    Debug.logWarning(ge, "Cannot get UserLoginSession for
UserLogin ID: " +
-                                            userLogin.getString("userLoginId"), module);
-                                } catch (Exception e) {
-                                    Debug.logWarning(e, "Problems deserializing UserLoginSession",
module);
-                                }
 
                                 // return the UserLoginSession Map
                                 if (userLoginSessionMap != null) {
@@ -780,5 +767,25 @@
         }
 
         return HashCrypt.getDigestHash(str, hashType);
+    }
+
+    public static Map getUserLoginSession(GenericValue userLogin) {
+        GenericDelegator delegator = userLogin.getDelegator();
+        GenericValue userLoginSession;
+        Map userLoginSessionMap = null;
+        try {
+            userLoginSession = userLogin.getRelatedOne("UserLoginSession");
+            if (userLoginSession != null) {
+                Object deserObj = XmlSerializer.deserialize(userLoginSession.getString("sessionData"),
delegator);
+                //don't check, just cast, if it fails it will get caught and reported below;
if (deserObj instanceof Map)
+                userLoginSessionMap = (Map) deserObj;
+            }
+        } catch (GenericEntityException ge) {
+            Debug.logWarning(ge, "Cannot get UserLoginSession for UserLogin ID: " +
+                    userLogin.getString("userLoginId"), module);
+        } catch (Exception e) {
+            Debug.logWarning(e, "Problems deserializing UserLoginSession", module);
+        }
+        return userLoginSessionMap;
     }
 }

Modified: ofbiz/trunk/framework/webapp/build.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/webapp/build.xml?view=diff&rev=527736&r1=527735&r2=527736
==============================================================================
--- ofbiz/trunk/framework/webapp/build.xml (original)
+++ ofbiz/trunk/framework/webapp/build.xml Wed Apr 11 17:14:37 2007
@@ -49,6 +49,7 @@
             <fileset dir="../service/lib" includes="*.jar"/>
             <fileset dir="../service/build/lib" includes="*.jar"/>
             <fileset dir="../minilang/build/lib" includes="*.jar"/>
+            <fileset dir="../common/build/lib" includes="*.jar"/>
         </path>
     </target>
 

Modified: ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/LoginWorker.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/LoginWorker.java?view=diff&rev=527736&r1=527735&r2=527736
==============================================================================
--- ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/LoginWorker.java (original)
+++ ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/LoginWorker.java Wed Apr 11
17:14:37 2007
@@ -45,6 +45,7 @@
 import org.ofbiz.service.LocalDispatcher;
 import org.ofbiz.service.ModelService;
 import org.ofbiz.webapp.stats.VisitHandler;
+import org.ofbiz.common.login.LoginServices;
 
 /**
  * Common Workers
@@ -314,24 +315,28 @@
         if (ModelService.RESPOND_SUCCESS.equals(result.get(ModelService.RESPONSE_MESSAGE)))
{
             GenericValue userLogin = (GenericValue) result.get("userLogin");
             Map userLoginSession = (Map) result.get("userLoginSession");
-
-            if (userLogin != null && hasBasePermission(userLogin, request)) {
-                doBasicLogin(userLogin, request);
-            } else {
-                String errMsg = UtilProperties.getMessage(resourceWebapp, "loginevents.unable_to_login_this_application",
UtilHttp.getLocale(request));
-                request.setAttribute("_ERROR_MESSAGE_", errMsg);
-                return "error";
-            }
-
-            if (userLoginSession != null) {
-                session.setAttribute("userLoginSession", userLoginSession);
-            }
+            return doMainLogin(request, response, userLogin, userLoginSession);
         } else {
             Map messageMap = UtilMisc.toMap("errorMessage", (String) result.get(ModelService.ERROR_MESSAGE));
             String errMsg = UtilProperties.getMessage(resourceWebapp, "loginevents.following_error_occurred_during_login",
messageMap, UtilHttp.getLocale(request));
             request.setAttribute("_ERROR_MESSAGE_", errMsg);
             return "error";
         }
+    }
+
+    public static String doMainLogin(HttpServletRequest request, HttpServletResponse response,
GenericValue userLogin, Map userLoginSession) {
+        HttpSession session = request.getSession();
+        if (userLogin != null && hasBasePermission(userLogin, request)) {
+            doBasicLogin(userLogin, request);
+        } else {
+            String errMsg = UtilProperties.getMessage(resourceWebapp, "loginevents.unable_to_login_this_application",
UtilHttp.getLocale(request));
+            request.setAttribute("_ERROR_MESSAGE_", errMsg);
+            return "error";
+        }
+
+        if (userLoginSession != null) {
+            session.setAttribute("userLoginSession", userLoginSession);
+        }
 
         request.setAttribute("_LOGIN_PASSED_", "TRUE");
 
@@ -514,7 +519,8 @@
         HttpSession session = request.getSession();
         GenericValue currentUserLogin = (GenericValue) session.getAttribute("userLogin");
         if (currentUserLogin != null) {
-            if (LoginWorker.isFlaggedLoggedOut(currentUserLogin)) {
+            String hasLoggedOut = currentUserLogin.getString("hasLoggedOut");
+            if (hasLoggedOut != null && "Y".equals(hasLoggedOut)) {
                 currentUserLogin = null;
             }
         }
@@ -535,16 +541,21 @@
                         Debug.logError(e, module);
                     }
 
-                    if (userLogins != null && userLogins.size() > 0) {
-                        Debug.log("Found [" + userLogins.size() + "] possible UserLogin records.",
module);
+                    if (userLogins != null && userLogins.size() > 0) {       
                
                         Iterator it = userLogins.iterator();
                         while (it.hasNext()) {
                             GenericValue ul = (GenericValue) it.next();
                             String enabled = ul.getString("enabled");
+
                             if (enabled == null || "Y".equals(enabled)) {
-                                Debug.log("Found x.509 cert for login; logging in as [" +
ul.getString("userLoginId") + "]", module);
-                                doBasicLogin(ul, request);
-                                return "success";
+                                ul.set("hasLoggedOut", "N");
+                                try {
+                                    ul.store();
+                                } catch (GenericEntityException e) {
+                                    Debug.logWarning(e, module);
+                                }
+                                Map ulSessionMap = LoginServices.getUserLoginSession(ul);
+                                return doMainLogin(request, response, ul, ulSessionMap);
// doing the main login                                                                
                             }
                         }
                     }



Mime
View raw message