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

ability() click to toggle source
# 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
affiliation() click to toggle source

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

# File lib/ddr/auth/auth_context.rb, line 98
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 50
def agent
  anonymous? ? nil : user.agent
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 86
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 28
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 34
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 80
def authorized_to_act_as_superuser?
  member_of? Ddr::Auth.superuser_group
end
default_ability_class() click to toggle source
# File lib/ddr/auth/auth_context.rb, line 22
def default_ability_class
  Ddr::Auth::default_ability.constantize
end
duke_agent?() click to toggle source

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

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

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

# File lib/ddr/auth/auth_context.rb, line 92
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 104
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 69
def member_of?(group)
  if group.is_a? Group
    groups.include? group
  else
    member_of? Group.new(group)
  end
end
metadata_manager?() click to toggle source
# File lib/ddr/auth/auth_context.rb, line 44
def metadata_manager?
  member_of? Ddr::Auth.metadata_managers_group
end
superuser?() click to toggle source

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