Class: Shamu::Security::Principal
- Inherits:
-
Object
- Object
- Shamu::Security::Principal
- Defined in:
- lib/shamu/security/principal.rb
Overview
...
Direct Known Subclasses
Attributes collapse
-
#elevated ⇒ Boolean
(also: #elevated?)
True if the user has elevated this session by providing their credentials.
-
#parent_principal ⇒ Principal
The parent principal when a user or service is impersonating another user.
-
#remote_ip ⇒ String
The IP address of the remote user.
-
#user_id ⇒ Object
Id of the currently authenticated user.
Instance Method Summary collapse
-
#impersonate(user_id) ⇒ Principal
Create a new impersonation Principal, cloning relevant principal to the new instance.
-
#impersonated? ⇒ Boolean
True if the [#user_id] is being impersonated.
-
#initialize(user_id: nil, parent_principal: nil, remote_ip: nil, elevated: false) ⇒ Principal
constructor
A new instance of Principal.
-
#service_delegate? ⇒ Boolean
True if the principal was offered by one service to another and requesting that the downstream service delegate security checks to the calling service.
-
#user_id_chain ⇒ Array<Object>
All of the user ids in the security principal chain, starting from the root.
Constructor Details
#initialize(user_id: nil, parent_principal: nil, remote_ip: nil, elevated: false) ⇒ Principal
Returns a new instance of Principal.
34 35 36 37 38 39 |
# File 'lib/shamu/security/principal.rb', line 34 def initialize( user_id: nil, parent_principal: nil, remote_ip: nil, elevated: false ) @user_id = user_id @parent_principal = parent_principal @remote_ip = remote_ip @elevated = elevated end |
Instance Attribute Details
#elevated ⇒ Boolean Also known as: elevated?
Returns true if the user has elevated this session by providing their credentials.
28 29 30 |
# File 'lib/shamu/security/principal.rb', line 28 def elevated @elevated end |
#parent_principal ⇒ Principal
Returns the parent principal when a user or service is impersonating another user.
19 20 21 |
# File 'lib/shamu/security/principal.rb', line 19 def parent_principal @parent_principal end |
#remote_ip ⇒ String
Returns the IP address of the remote user.
23 24 25 |
# File 'lib/shamu/security/principal.rb', line 23 def remote_ip @remote_ip end |
#user_id ⇒ Object
Returns id of the currently authenticated user. May be cached, for example bu via persistent cookie. See #elevated.
14 15 16 |
# File 'lib/shamu/security/principal.rb', line 14 def user_id @user_id end |
Instance Method Details
#impersonate(user_id) ⇒ Principal
Create a new impersonation Shamu::Security::Principal, cloning relevant principal to the new instance.
66 67 68 |
# File 'lib/shamu/security/principal.rb', line 66 def impersonate( user_id ) self.class.new( user_id: user_id, parent_principal: self, remote_ip: remote_ip, elevated: elevated ) end |
#impersonated? ⇒ Boolean
Returns true if the [#user_id] is being impersonated.
57 58 59 |
# File 'lib/shamu/security/principal.rb', line 57 def impersonated? !!parent_principal end |
#service_delegate? ⇒ Boolean
Returns true if the principal was offered by one service to another and requesting that the downstream service delegate security checks to the calling service.
73 74 |
# File 'lib/shamu/security/principal.rb', line 73 def service_delegate? end |
#user_id_chain ⇒ Array<Object>
Returns all of the user ids in the security principal chain, starting from the root.
43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/shamu/security/principal.rb', line 43 def user_id_chain @user_ids ||= begin user_ids = [] principal = self while principal user_ids << principal.user_id principal = principal.parent_principal end user_ids.reverse end end |