atoti.Session.user#
- property Session.user: User#
The user behind this session.
Example
A session without security configured has a single user, who is both anonymous and an administrator:
>>> user = session.user >>> user.name 'anonymousUser' >>> sorted(user.roles) ['ROLE_ADMIN', 'ROLE_ANONYMOUS', 'ROLE_USER']
The user that
started
a secured session has the same characteristics:>>> session_config = tt.SessionConfig(security=tt.SecurityConfig()) >>> secured_session = tt.Session.start(session_config) >>> root = secured_session.user >>> root.name 'anonymousUser' >>> sorted(root.roles) ['ROLE_ADMIN', 'ROLE_ANONYMOUS', 'ROLE_USER']
Adding a new user:
>>> username, password = "Cooper", "abcdef123456" >>> secured_session.security.individual_roles[username] = { ... "ROLE_PILOT", ... "ROLE_USER", ... } >>> secured_session.security.basic_authentication.credentials[username] = ( ... password ... )
Connecting as this new user:
>>> cooper_session = tt.Session.connect( ... secured_session.url, ... authentication=tt.BasicAuthentication(username, password), ... ) >>> cooper = cooper_session.user >>> cooper.name 'Cooper' >>> sorted(cooper.roles) ['ROLE_PILOT', 'ROLE_USER']