Compare commits
No commits in common. "44c11fd89b1f738308e2bfcefc33c927fb157bbd" and "ec4b5f76fe519ac7865e6f33dfc27f0935eadb51" have entirely different histories.
44c11fd89b
...
ec4b5f76fe
78
konova/sso/sso.py
Normal file
78
konova/sso/sso.py
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
"""
|
||||||
|
Author: Michel Peltriaux
|
||||||
|
Organization: Struktur- und Genehmigungsdirektion Nord, Rhineland-Palatinate, Germany
|
||||||
|
Contact: michel.peltriaux@sgdnord.rlp.de
|
||||||
|
Created on: 17.08.21
|
||||||
|
|
||||||
|
"""
|
||||||
|
from django.http import HttpResponse
|
||||||
|
from django.urls import re_path
|
||||||
|
from django.views import View
|
||||||
|
from django.views.decorators.csrf import csrf_exempt
|
||||||
|
from itsdangerous import TimedSerializer
|
||||||
|
from simple_sso.sso_client.client import Client
|
||||||
|
|
||||||
|
from user.models import User
|
||||||
|
|
||||||
|
|
||||||
|
class PropagateView(View):
|
||||||
|
""" View used to receive propagated sso-server user data
|
||||||
|
|
||||||
|
"""
|
||||||
|
client = None
|
||||||
|
signer = None
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
super().__init__(*args, **kwargs)
|
||||||
|
self.signer = TimedSerializer(self.client.private_key)
|
||||||
|
|
||||||
|
@csrf_exempt
|
||||||
|
def dispatch(self, request, *args, **kwargs):
|
||||||
|
return super().dispatch(request, *args, **kwargs)
|
||||||
|
|
||||||
|
def post(self, request):
|
||||||
|
user_data = request.body
|
||||||
|
user_data = self.signer.loads(user_data)
|
||||||
|
self.client.build_user(user_data)
|
||||||
|
return HttpResponse(status=200)
|
||||||
|
|
||||||
|
|
||||||
|
class KonovaSSOClient(Client):
|
||||||
|
""" Konova specialized derivative of general sso.Client.
|
||||||
|
|
||||||
|
Adds some custom behaviour for konova usage.
|
||||||
|
|
||||||
|
"""
|
||||||
|
propagate_view = PropagateView
|
||||||
|
|
||||||
|
def get_urls(self):
|
||||||
|
urls = super().get_urls()
|
||||||
|
urls += re_path(r'^propagate/$', self.propagate_view.as_view(client=self), name='simple-sso-propagate'),
|
||||||
|
return urls
|
||||||
|
|
||||||
|
def build_user(self, user_data):
|
||||||
|
""" Creates a user or updates user data
|
||||||
|
|
||||||
|
Args:
|
||||||
|
user_data ():
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
user = User.objects.get(username=user_data['username'])
|
||||||
|
# Update user data, excluding some changes
|
||||||
|
skipable_attrs = {
|
||||||
|
"username",
|
||||||
|
"is_staff",
|
||||||
|
"is_superuser",
|
||||||
|
}
|
||||||
|
for _attr, _val in user_data.items():
|
||||||
|
if _attr in skipable_attrs:
|
||||||
|
continue
|
||||||
|
setattr(user, _attr, _val)
|
||||||
|
except User.DoesNotExist:
|
||||||
|
user = User(**user_data)
|
||||||
|
user.set_unusable_password()
|
||||||
|
user.save()
|
||||||
|
return user
|
@ -83,6 +83,10 @@ INSTALLED_APPS = [
|
|||||||
'analysis',
|
'analysis',
|
||||||
'api',
|
'api',
|
||||||
]
|
]
|
||||||
|
if DEBUG:
|
||||||
|
INSTALLED_APPS += [
|
||||||
|
'debug_toolbar',
|
||||||
|
]
|
||||||
|
|
||||||
MIDDLEWARE = [
|
MIDDLEWARE = [
|
||||||
'django.middleware.security.SecurityMiddleware',
|
'django.middleware.security.SecurityMiddleware',
|
||||||
@ -94,6 +98,10 @@ MIDDLEWARE = [
|
|||||||
'django.contrib.messages.middleware.MessageMiddleware',
|
'django.contrib.messages.middleware.MessageMiddleware',
|
||||||
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
||||||
]
|
]
|
||||||
|
if DEBUG:
|
||||||
|
MIDDLEWARE += [
|
||||||
|
"debug_toolbar.middleware.DebugToolbarMiddleware",
|
||||||
|
]
|
||||||
|
|
||||||
ROOT_URLCONF = 'konova.urls'
|
ROOT_URLCONF = 'konova.urls'
|
||||||
|
|
||||||
@ -193,6 +201,28 @@ STATICFILES_DIRS = [
|
|||||||
os.path.join(BASE_DIR, 'templates/map/client/libs'), # NETGIS map client files
|
os.path.join(BASE_DIR, 'templates/map/client/libs'), # NETGIS map client files
|
||||||
]
|
]
|
||||||
|
|
||||||
|
# DJANGO DEBUG TOOLBAR
|
||||||
|
INTERNAL_IPS = [
|
||||||
|
"127.0.0.1"
|
||||||
|
]
|
||||||
|
DEBUG_TOOLBAR_CONFIG = {
|
||||||
|
"DISABLE_PANELS": {
|
||||||
|
'debug_toolbar.panels.versions.VersionsPanel',
|
||||||
|
'debug_toolbar.panels.timer.TimerPanel',
|
||||||
|
'debug_toolbar.panels.settings.SettingsPanel',
|
||||||
|
'debug_toolbar.panels.headers.HeadersPanel',
|
||||||
|
'debug_toolbar.panels.request.RequestPanel',
|
||||||
|
'debug_toolbar.panels.sql.SQLPanel',
|
||||||
|
'debug_toolbar.panels.staticfiles.StaticFilesPanel',
|
||||||
|
'debug_toolbar.panels.templates.TemplatesPanel',
|
||||||
|
'debug_toolbar.panels.cache.CachePanel',
|
||||||
|
'debug_toolbar.panels.signals.SignalsPanel',
|
||||||
|
'debug_toolbar.panels.logging.LoggingPanel',
|
||||||
|
'debug_toolbar.panels.redirects.RedirectsPanel',
|
||||||
|
'debug_toolbar.panels.profiling.ProfilingPanel',
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
# EMAIL (see https://docs.djangoproject.com/en/dev/topics/email/)
|
# EMAIL (see https://docs.djangoproject.com/en/dev/topics/email/)
|
||||||
|
|
||||||
# CHANGE_ME !!! ONLY FOR DEVELOPMENT !!!
|
# CHANGE_ME !!! ONLY FOR DEVELOPMENT !!!
|
||||||
|
@ -5,10 +5,14 @@ Contact: michel.peltriaux@sgdnord.rlp.de
|
|||||||
Created on: 31.01.22
|
Created on: 31.01.22
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
import random
|
||||||
|
import string
|
||||||
|
|
||||||
# SSO settings
|
# Django-simple-SSO settings
|
||||||
SSO_SERVER_BASE = "http://127.0.0.1:8000/"
|
SSO_SERVER_BASE = "http://127.0.0.1:8000/"
|
||||||
SSO_SERVER = f"{SSO_SERVER_BASE}sso/"
|
SSO_SERVER = f"{SSO_SERVER_BASE}sso/"
|
||||||
|
SSO_PRIVATE_KEY = "CHANGE_ME"
|
||||||
|
SSO_PUBLIC_KEY = "CHANGE_ME"
|
||||||
|
|
||||||
# OAuth settings
|
# OAuth settings
|
||||||
OAUTH_CODE_VERIFIER = "CHANGE_ME"
|
OAUTH_CODE_VERIFIER = "CHANGE_ME"
|
||||||
|
@ -13,17 +13,22 @@ Including another URLconf
|
|||||||
1. Import the include() function: from django.urls import include, path
|
1. Import the include() function: from django.urls import include, path
|
||||||
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
|
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
|
||||||
"""
|
"""
|
||||||
|
import debug_toolbar
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from django.urls import path, include
|
from django.urls import path, include
|
||||||
|
|
||||||
|
from konova.settings import SSO_SERVER, SSO_PUBLIC_KEY, SSO_PRIVATE_KEY, DEBUG
|
||||||
|
from konova.sso.sso import KonovaSSOClient
|
||||||
from konova.views.logout import LogoutView
|
from konova.views.logout import LogoutView
|
||||||
from konova.views.geometry import GeomParcelsView, GeomParcelsContentView
|
from konova.views.geometry import GeomParcelsView, GeomParcelsContentView
|
||||||
from konova.views.home import HomeView
|
from konova.views.home import HomeView
|
||||||
from konova.views.map_proxy import ClientProxyParcelSearch, ClientProxyParcelWFS
|
from konova.views.map_proxy import ClientProxyParcelSearch, ClientProxyParcelWFS
|
||||||
from konova.views.oauth import OAuthLoginView, OAuthCallbackView
|
from konova.views.oauth import OAuthLoginView, OAuthCallbackView
|
||||||
|
|
||||||
|
sso_client = KonovaSSOClient(SSO_SERVER, SSO_PUBLIC_KEY, SSO_PRIVATE_KEY)
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('admin/', admin.site.urls),
|
path('admin/', admin.site.urls),
|
||||||
|
path('login/', include(sso_client.get_urls())),
|
||||||
path('oauth/callback/', OAuthCallbackView.as_view(), name="oauth-callback"),
|
path('oauth/callback/', OAuthCallbackView.as_view(), name="oauth-callback"),
|
||||||
path('oauth/login/', OAuthLoginView.as_view(), name="oauth-login"),
|
path('oauth/login/', OAuthLoginView.as_view(), name="oauth-login"),
|
||||||
path('logout/', LogoutView.as_view(), name="logout"),
|
path('logout/', LogoutView.as_view(), name="logout"),
|
||||||
@ -42,5 +47,10 @@ urlpatterns = [
|
|||||||
path('client/proxy/wfs', ClientProxyParcelWFS.as_view(), name="client-proxy-wfs"),
|
path('client/proxy/wfs', ClientProxyParcelWFS.as_view(), name="client-proxy-wfs"),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
if DEBUG:
|
||||||
|
urlpatterns += [
|
||||||
|
path('__debug__/', include(debug_toolbar.urls)),
|
||||||
|
]
|
||||||
|
|
||||||
handler404 = "konova.views.error.get_404_view"
|
handler404 = "konova.views.error.get_404_view"
|
||||||
handler500 = "konova.views.error.get_500_view"
|
handler500 = "konova.views.error.get_500_view"
|
||||||
|
@ -4,41 +4,43 @@ async-timeout==4.0.3
|
|||||||
beautifulsoup4==4.13.0b2
|
beautifulsoup4==4.13.0b2
|
||||||
billiard==4.2.0
|
billiard==4.2.0
|
||||||
cached-property==1.5.2
|
cached-property==1.5.2
|
||||||
celery==5.4.0
|
celery==5.4.0rc2
|
||||||
certifi==2024.6.2
|
certifi==2024.2.2
|
||||||
cffi==1.17.0rc1
|
cffi==1.16.0
|
||||||
chardet==5.2.0
|
chardet==5.2.0
|
||||||
charset-normalizer==3.3.2
|
charset-normalizer==3.3.2
|
||||||
click==8.1.7
|
click==8.1.7
|
||||||
click-didyoumean==0.3.1
|
click-didyoumean==0.3.1
|
||||||
click-plugins==1.1.1
|
click-plugins==1.1.1
|
||||||
click-repl==0.3.0
|
click-repl==0.3.0
|
||||||
coverage==7.5.3
|
coverage==7.4.4
|
||||||
cryptography==42.0.8
|
cryptography==42.0.5
|
||||||
Deprecated==1.2.14
|
Deprecated==1.2.14
|
||||||
Django==5.0.6
|
Django==5.0.4
|
||||||
django-autocomplete-light==3.11.0
|
django-autocomplete-light==3.11.0
|
||||||
django-bootstrap-modal-forms==3.0.4
|
django-bootstrap-modal-forms==3.0.4
|
||||||
django-bootstrap4==24.3
|
django-bootstrap4==24.1
|
||||||
|
django-debug-toolbar==4.3.0
|
||||||
django-environ==0.11.2
|
django-environ==0.11.2
|
||||||
django-filter==24.2
|
django-filter==24.2
|
||||||
django-fontawesome-5==1.0.18
|
django-fontawesome-5==1.0.18
|
||||||
django-oauth-toolkit==2.4.0
|
django-oauth-toolkit==2.3.0
|
||||||
|
django-simple-sso==1.2.0
|
||||||
django-tables2==2.7.0
|
django-tables2==2.7.0
|
||||||
et-xmlfile==1.1.0
|
et-xmlfile==1.1.0
|
||||||
gunicorn==22.0.0
|
|
||||||
idna==3.7
|
idna==3.7
|
||||||
importlib_metadata==7.1.0
|
importlib_metadata==7.1.0
|
||||||
|
itsdangerous==0.24
|
||||||
jwcrypto==1.5.6
|
jwcrypto==1.5.6
|
||||||
kombu==5.3.7
|
kombu==5.3.7
|
||||||
oauthlib==3.2.2
|
oauthlib==3.2.2
|
||||||
openpyxl==3.2.0b1
|
openpyxl==3.2.0b1
|
||||||
packaging==24.1
|
packaging==24.0
|
||||||
pika==1.3.2
|
pika==1.3.2
|
||||||
pillow==10.3.0
|
pillow==10.2.0
|
||||||
prompt_toolkit==3.0.47
|
prompt-toolkit==3.0.43
|
||||||
psycopg==3.1.19
|
psycopg==3.1.18
|
||||||
psycopg-binary==3.1.19
|
psycopg-binary==3.1.18
|
||||||
pycparser==2.22
|
pycparser==2.22
|
||||||
pyparsing==3.1.2
|
pyparsing==3.1.2
|
||||||
pypng==0.20220715.0
|
pypng==0.20220715.0
|
||||||
@ -47,16 +49,17 @@ python-dateutil==2.9.0.post0
|
|||||||
pytz==2024.1
|
pytz==2024.1
|
||||||
PyYAML==6.0.1
|
PyYAML==6.0.1
|
||||||
qrcode==7.3.1
|
qrcode==7.3.1
|
||||||
redis==5.1.0b6
|
redis==5.1.0b4
|
||||||
requests==2.32.3
|
requests==2.31.0
|
||||||
six==1.16.0
|
six==1.16.0
|
||||||
soupsieve==2.5
|
soupsieve==2.5
|
||||||
sqlparse==0.5.0
|
sqlparse==0.4.4
|
||||||
typing_extensions==4.12.2
|
typing_extensions==4.11.0
|
||||||
tzdata==2024.1
|
tzdata==2024.1
|
||||||
urllib3==2.2.1
|
urllib3==2.2.1
|
||||||
vine==5.1.0
|
vine==5.1.0
|
||||||
wcwidth==0.2.13
|
wcwidth==0.2.13
|
||||||
|
webservices==0.7
|
||||||
wrapt==1.16.0
|
wrapt==1.16.0
|
||||||
xmltodict==0.13.0
|
xmltodict==0.13.0
|
||||||
zipp==3.19.2
|
zipp==3.18.1
|
||||||
|
@ -112,7 +112,7 @@
|
|||||||
},
|
},
|
||||||
"import":
|
"import":
|
||||||
{
|
{
|
||||||
"geopackageLibURL": "/static/libs/geopackage/4.2.3/"
|
"geopackageLibURL": "/libs/geopackage/4.2.3/"
|
||||||
},
|
},
|
||||||
"export":
|
"export":
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user