authentik.providers.saml.migrations.0012_managed
1# Generated by Django 3.1.6 on 2021-02-02 19:21 2 3from django.db import migrations 4 5saml_name_map = { 6 "http://schemas.xmlsoap.org/claims/CommonName": ( 7 "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name" 8 ), 9 "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/givenname": ( 10 "http://schemas.microsoft.com/ws/2008/06/identity/claims/windowsaccountname" 11 ), 12 "member-of": "http://schemas.xmlsoap.org/claims/Group", 13 "http://schemas.xmlsoap.org/claims/Group": "http://schemas.xmlsoap.org/claims/Group", 14 "urn:oid:0.9.2342.19200300.100.1.1": "http://schemas.goauthentik.io/2021/02/saml/uid", 15 "urn:oid:0.9.2342.19200300.100.1.3": ( 16 "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress" 17 ), 18 "urn:oid:1.3.6.1.4.1.5923.1.1.1.6": "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/upn", 19 "urn:oid:2.16.840.1.113730.3.1.241": "http://schemas.goauthentik.io/2021/02/saml/username", 20 "urn:oid:2.5.4.3": "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name", 21} 22 23saml_name_uid_map = { 24 "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/upn": ( 25 "goauthentik.io/providers/saml/upn" 26 ), 27 "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name": ( 28 "goauthentik.io/providers/saml/name" 29 ), 30 "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress": ( 31 "goauthentik.io/providers/saml/email" 32 ), 33 "http://schemas.goauthentik.io/2021/02/saml/username": "goauthentik.io/providers/saml/username", 34 "http://schemas.goauthentik.io/2021/02/saml/uid": "goauthentik.io/providers/saml/uid", 35 "http://schemas.xmlsoap.org/claims/Group": "goauthentik.io/providers/saml/groups", 36 "http://schemas.microsoft.com/ws/2008/06/identity/claims/windowsaccountname": ( 37 "goauthentik.io/providers/saml/ms-windowsaccountname" 38 ), 39} 40 41 42def add_managed_update(apps, schema_editor): 43 """Create default SAML Property Mappings""" 44 SAMLPropertyMapping = apps.get_model("authentik_providers_saml", "SAMLPropertyMapping") 45 db_alias = schema_editor.connection.alias 46 for pm in SAMLPropertyMapping.objects.using(db_alias).filter(name__startswith="Autogenerated "): 47 if pm.saml_name not in saml_name_map: 48 continue 49 new_name = saml_name_map[pm.saml_name] 50 if not new_name: 51 pm.delete() 52 continue 53 pm.saml_name = new_name 54 pm.managed = saml_name_uid_map[new_name] 55 pm.save() 56 57 58class Migration(migrations.Migration): 59 dependencies = [ 60 ("authentik_core", "0017_managed"), 61 ("authentik_providers_saml", "0011_samlprovider_name_id_mapping"), 62 ] 63 64 operations = [ 65 migrations.RunPython(add_managed_update), 66 ]
saml_name_map =
{'http://schemas.xmlsoap.org/claims/CommonName': 'http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name', 'http://schemas.xmlsoap.org/ws/2005/05/identity/claims/givenname': 'http://schemas.microsoft.com/ws/2008/06/identity/claims/windowsaccountname', 'member-of': 'http://schemas.xmlsoap.org/claims/Group', 'http://schemas.xmlsoap.org/claims/Group': 'http://schemas.xmlsoap.org/claims/Group', 'urn:oid:0.9.2342.19200300.100.1.1': 'http://schemas.goauthentik.io/2021/02/saml/uid', 'urn:oid:0.9.2342.19200300.100.1.3': 'http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress', 'urn:oid:1.3.6.1.4.1.5923.1.1.1.6': 'http://schemas.xmlsoap.org/ws/2005/05/identity/claims/upn', 'urn:oid:2.16.840.1.113730.3.1.241': 'http://schemas.goauthentik.io/2021/02/saml/username', 'urn:oid:2.5.4.3': 'http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name'}
saml_name_uid_map =
{'http://schemas.xmlsoap.org/ws/2005/05/identity/claims/upn': 'goauthentik.io/providers/saml/upn', 'http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name': 'goauthentik.io/providers/saml/name', 'http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress': 'goauthentik.io/providers/saml/email', 'http://schemas.goauthentik.io/2021/02/saml/username': 'goauthentik.io/providers/saml/username', 'http://schemas.goauthentik.io/2021/02/saml/uid': 'goauthentik.io/providers/saml/uid', 'http://schemas.xmlsoap.org/claims/Group': 'goauthentik.io/providers/saml/groups', 'http://schemas.microsoft.com/ws/2008/06/identity/claims/windowsaccountname': 'goauthentik.io/providers/saml/ms-windowsaccountname'}
def
add_managed_update(apps, schema_editor):
43def add_managed_update(apps, schema_editor): 44 """Create default SAML Property Mappings""" 45 SAMLPropertyMapping = apps.get_model("authentik_providers_saml", "SAMLPropertyMapping") 46 db_alias = schema_editor.connection.alias 47 for pm in SAMLPropertyMapping.objects.using(db_alias).filter(name__startswith="Autogenerated "): 48 if pm.saml_name not in saml_name_map: 49 continue 50 new_name = saml_name_map[pm.saml_name] 51 if not new_name: 52 pm.delete() 53 continue 54 pm.saml_name = new_name 55 pm.managed = saml_name_uid_map[new_name] 56 pm.save()
Create default SAML Property Mappings
class
Migration(django.db.migrations.migration.Migration):
59class Migration(migrations.Migration): 60 dependencies = [ 61 ("authentik_core", "0017_managed"), 62 ("authentik_providers_saml", "0011_samlprovider_name_id_mapping"), 63 ] 64 65 operations = [ 66 migrations.RunPython(add_managed_update), 67 ]
The base class for all migrations.
Migration files will import this from django.db.migrations.Migration and subclass it as a class called Migration. It will have one or more of the following attributes:
- operations: A list of Operation instances, probably from django.db.migrations.operations
- dependencies: A list of tuples of (app_path, migration_name)
- run_before: A list of tuples of (app_path, migration_name)
- replaces: A list of migration_names
Note that all migrations come out of migrations and into the Loader or Graph as instances, having been initialized with their app label and name.