class Ddr::Auth::AuthContext
@abstract
Attributes
Public Class Methods
# File lib/ddr/auth/auth_context.rb, line 7 def initialize(user = nil, env = nil) @user = user @env = env end
Public Instance Methods
# File lib/ddr/auth/auth_context.rb, line 12 def ability if anonymous? AnonymousAbility.new(self) elsif superuser? SuperuserAbility.new(self) else default_ability_class.new(self) end end
The affiliation values associated with the context. @return [Array<String>]
# File lib/ddr/auth/auth_context.rb, line 98 def affiliation [] end
Return the user agent for this context. @return [String] or nil, if auth context is anonymous/
# File lib/ddr/auth/auth_context.rb, line 50 def agent anonymous? ? nil : user.agent end
Return the combined user and group agents for this context. @return [Array<String>]
# File lib/ddr/auth/auth_context.rb, line 86 def agents groups.map(&:agent).push(agent).compact end
Return whether a user is absent from the auth context. @return [Boolean]
# File lib/ddr/auth/auth_context.rb, line 28 def anonymous? user.nil? end
Return whether a user is present in the auth context. @return [Boolean]
# File lib/ddr/auth/auth_context.rb, line 34 def authenticated? !anonymous? end
# File lib/ddr/auth/auth_context.rb, line 22 def default_ability_class Ddr::Auth::default_ability.constantize end
Is the authenticated agent a Duke identity? @return [Boolean]
# File lib/ddr/auth/auth_context.rb, line 56 def duke_agent? !!(agent =~ /@duke\.edu\z/) end
Return the list of groups for this context. @return [Array<Group>]
# File lib/ddr/auth/auth_context.rb, line 62 def groups @groups ||= Groups.call(self) end
The IP address associated with the context. @return [String]
# File lib/ddr/auth/auth_context.rb, line 92 def ip_address nil end
The remote group values associated with the context. @return [Array<String>]
# File lib/ddr/auth/auth_context.rb, line 104 def ismemberof [] end
Is the user associated with the auth context a member of the group? @param group [Group, String] group object or group id @return [Boolean]
# File lib/ddr/auth/auth_context.rb, line 69 def member_of?(group) if group.is_a? Group groups.include? group else member_of? Group.new(group) end end
# File lib/ddr/auth/auth_context.rb, line 44 def metadata_manager? member_of? Ddr::Auth.metadata_managers_group end
Return whether context is authenticated in superuser scope. @return [Boolean]
# File lib/ddr/auth/auth_context.rb, line 40 def superuser? env && env.key?("warden") && env["warden"].authenticate?(scope: :superuser) end