Authentication class mixins

This module defines various mixins that can be used within the Authentication views to implement the different user creation strategies.

Classes:

CheckEmailMixin()

CreateUserMixin()

A mixin to create new users.

LoginUserMixin()

Mixin to login a user.

MapUserMixin()

A mixin to create new users.

NoUserExistsMixin()

PermissionDeniedReasonsClass(name, bases, attrs)

Metaclass for classes that can have media definitions.

PermissionRequiredReasoningMixin()

UpdateUserMixin()

Mixin to perform an update on the user.

class django_helmholtz_aai.views.auth.mixins.CheckEmailMixin

Bases: object

Classes:

PermissionDeniedReasons(value)

An enumeration.

Methods:

email_exists(email[, UserModel])

Get a user from the email.

class PermissionDeniedReasons(value)

Bases: TextChoices

An enumeration.

Attributes:

email_exists

helmholtz_email_exists

no_user_exists

email_exists = 'email_exists'
helmholtz_email_exists = 'helmholtz_email_exists'
no_user_exists = 'no_user_exists'
email_exists(email: str, UserModel: ~typing.Type[~django.contrib.auth.models.User] = <class 'django.contrib.auth.models.User'>, **kwargs) bool

Get a user from the email.

**kwargs are used to filter the existing django users.

class django_helmholtz_aai.views.auth.mixins.CreateUserMixin

Bases: object

A mixin to create new users.

Methods:

create_user(**kwargs)

Create a Django user for a Helmholtz AAI User.

get_or_create_user(**kwargs)

Create a Django user for a Helmholtz AAI User.

Attributes:

request

userinfo

create_user(**kwargs) HelmholtzUser

Create a Django user for a Helmholtz AAI User.

This method uses the create_aai_user() to create a new user.

Notes

Emits the aai_user_created signal

get_or_create_user(**kwargs) HelmholtzUser

Create a Django user for a Helmholtz AAI User.

This method uses the create_aai_user() to create a new user.

Notes

Emits the aai_user_created signal

request: Any
userinfo: Dict[str, Any]
class django_helmholtz_aai.views.auth.mixins.LoginUserMixin

Bases: object

Mixin to login a user.

Attributes:

disable_user

request

userinfo

Methods:

get_success_url()

Return the URL to redirect to after processing a valid form.

login_user(user)

Login the Helmholtz AAI user to the Django Application.

disable_user: bool | None = None
get_success_url() str

Return the URL to redirect to after processing a valid form.

login_user(user: HelmholtzUser)

Login the Helmholtz AAI user to the Django Application.

Login is done via the top-level django_helmholtz_aai.login() function.

Notes

Emits the aai_user_logged_in signal

request: Any
userinfo: Dict[str, Any]
class django_helmholtz_aai.views.auth.mixins.MapUserMixin

Bases: object

A mixin to create new users.

Methods:

get_user_from_email(email, **kwargs)

Get a user from the email.

map_user(**kwargs)

Create an Helmholtz AAI User for an existing django user.

Attributes:

userinfo

get_user_from_email(email: str, **kwargs) User

Get a user from the email.

**kwargs are used to filter the existing django users.

map_user(**kwargs) HelmholtzUser

Create an Helmholtz AAI User for an existing django user.

This method creates a new helmholtz user for an already existing django user. **kwargs are used to filter the existing django users.

userinfo: Dict[str, Any]
class django_helmholtz_aai.views.auth.mixins.NoUserExistsMixin

Bases: object

Classes:

PermissionDeniedReasons(value)

Reasons why permissions are denied to login.

Methods:

user_exists(*args, **kwargs)

Test if a user with the given id exists.

class PermissionDeniedReasons(value)

Bases: TextChoices

Reasons why permissions are denied to login.

Attributes:

no_helmholtz_user_exists

no_helmholtz_user_exists = 'no_helmholtz_user_exists'
user_exists(*args, **kwargs) bool

Test if a user with the given id exists.

class django_helmholtz_aai.views.auth.mixins.PermissionDeniedReasonsClass(name, bases, attrs)

Bases: type

Metaclass for classes that can have media definitions.

class django_helmholtz_aai.views.auth.mixins.PermissionRequiredReasoningMixin

Bases: PermissionRequiredMixin

Classes:

PermissionDeniedReasons(value)

Reasons why permissions are denied to login.

Methods:

get_permission_denied_message()

Get the permission denied message for a specific reason.

handle_no_permission()

Attributes:

permission_denied_reason

The reason why the user cannot login.

request

userinfo

class PermissionDeniedReasons(value)

Bases: TextChoices

Reasons why permissions are denied to login.

Attributes:

email_not_verified

vo_not_allowed

the virtual organization is not part of

email_not_verified = 'email_not_verified'
vo_not_allowed = 'vo_not_allowed'

the virtual organization is not part of

get_permission_denied_message() str

Get the permission denied message for a specific reason.

This method is called by the super-classes handle_no_permission() method.

handle_no_permission()
permission_denied_reason: PermissionDeniedReasons

The reason why the user cannot login.

request: Any
userinfo: Dict[str, Any]
class django_helmholtz_aai.views.auth.mixins.UpdateUserMixin

Bases: object

Mixin to perform an update on the user.

Attributes:

aai_user

request

userinfo

Methods:

apply_updates(to_update)

Apply the update to the user and send the signal.

create_vo(vo_name)

Create a new VO with the given name.

join_vo(vo)

Join the given VO.

leave_vo(vo)

Leave the given VO.

synchronize_vos()

Synchronize the memberships in the virtual organizations.

update_user(**to_update)

Update the user from the userinfo provided by the Helmholtz AAI.

aai_user: HelmholtzUser
apply_updates(to_update: Dict)

Apply the update to the user and send the signal.

create_vo(vo_name: str) HelmholtzVirtualOrganization

Create a new VO with the given name.

join_vo(vo: HelmholtzVirtualOrganization)

Join the given VO.

leave_vo(vo: HelmholtzVirtualOrganization)

Leave the given VO.

request: Any
synchronize_vos()

Synchronize the memberships in the virtual organizations.

This method checks the eduperson_entitlement of the AAI userinfo and

  1. creates the missing virtual organizations

  2. removes the user from virtual organizations that he or she does not belong to anymore

  3. adds the user to the virtual organizations that are new.

Notes

As we remove users from virtual organizations, this might end up in a lot of VOs without any users. One can remove these VOs via:

python manage.py remove_empty_vos

Notes

Emits the aai_vo_created, aai_vo_entered and aai_vo_left signals.

update_user(**to_update)

Update the user from the userinfo provided by the Helmholtz AAI.

Notes

Emits the aai_user_updated signal

userinfo: Dict[str, Any]