Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
django auth plugin LDAP RemoteUser
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
uffd
django auth plugin LDAP RemoteUser
Commits
6db0ce33
Verified
Commit
6db0ce33
authored
4 years ago
by
nd
Browse files
Options
Downloads
Patches
Plain Diff
add session timeout middleware
parent
a36a9a71
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
django_auth_ldap_remoteuser/middleware.py
+48
-0
48 additions, 0 deletions
django_auth_ldap_remoteuser/middleware.py
setup.py
+1
-1
1 addition, 1 deletion
setup.py
with
49 additions
and
1 deletion
django_auth_ldap_remoteuser/middleware.py
0 → 100644
+
48
−
0
View file @
6db0ce33
# Based on https://github.com/labd/django-session-timeout
# Copyright (c) 2017 Michael van Tellingen
import
time
from
django.conf
import
settings
from
django.contrib.auth.views
import
redirect_to_login
from
django.shortcuts
import
redirect
try
:
from
django.utils.deprecation
import
MiddlewareMixin
except
ImportError
:
MiddlewareMixin
=
object
SESSION_TIMEOUT_KEY
=
"
_session_init_timestamp_
"
class
SessionTimeoutMiddleware
(
MiddlewareMixin
):
def
process_request
(
self
,
request
):
if
not
hasattr
(
request
,
"
session
"
)
or
request
.
session
.
is_empty
():
return
init_time
=
request
.
session
.
setdefault
(
SESSION_TIMEOUT_KEY
,
time
.
time
())
expire_seconds
=
getattr
(
settings
,
"
SESSION_EXPIRE_SECONDS
"
,
settings
.
SESSION_COOKIE_AGE
)
session_is_expired
=
time
.
time
()
-
init_time
>
expire_seconds
if
session_is_expired
:
request
.
session
.
flush
()
redirect_url
=
getattr
(
settings
,
"
SESSION_TIMEOUT_REDIRECT
"
,
None
)
if
redirect_url
:
return
redirect
(
redirect_url
)
else
:
return
redirect_to_login
(
next
=
request
.
path
)
expire_since_last_activity
=
getattr
(
settings
,
"
SESSION_EXPIRE_AFTER_LAST_ACTIVITY
"
,
False
)
grace_period
=
getattr
(
settings
,
"
SESSION_EXPIRE_AFTER_LAST_ACTIVITY_GRACE_PERIOD
"
,
1
)
if
expire_since_last_activity
and
time
.
time
()
-
init_time
>
grace_period
:
request
.
session
[
SESSION_TIMEOUT_KEY
]
=
time
.
time
()
This diff is collapsed.
Click to expand it.
setup.py
+
1
−
1
View file @
6db0ce33
from
setuptools
import
setup
,
find_packages
setup
(
name
=
'
django_auth_ldap_remoteuser
'
,
version
=
'
2
.0
'
,
version
=
'
3
.0
'
,
description
=
'
Combine the RemoteUser and django-auth-ldap backends for django
'
,
url
=
'
https://git.cccv.de/infra/uffd/django-auth-ldap-remoteuser
'
,
author
=
'
Andreas Valder
'
,
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment