Sha256: f77cb1ab24bde2b596689501807c1f24a8b19df21d1e73afab0e65eca2063e05

Contents?: true

Size: 1.83 KB

Versions: 1

Compression:

Stored size: 1.83 KB

Contents

module Castronaut
  module Presenters

    class Login < Base
      def gateway?
        return true if params['gateway'] == 'true'
        return true if params['gateway'] == '1'
        false
      end

      def ticket_generating_ticket_cookie
        cookies['tgt']
      end

      def redirection_loop?
        params.has_key?('redirection_loop_intercepted')
      end
      
      def login_ticket
        Castronaut::Models::LoginTicket.generate_from(client_host).ticket
      end

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

        if @ticket_granting_ticket.valid?
          messages << "You are currently logged in as #{@ticket_granting_ticket.identifier}.  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.valid?
              service_ticket = Castronaut::Models::ServiceTicket.generate_ticket_for(service, client_host, @ticket_granting_ticket.ticket)
            
              if service_ticket.service_uri
                @your_mission = { :redirect => service_ticket.service_uri, :status => 303 }
              else
                messages << "The target service your browser supplied appears to be invalid. Please contact your system administrator for help."
              end            
            end
          elsif gateway?
            messages << "The server cannot fulfill this gateway request because no service parameter was given."
          end
          
        end
        
        @your_mission = { :template => :login }
                
        self
      end
    
    end

  end
  
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
3mix-castronaut-0.5.0.2 lib/castronaut/presenters/login.rb