Class: TicketGrantingTicket

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user, ticket = nil) ⇒ TicketGrantingTicket

Returns a new instance of TicketGrantingTicket.



19
20
21
22
# File 'lib/ticket_granting_ticket.rb', line 19

def initialize(user, ticket = nil)
  @username = user
  @ticket = ticket
end

Instance Attribute Details

#usernameObject (readonly)

Returns the value of attribute username.



17
18
19
# File 'lib/ticket_granting_ticket.rb', line 17

def username
  @username
end

Class Method Details

.create!(user, store) ⇒ Object



9
10
11
12
13
# File 'lib/ticket_granting_ticket.rb', line 9

def create!(user, store)
  tgt = self.new(user)
  tgt.save!(store)
  tgt
end

.validate(ticket, store) ⇒ Object



3
4
5
6
7
# File 'lib/ticket_granting_ticket.rb', line 3

def validate(ticket, store)
  if ticket && username = store[ticket]
    new(username, ticket)
  end
end

Instance Method Details

#destroy!(store) ⇒ Object



28
29
30
# File 'lib/ticket_granting_ticket.rb', line 28

def destroy!(store)
  store.del self.ticket
end

#save!(store) ⇒ Object



32
33
34
# File 'lib/ticket_granting_ticket.rb', line 32

def save!(store)
  store[ticket] = username
end

#ticketObject



24
25
26
# File 'lib/ticket_granting_ticket.rb', line 24

def ticket
  @ticket ||= "TGC-#{rand(100000000000000000)}".to_s
end


36
37
38
39
40
41
42
# File 'lib/ticket_granting_ticket.rb', line 36

def to_cookie(domain, path = "/")
  ["tgt", {
    :value => ticket,
    # :domain => domain,
    :path => path
  }]
end