User.get - Python API

Both regular and super-users can access information about their own accounts using self.sso.user.get_current_user, which accepts current session’s UST on input. Further, super-users may query for other users by the latter’s ID with self.sso.user.get_user_by_id.

On out, a zato.sso.User object is returned which describes a given user with a range of attributes. Further, the object’s .to_dict() method will serialize all the data to a Python dictionary.

Passwords are never returned regardless of user type.

API

self.sso.user.get_current_user

get_current_user(self, cid, current_ust, current_app, remote_addr)

Returns information about user using this person’s current session

Parameters:
  • cid (string) – Correlation ID used by audit log
  • current_ust (string) – Current user’s UST
  • current_app (string) – Name of application the current user is issuing the call from
  • remote_addr (string) – User’s remote address
Return type:

A zato.sso.User object with attributes out of which only user_id and username are guaranteed to always exist. The rest is optional and additionally, some of attributes are set to meaningful values, if they exist at all, only if current user is a super-user.

Accessible no matter the user type is:

  • user_id
  • username
  • email
  • display_name
  • first_name
  • middle_name
  • last_name

Accessible to super-users only:

  • is_active
  • is_internal
  • is_super_user
  • is_locked
  • is_approval_needed
  • approval_status
  • approval_status_mod_by
  • approval_status_mod_time
  • locked_time
  • creation_ctx
  • locked_by
  • approv_rej_time
  • approv_rej_by
  • password_expiry
  • password_is_set
  • password_must_change
  • password_last_set
  • sign_up_status
  • sign_up_time

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
# -*- coding: utf-8 -*-

from __future__ import absolute_import, division, print_function, unicode_literals

# Zato
from zato.server.service import Service

class GetCurrentUser(Service):

    def handle(self):

        # Data obtained from request and/or WSGI environment
        ust = 'gAAAAABalFycY50Budi...'
        current_app = 'CRM'
        remote_addr = '127.0.0.1'

        # Get user by UST
        user_info = self.sso.user.get_current_user(self.cid, ust, current_app, remote_addr)

        # Log output for confirmation
        self.logger.info(user_info.to_dict())
1
2
3
4
5
6
INFO - {
  'user_id': 'zusrx2efj1q1h98n9q00tgx8scefv',
  'username': 'regular1',
  'display_name': 'John Doe',
  'email': 'hello@example.com'
  }

self.sso.user.get_user_by_id

get_user_by_id(self, cid, user_id, current_ust, current_app, remote_addr)

Returns information about a user using that person’s ID. Current user must be a super-user.

Parameters:
  • cid (string) – Correlation ID used by audit log
  • user_id – User ID (another person or possibly current user)
  • current_ust (string) – Current user’s UST - must belong to a super-user
  • current_app (string) – Name of application current user is issuing the call from
  • remote_addr (string) – Current user’s remote address
Return type:

Same as with self.sso.user.get_current_user