/// <summary> /// Ensures the access. /// </summary> /// <param name="method">The method.</param> /// <param name="mode">The mode.</param> /// <param name="tag">The tag.</param> /// <param name="value">The value.</param> /// <returns></returns> protected override bool EnsureAccess(AccessMethod method, AccessMode mode, ref object tag, object value = null) { switch (mode) { case AccessMode.Exception: { var valueAsString = ((string)value); return(valueAsString.IndexOf("(400) Bad Request") != -1 || valueAsString.IndexOf("(401) Unauthorized") != -1); //return (valueAsString.IndexOf("(401) Unauthorized") != -1); } case AccessMode.Request: { var valueAsString = (value as string); if (valueAsString != null) { if (valueAsString.IndexOf("User does not have page access") != -1) { throw new UnauthorizedAccessException("User does not have page access"); } int loginStart, loginEnd; if ((loginStart = valueAsString.IndexOf("<form id=\"login_form\" action=\"/login.php?login_attempt=1&")) > -1 && (loginEnd = valueAsString.IndexOf("</form>", loginStart)) > -1) { return(true); } } return(false); } } return(false); }
public async Task InterceptAsync(HttpRequestMessage request, CancellationToken cancellationToken) { var accessToken = await GetAccessTokenForRequestAsync(request.RequestUri.ToString(), cancellationToken) .ConfigureAwait(false); AccessMethod.Intercept(request, accessToken); }
private IFuturePrototype GetAccessPrototype(AccessMethod accessMethod, FutureFeatures openDocFeatures, params IFuturePrototype[] methodParams) { IFuturePrototype[] array = new IFuturePrototype[2 + methodParams.Length]; array[0] = this.GetOpenDocumentFuture(openDocFeatures); array[1] = new ConstantFuture(new IntParameter((int)accessMethod)); Array.Copy(methodParams, 0, array, 2, methodParams.Length); return(new ApplyPrototype(new ApplyVerbPresent(), array)); }
private IFuturePrototype GetAccessPrototype(AccessMethod accessMethod, FutureFeatures openDocFeatures, params IFuturePrototype[] methodParams) { IFuturePrototype[] array = new IFuturePrototype[2 + methodParams.Length]; array[0] = this.GetOpenDocumentFuture(openDocFeatures); array[1] = new ConstantFuture(new IntParameter((int)accessMethod)); Array.Copy(methodParams, 0, array, 2, methodParams.Length); return new ApplyPrototype(new ApplyVerbPresent(), array); }
/// <summary> /// Ensures the access. /// </summary> /// <param name="method">The method.</param> /// <param name="mode">The mode.</param> /// <param name="tag">The tag.</param> /// <param name="value">The value.</param> /// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns> public override bool EnsureAccess(AccessMethod method, AccessMode mode, ref object tag, object value = null) { switch (mode) { //case AccessMode.Exception: return (((string)value).IndexOf("(400) Bad Request") != -1); default: return(true); } }
public override bool EnsureAccess(AccessMethod method, AccessMode mode, ref object tag, object value = null) { switch (mode) { case AccessMode.Request: return(((string)value).IndexOf($"/authgwy/{_oktaId}/login.htmld") != -1); } return(false); }
/// <summary> /// Ensures the access. /// </summary> /// <param name="method">The method.</param> /// <param name="mode">The mode.</param> /// <param name="tag">The tag.</param> /// <param name="value">The value.</param> /// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns> public override bool EnsureAccess(AccessMethod method, AccessMode mode, ref object tag, object value = null) { switch (mode) { case AccessMode.Request: return(((string)value).IndexOf("Session Expired") != -1); } return(false); }
public async Task <bool> HandleResponseAsync(HandleUnsuccessfulResponseArgs args) { // TODO(peleyal): check WWW-Authenticate header. if (args.Response.StatusCode == HttpStatusCode.Unauthorized) { return(!Object.Equals(Token.AccessToken, AccessMethod.GetAccessToken(args.Request)) || await RequestAccessTokenAsync(args.CancellationToken).ConfigureAwait(false)); } return(false); }
public async Task InterceptAsync(HttpRequestMessage request, CancellationToken cancellationToken) { if (Token == null || Token.IsExpired(Clock)) { Logger.Debug("Token has expired, trying to get a new one."); if (!await RequestAccessTokenAsync(cancellationToken).ConfigureAwait(false)) { throw new InvalidOperationException("The access token has expired but we can't refresh it"); } Logger.Info("New access token was received successfully"); } AccessMethod.Intercept(request, Token.AccessToken); }
/// <summary> /// /// </summary> /// <returns></returns> public override int GetHashCode() { int hash = base.GetHashCode(); hash = hash * 23 + BasicAuthentication.GetHashCode(); hash = hash * 23 + WithCredentials.GetHashCode(); hash = hash * 23 + TlsClientAuth.GetHashCode(); hash = hash * 23 + WithCaCert.GetHashCode(); hash = hash * 23 + SkipTlsVerification.GetHashCode(); hash = hash * 23 + Database.GetHashCode(); hash = hash * 23 + User.GetHashCode(); hash = hash * 23 + Password.GetHashCode(); hash = hash * 23 + AccessMethod.GetHashCode(); return(hash); }
private DerObjectIdentifier toOID(AccessMethod method) { switch (method) { case AccessMethod.CAIssuers: return(AccessDescription.IdADCAIssuers); case AccessMethod.Ocsp: return(AccessDescription.IdADOcsp); case AccessMethod.CARepository: return(AccessDescription.IdADCARepository); case AccessMethod.TimeStamping: return(AccessDescription.IdADTimeStamping); } return(null); }
/// <summary> /// Decorates unsuccessful responses, returns true if the response gets modified. /// See IHttpUnsuccessfulResponseHandler for more information. /// </summary> public async Task <bool> HandleResponseAsync(HandleUnsuccessfulResponseArgs args) { // If the response was unauthorized, request a new access token so that the original // request can be retried. // TODO(peleyal): check WWW-Authenticate header. if (args.Response.StatusCode == HttpStatusCode.Unauthorized) { bool tokensEqual = false; if (Token != null) { tokensEqual = Object.Equals( Token.AccessToken, AccessMethod.GetAccessToken(args.Request)); } return(!tokensEqual || await RequestAccessTokenAsync(args.CancellationToken).ConfigureAwait(false)); } return(false); }
private void updateDataSet(AccessMethod method, OSCAGeneralName gn, int index) { switch (method) { case AccessMethod.CARepository: dr = ds.Tables["caRepository"].NewRow(); dr["#"] = (index + 1).ToString(); dr["Type"] = gn.Type.ToString(); dr["Name"] = gn.Name; ds.Tables["caRepository"].Rows.Add(dr); break; case AccessMethod.TimeStamping: dr = ds.Tables["timeStamping"].NewRow(); dr["#"] = (index + 1).ToString(); dr["Type"] = gn.Type.ToString(); dr["Name"] = gn.Name; ds.Tables["timeStamping"].Rows.Add(dr); break; } }
private void updateDataSet(AccessMethod method, OSCAGeneralName gn, int index) { switch (method) { case AccessMethod.CAIssuers: dr = ds.Tables["caIssuers"].NewRow(); dr["#"] = (index + 1).ToString(); dr["Type"] = gn.Type.ToString(); dr["Name"] = gn.Name; ds.Tables["caIssuers"].Rows.Add(dr); break; case AccessMethod.Ocsp: dr = ds.Tables["ocsp"].NewRow(); dr["#"] = (index + 1).ToString(); dr["Type"] = gn.Type.ToString(); dr["Name"] = gn.Name; ds.Tables["ocsp"].Rows.Add(dr); break; } }
static void Main(string[] args) { //string AccessMethod = "google_cn"; AccessMethod AM = AccessMethod.google_ipv6; IPAddress ip = IPAddress.Any; string iniFilePath = string.Empty, exeFilePath = string.Empty; bool changeRepo = false, changeIP = false; try { string dir = AppDomain.CurrentDomain.BaseDirectory; Console.WriteLine("dir = {0}", dir); if (File.Exists(dir + @"local\goagent.exe")) { iniFilePath = dir + @"local\proxy.ini"; exeFilePath = dir + @"local\goagent.exe"; } if (File.Exists(dir + @"goagent\local\goagent.exe")) { iniFilePath = dir + @"goagent\local\proxy.ini"; exeFilePath = dir + @"goagent\local\goagent.exe"; } if (exeFilePath == string.Empty)// not set yet { throw new FileNotFoundException("Cannot find goagent main executable. Press any key to exit."); } switch (args.Length) { case 2: if (args[1].ToLower() == "changeip") { changeIP = true; int AvailableIP = 0; IPAddress[] ips = Dns.GetHostAddresses(Dns.GetHostName()); for (int i = 0; i < ips.Length; i++) { if (ips[i].AddressFamily == AddressFamily.InterNetwork) { ip = ips[i]; Console.WriteLine("{0}: {1}", i, ips[i]); ++AvailableIP; } } if (AvailableIP > 1) // multiple IPv4 address detected { Console.WriteLine("Please select the address to listen."); int select = Console.ReadKey().KeyChar - '0'; if (select > ips.Length || ips[select].AddressFamily != AddressFamily.InterNetwork) { Console.WriteLine("No such option, exit."); return; } ip = ips[select]; } } else { try { ip = IPAddress.Parse(args[1]); changeIP = true; } catch { Console.WriteLine("This is not a correct IP, exit."); return; } } goto case 1; case 1: if ((args[0].ToLower() == "cn") || (args[0].ToLower() == "ipv4")) { AM = AccessMethod.google_cn; } if (args[0].ToLower() == "ipv6" || args[0].ToLower() == "v6") { AM = AccessMethod.google_ipv6; } if (args[0].ToLower() == "hk") { AM = AccessMethod.google_hk; } changeRepo = true; if (args[0].ToLower() == "default") // use the default option { changeRepo = false; } break; case 0: break; default: return; } if (changeRepo || changeIP) { string[] iniFile = File.ReadAllLines(iniFilePath); for (int i = 0; i < iniFile.Length; i++) { if (changeRepo) { if (iniFile[i].Contains("profile = ")) { iniFile[i] = "profile = " + AM.ToString(); Console.WriteLine("Changed appspot to {0}.", AM.ToString()); continue; } } if (changeIP) { if (iniFile[i].StartsWith("ip = ")) { iniFile[i] = "ip = " + ip.ToString(); Console.WriteLine("Changed listen ip to {0}.", ip.ToString()); continue; } } /// 1.8.5 version doesn't need this part any more. //if (iniFile[i].Contains("hosts = ")) //{ // iniFile[i] = "hosts = " + AccessMethod; // Console.WriteLine("Changed hosts to {0}.", AccessMethod); // continue; //} } File.WriteAllLines(iniFilePath, iniFile); } if (Process.GetProcessesByName("Goagent").Length > 1) { Console.WriteLine("Already started."); return; } Process p = new Process(); p.StartInfo = new ProcessStartInfo(exeFilePath); p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; p.Start(); } catch (IOException ioe) { Console.WriteLine("iniFilePath = {0}", iniFilePath); Console.WriteLine("exeFilePath = {0}", exeFilePath); Console.WriteLine(ioe.Message); Console.WriteLine(ioe.StackTrace); Console.ReadKey(); } //Console.ReadKey(); }
public GlobalReference(Global global, AccessMethod method) { m_global = global; m_method = method; }
public override bool EnsureAccess(AccessMethod method, AccessMode mode, ref object tag, object value = null) => mode == AccessMode.Request && tag == ValidationReport && method == AccessMethod.TryFunc ? ((string)value).Contains("<h2>Enter Your User ID</h2>") : ((string)value).IndexOf("authorization process") != -1;
public void SetAccessToken(HttpRequestMessage request, string accessToken) { AccessMethod.Set(request, accessToken); }