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
The affiliation values associated with the context. @return [Array<String>]
# File lib/ddr/auth/auth_context.rb, line 80 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 32 def agent user.agent if authenticated? end
Return the combined user and group agents for this context. @return [Array<String>]
# File lib/ddr/auth/auth_context.rb, line 68 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 14 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 20 def authenticated? !anonymous? end
Is the authenticated agent a Duke identity? @return [Boolean]
# File lib/ddr/auth/auth_context.rb, line 38 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 44 def groups @groups ||= Groups.call(self) end
The IP address associated with the context. @return [String]
# File lib/ddr/auth/auth_context.rb, line 74 def ip_address nil end
The remote group values associated with the context. @return [Array<String>]
# File lib/ddr/auth/auth_context.rb, line 86 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 51 def member_of?(group) if group.is_a? Group groups.include? group else member_of? Group.new(group) end end
Return whether context is authenticated in superuser scope. @return [Boolean]
# File lib/ddr/auth/auth_context.rb, line 26 def superuser? env && env.key?("warden") && env["warden"].authenticate?(scope: :superuser) end