Class: Ddr::Auth::AuthContext Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/ddr/auth/auth_context.rb

Overview

This class is abstract.

Direct Known Subclasses

DetachedAuthContext, WebAuthContext

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#envObject (readonly)

Returns the value of attribute env.



5
6
7
# File 'lib/ddr/auth/auth_context.rb', line 5

def env
  @env
end

#userObject (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

#abilityObject



12
13
14
15
16
17
18
19
20
# 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

#affiliationArray<String>

The affiliation values associated with the context.

Returns:

  • (Array<String>)


98
99
100
# File 'lib/ddr/auth/auth_context.rb', line 98

def affiliation
  []
end

#agentString

Return the user agent for this context.

Returns:

  • (String)

    or nil, if auth context is anonymous/



50
51
52
# File 'lib/ddr/auth/auth_context.rb', line 50

def agent
  anonymous? ? nil : user.agent
end

#agentsArray<String>

Return the combined user and group agents for this context.

Returns:

  • (Array<String>)


86
87
88
# File 'lib/ddr/auth/auth_context.rb', line 86

def agents
  groups.map(&:agent).push(agent).compact
end

#anonymous?Boolean

Return whether a user is absent from the auth context.

Returns:

  • (Boolean)


28
29
30
# File 'lib/ddr/auth/auth_context.rb', line 28

def anonymous?
  user.nil?
end

#authenticated?Boolean

Return whether a user is present in the auth context.

Returns:

  • (Boolean)


34
35
36
# File 'lib/ddr/auth/auth_context.rb', line 34

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.

Returns:

  • (Boolean)


80
81
82
# File 'lib/ddr/auth/auth_context.rb', line 80

def authorized_to_act_as_superuser?
  member_of? Ddr::Auth.superuser_group
end

#default_ability_classObject



22
23
24
# File 'lib/ddr/auth/auth_context.rb', line 22

def default_ability_class
  Ddr::Auth::default_ability.constantize
end

#duke_agent?Boolean

Is the authenticated agent a Duke identity?

Returns:

  • (Boolean)


56
57
58
# File 'lib/ddr/auth/auth_context.rb', line 56

def duke_agent?
  !!(agent =~ /@duke\.edu\z/)
end

#groupsArray<Group>

Return the list of groups for this context.

Returns:



62
63
64
# File 'lib/ddr/auth/auth_context.rb', line 62

def groups
  @groups ||= Groups.call(self)
end

#ip_addressString

The IP address associated with the context.

Returns:

  • (String)


92
93
94
# File 'lib/ddr/auth/auth_context.rb', line 92

def ip_address
  nil
end

#ismemberofArray<String>

The remote group values associated with the context.

Returns:

  • (Array<String>)


104
105
106
# File 'lib/ddr/auth/auth_context.rb', line 104

def ismemberof
  []
end

#member_of?(group) ⇒ Boolean

Is the user associated with the auth context a member of the group?

Parameters:

  • group (Group, String)

    group object or group id

Returns:

  • (Boolean)


69
70
71
72
73
74
75
# 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?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/ddr/auth/auth_context.rb', line 44

def 
  member_of? Ddr::Auth.
end

#superuser?Boolean

Return whether context is authenticated in superuser scope.

Returns:

  • (Boolean)


40
41
42
# File 'lib/ddr/auth/auth_context.rb', line 40

def superuser?
  env && env.key?("warden") && env["warden"].authenticate?(scope: :superuser)
end