Class: Castronaut::Presenters::Login

Inherits:
Object
  • Object
show all
Defined in:
lib/castronaut/presenters/login.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(controller) ⇒ Login

Returns a new instance of Login.



11
12
13
14
15
# File 'lib/castronaut/presenters/login.rb', line 11

def initialize(controller)
  @controller = controller
  @messages = []
  @your_mission = nil
end

Instance Attribute Details

#controllerObject (readonly)

Returns the value of attribute controller.



5
6
7
# File 'lib/castronaut/presenters/login.rb', line 5

def controller
  @controller
end

#messagesObject

Returns the value of attribute messages.



6
7
8
# File 'lib/castronaut/presenters/login.rb', line 6

def messages
  @messages
end

#your_missionObject (readonly)

Returns the value of attribute your_mission.



5
6
7
# File 'lib/castronaut/presenters/login.rb', line 5

def your_mission
  @your_mission
end

Instance Method Details

#client_hostObject



39
40
41
# File 'lib/castronaut/presenters/login.rb', line 39

def client_host
  env['HTTP_X_FORWARDED_FOR'] || env['REMOTE_HOST'] || env['REMOTE_ADDR']
end

#gateway?Boolean

Returns:

  • (Boolean)


25
26
27
28
29
# File 'lib/castronaut/presenters/login.rb', line 25

def gateway?
  return true if params['gateway'] == 'true'
  return true if params['gateway'] == '1'
  false
end

#login_ticketObject



43
44
45
# File 'lib/castronaut/presenters/login.rb', line 43

def 
  Castronaut::Models::LoginTicket.generate_from(client_host).ticket
end

#redirection_loop?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/castronaut/presenters/login.rb', line 35

def redirection_loop?
  params.has_key?('redirection_loop_intercepted')
end

#renewalObject



21
22
23
# File 'lib/castronaut/presenters/login.rb', line 21

def renewal
  params['renew']
end

#represent!Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/castronaut/presenters/login.rb', line 47

def represent!
  ticket_granting_ticket_result = Castronaut::Models::TicketGrantingTicket.validate_cookie(ticket_generating_ticket_cookie)

  if ticket_granting_ticket_result.valid?
    messages << "You are currently logged in as #{ticket_granting_ticket_result.username}.  If this is not you, please log in below."
  end

  if redirection_loop?
    messages << "The client and server are unable to negotiate authentication.  Please try logging in again later."
  else

    if service
      if !renewal && ticket_granting_ticket_result.valid?
        service_ticket = Castronaut::Models::ServiceTicket.generate_ticket_for(service, client_host, ticket_granting_ticket_result.ticket)
      
        if service_ticket.service_uri
          return controller.redirect(service_ticket.service_uri, 303)
        else
          messages << "The target service your browser supplied appears to be invalid. Please contact your system administrator for help."
        end            
      elsif gateway?            
        return controller.redirect(service, 303)
      end
    elsif gateway?
      messages << "The server cannot fulfill this gateway request because no service parameter was given."
    end
    
  end
  
  @your_mission = lambda { controller.erb :login, :locals => { :presenter => self } }
          
  self
end

#serviceObject



17
18
19
# File 'lib/castronaut/presenters/login.rb', line 17

def service
  params['service']
end


31
32
33
# File 'lib/castronaut/presenters/login.rb', line 31

def ticket_generating_ticket_cookie
  cookies['tgt']
end