Пример #1
0
        /// <summary>
        /// Attempts to validate a ticket for the provided service.
        /// </summary>
        /// <param name="ticket">the ticket to validate</param>
        /// <returns>
        /// The ICasPrincipal backed by the CAS Assertion included in the response
        /// from the CAS server for a successful ticket validation.
        /// </returns>
        /// <exception cref="TicketValidationException">
        /// Thrown if ticket validation fails.
        /// </exception>
        public ICasPrincipal Validate(string ticket)
        {
            string validationUrl = UrlUtil.ConstructValidateUrl(ticket, CasAuthentication.Gateway, CasAuthentication.Renew, CustomParameters);

            protoLogger.Debug("Constructed validation URL " + validationUrl);

            string serverResponse;

            try
            {
                serverResponse = RetrieveResponseFromServer(validationUrl, ticket);
            }
            catch (Exception e)
            {
                protoLogger.Info("Ticket validation failed: " + e);
                throw new TicketValidationException("CAS server ticket validation threw an Exception", e);
            }

            if (serverResponse == null)
            {
                protoLogger.Warn("CAS server returned no response");
                throw new TicketValidationException("The CAS server returned no response.");
            }

            protoLogger.Debug("Ticket validation response:{0}{1}", Environment.NewLine, serverResponse);

            return(ParseResponseFromServer(serverResponse, ticket));
        }