From ec92b5a16095c974306079599edd09a98fb32a0c Mon Sep 17 00:00:00 2001 From: vermaas <vermaas@astron.nl> Date: Mon, 6 Feb 2023 16:14:02 +0100 Subject: [PATCH] adding astronauth package --- atdb/atdb/settings/base.py | 25 +++++++++++- atdb/atdb/settings/dev.py | 12 +++++- atdb/atdb/urls.py | 1 + atdb/requirements/base.txt | 37 ++++++++++++++---- .../templates/astronauth/navbar.html | 39 +++++++++++++++++++ .../templates/taskdatabase/base.html | 5 ++- .../templates/taskdatabase/index.html | 2 +- 7 files changed, 109 insertions(+), 12 deletions(-) create mode 100644 atdb/taskdatabase/templates/astronauth/navbar.html diff --git a/atdb/atdb/settings/base.py b/atdb/atdb/settings/base.py index d50d1746..24d55402 100644 --- a/atdb/atdb/settings/base.py +++ b/atdb/atdb/settings/base.py @@ -31,7 +31,16 @@ INSTALLED_APPS = [ 'bootstrap_pagination', 'django_tables2', 'bootstrap3', - 'fontawesome-free' + 'fontawesome-free', + + ## These are required for ASTRONauth + 'django.contrib.sites', + "astronauth", # it is important that astronauth is included before allauth + 'allauth', + 'allauth.account', + 'allauth.socialaccount', + 'allauth.socialaccount.providers.keycloak', + ] MIDDLEWARE = [ @@ -202,3 +211,17 @@ AGGREGATES = ['failed','active','total'] QUERY_LIMIT_MULTI_CHANGE = 1000 MAX_MONITORING_HISTORY_HOURS = 7 * 24 SERVICES_LATE_WARNING_SECONDS = 1800 + +# astronauth settings +SITE_ID = 1 + +SOCIALACCOUNT_PROVIDERS = { + 'keycloak': { + 'KEYCLOAK_URL': 'https://sdc-dev.astron.nl/auth', # replace by https://keycloak.astron.nl/auth for production + 'KEYCLOAK_REALM': 'SDC', # change this depending on which realm to use + 'SCOPE': ['openid', 'profile', 'email'] + } +} + +SESSION_COOKIE_NAME = 'my_service_name_session_id' +CSRF_COOKIE_NAME = 'my_service_csrftoken' diff --git a/atdb/atdb/settings/dev.py b/atdb/atdb/settings/dev.py index 3e9765a6..8d068e9f 100644 --- a/atdb/atdb/settings/dev.py +++ b/atdb/atdb/settings/dev.py @@ -13,7 +13,7 @@ DATABASES = { 'ENGINE': 'django.db.backends.postgresql_psycopg2', 'USER': 'atdb_admin', 'PASSWORD': 'atdb123', - 'NAME': 'atdb_ldv_27jan2023', + 'NAME': 'atdb_ldv_astronauth_6feb2023', 'HOST': 'localhost', 'PORT': '5432', }, @@ -23,3 +23,13 @@ DATABASES = { # https://docs.djangoproject.com/en/1.10/ref/settings/#auth-password-validators AUTH_PASSWORD_VALIDATORS = [] + +SOCIALACCOUNT_PROVIDERS = { + 'keycloak': { + 'KEYCLOAK_URL': 'https://sdc-dev.astron.nl/auth', # replace by https://keycloak.astron.nl/auth for production + 'KEYCLOAK_REALM': 'SDC', # change this depending on which realm to use + 'SCOPE': ['openid', 'profile', 'email'] + } +} + +LOGIN_REDIRECT_URL = "http://localhost:8000/" diff --git a/atdb/atdb/urls.py b/atdb/atdb/urls.py index b5e26030..772e9a54 100644 --- a/atdb/atdb/urls.py +++ b/atdb/atdb/urls.py @@ -6,4 +6,5 @@ urlpatterns = [ path('atdb/', include('taskdatabase.urls')), path('atdb/admin/', admin.site.urls), path('atdb/api-auth/', include('rest_framework.urls')), + path("atdb/astronauth/", include("astronauth.urls")), # include astronauth ] diff --git a/atdb/requirements/base.txt b/atdb/requirements/base.txt index ac71b471..f110b69e 100644 --- a/atdb/requirements/base.txt +++ b/atdb/requirements/base.txt @@ -1,12 +1,33 @@ +asgiref==3.5.2 +astronauth==0.3.3 +certifi==2022.12.7 +cffi==1.15.1 +charset-normalizer==3.0.1 +cryptography==39.0.0 +defusedxml==0.7.1 Django==3.1.4 -djangorestframework==3.12.2 -django-filter==2.3.0 -psycopg2-binary==2.9.3 +django-allauth==0.52.0 +django-bootstrap-pagination==1.7.0 +django-bootstrap3==14.2.0 django-cors-headers==3.6.0 +django-crispy-forms==1.14.0 django-extensions==3.1.0 -django-bootstrap-pagination==1.7.0 -whitenoise==5.0.1 -six==1.15.0 +django-filter==2.3.0 +django-property-filter==1.1.2 django-tables2==2.3.4 -django-bootstrap3==14.2.0 -fontawesome-free==5.15.2 \ No newline at end of file +djangorestframework==3.12.2 +fontawesome-free==5.15.2 +idna==3.4 +oauthlib==3.2.2 +psycopg2-binary==2.9.3 +pycparser==2.21 +PyJWT==2.6.0 +python3-openid==3.2.0 +pytz==2022.6 +requests==2.28.2 +requests-oauthlib==1.3.1 +six==1.15.0 +sqlparse==0.4.3 +tzdata==2022.7 +urllib3==1.26.14 +whitenoise==5.0.1 \ No newline at end of file diff --git a/atdb/taskdatabase/templates/astronauth/navbar.html b/atdb/taskdatabase/templates/astronauth/navbar.html new file mode 100644 index 00000000..2e4a6bda --- /dev/null +++ b/atdb/taskdatabase/templates/astronauth/navbar.html @@ -0,0 +1,39 @@ +{% load static %} +{% load account %} + +<nav class="h-navbar custom--navbar"> + <ol class="h-navbar-list"> + <li class="h-navbar-list__item"> + <a href="{% url 'index' %}"> + <img class="h-navbar-logo" src="{% static 'astronauth/images/astronauth.svg' %}" + alt="ASTRONauth" /> + </a> + </li> + + <li class="h-navbar-list__item">Custom Header</li> + + {% if user.is_authenticated and user.is_staff %} + <li class="h-navbar-list__item"> + <a class="button text--primary" href="{% url 'admin:index' %}"> + Admin Page + </a> + </li> + {% endif %} + </ol> + + <ul class="h-navbar-list margin-right"> + {% if "/login/" in request.path or "/logout/" in request.path %} + {# don't render antyhing #} + {% elif user.is_authenticated %} + <li class="h-navbar-list__item"> + Logged in as:<p class="text text--semi-bold margin-left"> {{ user.get_username }}</p> + </li> + <li class="h-navbar-list__item"> + <a class="button button--secondary margin-right" href="{% url 'account_logout' %}">Logout</a> + </li> + {% else %} + <li class="h-navbar-list__item"> + <a class="button button--secondary margin-right" href="{% url 'account_login' %}">Sign in</a> + </li> + {% endif %} + </ul> diff --git a/atdb/taskdatabase/templates/taskdatabase/base.html b/atdb/taskdatabase/templates/taskdatabase/base.html index 384c0fd7..4e81c7b5 100644 --- a/atdb/taskdatabase/templates/taskdatabase/base.html +++ b/atdb/taskdatabase/templates/taskdatabase/base.html @@ -27,14 +27,17 @@ <link rel="stylesheet" type="text/css" href="{% static 'taskdatabase/style.css' %}"/> <link rel="icon" href="{% static 'favicon.ico' %}"> - + <link rel="stylesheet" href="{% static 'astronauth/css/dias.css' %}"> {% block extra_js %}{% endblock %} </head> <body onload="readFromLocalStorage('search_box')"> + {% include "astronauth/navbar.html" %} <nav class="navbar navbar-expand-lg navbar-light bg-light"> <div class="container-fluid"> + + <ul class="nav navbar-nav"> <!-- Header --> <li><a class="navbar-brand" href="{% url 'index' %}"> diff --git a/atdb/taskdatabase/templates/taskdatabase/index.html b/atdb/taskdatabase/templates/taskdatabase/index.html index 8c8de66b..d83edee3 100644 --- a/atdb/taskdatabase/templates/taskdatabase/index.html +++ b/atdb/taskdatabase/templates/taskdatabase/index.html @@ -34,7 +34,7 @@ {% include 'taskdatabase/pagination.html' %} </div> </div> - <p class="footer"> Version 6 Februari 2023 + <p class="footer"> Version 6 Februari 2023 - 14:00 </div> -- GitLab