Sha256: e116c9f969822a728b2001ac7179b0df6f612b8d866e61b5b1ae8721c4846162

Contents?: true

Size: 1.69 KB

Versions: 1

Compression:

Stored size: 1.69 KB

Contents

module Castronaut
  module Presenters

    class ServiceValidate
      MissingCredentialsMessage = "Please supply a username and password to login."

      attr_reader :controller, :your_mission, :extra_attributes
      attr_accessor :messages, :login_ticket

      delegate :params, :request, :to => :controller
      delegate :cookies, :env, :to => :request

      def initialize(controller)
        @controller = controller
        @messages = []
        @your_mission = nil
        @extra_attributes = Castronaut::ExtraAttributes.new
      end

      def service
        params['service']
      end

      def renewal
        params['renew']
      end

      def ticket
        params['ticket']
      end

      def proxy_granting_ticket_url
        params['pgtUrl']
      end

      def proxy_granting_ticket_iou
        @proxy_granting_ticket_result && @proxy_granting_ticket_result.iou
      end

      def username
        @service_ticket_result.username
      end

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

      def service_ticket_result
        @service_ticket_result
      end

      def represent!
        @service_ticket_result = Castronaut::Models::ServiceTicket.validate_ticket(service, ticket)

        if @service_ticket_result.valid?
          if proxy_granting_ticket_url
            @proxy_granting_ticket_result = Castronaut::Models::ProxyGrantingTicket.generate_ticket(proxy_granting_ticket_url, client_host, @service_ticket_result.ticket)
          end
        end

        @your_mission = lambda { controller.erb :service_validate, :layout => false, :locals => { :presenter => self } }

        self
      end

    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
nbudin-castronaut-0.7.5 lib/castronaut/presenters/service_validate.rb