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

#affiliationArray<String>

The affiliation values associated with the context.

Returns:

  • (Array<String>)


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

def affiliation
  []
end

#agentString

Return the user agent for this context.

Returns:

  • (String)

    or nil, if auth context is anonymous/



32
33
34
# File 'lib/ddr/auth/auth_context.rb', line 32

def agent
  user.agent if authenticated?
end

#agentsArray<String>

Return the combined user and group agents for this context.

Returns:

  • (Array<String>)


68
69
70
# File 'lib/ddr/auth/auth_context.rb', line 68

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

#anonymous?Boolean

Return whether a user is absent from the auth context.

Returns:

  • (Boolean)


14
15
16
# File 'lib/ddr/auth/auth_context.rb', line 14

def anonymous?
  user.nil?
end

#authenticated?Boolean

Return whether a user is present in the auth context.

Returns:

  • (Boolean)


20
21
22
# File 'lib/ddr/auth/auth_context.rb', line 20

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)


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

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

#duke_agent?Boolean

Is the authenticated agent a Duke identity?

Returns:

  • (Boolean)


38
39
40
# File 'lib/ddr/auth/auth_context.rb', line 38

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

#groupsArray<Group>

Return the list of groups for this context.

Returns:



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

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

#ip_addressString

The IP address associated with the context.

Returns:

  • (String)


74
75
76
# File 'lib/ddr/auth/auth_context.rb', line 74

def ip_address
  nil
end

#ismemberofArray<String>

The remote group values associated with the context.

Returns:

  • (Array<String>)


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

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)


51
52
53
54
55
56
57
# 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?Boolean

Return whether context is authenticated in superuser scope.

Returns:

  • (Boolean)


26
27
28
# File 'lib/ddr/auth/auth_context.rb', line 26

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