Class: Tep::Identity

Inherits:
Object
  • Object
show all
Defined in:
lib/tep/identity.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(principal_id, acting_via, capabilities) ⇒ Identity

Returns a new instance of Identity.



25
26
27
28
29
# File 'lib/tep/identity.rb', line 25

def initialize(principal_id, acting_via, capabilities)
  @principal_id = principal_id
  @acting_via   = acting_via
  @capabilities = capabilities
end

Instance Attribute Details

#acting_viaObject (readonly)

Tep::AgentDelegation or nil



22
23
24
# File 'lib/tep/identity.rb', line 22

def acting_via
  @acting_via
end

#capabilitiesObject (readonly)

Array of symbols



23
24
25
# File 'lib/tep/identity.rb', line 23

def capabilities
  @capabilities
end

#principal_idObject (readonly)

String, opaque to tep (apps own the format)



21
22
23
# File 'lib/tep/identity.rb', line 21

def principal_id
  @principal_id
end

Class Method Details

.anonymousObject

The unauthenticated identity. Used by the Tep::Auth before- filter when no provider sniffed a credential off the request. Apps that gate routes on identity check the principal_id == “” shape; #may? returns false for everything since the cap array is empty.



36
37
38
39
40
# File 'lib/tep/identity.rb', line 36

def self.anonymous
  seed = [:_seed]
  seed.delete_at(0)
  Identity.new("", nil, seed)
end

Instance Method Details

#agent?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/tep/identity.rb', line 46

def agent?
  @acting_via != nil
end

#human?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/tep/identity.rb', line 42

def human?
  @acting_via == nil
end

#may?(cap) ⇒ Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/tep/identity.rb', line 50

def may?(cap)
  @capabilities.include?(cap)
end

#subjectObject

Audit-friendly string. Humans render as “user:<principal>”; agents render as “agent:<agent_id>/<principal>” – the slash makes the principal-of-record visible at a glance and is the standard shape every log line and Broadcast ‘from` field should carry.



59
60
61
62
63
64
65
# File 'lib/tep/identity.rb', line 59

def subject
  if @acting_via == nil
    "user:" + @principal_id
  else
    "agent:" + @acting_via.agent_id + "/" + @principal_id
  end
end