Author: jleroux
Date: Mon Feb 19 19:23:36 2018
New Revision: 1824803

URL: http://svn.apache.org/viewvc?rev=1824803&view=rev
Log:
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/trunk/framework/base/dtd/ofbiz-component.xsd
    
ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/component/ComponentConfig.java
    
ofbiz/ofbiz-framework/trunk/framework/webapp/src/main/java/org/apache/ofbiz/webapp/control/LoginWorker.java
    ofbiz/ofbiz-plugins/trunk/ecommerce/ofbiz-component.xml
    ofbiz/ofbiz-plugins/trunk/webpos/ofbiz-component.xml

Modified: ofbiz/ofbiz-framework/trunk/framework/base/dtd/ofbiz-component.xsd
URL: 
http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/base/dtd/ofbiz-component.xsd?rev=1824803&r1=1824802&r2=1824803&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/base/dtd/ofbiz-component.xsd 
(original)
+++ ofbiz/ofbiz-framework/trunk/framework/base/dtd/ofbiz-component.xsd Mon Feb 
19 19:23:36 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/trunk/framework/base/src/main/java/org/apache/ofbiz/base/component/ComponentConfig.java
URL: 
http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/component/ComponentConfig.java?rev=1824803&r1=1824802&r2=1824803&view=diff
==============================================================================
--- 
ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/component/ComponentConfig.java
 (original)
+++ 
ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/component/ComponentConfig.java
 Mon Feb 19 19:23:36 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/trunk/framework/webapp/src/main/java/org/apache/ofbiz/webapp/control/LoginWorker.java
URL: 
http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/webapp/src/main/java/org/apache/ofbiz/webapp/control/LoginWorker.java?rev=1824803&r1=1824802&r2=1824803&view=diff
==============================================================================
--- 
ofbiz/ofbiz-framework/trunk/framework/webapp/src/main/java/org/apache/ofbiz/webapp/control/LoginWorker.java
 (original)
+++ 
ofbiz/ofbiz-framework/trunk/framework/webapp/src/main/java/org/apache/ofbiz/webapp/control/LoginWorker.java
 Mon Feb 19 19:23:36 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");

Modified: ofbiz/ofbiz-plugins/trunk/ecommerce/ofbiz-component.xml
URL: 
http://svn.apache.org/viewvc/ofbiz/ofbiz-plugins/trunk/ecommerce/ofbiz-component.xml?rev=1824803&r1=1824802&r2=1824803&view=diff
==============================================================================
--- ofbiz/ofbiz-plugins/trunk/ecommerce/ofbiz-component.xml (original)
+++ ofbiz/ofbiz-plugins/trunk/ecommerce/ofbiz-component.xml Mon Feb 19 19:23:36 
2018
@@ -56,12 +56,14 @@ under the License.
         server="default-server"
         location="webapp/ecommerce"
         mount-point="/ecommerce"
-        app-bar-display="false"/>
+        app-bar-display="false"
+        keep-autologin-cookie="true"/>
     <webapp name="ecomseo"
         title="SEO enhanced eCommerce"
         server="default-server"
         location="webapp/ecomseo"
         mount-point="/ecomseo"
-        app-bar-display="false"/>
+        app-bar-display="false"
+        keep-autologin-cookie="true"/>
 </ofbiz-component>
 

Modified: ofbiz/ofbiz-plugins/trunk/webpos/ofbiz-component.xml
URL: 
http://svn.apache.org/viewvc/ofbiz/ofbiz-plugins/trunk/webpos/ofbiz-component.xml?rev=1824803&r1=1824802&r2=1824803&view=diff
==============================================================================
--- ofbiz/ofbiz-plugins/trunk/webpos/ofbiz-component.xml (original)
+++ ofbiz/ofbiz-plugins/trunk/webpos/ofbiz-component.xml Mon Feb 19 19:23:36 
2018
@@ -51,5 +51,6 @@ under the License.
         location="webapp/webpos"
         base-permission="WEBPOS"
         mount-point="/webpos"
-        app-bar-display="true"/>
+        app-bar-display="true"
+        keep-autologin-cookie="true"/>
 </ofbiz-component>


Reply via email to