Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Public contract registry
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
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TO
Public contract registry
Commits
26169b99
"src/git@gitlab.pirati.cz:vpfafrin/cf2021.git" did not exist on "279ddfef279480fb0331ddf127c095f47180b203"
Commit
26169b99
authored
2 years ago
by
Tomáš Valenta
Browse files
Options
Downloads
Patches
Plain Diff
group sync with SSO
parent
0746cf06
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
oidc/auth.py
+18
-22
18 additions, 22 deletions
oidc/auth.py
registry/settings/base.py
+2
-2
2 additions, 2 deletions
registry/settings/base.py
with
20 additions
and
24 deletions
oidc/auth.py
+
18
−
22
View file @
26169b99
import
jwt
import
logging
import
logging
from
django.conf
import
settings
from
django.conf
import
settings
...
@@ -7,15 +8,13 @@ from pirates.auth import PiratesOIDCAuthenticationBackend
...
@@ -7,15 +8,13 @@ from pirates.auth import PiratesOIDCAuthenticationBackend
logging
.
basicConfig
(
level
=
logging
.
DEBUG
)
logging
.
basicConfig
(
level
=
logging
.
DEBUG
)
class
Nastenka
OIDCAuthenticationBackend
(
PiratesOIDCAuthenticationBackend
):
class
Registry
OIDCAuthenticationBackend
(
PiratesOIDCAuthenticationBackend
):
def
_assign_new_user_groups
(
self
,
user
,
claims
,
user_groups
=
None
)
->
None
:
def
_assign_new_user_groups
(
self
,
user
,
access_token
,
user_groups
=
None
)
->
None
:
if
user_groups
is
None
:
if
user_groups
is
None
:
user_groups
=
user
.
groups
.
all
()
user_groups
=
user
.
groups
.
all
()
for
role
in
claims
[
"
resource_access
"
][
settings
.
OIDC_RP_RESOURCE_ACCESS_CLIENT
][
for
group
in
access_token
[
"
groups
"
]:
"
roles
"
group_name
=
f
"
sso_
{
group
}
"
]:
group_name
=
f
"
sso_
{
role
}
"
group
=
Group
.
objects
.
filter
(
name
=
group_name
)
group
=
Group
.
objects
.
filter
(
name
=
group_name
)
...
@@ -30,28 +29,25 @@ class NastenkaOIDCAuthenticationBackend(PiratesOIDCAuthenticationBackend):
...
@@ -30,28 +29,25 @@ class NastenkaOIDCAuthenticationBackend(PiratesOIDCAuthenticationBackend):
user
.
save
()
user
.
save
()
def
create_user
(
self
,
claims
):
def
_remove_old_user_groups
(
self
,
user
,
access_token
,
user_groups
=
None
)
->
None
:
user
=
super
().
create_user
(
claims
)
if
user_groups
is
None
:
user_groups
=
user
.
groups
.
all
()
if
"
resource_access
"
not
in
claims
:
for
group
in
user_groups
:
return
user
if
group
.
name
.
replace
(
"
sso_
"
,
""
)
not
in
access_token
[
"
groups
"
]:
user
.
groups
.
remove
(
group
)
self
.
_assign_new_user_groups
(
user
,
claims
)
def
get_or_create_user
(
self
,
access_token
,
id_token
,
payload
):
user
=
super
().
get_or_create_user
(
access_token
,
id_token
,
payload
)
return
user
if
user
is
None
:
return
def
update_user
(
self
,
user
,
claims
):
decoded_access_token
=
jwt
.
decode
(
access_token
,
options
=
{
"
verify_signature
"
:
False
})
if
"
resource_access
"
not
in
claims
:
return
user
user_groups
=
user
.
groups
.
all
()
user_groups
=
user
.
groups
.
all
()
for
group
in
user_groups
:
self
.
_remove_old_user_groups
(
user
,
decoded_access_token
,
user_groups
=
user_groups
)
if
group
.
name
.
replace
(
"
sso_
"
,
""
)
not
in
(
self
.
_assign_new_user_groups
(
user
,
decoded_access_token
,
user_groups
=
user_groups
)
claims
[
"
resource_access
"
][
settings
.
OIDC_RP_CLIENT_ID
][
"
roles
"
]
):
user
.
groups
.
remove
(
group
)
self
.
_assign_new_user_groups
(
user
,
claims
,
user_groups
)
return
user
return
user
This diff is collapsed.
Click to expand it.
registry/settings/base.py
+
2
−
2
View file @
26169b99
...
@@ -129,7 +129,7 @@ AUTH_PASSWORD_VALIDATORS = [
...
@@ -129,7 +129,7 @@ AUTH_PASSWORD_VALIDATORS = [
AUTH_USER_MODEL
=
"
users.User
"
AUTH_USER_MODEL
=
"
users.User
"
AUTHENTICATION_BACKENDS
=
(
AUTHENTICATION_BACKENDS
=
(
"
oidc.auth.
Nastenka
OIDCAuthenticationBackend
"
,
"
oidc.auth.
Registry
OIDCAuthenticationBackend
"
,
"
django.contrib.auth.backends.ModelBackend
"
,
"
django.contrib.auth.backends.ModelBackend
"
,
"
guardian.backends.ObjectPermissionBackend
"
,
"
guardian.backends.ObjectPermissionBackend
"
,
)
)
...
@@ -141,7 +141,7 @@ LOGOUT_REDIRECT_URL = "/"
...
@@ -141,7 +141,7 @@ LOGOUT_REDIRECT_URL = "/"
OIDC_RP_CLIENT_ID
=
env
.
str
(
"
OIDC_RP_CLIENT_ID
"
)
OIDC_RP_CLIENT_ID
=
env
.
str
(
"
OIDC_RP_CLIENT_ID
"
)
OIDC_RP_CLIENT_SECRET
=
env
.
str
(
"
OIDC_RP_CLIENT_SECRET
"
)
OIDC_RP_CLIENT_SECRET
=
env
.
str
(
"
OIDC_RP_CLIENT_SECRET
"
)
OIDC_RP_REALM_URL
=
env
.
str
(
"
OIDC_RP_REALM_URL
"
)
OIDC_RP_REALM_URL
=
env
.
str
(
"
OIDC_RP_REALM_URL
"
)
OIDC_RP_SCOPES
=
"
openid
email role
s
"
OIDC_RP_SCOPES
=
"
openid
profile group
s
"
OIDC_RP_SIGN_ALGO
=
"
RS256
"
OIDC_RP_SIGN_ALGO
=
"
RS256
"
OIDC_RP_RESOURCE_ACCESS_CLIENT
=
env
.
str
(
OIDC_RP_RESOURCE_ACCESS_CLIENT
=
env
.
str
(
"
OIDC_RESOURCE_ACCESS_CLIENT
"
,
OIDC_RP_CLIENT_ID
"
OIDC_RESOURCE_ACCESS_CLIENT
"
,
OIDC_RP_CLIENT_ID
...
...
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