static public CASTicketResult GetToken(DbBase database, Uri service, String grantTicket, String username) { CASTicketResult ret = null; if (service != null) { DataTable dtTickets = database.ExecuteDataTable(String.Format("select * from [CAS_Ticket] where [Service_Uri] = '{0}' and (Grant_Ticket = '{1}' or User_Name = '{2}')", CASPluginService.Normalize(service).AbsoluteUri, grantTicket, username)); if ((dtTickets != null) && (dtTickets.Rows.Count > 0)) { ret = new CASTicketResult(); ret.Success = true; ret.Service = CASPluginService.Normalize(dtTickets.Rows[0]["Service_Uri"].ToString()); ret.UserId = dtTickets.Rows[0]["User_Id"].ToString(); ret.UserName = dtTickets.Rows[0]["User_Name"].ToString(); ret.GrantTicket = dtTickets.Rows[0]["Grant_Ticket"].ToString(); ret.LongTicket = dtTickets.Rows[0]["Long_Ticket"].ToString(); ret.ProxyTicket = dtTickets.Rows[0]["Proxy_Ticket"].ToString(); ret.CreateDate = (DateTime)dtTickets.Rows[0]["Create_Date"]; ret.Expires = (DateTime)dtTickets.Rows[0]["Expires"]; ret.CreateByCredentials = (Boolean)dtTickets.Rows[0]["Create_By_Credentials"]; } } if (ret == null) { ret = new CASTicketResult(); } if (ret.Success) { if (service == null) { ret.Success = false; return(ret); } //Verifica se o ticket pode ser validado no serviço atual if ((ret.Service == null) || (!ret.Service.Equals(service))) { if (database.ExecuteScalar <Int64>(String.Format("select COUNT(*) from [CAS_Service] where Uri = '{0}' and Context_Name = (select Context_Name from [CAS_Service] where Uri = '{1}')", CASPluginService.Normalize(service).AbsoluteUri, ret.Service.AbsoluteUri)) > 0) { ret.CreateByCredentials = false; //Define que as informações foram copiadas de outro token e não a partir de uma autenticação usuário/senha } else { ret.Success = false; } } //Define o serviço atual ret.Service = service; //Salva o token copiado //ret.SaveToFile(basePath); ret.SaveToDb(database); } return(ret); }
public Object Clone() { CASTicketResult newItem = new CASTicketResult(); newItem.Success = this.Success; newItem.Service = CASPluginService.Normalize(this.Service); newItem.UserId = this.UserId; newItem.UserName = this.UserName; newItem.GrantTicket = this.GrantTicket; newItem.LongTicket = this.LongTicket; newItem.ProxyTicket = this.ProxyTicket; newItem.CreateDate = this.CreateDate; newItem.Expires = this.Expires; newItem.CreateByCredentials = this.CreateByCredentials; newItem.ChangePasswordNextLogon = this.ChangePasswordNextLogon; newItem.ErrorText = this.ErrorText; newItem.Attributes = this.Attributes; return(newItem); }
public void SaveToDb(DbBase database) { //Exclui ticket com o mesmo serviço e grant ticket database.ExecuteNonQuery(String.Format("delete from [CAS_Ticket] where [Service_Uri] = '{0}' and Grant_Ticket = '{1}'", CASPluginService.Normalize(this.Service).AbsoluteUri, this.GrantTicket)); if (!this.Success) { return; } //Adiciona o ticket database.ExecuteNonQuery(String.Format("insert into [CAS_Ticket] ([Service_Uri],[User_Id],[User_Name],[Grant_Ticket],[Long_Ticket],[Proxy_Ticket],[Create_Date],[Expires],[Create_By_Credentials]) VALUES ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}',{8})", CASPluginService.Normalize(this.Service).AbsoluteUri, this.UserId, this.UserName, this.GrantTicket, this.LongTicket, this.ProxyTicket, this.CreateDate.ToString("yyyy-MM-dd HH:mm:ss"), this.Expires.ToString("yyyy-MM-dd HH:mm:ss"), (this.CreateByCredentials ? 1 : 0))); }
public void Destroy(DbBase database) { if ((this.Service == null) || (this.GrantTicket == null)) { return; } database.ExecuteNonQuery(String.Format("delete from [CAS_Ticket] where [Service_Uri] = '{0}' and Grant_Ticket = '{1}'", CASPluginService.Normalize(this.Service).AbsoluteUri, this.GrantTicket)); }
public void LoadFromXMLText(String xml) { XmlDocument doc = new XmlDocument(); doc.LoadXml(xml); XmlNamespaceManager namespaceManager = new XmlNamespaceManager(doc.NameTable); namespaceManager.AddNamespace("cas", "http://www.safetrend.com.br/tp/cas"); XmlNode tNode = doc.SelectSingleNode("/cas:serviceConfig/cas:service", namespaceManager); if ((tNode == null) || (String.IsNullOrEmpty(tNode.ChildNodes[0].Value))) { return; } this.Service = CASPluginService.Normalize(tNode.ChildNodes[0].Value); try { tNode = doc.SelectSingleNode("/cas:serviceConfig/cas:context", namespaceManager); if ((tNode != null) && (!String.IsNullOrEmpty(tNode.ChildNodes[0].Value))) { this.Context = tNode.ChildNodes[0].Value; } } catch { } try { tNode = doc.SelectSingleNode("/cas:serviceConfig/cas:pluginAssembly", namespaceManager); if ((tNode != null) && (!String.IsNullOrEmpty(tNode.ChildNodes[0].Value))) { this.PluginAssembly = tNode.ChildNodes[0].Value; } } catch { } try { tNode = doc.SelectSingleNode("/cas:serviceConfig/cas:permitPasswordRecover", namespaceManager); if ((tNode != null) && (!String.IsNullOrEmpty(tNode.ChildNodes[0].Value))) { this.PermitPasswordRecover = Boolean.Parse(tNode.ChildNodes[0].Value); } } catch { } try { tNode = doc.SelectSingleNode("/cas:serviceConfig/cas:externalPasswordRecover", namespaceManager); if ((tNode != null) && (!String.IsNullOrEmpty(tNode.ChildNodes[0].Value))) { this.ExternalPasswordRecover = Boolean.Parse(tNode.ChildNodes[0].Value); } } catch { } try { tNode = doc.SelectSingleNode("/cas:serviceConfig/cas:passwordRecoverUri", namespaceManager); if ((tNode != null) && (!String.IsNullOrEmpty(tNode.ChildNodes[0].Value))) { this.PasswordRecoverUri = new Uri(tNode.ChildNodes[0].Value); } } catch { } try { tNode = doc.SelectSingleNode("/cas:serviceConfig/cas:permitChangePassword", namespaceManager); if ((tNode != null) && (!String.IsNullOrEmpty(tNode.ChildNodes[0].Value))) { this.PermitChangePassword = Boolean.Parse(tNode.ChildNodes[0].Value); } } catch { } try { tNode = doc.SelectSingleNode("/cas:serviceConfig/cas:admin", namespaceManager); if ((tNode != null) && (!String.IsNullOrEmpty(tNode.ChildNodes[0].Value))) { this.Admin = tNode.ChildNodes[0].Value; } } catch { } XmlNodeList lNode = doc.SelectNodes("/cas:serviceConfig/cas:attributes/cas:attribute", namespaceManager); foreach (XmlNode n in lNode) { String key = null; Object value = null; try { tNode = n.SelectSingleNode("cas:key", namespaceManager); if ((tNode != null) && (!String.IsNullOrEmpty(tNode.ChildNodes[0].Value))) { key = tNode.ChildNodes[0].Value; } tNode = n.SelectSingleNode("cas:value", namespaceManager); if ((tNode != null) && (!String.IsNullOrEmpty(tNode.ChildNodes[0].Value))) { //Testa parses try { value = Int64.Parse(tNode.ChildNodes[0].Value); } catch { } if (value == null) { try { value = Boolean.Parse(tNode.ChildNodes[0].Value); } catch { } } if (value == null) { try { value = DateTime.Parse(tNode.ChildNodes[0].Value); } catch { } } if (value == null) { try { value = tNode.ChildNodes[0].Value.ToString(); } catch { } } } if ((key != null && value != null) && (!Attributes.ContainsKey(key))) { Attributes.Add(key, value); } } catch { } } }