Class: Ddr::Auth::AuthContext Abstract
- Inherits:
-
Object
- Object
- Ddr::Auth::AuthContext
- Defined in:
- lib/ddr/auth/auth_context.rb
Overview
Direct Known Subclasses
Instance Attribute Summary collapse
-
#env ⇒ Object
readonly
Returns the value of attribute env.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Instance Method Summary collapse
-
#affiliation ⇒ Array<String>
The affiliation values associated with the context.
-
#agent ⇒ String
Return the user agent for this context.
-
#agents ⇒ Array<String>
Return the combined user and group agents for this context.
-
#anonymous? ⇒ Boolean
Return whether a user is absent from the auth context.
-
#authenticated? ⇒ Boolean
Return whether a user is present in the auth context.
-
#authorized_to_act_as_superuser? ⇒ Boolean
Is the auth context authorized to act as superuser? This is separate from whether the context is authenticated in superuser scope.
-
#duke_agent? ⇒ Boolean
Is the authenticated agent a Duke identity?.
-
#groups ⇒ Array<Group>
Return the list of groups for this context.
-
#initialize(user = nil, env = nil) ⇒ AuthContext
constructor
A new instance of AuthContext.
-
#ip_address ⇒ String
The IP address associated with the context.
-
#ismemberof ⇒ Array<String>
The remote group values associated with the context.
-
#member_of?(group) ⇒ Boolean
Is the user associated with the auth context a member of the group?.
-
#superuser? ⇒ Boolean
Return whether context is authenticated in superuser scope.
Constructor Details
#initialize(user = nil, env = nil) ⇒ AuthContext
Returns a new instance of AuthContext.
7 8 9 10 |
# File 'lib/ddr/auth/auth_context.rb', line 7 def initialize(user = nil, env = nil) @user = user @env = env end |
Instance Attribute Details
#env ⇒ Object (readonly)
Returns the value of attribute env.
5 6 7 |
# File 'lib/ddr/auth/auth_context.rb', line 5 def env @env end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
5 6 7 |
# File 'lib/ddr/auth/auth_context.rb', line 5 def user @user end |
Instance Method Details
#affiliation ⇒ Array<String>
The affiliation values associated with the context.
80 81 82 |
# File 'lib/ddr/auth/auth_context.rb', line 80 def affiliation [] end |
#agent ⇒ String
Return the user agent for this context.
32 33 34 |
# File 'lib/ddr/auth/auth_context.rb', line 32 def agent user.agent if authenticated? end |
#agents ⇒ Array<String>
Return the combined user and group agents for this context.
68 69 70 |
# File 'lib/ddr/auth/auth_context.rb', line 68 def agents groups.map(&:agent).push(agent).compact end |
#anonymous? ⇒ Boolean
Return whether a user is absent from the auth context.
14 15 16 |
# File 'lib/ddr/auth/auth_context.rb', line 14 def anonymous? user.nil? end |
#authenticated? ⇒ Boolean
Return whether a user is present in the auth context.
20 21 22 |
# File 'lib/ddr/auth/auth_context.rb', line 20 def authenticated? !anonymous? end |
#authorized_to_act_as_superuser? ⇒ Boolean
Is the auth context authorized to act as superuser?
This is separate from whether the context is authenticated in superuser scope.
62 63 64 |
# File 'lib/ddr/auth/auth_context.rb', line 62 def member_of? Ddr::Auth.superuser_group end |
#duke_agent? ⇒ Boolean
Is the authenticated agent a Duke identity?
38 39 40 |
# File 'lib/ddr/auth/auth_context.rb', line 38 def duke_agent? !!(agent =~ /@duke\.edu\z/) end |
#groups ⇒ Array<Group>
Return the list of groups for this context.
44 45 46 |
# File 'lib/ddr/auth/auth_context.rb', line 44 def groups @groups ||= Groups.call(self) end |
#ip_address ⇒ String
The IP address associated with the context.
74 75 76 |
# File 'lib/ddr/auth/auth_context.rb', line 74 def ip_address nil end |
#ismemberof ⇒ Array<String>
The remote group values associated with the context.
86 87 88 |
# File 'lib/ddr/auth/auth_context.rb', line 86 def ismemberof [] end |
#member_of?(group) ⇒ Boolean
Is the user associated with the auth context a member of the group?
51 52 53 54 55 56 57 |
# File 'lib/ddr/auth/auth_context.rb', line 51 def member_of?(group) if group.is_a? Group groups.include? group else member_of? Group.new(group) end end |
#superuser? ⇒ Boolean
Return whether context is authenticated in superuser scope.
26 27 28 |
# File 'lib/ddr/auth/auth_context.rb', line 26 def superuser? env && env.key?("warden") && env["warden"].authenticate?(scope: :superuser) end |