hbp_nrp_backend.user_authentication module

This module contains a helper class for the REST services to identify and check the user calling the service.

class hbp_nrp_backend.user_authentication.UserAuthentication[source]

Bases: object

Helper class to get the user, authenticated at the HBP Unified Portal, from a HTTP request. This is done by reading the value of the ‘X-User-Name’ header. If this header is not present, the user name ‘default-owner’ ist used to allow testing outside the portal, etc.

DEFAULT_OWNER = 'default-owner'
HEADER_TOKEN = 'Authorization'
HTTP_HEADER_USER_NAME = 'X-User-Name'
NO_TOKEN = 'no_token'
static can_modify(simulation)[source]

Checks if the current HTTP request is authenticated by the simulation owner

Parameters

simulation – The simulation

Returns

True if the request was triggered by a simulation owner, False otherwise

static can_view(simulation)[source]

Checks if the current HTTP request is authenticated by someone the simulation was shared with

Parameters

simulation – The simulation

Returns

True if the simulation was shared with the request’s user, False otherwise

client = <hbp_nrp_backend.storage_client_api.storage_client.StorageClient object>
static get_header(header_name, default_value)[source]

Gets the value of the header_name header from the current HTTP

Parameters
  • header_name – the name of the header to get

  • default_value – If nothing is found, this will be returned

Returns

The value of the header_name header or if not found default_value

static get_header_token()[source]

Gets the value of the ‘Authorization’ header from the current HTTP

Returns

The value of the ‘Authorization’ header or if not found ‘no-token’

static get_token_owner(token)[source]

Gets the owner of an authentication token

Parameters

token – The authentication token

Returns

The user’s id

static get_user()[source]

Gets the owner of the current request, from the header data It uses the x-user-name if specified, else by the authentication token

Returns

The user’s id

static get_x_user_name_header()[source]

Gets the value of the ‘X-User-Name’ header from the current HTTP

Returns

The value of the ‘X-User-Name’ header or if not found ‘default-owner’