private void ResolveIssuers(X509Certificate2 certificate, X509Certificate2Collection issuers, int chainLength) { // // only look at simpleNames because intermediates are always going to be org-level, not email, certs // string issuerName = certificate.GetNameInfo(X509NameType.SimpleName, true); // true == "for issuer" // // If the issuer name matches the Cert name, we have a self-signed cert // if (certificate.MatchName(issuerName)) { return; } // // If the issuer is already known, then we are good // if (issuers.FindByName(issuerName) != null) { return; } if (chainLength == m_maxIssuerChainLength) { // // Chain too long. Ignore... // return; } // // Retrieve the issuer's certificate // X509Certificate2Collection issuerCertificates = IssuerResolver.SafeGetCertificates(certificate.ExtractEmailNameOrName(true)); if (CollectionExtensions.IsNullOrEmpty(issuerCertificates)) { return; } // // Recursively fetch the issuers who issued this set of certificates // foreach (X509Certificate2 issuerCertificate in issuerCertificates) { if (issuerCertificate.MatchName(issuerName) && !issuers.ContainsThumbprint(issuerCertificate.Thumbprint)) { // // New issuer // issuers.Add(issuerCertificate); // // And keep working up the chain // this.ResolveIssuers(issuerCertificate, issuers, chainLength + 1); } } }
public void When_IsNullOrEmpty() { List <string> source = null; bool expected = true; bool actual; actual = CollectionExtensions.IsNullOrEmpty(source); Assert.AreEqual(expected, actual); }
private static void HandleUsefulFaqLinks(DataMap resultObject, List <UsefulFaqLinksUtils> templateFaQs) { var usefulFaqLinks = FaqUtils.GetUsefulFaqLinks(templateFaQs); if (CollectionExtensions.IsNullOrEmpty(usefulFaqLinks)) { return; } resultObject.Attributes.Add("usefulFaqLinks", usefulFaqLinks); }
public ServiceResult SendRaw(string mobile, string content, long useId = 0) { if (!RegexHelper.CheckMobile(mobile)) { return(ServiceResult.Failure("手机号码格式不正确")); } var config = Resolve <IAutoConfigService>().GetValue <DefaultSmsGetWayConfig>(); if (CollectionExtensions.IsNullOrEmpty(config.Sign)) { return(ServiceResult.Failure("请设置短信签名")); } config.Sign = config.Sign.Replace("【", "").Replace("】", ""); if (CollectionExtensions.IsNullOrEmpty(config.AppId)) { return(ServiceResult.Failure("请设置短信通道账号(AppId)")); } if (CollectionExtensions.IsNullOrEmpty(config.Key)) { return(ServiceResult.Failure("请设置短信通道私钥(Key)")); } content = $"【{config.Sign.Trim()}】{content}"; var result = DefaultGateWayBase.Send(mobile, content, config); var sms = new Sms { Mobile = mobile.Trim(), Content = content.Trim(), IpAdress = HttpWeb.Ip, UserId = useId }; if (result.Code == "SUCCESS") { sms.Balance = ObjectExtension.ConvertToLong(result.Balance); sms.Status = SmsStatus.Success; Add(sms); } else { sms.Balance = ObjectExtension.ConvertToLong(result.Balance); sms.Status = SmsStatus.Error; sms.Message = result.Message; Add(sms); return(ServiceResult.Failure(result.Message)); } return(ServiceResult.Success); }
public string AssetWhereClauseForRegion(String regionName) { var locations = _locationManager.FindLocationsOfParentLocation(new PersonGroup { Name = regionName }); var hlagGroupedLocations = locations as HlagGroupedLocation[] ?? locations.ToArray(); if (CollectionExtensions.IsNullOrEmpty(hlagGroupedLocations)) { Log.WarnFormat("no locations found for region {0}, excluding everything from the filter", regionName); return("1=0"); } return(AssetWhereClauseFromLocations(hlagGroupedLocations.ToArray())); }
public virtual IEnumerable <IAssociationOption> GetHlagUserLocations(OptionFieldProviderParameters parameters) { var currentLocations = LocationManager.FindAllLocationsOfCurrentUser(parameters.ApplicationMetadata); var hlagUserlocations = currentLocations as HlagGroupedLocation[] ?? currentLocations.ToArray(); if (CollectionExtensions.IsNullOrEmpty(hlagUserlocations)) { Log.Warn(HapagErrorCatalog.Err001); return(hlagUserlocations); } if (parameters.OptionField.Options != null) { return(hlagUserlocations.Union(parameters.OptionField.Options)); } return(hlagUserlocations); }
public string AssetWhereClauseFromLocations(HlagGroupedLocation[] locations) { var sb = new StringBuilder(); var isWWUser = SecurityFacade.CurrentUser().IsWWUser(); var ctx = _contextLookuper.LookupContext(); if (isWWUser && ctx.IsInModule(FunctionalRole.XItc) || (ctx.ApplicationLookupContext != null && "r0042ExportExcel".EqualsIc(ctx.ApplicationLookupContext.Schema))) { return("1=1"); } if (CollectionExtensions.IsNullOrEmpty(locations)) { //if u dont have any location you should not be able to see anything sb.Append("0=1"); return(sb.ToString()); } var i = 0; if (!(ctx.IsInModule(FunctionalRole.XItc) && isWWUser)) { //HAP-838 item 6, only XITC ww users should see it, or tom itom (who actually see asset) sb.AppendFormat("asset.status != '{0}' and ", AssetConstants.Decommissioned); } foreach (var location in locations) { if (i == 0) { sb.Append(" ( "); } i++; sb.Append(String.Format("(asset.pluspcustomer in ('{0}') and {1})", location.SubCustomer, location.CostCentersForQuery("asset.glaccount"))); if (i < locations.Count()) { sb.Append(" or "); } else { sb.Append(" ) "); } } return(sb.ToString()); }
public int GetMaximumPossibleScoreInCategory(QuizCategory category) { if (!CollectionExtensions.IsNullOrEmpty(questions)) { // Get the questions with this type IEnumerable <QuizQuestion> questions = GetQuestionsWithCategory(category); // Initialize the max score int maxScore = 0; foreach (QuizQuestion q in questions) { maxScore += q.MaxPossibleScore; } return(maxScore); } else { return(0); } }
public IEnumerable <IAssociationOption> GetHlagAllCostCenters(OptionFieldProviderParameters parameters) { ISet <IAssociationOption> costcenters = new SortedSet <IAssociationOption>(); var currentLocations = LocationManager.FindAllLocations(); var hlagLocations = currentLocations as HlagGroupedLocation[] ?? currentLocations.ToArray(); if (CollectionExtensions.IsNullOrEmpty(hlagLocations)) { Log.Warn(HapagErrorCatalog.Err001); return(costcenters); } foreach (var hlagLocation in hlagLocations) { foreach (var costcenter in hlagLocation.CostCenters) { var result = new AssociationOption(costcenter, costcenter); costcenters.Add(result); } } return(costcenters); }
public IEnumerable <IAssociationOption> GetHlagUserLocationAndCostCenter(OptionFieldProviderParameters parameters) { ISet <IAssociationOption> costcenters = new SortedSet <IAssociationOption>(); var currentLocations = LocationManager.FindAllLocationsOfCurrentUser(parameters.ApplicationMetadata); var hlagUserlocations = currentLocations as HlagGroupedLocation[] ?? currentLocations.ToArray(); if (CollectionExtensions.IsNullOrEmpty(hlagUserlocations)) { Log.Warn(HapagErrorCatalog.Err001); return(costcenters); } foreach (var hlaguserlocation in hlagUserlocations) { foreach (var costcenter in hlaguserlocation.CostCenters) { var result = new AssociationOption(hlaguserlocation.SubCustomerSuffix + "-" + costcenter, hlaguserlocation.Label + " - " + costcenter); costcenters.Add(result); } } return(costcenters); }
public void IsNullOrEmptyReturnsTrueForNull() { var candidate = CollectionExtensions.IsNullOrEmpty <int>(null); Assert.IsTrue(candidate); }
/// <summary> /// Validates a certificate by walking the certificate chain for all trust anchor chain, validating the leaf certificate against the chain. /// </summary> /// <remarks> /// Chain buiding is implemented with P/Invoke to create a custom chain engine allowing CRL checking without installing the anchor was in a trusted location in the Windows certificate store. /// </remarks> /// <param name="certificate">The leaf <see cref="X509Certificate2"/> to validate</param> /// <param name="trustedRoots">The collection of certificates representing anchors or roots of trust.</param> /// <returns><c>true</c> if at least one anchor has a valid chain of certs that verify trust in the leaf certificate, /// <c>false</c> if no anchors validate trust in the leaf cert.</returns> public bool IsTrustedCertificate(X509Certificate2 certificate, X509Certificate2Collection trustedRoots) { if (certificate == null) { throw new ArgumentNullException("certificate"); } // if there are no anchors we should always fail if (CollectionExtensions.IsNullOrEmpty(trustedRoots)) { this.NotifyUntrusted(certificate); return(false); } try { var chainPolicy = ValidationPolicy.Clone(); chainPolicy.ExtraStore.Add(trustedRoots); if (this.HasCertificateResolver) { this.ResolveIntermediateIssuers(certificate, chainPolicy.ExtraStore); } X509Chain chainBuilder; if (IsNewerThanWin2008R2()) { using (X509ChainEngine secureChainEngine = new X509ChainEngine(trustedRoots.Enumerate())) { secureChainEngine.BuildChain(certificate, chainPolicy, out chainBuilder); } } else { chainBuilder = new X509Chain(); chainBuilder.ChainPolicy = chainPolicy; chainBuilder.Build(certificate); } // We're using the system class as a helper to build the chain // However, we will review each item in the chain ourselves, because we have our own rules... X509ChainElementCollection chainElements = chainBuilder.ChainElements; // If we don't have a trust chain, then we obviously have a problem... if (chainElements.IsNullOrEmpty()) { this.NotifyUntrusted(certificate); return(false); } bool foundAnchor = false; // walk the chain starting at the leaf and see if we hit any issues before the anchor foreach (X509ChainElement chainElement in chainElements) { bool isAnchor = trustedRoots.FindByThumbprint(chainElement.Certificate.Thumbprint) != null; if (isAnchor) { // Found a valid anchor! // Because we found an anchor we trust, we can skip trust foundAnchor = true; continue; } if (this.ChainElementHasProblems(chainElement)) { this.NotifyProblem(chainElement); // Whoops... problem with at least one cert in the chain. Stop immediately return(false); } } return(foundAnchor); } catch (Exception ex) { this.NotifyError(certificate, ex); // just eat it and drop out to return false } this.NotifyUntrusted(certificate); return(false); }
public static IList <NglErrorModel> GetNglErrors(this ModelStateDictionary modelState) { var errorAndFields = modelState.Where(k => !CollectionExtensions.IsNullOrEmpty(k.Value.Errors)); return(errorAndFields.Select(eaf => new NglErrorModel(eaf.Key, eaf.Value.Errors.First().ErrorMessage)).ToList()); }