Переглянути джерело

Test Cookies are filling django_session table (#2063)

* GH-2047 Test Cookies are filling django_session table
Akhil S Naik 4 роки тому
батько
коміт
4dba4435b8

+ 4 - 0
desktop/conf.dist/hue.ini

@@ -661,6 +661,10 @@
     # This can have any value that is not used by the other cookie names in your application.
     ## cookie_name=sessionid
 
+    # Configuration to determine whether test cookie should be added determine whether the user's browser supports cookies
+    # Should be disabled if django_session table is growing rapidly , Default value is true
+    ## enable_test_cookie=true
+
     # The cookie containing the users' session ID will expire after this amount of time in seconds.
     # Default is 2 weeks.
     ## ttl=1209600

+ 4 - 0
desktop/conf/pseudo-distributed.ini.tmpl

@@ -663,6 +663,10 @@
     # This can have any value that is not used by the other cookie names in your application.
     ## cookie_name=sessionid
 
+    # Configuration to determine whether test cookie should be added determine whether the user's browser supports cookies
+    # Should be disabled if django_session table is growing rapidly , Default value is true
+    ## enable_test_cookie=true
+
     # The cookie containing the users' session ID will expire after this amount of time in seconds.
     # Default is 2 weeks.
     ## ttl=1209600

+ 6 - 5
desktop/core/src/desktop/auth/views.py

@@ -44,7 +44,7 @@ from useradmin.views import ensure_home_directory, require_change_password
 from desktop.auth import forms as auth_forms
 from desktop.auth.backend import OIDCBackend
 from desktop.auth.forms import ImpersonationAuthenticationForm, OrganizationUserCreationForm, OrganizationAuthenticationForm
-from desktop.conf import OAUTH, ENABLE_ORGANIZATIONS
+from desktop.conf import OAUTH, ENABLE_ORGANIZATIONS, SESSION
 from desktop.lib import fsmanager
 from desktop.lib.django_util import render, login_notrequired, JsonResponse
 from desktop.lib.exceptions_renderable import PopupException
@@ -145,7 +145,7 @@ def dt_login(request, from_modal=False):
         userprofile = get_profile(user)
 
         login(request, user)
-
+        # If Test cookie exists , it should be deleted
         if request.session.test_cookie_worked():
           request.session.delete_test_cookie()
         if request.fs is None:
@@ -200,11 +200,12 @@ def dt_login(request, from_modal=False):
       request.method == 'POST' and request.user.username != request.POST.get('username'):
     # local user login failed, give the right auth_form with 'server' field
     auth_form = auth_forms.LdapAuthenticationForm()
-
-  if not from_modal:
+  
+  if not from_modal and SESSION.ENABLE_TEST_COOKIE.get() :
     request.session.set_test_cookie()
 
-  request.session['samlgroup_permitted_flag'] = samlgroup_check(request)
+  if 'SAML2Backend' in backend_names:
+    request.session['samlgroup_permitted_flag'] = samlgroup_check(request)
 
   renderable_path = 'login.mako'
   if from_modal:

+ 6 - 0
desktop/core/src/desktop/conf.py

@@ -863,6 +863,12 @@ SESSION = ConfigSection(
       type=str,
       default="sessionid",
     ),
+    ENABLE_TEST_COOKIE=Config(
+      key='enable_test_cookie',
+      help=_("Configuration to determine whether test cookie should be added determine whether the user's browser supports cookies."),
+      type=coerce_bool,
+      default=True,
+    ),
     TTL=Config(
       key='ttl',
       help=_("The cookie containing the users' session ID will expire after this amount of time in seconds."),