Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
scheduling-system
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
External wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
SMASCH
scheduling-system
Commits
bb8e41f6
Commit
bb8e41f6
authored
3 years ago
by
Piotr Gawron
Browse files
Options
Downloads
Patches
Plain Diff
lint issues
parent
52f17ca0
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!352
Resolve "LDAP connector"
Pipeline
#47725
failed
3 years ago
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
smash/smash/settings.py
+5
-0
5 additions, 0 deletions
smash/smash/settings.py
smash/web/auth/CustomLDAPBackend.py
+3
-5
3 additions, 5 deletions
smash/web/auth/CustomLDAPBackend.py
smash/web/auth/CustomModelBackend.py
+2
-4
2 additions, 4 deletions
smash/web/auth/CustomModelBackend.py
with
10 additions
and
9 deletions
smash/smash/settings.py
+
5
−
0
View file @
bb8e41f6
...
...
@@ -120,9 +120,14 @@ AUTHENTICATION_BACKENDS = [
# by default disable LDAP
AUTH_LDAP_SERVER_URI
=
None
AUTH_LDAP_BIND_DN
=
''
AUTH_LDAP_BIND_PASSWORD
=
''
AUTH_LDAP_BASE_DN
=
"
cn=users,cn=accounts,dc=uni,dc=lu
"
AUTH_LDAP_FILTER
=
"
(uid=%(user)s)
"
AUTH_LDAP_ALWAYS_UPDATE_USER
=
False
AUTH_LDAP_CONNECTION_OPTIONS
=
{
ldap
.
OPT_REFERRALS
:
0
}
INTERNAL_IPS
=
[
'
127.0.0.1
'
...
...
This diff is collapsed.
Click to expand it.
smash/web/auth/CustomLDAPBackend.py
+
3
−
5
View file @
bb8e41f6
import
logging
from
django_auth_ldap.backend
import
LDAPBackend
,
_LDAPUser
from
django_auth_ldap.backend
import
LDAPBackend
from
web.models
import
Worker
...
...
@@ -8,12 +8,10 @@ logger = logging.getLogger(__name__)
class
CustomLDAPBackend
(
LDAPBackend
):
def
authenticate_ldap_user
(
self
,
ldap_user
:
_LDAPUser
,
password
):
username
=
self
.
ldap_to_django_username
(
ldap_user
.
_username
)
def
authenticate
(
self
,
request
,
username
=
None
,
password
=
None
,
**
kwargs
):
count
=
Worker
.
objects
.
filter
(
user__username
=
username
,
user__is_active
=
True
,
ldap_user
=
True
).
count
()
if
count
==
1
:
logger
.
debug
(
"
Trying LDAP auth with:
"
+
username
)
return
super
().
authenticate
_ldap_user
(
ldap_user
,
password
)
return
super
().
authenticate
(
request
,
username
,
password
,
**
kwargs
)
else
:
return
None
This diff is collapsed.
Click to expand it.
smash/web/auth/CustomModelBackend.py
+
2
−
4
View file @
bb8e41f6
...
...
@@ -9,14 +9,12 @@ logger = logging.getLogger(__name__)
class
CustomModelBackend
(
ModelBackend
):
def
authenticate
(
self
,
request
,
**
kwargs
):
username
=
kwargs
[
'
username
'
]
def
authenticate
(
self
,
request
,
username
=
None
,
password
=
None
,
**
kwargs
):
logger
.
debug
(
"
Trying LOCAL auth with:
"
+
username
)
count
=
Worker
.
objects
.
filter
(
user__username
=
username
,
user__is_active
=
True
,
ldap_user
=
False
).
count
()
if
count
==
1
:
return
super
().
authenticate
(
request
,
**
kwargs
)
return
super
().
authenticate
(
request
,
username
,
password
,
**
kwargs
)
else
:
return
None
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