class Ddr::Auth::AuthContext

@abstract

Attributes

env[R]
user[R]

Public Class Methods

new(user = nil, env = nil) click to toggle source
# File lib/ddr/auth/auth_context.rb, line 7
def initialize(user = nil, env = nil)
  @user = user
  @env = env
end

Public Instance Methods

affiliation() click to toggle source

The affiliation values associated with the context. @return [Array<String>]

# File lib/ddr/auth/auth_context.rb, line 80
def affiliation
  []
end
agent() click to toggle source

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
agents() click to toggle source

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
anonymous?() click to toggle source

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
authenticated?() click to toggle source

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
authorized_to_act_as_superuser?() click to toggle source

Is the auth context authorized to act as superuser?

This is separate from whether the context is authenticated in superuser scope.

@return [Boolean]

# File lib/ddr/auth/auth_context.rb, line 62
def authorized_to_act_as_superuser?
  member_of? Ddr::Auth.superuser_group
end
duke_agent?() click to toggle source

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
groups() click to toggle source

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
ip_address() click to toggle source

The IP address associated with the context. @return [String]

# File lib/ddr/auth/auth_context.rb, line 74
def ip_address
  nil
end
ismemberof() click to toggle source

The remote group values associated with the context. @return [Array<String>]

# File lib/ddr/auth/auth_context.rb, line 86
def ismemberof
  []
end
member_of?(group) click to toggle source

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
superuser?() click to toggle source

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