public SSOCallResult TicketVerification(string ticket, string clientIP) { try { if (string.IsNullOrEmpty(ticket)) return new SSOCallResult(-1, "票据为空。"); else if (string.IsNullOrEmpty(clientIP)) return new SSOCallResult(-1, "客户端IP地址为空。"); else { SSOAuthTicket authTicket = new SSOAuthTicket(ticket); if (authTicket == null) return new SSOCallResult(-1, "票据格式不正确。"); else if (!authTicket.HasValid) return new SSOCallResult(-1, "票据无效。"); else { string err = null; bool result = this.provider.TicketVerification(ref authTicket, clientIP, out err); if (result) return new SSOCallResult(0, authTicket.ToString(), err); return new SSOCallResult(-1, err); } } } catch (Exception e) { return new SSOCallResult(-1, e.Message); } }
public SSOCallResult TicketVerification(string ticket) { try { SSOCallResult callResult = null; if (this.VerifyCredential(this)) { if (string.IsNullOrEmpty(ticket)) throw new ArgumentNullException("ticket", "票据为空!"); SSOAuthTicket authTicket = new SSOAuthTicket(ticket); if (authTicket == null) throw new ArgumentException("票据格式不正确!"); if (!authTicket.HasValid) callResult = new SSOCallResult(-1, "票据无效!"); else { string clientIP = this.Context.Request.UserHostAddress; string err = null; bool result = this.factory.TicketVerification(ref authTicket, clientIP, out err); if (result) callResult = new SSOCallResult(0, authTicket.ToString(), "验证票据成功。"); else callResult = new SSOCallResult(-1, err); } } return callResult; } catch (Exception e) { this.log.CreateErrorLog(e.Message); return new SSOCallResult(-1, e.Message); } }
public SSOCallResult DestroyTicket(string ticket, string clientIP) { try { if (string.IsNullOrEmpty(ticket)) return new SSOCallResult(-1, "票据为空。"); else if (string.IsNullOrEmpty(clientIP)) return new SSOCallResult(-1, "客户端IP地址为空。"); else { SSOAuthTicket authTicket = new SSOAuthTicket(ticket); if (authTicket == null) return new SSOCallResult(-1, "票据格式不正确。"); else if (!authTicket.HasValid) return new SSOCallResult(-1, "票据无效。"); else { bool result = this.provider.DestroyTicket(ref authTicket, clientIP); if (result) return new SSOCallResult(0, authTicket.ToString(), "销毁票据成功。"); return new SSOCallResult(-1, "发生未知错误。"); } } } catch (Exception e) { return new SSOCallResult(-1, e.Message); } }
/// <summary> /// 设置当前上下文的票据。 /// </summary> /// <param name="context"></param> /// <param name="ticket"></param> /// <returns></returns> bool SetCurrentAuthTicket(HttpContext context, SSOAuthTicket ticket) { bool result = false; string ticketName = this.config.TicketName; if (context != null && ticket != null && !string.IsNullOrEmpty(ticketName)) { switch (this.config.LocalStorage) { case EnumLocalStorage.Cookies: HttpCookie cookie = context.Request.Cookies[ticketName]; if (cookie != null) { cookie.Value = ticket.ToString(); context.Response.SetCookie(cookie); } else { cookie = new HttpCookie(ticketName, ticket.ToString()); context.Response.AppendCookie(cookie); } result = true; break; case EnumLocalStorage.Session: context.Session[ticketName] = ticket.ToString(); result = true; break; } } return result; }
public bool TicketVerification(ref SSOAuthTicket ticket, string clientIP, out string err) { try { Poxy.SSOCallResult callResult = this.providerService.TicketVerification(ticket.ToString(), clientIP); err = callResult.ResultMessage; bool result = callResult.ResultCode == 0; if (result) ticket = new SSOAuthTicket(callResult.Ticket); return result; } catch (Exception e) { err = e.Message; return false; } }
public bool DestroyTicket(ref SSOAuthTicket ticket, string clientIP) { Poxy.SSOCallResult callResult = this.providerService.DestroyTicket(ticket.ToString(), clientIP); bool result = callResult.ResultCode == 0; if (result) ticket = new SSOAuthTicket(callResult.Ticket); else throw new Exception(callResult.ResultMessage); return result; }
public bool CreateTicket(SSOAuthTicket ticket, string clientIP) { Poxy.CallResult callResult = this.providerService.CreateTicket(ticket.ToString(), clientIP); bool result = (callResult.ResultCode == 0); if (!result) throw new Exception(callResult.ResultMessage); return result; }