Exemplo n.º 1
0
        /// <summary>
        /// Retorna um XmlElement contendo informações do Identity
        /// </summary>
        /// <returns></returns>
        protected virtual XmlElement GetElementIdentity(bool full)
        {
            // Cria elemento Identity
            XmlElement xmlElementIdentity = xml.CreateElement("Identity");

            try
            {
                xmlElementIdentity.SetAttribute("type", HttpContext.Current.User.Identity.AuthenticationType);
                xmlElementIdentity.SetAttribute("authenticated", HttpContext.Current.User.Identity.IsAuthenticated.ToString());

                if (full)
                {
                    // Cria elemento FormsIdentity
                    string     statusFormsIdentity     = string.Empty;
                    XmlElement xmlElementFormsIdentity = xml.CreateElement("FormsIdentity");
                    xmlElementIdentity.AppendChild(xmlElementFormsIdentity);

                    var formsIdentity = HttpContext.Current.User.Identity as FormsIdentity;
                    if (formsIdentity != null)
                    {
                        try
                        {
                            xmlElementFormsIdentity.SetAttribute("name", UtilBO.GetNameFormsAuthentication(formsIdentity.Name, UtilBO.TypeName.Login));
                            statusFormsIdentity = Success;
                        }
                        catch
                        {
                            statusFormsIdentity = "Propriedade name inválida.";
                        }

                        // Cria elemento Ticket
                        string     statusTicket     = string.Empty;
                        XmlElement xmlElementTicket = xml.CreateElement("Ticket");
                        xmlElementFormsIdentity.AppendChild(xmlElementTicket);
                        try
                        {
                            xmlElementTicket.SetAttribute("version", formsIdentity.Ticket.Version.ToString());
                            xmlElementTicket.SetAttribute("userData", formsIdentity.Ticket.UserData.ToString());
                            xmlElementTicket.SetAttribute("issueDate", formsIdentity.Ticket.IssueDate.ToString());
                            xmlElementTicket.SetAttribute("expiration", formsIdentity.Ticket.Expiration.ToString());
                            xmlElementTicket.SetAttribute("expired", formsIdentity.Ticket.Expired.ToString());
                            statusTicket = Success;
                        }
                        catch
                        {
                            statusTicket = "Ticket de autenticação inválido.";
                        }
                        xmlElementTicket.SetAttribute("status", statusTicket);
                    }
                    else
                    {
                        statusFormsIdentity = "Não foi possível recuperar informações do FormsIdentity.";
                    }
                    xmlElementFormsIdentity.SetAttribute("status", statusFormsIdentity);
                }
            }
            catch (Exception ex)
            {
                xmlElementIdentity.SetAttribute("error", ex.Message);
            }

            return(xmlElementIdentity);
        }