Class: Castanet::ProxyTicket

Inherits:
ServiceTicket show all
Defined in:
lib/castanet/proxy_ticket.rb

Instance Attribute Summary collapse

Attributes inherited from ServiceTicket

#https_required, #pgt, #proxy_callback_url, #proxy_retrieval_url, #response, #service, #service_validate_url

Instance Method Summary collapse

Methods inherited from ServiceTicket

#present!, #retrieve_pgt!

Methods included from QueryBuilding

#query

Methods included from Responses

#parsed_proxy_response, #parsed_ticket_validate_response

Constructor Details

#initialize(pt, pgt, service) ⇒ ProxyTicket

Initializes an instance of ProxyTicket.

Instantiation guide

  1. If requesting a proxy ticket, set pt to nil, service to the service URL, and pgt to the proxy granting ticket.
  2. If checking a proxy ticket, set pt to the proxy ticket, service to the service URL, and pgt to nil.

Parameters:

  • pt (String, nil)

    the proxy ticket

  • pgt (String, nil)

    the proxy granting ticket

  • service (String)

    the service URL



45
46
47
48
49
# File 'lib/castanet/proxy_ticket.rb', line 45

def initialize(pt, pgt, service)
  super(pt, service)

  self.pgt = pgt
end

Instance Attribute Details

#proxy_response#ticket

The /proxy response from the CAS server.

This is set by #reify!, but can be set manually for testing purposes.

Returns:



25
26
27
# File 'lib/castanet/proxy_ticket.rb', line 25

def proxy_response
  @proxy_response
end

#proxy_urlString

The URL of the CAS server's proxy ticket granting service.

Returns:

  • (String)


11
12
13
# File 'lib/castanet/proxy_ticket.rb', line 11

def proxy_url
  @proxy_url
end

#proxy_validate_urlString

The URL of the CAS server's proxy ticket validation service.

Returns:

  • (String)


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

def proxy_validate_url
  @proxy_validate_url
end

Instance Method Details

#reify!Object

Requests a proxy ticket from #proxy_url and stores it in #ticket.

If a proxy ticket cannot be issued for any reason, this method raises a Castanet::ProxyTicketError containing the failure code and reason returned by the CAS server.

This method should only be run once per ProxyTicket instance. It can be run multiple times, but each invocation will overwrite #ticket with a new ticket.

This method is automatically called by Client#issue_proxy_ticket, and as such should never need to be called by users of Castanet; however, in the interest of program organization, the method is public and located here. Also, if you're managing ProxyTicket instances manually for some reason, you may find this method useful.

Returns:

  • void

Raises:



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/castanet/proxy_ticket.rb', line 95

def reify!
  raise ProxyTicketError, 'A PGT is not present.' unless pgt

  uri = URI.parse(proxy_url).tap do |u|
    u.query = grant_parameters
  end

  net_http(uri).start do |h|
    cas_response = h.get(uri.to_s)

    self.proxy_response = parsed_proxy_response(cas_response.body)

    unless issued?
      raise ProxyTicketError, "A proxy ticket could not be issued.  Code: <#{failure_code}>, reason: <#{failure_reason}>."
    end
  end
end

#ticketString?

The proxy ticket wrapped by this object. This can come either from a proxy ticket issuance via #reify! or be set at instantiation. Tickets issued via #reify! have higher precedence.

If a proxy ticket was neither supplied at instantiation nor requested via #reify!, then ticket will return nil.

Returns:

  • (String, nil)

    the proxy ticket



60
61
62
# File 'lib/castanet/proxy_ticket.rb', line 60

def ticket
  proxy_response ? proxy_response.ticket : super
end

#to_sString

Returns the string representation of #ticket.

If #ticket is not nil, then the return value of this method is #ticket; otherwise, it is "".

Returns:

  • (String)

    the ticket or empty string



71
72
73
# File 'lib/castanet/proxy_ticket.rb', line 71

def to_s
 ticket.to_s
end