public void OnRenew(Session session, RenewRequest request, RenewResponse response) { Console.WriteLine("Renew Message"); response.Ok = true; response.RenewalOk = false; response.MagneticMedia = ThreeStateBool.Unknown; response.Desensitize = true; response.TransactionDate = DateTime.Now; response.InstitutionId = "The Institiotion Id"; response.PatronIdentifier = request.PatronIdentifier + " (took from request)"; response.ItemIdentifier = request.ItemIdentifier + " (also took from request)"; response.TitleIdentifier = "The MEGA Title"; response.DueDate = DateTime.Now; response.FeeType = FeeType.OTHER_UNKNOWN; response.SecurityInhibit = true; response.CurrencyType = Currency.USD; response.FeeAmount = 100; response.MediaType = MediaType.BOOK_WITH_CD; response.ItemProperties = "The SUPA DUPA Properies"; response.TransactionId = "The Trans Id"; response.ScreenMessage = "F**K The Police"; response.PrintLine = "The Print Line"; }
/// <summary> /// Validates Renew response. /// </summary> /// <param name="renewResponse">Response to the Renew command.</param> /// <param name="seconds">Termination time (in seconds) passed to the Renew command</param> void ValidateRenewResponse(RenewResponse renewResponse, int seconds) { ValidateRenewResponse(renewResponse); Assert(renewResponse.CurrentTime.AddSeconds(seconds) <= renewResponse.TerminationTime.Value, "TerminationTime < CurrentTime + InitialTerminationTime", "Validate times"); }
void ValidateRenewResponse(RenewResponse renewResponse) { Assert(renewResponse != null, "The DUT did not return Renew response", "Check that the DUT returned Renew response"); Assert(renewResponse.CurrentTimeSpecified, "Current time is not specified", "Check that CurrentTime is specified"); Assert(renewResponse.TerminationTime.HasValue, "Termination time is not specified", "Check that TerminationTime is specified"); }
/// <summary> /// /// </summary> /// <param name="request"></param> /// <param name="stepName"></param> /// <returns></returns> /// <remarks>As this method uses SubscriptionManager client, care should be taken that client is created. /// It's not posisble to create it here since Subscribe method should be called first to get endpoint address.</remarks> protected RenewResponse Renew(Renew request, string stepName) { RenewResponse response = null; RunStep(() => { response = _subscriptionManagerClient.Renew(request); }, stepName); return(response); }
/// <summary> /// Renews the SubscriptionManagerClient's subscription /// </summary> private void Renew() { Console.WriteLine(System.DateTime.Now + "\tIssue subscription renew"); RenewResponse oRenewResult = SubscriptionManagerClient.Renew(new Renew() { TerminationTime = "PT60S" }); SubTermTime = oRenewResult.TerminationTime; Console.WriteLine(string.Format("Current Time: {0}\tTermination Time: {1}", oRenewResult.CurrentTime.ToString(), oRenewResult.TerminationTime.Value.ToString())); //OnNotification(string.Format("Subscription renewed - Current Time: {0}\tTermination Time: {1}", oRenewResult.CurrentTime.ToString(), oRenewResult.TerminationTime.Value.ToString())); }
public void RenewTest() { EndpointReferenceType endpointReference = null; int actualTerminationTime = 10; RunTest <object>( () => { return(null); }, () => { EnsureEventPortTypeClientCreated(); endpointReference = CreateStandardSubscription(ref actualTerminationTime); if (endpointReference == null) { return; } Renew renew = new Renew(); renew.TerminationTime = "PT10S"; // there was no requirement to retry Renew for this test RenewResponse renewResponse = Renew(renew); Assert(renewResponse != null, "The DUT did not return Renew response", "Check that the DUT returned Renew response"); Assert(renewResponse.CurrentTimeSpecified, "Current time is not specified", "Check that CurrentTime is specified"); Assert(renewResponse.TerminationTime.HasValue, "Termination time is not specified", "Check that TerminationTime is specified"); Assert(renewResponse.CurrentTime.AddSeconds(10) <= renewResponse.TerminationTime.Value, "TerminationTime < CurrentTime + InitialTerminationTime", "Validate times"); }, (o) => { if (endpointReference != null) { if (endpointReference.Address != null && _subscriptionManagerClient == null) { CreateSubscriptionManagerClient(endpointReference); } ReleaseSubscriptionManager(actualTerminationTime * 1000); } }); }
/// <summary> /// Renews the SubscriptionManagerClient's subscription /// </summary> public void Renew() { Console.WriteLine(DateTime.Now + "\tIssue subscription renew"); RenewResponse oRenewResult = SubscriptionManagerClient.Renew(new Renew() { TerminationTime = "PT60S" }); SubTermTime = oRenewResult.TerminationTime; Console.WriteLine(string.Format("Current Time: {0}\tTermination Time: {1}", oRenewResult.CurrentTime.ToString(), oRenewResult.TerminationTime.Value.ToString())); listBox1.Items.Add(string.Format("Subscription renewed - Current Time: {0}\tTermination Time: {1}", oRenewResult.CurrentTime.ToString(), oRenewResult.TerminationTime.Value.ToString())); listBox1.SelectedIndex = listBox1.Items.Count - 1; }
private void btnRenew_Click(object sender, EventArgs e) { SafeInvoke(() => { Renew renew = new Renew(); renew.TerminationTime = tbRenewTime.Text; RenewResponse response = _subscriptionManager.Renew(renew); if (response.TerminationTime.HasValue) { _terminationTime = response.TerminationTime.Value; tbTerminationTime.Text = _terminationTime.ToString("hh:mm:ss.fff"); } }); }
/// <summary> /// Validates Renew response. /// </summary> /// <param name="renewResponse">Response to the Renew command.</param> /// <param name="seconds">Termination time (in seconds) passed to the Renew command</param> void ValidateRenewResponse(RenewResponse renewResponse, int seconds) { Assert(renewResponse != null, "The DUT did not return Renew response", "Check that the DUT returned Renew response"); Assert(renewResponse.CurrentTimeSpecified, "Current time is not specified", "Check that CurrentTime is specified"); Assert(renewResponse.TerminationTime.HasValue, "Termination time is not specified", "Check that TerminationTime is specified"); Assert(renewResponse.CurrentTime.AddSeconds(seconds) <= renewResponse.TerminationTime.Value, "TerminationTime < CurrentTime + InitialTerminationTime", "Validate times"); }
public override RenewResponse Renew([System.Xml.Serialization.XmlElementAttribute("Renew", Namespace = "http://docs.oasis-open.org/wsn/b-2")] Renew Renew1) { SoapHeaderProcessing(unknownHeaders); ParametersValidation validation = new ParametersValidation(); validation.Add(ParameterType.Log, "TerminationTime", Renew1.TerminationTime); ExecuteVoidCommand(validation, PullPointSubscriptionServiceTest.RenewTest); RenewResponse result = new RenewResponse(); result.CurrentTimeSpecified = true; result.CurrentTime = PullPointSubscriptionServiceTest.TakeCurrentTime(); result.TerminationTime = PullPointSubscriptionServiceTest.TakeTerminationTime(result.CurrentTime); actionHeader.actionValue = "http://docs.oasis-open.org/wsn/bw-2/SubscriptionManager/RenewResponse"; return(result); }
/// <summary> /// Validates Renew response. /// </summary> /// <param name="renewResponse">Response to the Renew command.</param> /// <param name="terminationTime">Termination Time.</param> void ValidateRenewResponse(RenewResponse renewResponse, DateTime terminationTime) { ValidateRenewResponse(renewResponse); DateTime responseTerminationTimeUtc = renewResponse.TerminationTime.Value; if (renewResponse.TerminationTime.Value.Kind != DateTimeKind.Utc) { responseTerminationTimeUtc = renewResponse.TerminationTime.Value.ToUniversalTime(); } DateTime terminationTimeUtc = terminationTime.ToUniversalTime(); Assert(terminationTimeUtc <= responseTerminationTimeUtc, "TerminationTime (in Response) < InitialTerminationTime", "Check termination time in request and response"); Assert(renewResponse.CurrentTime <= renewResponse.TerminationTime.Value, "TerminationTime (in Response) < CurrentTime (in Response)", "Check TerminationTime and CurrentTime in response"); }
public override RenewResponse Renew([System.Xml.Serialization.XmlElementAttribute("Renew", Namespace = "http://docs.oasis-open.org/wsn/b-2")] Renew Renew1) { int subscriptionKey = SoapReferanceHeaderProcessing(unknownHeaders); ConfStorageLoad(); EventServerLoad(); DateTime terminationTime; try { TimeSpan timeSpan = System.Xml.XmlConvert.ToTimeSpan(Renew1.TerminationTime); terminationTime = DateTime.UtcNow.Add(timeSpan.Add(new TimeSpan(0, 0, 1))); } catch (Exception) { try { terminationTime = System.Xml.XmlConvert.ToDateTime(Renew1.TerminationTime, XmlDateTimeSerializationMode.Utc); } catch (Exception) { throw FaultLib.GetSoapException(FaultType.General, "Wrong Initial Termination Time."); } } EventServer.RenewSubscribtion(subscriptionKey, terminationTime); RenewResponse res = new RenewResponse(); res.CurrentTimeSpecified = true; res.CurrentTime = DateTime.UtcNow; res.TerminationTime = terminationTime; EventServerSave(); ConfStorageSave(); actionHeader.actionValue = "http://docs.oasis-open.org/wsn/bw-2/SubscriptionManager/RenewResponse"; return(res); }
/// <summary> /// Renew token. This operation allows a long-lvide task operation to scheduled in a service /// giving the server a renewable token. Then the service can renew the token before use it /// to authorize access for the operation. /// Use-case: https://wiki.eng.vmware.com/SSO/UseCases#Scheduling_long_lived_task_.28delegation_.2B_renew.29 /// </summary> /// <param name="renewableToken"></param> /// <param name="signingCertificate"></param> /// <param name="lifetime"></param> /// <returns></returns> public XmlElement RenewToken( XmlElement renewableToken, X509Certificate2 signingCertificate, TimeSpan?lifetime = null) { if (renewableToken == null) { throw new ArgumentNullException("renewableToken"); } var securityTokenRequest = new RequestSecurityTokenType { RequestType = @"http://docs.oasis-open.org/ws-sx/ws-trust/200512/Renew", TokenType = "urn:oasis:names:tc:SAML:2.0:assertion", RenewTarget = renewableToken, Lifetime = GetLifetime(lifetime) }; var securityContext = new WsSecurityContext { ClientChannel = _stsServiceClient.InnerChannel, Properties = { Credentials = { ClientCertificate = signingCertificate }, SigningKey = signingCertificate.PrivateKey } }; RenewResponse response = securityContext.InvokeOperation(() => _stsServiceClient.RenewAsync(securityTokenRequest).Result); return((XmlElement) response. RequestSecurityTokenResponse. Items[0]); #endregion }
public RenewResponse Renew([System.Xml.Serialization.XmlElementAttribute("Renew", Namespace = "http://docs.oasis-open.org/wsn/b-2")] Renew Renew1) { if (Application["consumer"] == null) { SoapFaultSubCode subCode = new SoapFaultSubCode(new XmlQualifiedName("ResourseUnknown1", "http://www.onvif.org/ver10/error")); SoapException exception = new SoapException("Invalid Argument", new XmlQualifiedName("Sender", "http://www.w3.org/2003/05/soap-envelope"), subCode); throw exception; } RenewResponse response = new RenewResponse(); response.CurrentTime = System.DateTime.Now; response.CurrentTimeSpecified = true; response.TerminationTime = response.CurrentTime.AddSeconds(15); return(response); }
public void RenewTest() { EndpointReferenceType subscriptionReference = null; bool subscribed = false; int terminationTime = 10; RunTest <object>( new Backup <object>( () => { return(null); }), () => { SubscribeResponse subscribeResponse = CreateStandardSubscription(); if (subscribeResponse == null) { return; } subscribed = true; subscriptionReference = subscribeResponse.SubscriptionReference; Renew renew = new Renew(); renew.TerminationTime = "PT10S"; RenewResponse renewResponse = null; bool retry = false; try { renewResponse = Renew(renew); } catch (FaultException exc) { FaultException <UnacceptableTerminationTimeFaultType> invalidTerminationTimeFault = exc as FaultException <UnacceptableTerminationTimeFaultType>; if (invalidTerminationTimeFault != null) { LogStepEvent(string.Format("Exception of type FaultException<UnacceptableTerminationTimeFaultType> received. Try to renew subscription with new parameters")); StepPassed(); string duration = string.Empty; terminationTime = GetRecommendedDuration <UnacceptableTerminationTimeFaultType>(invalidTerminationTimeFault, out duration); retry = true; renew.TerminationTime = duration; } else { throw; } } if (retry) { renewResponse = Renew(renew); } ValidateRenewResponse(renewResponse, terminationTime); DateTime requestTerminationTime = DateTime.UtcNow.AddSeconds(terminationTime); requestTerminationTime = new DateTime(requestTerminationTime.Year, requestTerminationTime.Month, requestTerminationTime.Day, requestTerminationTime.Hour, requestTerminationTime.Minute, requestTerminationTime.Second, requestTerminationTime.Kind); // TEST --> // requestTerminationTime = DateTime.Parse("2011-06-09T13:27:46Z").ToUniversalTime(); // TEST <-- string xsDateTime = requestTerminationTime.ToString("yyyy-MM-ddTHH:mm:ssZ"); // TEST --> //xsDateTime = "2011-06-09T13:27:46Z"; //requestTerminationTime = DateTime.Parse(xsDateTime); // <-- renew.TerminationTime = xsDateTime; try { renewResponse = Renew(renew, "Renew subscription - use xs:DateTime format for TerminationTime"); } catch (FaultException exc) { FaultException <UnacceptableTerminationTimeFaultType> invalidTerminationTimeFault = exc as FaultException <UnacceptableTerminationTimeFaultType>; if (invalidTerminationTimeFault != null) { LogStepEvent(string.Format("Exception of type FaultException<UnacceptableTerminationTimeFaultType> received. Try to renew subscription with new parameters")); StepPassed(); string duration = string.Empty; terminationTime = GetRecommendedDuration <UnacceptableTerminationTimeFaultType>(invalidTerminationTimeFault, out duration); requestTerminationTime = DateTime.UtcNow.AddSeconds(terminationTime); requestTerminationTime = new DateTime(requestTerminationTime.Year, requestTerminationTime.Month, requestTerminationTime.Day, requestTerminationTime.Hour, requestTerminationTime.Minute, requestTerminationTime.Second, requestTerminationTime.Kind); xsDateTime = requestTerminationTime.ToString("yyyy-MM-ddTHH:mm:ssZ"); //LogStepEvent(string.Format("Send TerminationTime '{0}'", xsDateTime)); retry = true; renew.TerminationTime = xsDateTime; } else { throw; } } if (retry) { renewResponse = Renew(renew); } ValidateRenewResponse(renewResponse, requestTerminationTime); }, (o) => { if (subscribed) { if (subscriptionReference != null) { CreateSubscriptionManagerClient(subscriptionReference); } ReleaseSubscriptionManager(terminationTime * 1000); } }); }
private void EnumerateInternalWithADWS(string distinguishedName, string filter, string[] properties, string scope, ReceiveItems callback) { bool nTSecurityDescriptor = false; List <string> listproperties = new List <string>(); Enumerate enumerate = new Enumerate(); enumerate.Filter = new FilterType(); enumerate.Filter.LdapQuery = new LdapQuery(); enumerate.Filter.LdapQuery.BaseObject = distinguishedName; Trace.WriteLine("LdapQuery.BaseObject=" + enumerate.Filter.LdapQuery.BaseObject); enumerate.Filter.LdapQuery.Scope = scope; enumerate.Filter.LdapQuery.Filter = filter; Trace.WriteLine("LdapQuery.Filter=" + enumerate.Filter.LdapQuery.Filter); if (properties != null) { listproperties.AddRange(properties); enumerate.Selection = new Selection(); enumerate.Selection.SelectionProperty = BuildProperties(listproperties); } EnumerateResponse enumerateResponse = null; Trace.WriteLine("[" + DateTime.Now.ToLongTimeString() + "] Running enumeration"); bool hasNewProperties = true; while (hasNewProperties) { try { enumerateResponse = Search.Enumerate(enumerate); hasNewProperties = false; } catch (FaultException <schemas.microsoft.com._2008._1.ActiveDirectory.EnumerateFault> ex) { // handle the case where the property is not available in the schema. // an exception is thrown // remove the litigious property and resume the query Trace.WriteLine("The server doesn't support the property: " + ex.Detail.InvalidProperty); int postns = ex.Detail.InvalidProperty.IndexOf(':'); string property = ex.Detail.InvalidProperty; if (postns > 0) { property = ex.Detail.InvalidProperty.Substring(postns + 1); } if (!listproperties.Remove(property)) { throw; } if (listproperties.Count == 0) { return; } enumerate.Selection.SelectionProperty = BuildProperties(listproperties); } } Trace.WriteLine("[" + DateTime.Now.ToLongTimeString() + "]Enumeration successful"); Trace.WriteLine("Enumeration expires at " + enumerateResponse.Expires); Trace.WriteLine("Enumeration context is " + String.Join(",", enumerateResponse.EnumerationContext.Text)); // prepare the flag for the ntsecuritydescriptor foreach (string property in listproperties) { if (String.Compare("nTSecurityDescriptor", property, true) == 0) { nTSecurityDescriptor = true; } } // do not fail if the expiration cannot be parsed DateTime expiration = DateTime.Now.AddMinutes(30); DateTime.TryParse(enumerateResponse.Expires, out expiration); bool bcontinue = true; int pagenum = 0; while (bcontinue) { if (expiration.AddMinutes(-5) < DateTime.Now) { Trace.WriteLine("[" + DateTime.Now.ToLongTimeString() + "]Renewing the enumeration (expiration)"); Renew renew = new Renew(); renew.EnumerationContext = enumerateResponse.EnumerationContext; renew.Expires = DateTime.Now.AddMinutes(20).ToString("O"); RenewResponse renewresponse = Search.Renew(renew); Trace.WriteLine("New expiration at " + renewresponse.Expires); DateTime.TryParse(renewresponse.Expires, out expiration); Trace.WriteLine("New enumeration context " + String.Join(",", renewresponse.EnumerationContext.Text)); enumerateResponse.EnumerationContext = renewresponse.EnumerationContext; } Trace.WriteLine("[" + DateTime.Now.ToLongTimeString() + "]Getting Enumerate page " + pagenum); Pull pull = new Pull(); pull.EnumerationContext = enumerateResponse.EnumerationContext; pull.MaxElements = "500"; if (nTSecurityDescriptor || DomainScope) { List <controlsControl> controls = new List <controlsControl>(); if (nTSecurityDescriptor) { // this is the flag https://msdn.microsoft.com/en-us/library/cc223323.aspx // the last byte, 0x07, is OWNER_SECURITY_INFORMATION | GROUP_SECURITY_INFORMATION | DACL_SECURITY_INFORMATION controlsControl control = new controlsControl(); controls.Add(control); control.controlValue = Convert.ToBase64String(new byte[] { 0x30, 0x84, 0x00, 0x00, 0x00, 0x03, 0x02, 0x01, 0x07 }); control.criticality = true; control.type = "1.2.840.113556.1.4.801"; } if (DomainScope) { // this is the flag https://msdn.microsoft.com/en-us/library/cc223323.aspx // the last byte, 0x07, is OWNER_SECURITY_INFORMATION | GROUP_SECURITY_INFORMATION | DACL_SECURITY_INFORMATION controlsControl control = new controlsControl(); controls.Add(control); control.criticality = true; control.type = "1.2.840.113556.1.4.1339"; } pull.controls = controls.ToArray(); } PullResponse pullResponse = null; try { pullResponse = Search.Pull(pull); } catch (FaultException ex) { Trace.WriteLine("[" + DateTime.Now.ToLongTimeString() + "]Pull unsuccessful"); Trace.WriteLine("Fault Exception: " + ex.Message); Trace.WriteLine("Reason: " + ex.Reason); var stringWriter = new StringWriter(); var xmlTextWriter = new XmlTextWriter(stringWriter); var messageFault = ex.CreateMessageFault(); messageFault.WriteTo(xmlTextWriter, EnvelopeVersion.Soap12); var stringValue = Convert.ToString(stringWriter); Trace.WriteLine("Detail:"); Trace.WriteLine(stringValue); throw new PingCastleException("An ADWS exception occured (fault:" + ex.Message + ";reason:" + ex.Reason + ").\r\nADWS is a faster protocol than LDAP but bound to a default 30 minutes limitation. If this error persists, we recommand to force the LDAP protocol. Run PingCastle with the following switches: --protocol LDAPOnly --interactive"); } Trace.WriteLine("[" + DateTime.Now.ToLongTimeString() + "]Pull successful"); if (pullResponse.EndOfSequence != null) { bcontinue = false; } callback(pullResponse.Items); pagenum++; } Trace.WriteLine("[" + DateTime.Now.ToLongTimeString() + "]Releasing the enumeration context"); Release relase = new Release(); relase.EnumerationContext = enumerateResponse.EnumerationContext; Search.Release(relase); }
internal StepType SMSRenewTest(out RenewResponse target, out SoapException ex, out int timeOut, Renew Renew1) { StepType res = StepType.None; target = new RenewResponse(); timeOut = 0; ex = null; bool passed = true; string logMessage = ""; //Get step list for command XmlNodeList m_testList = m_TestCommon.GetStepsForCommand("SMSRenew"); if (m_testList != null) { //Get current step XmlNode test = m_testList[m_commandCount[SMSRenew]]; #region Analyze request //TerminationTime if (test.SelectNodes("RequestParameters/TerminationTime[@type=\"now+diff\"]").Count == 0) { CommonCompare.StringCompare("RequestParameters/TerminationTime", "TerminationTime", Renew1.TerminationTime, ref logMessage, ref passed, test); } else { CommonCompare.CompareRealTime("RequestParameters/TerminationTime", "TerminationTime", Renew1.TerminationTime, ref logMessage, ref passed, test); } #endregion //Analyze request //Generate response object targetObj; res = m_TestCommon.GenerateResponseStepTypeNotVoid(test, out targetObj, out ex, out timeOut, typeof(RenewResponse)); target = (RenewResponse)targetObj; #region Serialization Temp //Events.EndpointReferenceType dsr = new Events.EndpointReferenceType(); //dsr.Address = new Events.AttributedURIType(); //dsr.Address.Value = "http://192.168.10.203/onvif/event"; //dsr.Metadata = new Events.MetadataType(); //dsr.ReferenceParameters = new Events.ReferenceParametersType(); //XmlSerializer serializer1 = new XmlSerializer(typeof(Events.EndpointReferenceType)); //TextWriter textWriter = new StreamWriter("c:\\2.txt"); //serializer1.Serialize(textWriter, dsr); #endregion //Serialization Temp if (res == StepType.Normal) { //CurrentTime string CurrentTimeType = test.SelectSingleNode("ResponseParametersAdditional/CurrentTime/@type").InnerText; switch (CurrentTimeType) { case "now": { target.CurrentTime = System.DateTime.UtcNow; break; } case "value": { target.CurrentTime = Convert.ToDateTime(test.SelectSingleNode("ResponseParametersAdditional/CurrentTime").InnerText); break; } case "nowDiff": { int timeDiff = Convert.ToInt32(test.SelectSingleNode("ResponseParametersAdditional/CurrentTime").InnerText); target.CurrentTime = System.DateTime.UtcNow.AddSeconds(timeDiff); break; } case "none": { target.CurrentTimeSpecified = false; break; } } //TerminationTime if (test.SelectNodes("ResponseParametersAdditional/TerminationTime[@type=\"fromrequest\"]").Count != 0) { target.TerminationTime = Convert.ToDateTime(Renew1.TerminationTime); } else { if (test.SelectNodes("ResponseParametersAdditional/TerminationTime[@differance=\"true\"]").Count != 0) { int timeDiff = Convert.ToInt32(test.SelectSingleNode("ResponseParametersAdditional/TerminationTime").InnerText); target.TerminationTime = target.CurrentTime.AddSeconds(timeDiff); } else { target.TerminationTime = Convert.ToDateTime(test.SelectSingleNode("ResponseParametersAdditional/TerminationTime").InnerText); } } } m_TestCommon.writeToLog(test, logMessage, passed); Increment(m_testList.Count, SMSRenew); } else { timeOut = 0; target = null; ex = null; res = StepType.None; } return(res); }