Author: jleroux
Date: Mon Feb 19 19:24:14 2018
New Revision: 1824804

URL: http://svn.apache.org/viewvc?rev=1824804&view=rev
Log:
"Applied fix from trunk for revision: 1824803  " 
------------------------------------------------------------------------
r1824803 | jleroux | 2018-02-19 20:23:36 +0100 (lun., 19 févr. 2018) | 18 lines

Fixed: Logout do not remove autoLogin
(OFBIZ-4959)

Logout method do not disable autoLogin functionality. 
Instead of that it just initializes autoLogin in session and request.

jleroux: this was also needed by OFBIZ-10206 "Security issue in Token Based 
Authentication". 
This creates a keep-autologin-cookie boolean attribute in the webapp element of 
the  ofbiz-component.xml, documented in ofbiz-component.xsd
This attribute is used to get the value from the ofbiz-component.xml files in a
new autoLogoutCleanCookies() LoginWorker method? This method is used not only 
when login out but also when login in? This to be sure that in every cases the 
cookies related to the webapps not keeping it are removed.
For now only the ecommerce, ecomseo et webpos webapps are keeping and using 
their autologin cookies

Thanks: Roberto Benítez Monje for report and Taher for discussion and suggestion
------------------------------------------------------------------------

Modified:
    ofbiz/ofbiz-framework/branches/release17.12/   (props changed)
    
ofbiz/ofbiz-framework/branches/release17.12/framework/base/dtd/ofbiz-component.xsd
    
ofbiz/ofbiz-framework/branches/release17.12/framework/base/src/main/java/org/apache/ofbiz/base/component/ComponentConfig.java
    
ofbiz/ofbiz-framework/branches/release17.12/framework/webapp/src/main/java/org/apache/ofbiz/webapp/control/LoginWorker.java

Propchange: ofbiz/ofbiz-framework/branches/release17.12/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Mon Feb 19 19:24:14 2018
@@ -10,4 +10,4 @@
 /ofbiz/branches/json-integration-refactoring:1634077-1635900
 /ofbiz/branches/multitenant20100310:921280-927264
 /ofbiz/branches/release13.07:1547657
-/ofbiz/ofbiz-framework/trunk:1819499,1819598,1819800,1819805,1819811,1820038,1820262,1820374-1820375,1820441,1820457,1820644,1820658,1820790,1820823,1820949,1820966,1821012,1821036,1821112,1821115,1821144,1821186,1821219,1821226,1821230,1821386,1821600,1821613,1821628,1821965,1822125,1822310,1822377,1822383,1822393,1822882,1823324,1823467,1823562,1823876,1824260,1824314,1824316,1824732
+/ofbiz/ofbiz-framework/trunk:1819499,1819598,1819800,1819805,1819811,1820038,1820262,1820374-1820375,1820441,1820457,1820644,1820658,1820790,1820823,1820949,1820966,1821012,1821036,1821112,1821115,1821144,1821186,1821219,1821226,1821230,1821386,1821600,1821613,1821628,1821965,1822125,1822310,1822377,1822383,1822393,1822882,1823324,1823467,1823562,1823876,1824260,1824314,1824316,1824732,1824803

Modified: 
ofbiz/ofbiz-framework/branches/release17.12/framework/base/dtd/ofbiz-component.xsd
URL: 
http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/branches/release17.12/framework/base/dtd/ofbiz-component.xsd?rev=1824804&r1=1824803&r2=1824804&view=diff
==============================================================================
--- 
ofbiz/ofbiz-framework/branches/release17.12/framework/base/dtd/ofbiz-component.xsd
 (original)
+++ 
ofbiz/ofbiz-framework/branches/release17.12/framework/base/dtd/ofbiz-component.xsd
 Mon Feb 19 19:24:14 2018
@@ -251,6 +251,20 @@ under the License.
                 </xs:restriction>
             </xs:simpleType>
         </xs:attribute>
+        <xs:attribute name="keep-autologin-cookie" default="false">
+            <xs:simpleType>
+                <xs:annotation>
+                    <xs:documentation>
+                        Defines if the webapp uses the auto login feature 
which keeps a memory of the user last visit.
+                        This allows an user easier login by showing his/her 
username.
+                    </xs:documentation>
+                </xs:annotation>
+                <xs:restriction base="xs:token">
+                    <xs:enumeration value="true"/>
+                    <xs:enumeration value="false"/>
+                </xs:restriction>
+            </xs:simpleType>
+        </xs:attribute>
     </xs:attributeGroup>
     <xs:element name="virtual-host">
         <xs:complexType>

Modified: 
ofbiz/ofbiz-framework/branches/release17.12/framework/base/src/main/java/org/apache/ofbiz/base/component/ComponentConfig.java
URL: 
http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/branches/release17.12/framework/base/src/main/java/org/apache/ofbiz/base/component/ComponentConfig.java?rev=1824804&r1=1824803&r2=1824804&view=diff
==============================================================================
--- 
ofbiz/ofbiz-framework/branches/release17.12/framework/base/src/main/java/org/apache/ofbiz/base/component/ComponentConfig.java
 (original)
+++ 
ofbiz/ofbiz-framework/branches/release17.12/framework/base/src/main/java/org/apache/ofbiz/base/component/ComponentConfig.java
 Mon Feb 19 19:24:14 2018
@@ -311,6 +311,20 @@ public final class ComponentConfig {
         }
         return info;
     }
+    
+    public static WebappInfo getWebappInfo(String serverName, String 
webAppName) {
+        WebappInfo webappInfo = null;
+        List<WebappInfo> webappsInfo = getAppBarWebInfos(serverName);
+        for(WebappInfo currApp : webappsInfo) {
+            if (webAppName.equals(currApp.getName())) {
+                webappInfo = currApp;
+                break;
+            }
+        }
+        return webappInfo;
+    }    
+
+    
 
     public static boolean isFileResourceLoader(String componentName, String 
resourceLoaderName) throws ComponentException {
         ComponentConfig cc = getComponentConfig(componentName);
@@ -812,6 +826,7 @@ public final class ComponentConfig {
         // CatalinaContainer modifies this field.
         private volatile boolean appBarDisplay;
         private final String accessPermission;
+        private final boolean keepAutologinCookie;
 
         private WebappInfo(ComponentConfig componentConfig, Element element) {
             this.componentConfig = componentConfig;
@@ -851,6 +866,7 @@ public final class ComponentConfig {
             this.appBarDisplay = 
!"false".equals(element.getAttribute("app-bar-display"));
             this.privileged = 
!"false".equals(element.getAttribute("privileged"));
             this.accessPermission = element.getAttribute("access-permission");
+            this.keepAutologinCookie = 
!"false".equals(element.getAttribute("keep-autologin-cookie"));
             String basePermStr = element.getAttribute("base-permission");
             if (!basePermStr.isEmpty()) {
                 this.basePermission = basePermStr.split(",");
@@ -936,6 +952,10 @@ public final class ComponentConfig {
             return virtualHosts;
         }
 
+        public boolean getKeepAutologinCookie() {
+            return keepAutologinCookie;
+        }
+
         public synchronized void setAppBarDisplay(boolean appBarDisplay) {
             this.appBarDisplay = appBarDisplay;
         }

Modified: 
ofbiz/ofbiz-framework/branches/release17.12/framework/webapp/src/main/java/org/apache/ofbiz/webapp/control/LoginWorker.java
URL: 
http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/branches/release17.12/framework/webapp/src/main/java/org/apache/ofbiz/webapp/control/LoginWorker.java?rev=1824804&r1=1824803&r2=1824804&view=diff
==============================================================================
--- 
ofbiz/ofbiz-framework/branches/release17.12/framework/webapp/src/main/java/org/apache/ofbiz/webapp/control/LoginWorker.java
 (original)
+++ 
ofbiz/ofbiz-framework/branches/release17.12/framework/webapp/src/main/java/org/apache/ofbiz/webapp/control/LoginWorker.java
 Mon Feb 19 19:24:14 2018
@@ -43,6 +43,7 @@ import javax.servlet.jsp.PageContext;
 import javax.transaction.Transaction;
 
 import org.apache.ofbiz.base.component.ComponentConfig;
+import org.apache.ofbiz.base.component.ComponentConfig.WebappInfo;
 import org.apache.ofbiz.base.util.Debug;
 import org.apache.ofbiz.base.util.GeneralException;
 import org.apache.ofbiz.base.util.KeyStoreUtil;
@@ -513,7 +514,9 @@ public class LoginWorker {
             } catch (GenericServiceException e) {
                 Debug.logError(e, "Error setting user preference", module);
             }
-
+            // start with a clean state, in case the user has quit the session 
w/o login out
+            autoLogoutCleanCookies(userLogin, request, response);
+            
             // finally do the main login routine to set everything else up in 
the session, etc
             return doMainLogin(request, response, userLogin, userLoginSession);
         } else {
@@ -627,7 +630,7 @@ public class LoginWorker {
 
         doBasicLogout(userLogin, request, response);
         
-        //autoLogoutFromAllBackendSessions(userLogin, request, response);
+        autoLogoutCleanCookies(userLogin, request, response);
         if (request.getAttribute("_AUTO_LOGIN_LOGOUT_") == null) {
             return autoLoginCheck(request, response);
         }
@@ -820,27 +823,27 @@ public class LoginWorker {
         }
         return "success";
     }
-
-    public static String autoLogoutFromAllBackendSessions(GenericValue 
userLogin, HttpServletRequest request, HttpServletResponse response) {
+    
+    // Removes all the autoLoginCookies but if the webapp requires keeping it
+public static String autoLogoutCleanCookies(GenericValue userLogin, 
HttpServletRequest request, HttpServletResponse response) {
         HttpSession session = request.getSession();
 
-        // remove all the autoLoginCookies but if in ecommerce/ecomseo and 
webpos (it's done manually there, not sure for webpos TODO: check)
         Cookie[] cookies = request.getCookies();
         if (Debug.verboseOn()) {
             Debug.logVerbose("Cookies: " + Arrays.toString(cookies), module);
         }
         if (cookies != null && userLogin != null) {
             for (Cookie autoLoginCookie: cookies) {
-                if (autoLoginCookie.getName().contains("autoUserLoginId")
-                        && !(autoLoginCookie.getName().contains("ecommerce") 
-                        || autoLoginCookie.getName().contains("ecomseo") 
-                        || autoLoginCookie.getName().contains("webpos")))
-                autoLoginCookie.setMaxAge(0);
-                autoLoginCookie.setPath("/");
-                response.addCookie(autoLoginCookie);
+                String autoLoginName = 
autoLoginCookie.getName().replace(".autoUserLoginId", "");
+                WebappInfo webappInfo = 
ComponentConfig.getWebappInfo("default-server", autoLoginName);
+                if (webappInfo != null && 
!webappInfo.getKeepAutologinCookie()) {
+                    autoLoginCookie.setMaxAge(0);
+                    autoLoginCookie.setPath("/");
+                    response.addCookie(autoLoginCookie);
+                }
             }
         }
-        
+
         // remove the session attributes
         session.removeAttribute("autoUserLogin");
         session.removeAttribute("autoName");


Reply via email to