Skip to content

Commit

Permalink
Merge branch 'dev' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
peppelinux committed Mar 20, 2021
2 parents 5b7a0e6 + 9fed0e0 commit 97eabde
Show file tree
Hide file tree
Showing 52 changed files with 1,500 additions and 643 deletions.
12 changes: 12 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# .coveragerc to control coverage.py
[coverage:run]
branch = True
source = src/djangosaml2_spid/
omit =
*manage.py
*/distutils/*
tests/*
*/apps/*
*/migrations/*
*/site-packages/*
*/tests.py
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ __pycache__/
*.py[cod]
*$py.class



# C extensions
*.so

Expand Down Expand Up @@ -129,3 +127,7 @@ dmypy.json

# Pyre type checker
.pyre/

# example project downloaded metadata
example/spid_config/metadata/idp_*.xml
example/djangosaml2_spid
5 changes: 4 additions & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "spid-compliant-certificates"]
path = spid-compliant-certificates
url = https://github.com/italia/spid-compliant-certificates.git
[submodule "spid-saml-check"]
path = spid-saml-check
url = ./spid-saml-check
url = https://github.com/italia/spid-saml-check.git
42 changes: 29 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
Djangosaml2 SPID
================
SPID Django

![CI build](https://github.com/italia/spid-django/workflows/spid-django/badge.svg)
![Python version](https://img.shields.io/badge/license-Apache%202-blue.svg)
Expand All @@ -15,7 +14,7 @@ Introduction
This is a Django application that provides a SAML2 Service Provider
for a Single Sign On with SPID, the Italian Digital Identity System.

This project comes with a demo on a Spid button template with both *spid-testenv2*
This project comes with a demo on a Spid button template with both *spid-testenv2*
and *spid-saml-check* IDP preconfigured. See running the Demo project paragaph for details.

The technical documentation on SPID and SAML is available at [Docs Italia](https://docs.italia.it/italia/spid/spid-regole-tecniche/it/34.1.1/index.html)
Expand All @@ -26,7 +25,7 @@ The technical documentation on SPID and SAML is available at [Docs Italia](https
Dependencies
------------

These libraries are required on your operating system environment
These libraries are required on your operating system environment
in order to compile external modules of some dependencies:

- xmlsec
Expand All @@ -39,7 +38,7 @@ in order to compile external modules of some dependencies:
Running the Demo project
------------------------

The demo project is configured within `example/` subdirectory.
The demo project is configured within `example/` subdirectory.
This project uses **spid-saml-check** and **spid-testenv2** as
additional IDPs configured in a demo SPID button.

Expand All @@ -51,28 +50,28 @@ source env/bin/activate
pip install -r ../requirements.txt
````

Your example saml2 configuration is in `spid_config/spid_settings.py`.
Your example saml2 configuration is in `spid_config/spid_settings.py`.
See djangosaml2 or pysaml2 official docs for clarifications.

To run the demo project:
- create the database `./manage.py migrate`
- run `./manage.py runserver 0.0.0.0:8000`

or execute the run.sh script with these environment settings:

````
SPID_SAML_CHECK_REMOTE_METADATA_ACTIVE=True SPID_TESTENV2_REMOTE_METADATA_ACTIVE=True bash run.sh
````

If you choosed to use *spid-testenv2*, fefore starting it, you just have to save the
If you choosed to use *spid-testenv2*, fefore starting it, you just have to save the
current demo metadata in *spid-testenv2* configuration, this way:

````
# cd into spid-testenv2/ base dir ...
wget http://localhost:8000/spid/metadata -O conf/sp_metadata.xml
````

Finally, start spid-testenv2 and spid-saml-check (docker is suggested) and
Finally, start spid-testenv2 and spid-saml-check (docker is suggested) and
then open 'http://localhost:8000' in your browser.


Expand All @@ -90,14 +89,14 @@ then use `docker-compose --env-file docker-compose.env up` (the process takes so
under `./example/configs/` to match the new configurations, changing only `./docker-compose.env` will not suffice.


Setup for an existing project
Setup for an existing project
-----------------------------

djangosaml2_spid uses a pySAML2 fork.

* `pip install git+https://github.com/peppelinux/[email protected]`
* `pip install git+https://github.com/italia/spid-django`
* Copy the `example/spid_config/` to your project base dir
* Copy the `example/spid_config/` to your project base dir
* Import SAML2 entity configuration in your project settings file: `from spid_config.spid_settings import *`
* Add in `settings.INSTALLED_APPS` the following
```
Expand Down Expand Up @@ -135,15 +134,32 @@ SAML_ATTRIBUTE_MAPPING = {
}
````

Download identity providers metadata
-----------------------------------

To update the list of entity providers use the custom django command `update_idps`.
In the example project you can do it as follows:

````
cd example/
python ./manage.py update_idps
````

Running tests (only for developers)
-----------------------------------

Tests are integrated into the demo project and are intended for use
Tests are integrated into the demo project and are intended for use
only by developers.

To test the application:
````
pip install -r requirements-dev.txt
python runtests.py
````

For running tests using the settings of the Demo project:
````
pip install requirements-dev.txt
pip install -r requirements-dev.txt
cd example/
coverage erase
coverage run ./manage.py test djangosaml2_spid.tests
Expand Down
1 change: 0 additions & 1 deletion example/djangosaml2_spid

This file was deleted.

2 changes: 1 addition & 1 deletion example/example/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@

'djangosaml2',
'djangosaml2_spid',
'spid_config'
'spid_config',
]

MIDDLEWARE = [
Expand Down
26 changes: 4 additions & 22 deletions example/example/urls.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,11 @@
"""example URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/3.1/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.conf import settings
from django.contrib import admin
from django.urls import path, include
from django.views.generic.base import RedirectView
import djangosaml2_spid.urls

urlpatterns = [
path('admin/', admin.site.urls),
path('', include((djangosaml2_spid.urls, 'djangosaml2_spid',))),
path('', RedirectView.as_view(url=settings.SPID_BASE_URL), name='example-index')
]

if 'djangosaml2_spid' in settings.INSTALLED_APPS:
import djangosaml2_spid.urls

urlpatterns.extend([
path('', include((djangosaml2_spid.urls, 'djangosaml2_spid',)))
])
1 change: 1 addition & 0 deletions example/manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ def main():


if __name__ == '__main__':
__spec__ = None
main()
Loading

0 comments on commit 97eabde

Please sign in to comment.