Example #1
0
        /// <summary>
        /// Gets the orders items.
        /// </summary>
        /// <typeparam name="TQuery">The type of the query.</typeparam>
        /// <param name="searchQuery">The search query.</param>
        /// <returns>Returns orders items.</returns>
        protected virtual IEnumerable <Item> GetOrdersItems <TQuery>(TQuery searchQuery)
        {
            Assert.ArgumentNotNull(searchQuery, "Query");
            Assert.IsTrue(searchQuery is Query, "Query type is invalid");

            Query query = searchQuery as Query;

            if (string.IsNullOrEmpty(query.SearchRoot))
            {
                Item orderRoot = this.OrdersItem;
                Assert.IsNotNull(orderRoot, "Orders root item is null");

                query.SearchRoot = orderRoot.ID.ToString();
            }

            AttributeQuery templateId = new AttributeQuery("TemplateId", this.orderItemTempalteId.ToString(), MatchVariant.Exactly);

            if (!query.Contains(templateId))
            {
                if (!query.IsEmpty())
                {
                    query.AppendCondition(QueryCondition.And);
                }

                query.Add(templateId);
            }

            return(this.SearchProvider.Search(query, this.OrdersItem.Database).OrderByDescending(itm => itm["OrderNumber"]));
        }
        /// <summary>
        /// Fetches the given attribute from the given MemberInfo. This method
        /// applies caching and is allocation free (after caching has been
        /// performed).
        /// </summary>
        /// <param name="element">
        /// The MemberInfo the get the attribute from.
        /// </param>
        /// <param name="attributeType">The type of attribute to fetch.</param>
        /// <returns>The attribute or null.</returns>
        public static Attribute GetAttribute(MemberInfo element, Type attributeType, bool shouldCache)
        {
            var query = new AttributeQuery
            {
                MemberInfo    = element,
                AttributeType = attributeType
            };

            Attribute attribute;

            if (_cachedAttributeQueries.TryGetValue(query, out attribute) == false)
            {
                // LAZLO / LUDIQ FIX
                // Inheritance on property overrides. MemberInfo.IsDefined ignores the inherited parameter
                //var attributes = element.GetCustomAttributes(attributeType, /*inherit:*/ true).ToArray();
                var attributes = Attribute.GetCustomAttributes(element, attributeType, true).ToArray();

                if (attributes.Length > 0)
                {
                    attribute = (Attribute)attributes[0];
                }
                if (shouldCache)
                {
                    _cachedAttributeQueries[query] = attribute;
                }
            }

            return(attribute);
        }
        /// <summary>
        /// Fetches the given attribute from the given MemberInfo. This method
        /// applies caching and is allocation free (after caching has been
        /// performed).
        /// </summary>
        /// <param name="element">
        /// The MemberInfo the get the attribute from.
        /// </param>
        /// <param name="attributeType">The type of attribute to fetch.</param>
        /// <returns>The attribute or null.</returns>
        public static Attribute GetAttribute(MemberInfo element, Type attributeType, bool shouldCache)
        {
            var query = new AttributeQuery {
                MemberInfo    = element,
                AttributeType = attributeType
            };

            Attribute attribute;

            if (_cachedAttributeQueries.TryGetValue(query, out attribute) == false)
            {
                // changed from base FullSerializer because otherwise inherited attributes are ignored on properties
                // https://github.com/jacobdufault/fullserializer/issues/148
                var attributes = Attribute.GetCustomAttributes(element, attributeType, /*inherit:*/ true);
                if (attributes.Any())
                {
                    attribute = (Attribute)attributes.First();
                }
                if (shouldCache)
                {
                    _cachedAttributeQueries[query] = attribute;
                }
            }

            return(attribute);
        }
Example #4
0
        /// <summary>
        ///     Fetches the given attribute from the given MemberInfo. This method
        ///     applies caching and is allocation free (after caching has been
        ///     performed).
        /// </summary>
        /// <param name="element">
        ///     The MemberInfo the get the attribute from.
        /// </param>
        /// <param name="attributeType">The type of attribute to fetch.</param>
        /// <returns>The attribute or null.</returns>
        public static Attribute GetAttribute(MemberInfo element, Type attributeType, bool shouldCache)
        {
            AttributeQuery query = new AttributeQuery
            {
                MemberInfo    = element,
                AttributeType = attributeType
            };

            Attribute attribute;

            if (_cachedAttributeQueries.TryGetValue(query, out attribute) == false)
            {
                object[] attributes = element.GetCustomAttributes(attributeType, /*inherit:*/ true);
                if (attributes.Any())
                {
                    attribute = (Attribute)attributes.First();
                }

                if (shouldCache)
                {
                    _cachedAttributeQueries[query] = attribute;
                }
            }

            return(attribute);
        }
        public ICollection <Resource.Attribute> query(AttributeQuery query)
        {
            IQueryable <DB.Models.Attribute> attributes =
                context.Attribute.Include(att => att.AttributeType).Where(query.asExpression());

            attributes = query.getOrdering(attributes).Skip(query.page * query.results).Take(query.results);
            return(mapper.Map <ICollection <DB.Models.Attribute>, ICollection <API.Resource.Attribute> >(attributes.ToList()));
        }
Example #6
0
 private Saml20AttributeQuery()
 {
     _attrQuery              = new AttributeQuery();
     _attrQuery.Version      = Saml20Constants.Version;
     _attrQuery.ID           = "id" + Guid.NewGuid().ToString("N");
     _attrQuery.Issuer       = new NameID();
     _attrQuery.IssueInstant = DateTime.Now;
     _attrQuery.Subject      = new Subject();
     _attributes             = new List <SamlAttribute>();
 }
 /// <summary>
 /// Prevents a default instance of the <see cref="Saml20AttributeQuery"/> class from being created.
 /// </summary>
 private Saml20AttributeQuery()
 {
     _attrQuery = new AttributeQuery
     {
         Version      = Saml20Constants.Version,
         Id           = "id" + Guid.NewGuid().ToString("N"),
         Issuer       = new NameId(),
         IssueInstant = DateTime.Now,
         Subject      = new Subject()
     };
     _attributes = new List <SamlAttribute>();
 }
Example #8
0
                    public static AttributeQuery FromBaseObject(BaseObject baseObj)
                    {
                        if (baseObj == null || baseObj.NativeObject == IntPtr.Zero)
                        {
                            return(null);
                        }
                        AttributeQuery obj = baseObj as  AttributeQuery;

                        if (object.Equals(obj, null))
                        {
                            obj = new AttributeQuery(CreatedWhenConstruct.CWC_NotToCreate);
                            obj.BindNativeObject(baseObj.NativeObject, "CAttributeQuery");
                            obj.IncreaseCast();
                        }

                        return(obj);
                    }
Example #9
0
        /// <summary>
        /// Fetches the given attribute from the given MemberInfo. This method applies caching
        /// and is allocation free (after caching has been performed).
        /// </summary>
        /// <param name="element">The MemberInfo the get the attribute from.</param>
        /// <param name="attributeType">The type of attribute to fetch.</param>
        /// <returns>The attribute or null.</returns>
        public static Attribute GetAttribute(MemberInfo element, Type attributeType)
        {
            var query = new AttributeQuery {
                MemberInfo    = element,
                AttributeType = attributeType
            };

            Attribute attribute;

            if (_cachedAttributeQueries.TryGetValue(query, out attribute) == false)
            {
                var attributes = element.GetCustomAttributes(attributeType, /*inherit:*/ true);
                attribute = (Attribute)attributes.FirstOrDefault();
                _cachedAttributeQueries[query] = attribute;
            }

            return(attribute);
        }
Example #10
0
        public XElement Serialize()
        {
            var result = new XElement(Constants.XMLNamespaces.SAMLP + "Request",
                                      new XAttribute(XNamespace.Xmlns + "samlp", Constants.XMLNamespaces.SAMLP),
                                      new XAttribute(XNamespace.Xmlns + "ds", Constants.XMLNamespaces.DS),
                                      new XAttribute(XNamespace.Xmlns + "saml", Constants.XMLNamespaces.SAML),
                                      new XAttribute("IssueInstant", IssueInstant.ToUTCString()),
                                      new XAttribute("MajorVersion", MajorVersion),
                                      new XAttribute("MinorVersion", MinorVersion),
                                      new XAttribute("RequestID", RequestId));

            if (Signature != null)
            {
                result.Add(Signature.Serialize());
            }

            if (AttributeQuery != null)
            {
                result.Add(AttributeQuery.Serialize());
            }

            return(result);
        }
Example #11
0
        /// <summary>
        /// Fetches the given attribute from the given MemberInfo. This method
        /// applies caching and is allocation free (after caching has been
        /// performed).
        /// </summary>
        /// <param name="element">
        /// The MemberInfo the get the attribute from.
        /// </param>
        /// <param name="attributeType">The type of attribute to fetch.</param>
        /// <returns>The attribute or null.</returns>
        public static Attribute GetAttribute(MemberInfo element, Type attributeType, bool shouldCache)
        {
            var query = new AttributeQuery {
                MemberInfo    = element,
                AttributeType = attributeType
            };

            Attribute attribute;

            if (_cachedAttributeQueries.TryGetValue(query, out attribute) == false)
            {
                var attributes = element.GetCustomAttributes(attributeType, /*inherit:*/ true).ToArray();
                if (attributes.Length > 0)
                {
                    attribute = (Attribute)attributes[0];
                }
                if (shouldCache)
                {
                    _cachedAttributeQueries[query] = attribute;
                }
            }

            return(attribute);
        }
Example #12
0
        public JsonResult Get([FromQuery][Bind] AttributeQuery attQuery)
        {
            ICollection <Resource.Attribute> attributes = _attributeRepo.query(attQuery);

            return(Json(attributes));
        }
Example #13
0
        private Query ProcessAxis(Axis root, Flags flags, out Props props)
        {
            Query result = null;
            if (root.Prefix.Length > 0)
            {
                _needContext = true;
            }
            _firstInput = null;
            Query qyInput;
            {
                if (root.Input != null)
                {
                    Flags inputFlags = Flags.None;
                    if ((flags & Flags.PosFilter) == 0)
                    {
                        Axis input = root.Input as Axis;
                        if (input != null)
                        {
                            if (
                                root.TypeOfAxis == Axis.AxisType.Child &&
                                input.TypeOfAxis == Axis.AxisType.DescendantOrSelf && input.NodeType == XPathNodeType.All
                            )
                            {
                                Query qyGrandInput;
                                if (input.Input != null)
                                {
                                    qyGrandInput = ProcessNode(input.Input, Flags.SmartDesc, out props);
                                }
                                else
                                {
                                    qyGrandInput = new ContextQuery();
                                    props = Props.None;
                                }
                                result = new DescendantQuery(qyGrandInput, root.Name, root.Prefix, root.NodeType, false, input.AbbrAxis);
                                if ((props & Props.NonFlat) != 0)
                                {
                                    result = new DocumentOrderQuery(result);
                                }
                                props |= Props.NonFlat;
                                return result;
                            }
                        }
                        if (root.TypeOfAxis == Axis.AxisType.Descendant || root.TypeOfAxis == Axis.AxisType.DescendantOrSelf)
                        {
                            inputFlags |= Flags.SmartDesc;
                        }
                    }

                    qyInput = ProcessNode(root.Input, inputFlags, out props);
                }
                else
                {
                    qyInput = new ContextQuery();
                    props = Props.None;
                }
            }

            switch (root.TypeOfAxis)
            {
                case Axis.AxisType.Ancestor:
                    result = new XPathAncestorQuery(qyInput, root.Name, root.Prefix, root.NodeType, false);
                    props |= Props.NonFlat;
                    break;
                case Axis.AxisType.AncestorOrSelf:
                    result = new XPathAncestorQuery(qyInput, root.Name, root.Prefix, root.NodeType, true);
                    props |= Props.NonFlat;
                    break;
                case Axis.AxisType.Child:
                    if ((props & Props.NonFlat) != 0)
                    {
                        result = new CacheChildrenQuery(qyInput, root.Name, root.Prefix, root.NodeType);
                    }
                    else
                    {
                        result = new ChildrenQuery(qyInput, root.Name, root.Prefix, root.NodeType);
                    }
                    break;
                case Axis.AxisType.Parent:
                    result = new ParentQuery(qyInput, root.Name, root.Prefix, root.NodeType);
                    break;
                case Axis.AxisType.Descendant:
                    if ((flags & Flags.SmartDesc) != 0)
                    {
                        result = new DescendantOverDescendantQuery(qyInput, false, root.Name, root.Prefix, root.NodeType, /*abbrAxis:*/false);
                    }
                    else
                    {
                        result = new DescendantQuery(qyInput, root.Name, root.Prefix, root.NodeType, false, /*abbrAxis:*/false);
                        if ((props & Props.NonFlat) != 0)
                        {
                            result = new DocumentOrderQuery(result);
                        }
                    }
                    props |= Props.NonFlat;
                    break;
                case Axis.AxisType.DescendantOrSelf:
                    if ((flags & Flags.SmartDesc) != 0)
                    {
                        result = new DescendantOverDescendantQuery(qyInput, true, root.Name, root.Prefix, root.NodeType, root.AbbrAxis);
                    }
                    else
                    {
                        result = new DescendantQuery(qyInput, root.Name, root.Prefix, root.NodeType, true, root.AbbrAxis);
                        if ((props & Props.NonFlat) != 0)
                        {
                            result = new DocumentOrderQuery(result);
                        }
                    }
                    props |= Props.NonFlat;
                    break;
                case Axis.AxisType.Preceding:
                    result = new PrecedingQuery(qyInput, root.Name, root.Prefix, root.NodeType);
                    props |= Props.NonFlat;
                    break;
                case Axis.AxisType.Following:
                    result = new FollowingQuery(qyInput, root.Name, root.Prefix, root.NodeType);
                    props |= Props.NonFlat;
                    break;
                case Axis.AxisType.FollowingSibling:
                    result = new FollSiblingQuery(qyInput, root.Name, root.Prefix, root.NodeType);
                    if ((props & Props.NonFlat) != 0)
                    {
                        result = new DocumentOrderQuery(result);
                    }
                    break;
                case Axis.AxisType.PrecedingSibling:
                    result = new PreSiblingQuery(qyInput, root.Name, root.Prefix, root.NodeType);
                    break;
                case Axis.AxisType.Attribute:
                    result = new AttributeQuery(qyInput, root.Name, root.Prefix, root.NodeType);
                    break;
                case Axis.AxisType.Self:
                    result = new XPathSelfQuery(qyInput, root.Name, root.Prefix, root.NodeType);
                    break;
                case Axis.AxisType.Namespace:
                    if ((root.NodeType == XPathNodeType.All || root.NodeType == XPathNodeType.Element || root.NodeType == XPathNodeType.Attribute) && root.Prefix.Length == 0)
                    {
                        result = new NamespaceQuery(qyInput, root.Name, root.Prefix, root.NodeType);
                    }
                    else
                    {
                        result = new EmptyQuery();
                    }
                    break;
                default:
                    throw XPathException.Create(SR.Xp_NotSupported, _query);
            }

            return result;
        }
Example #14
0
                    public BaseObject Create()
                    {
                        AttributeQuery emptyInstance = new AttributeQuery(CreatedWhenConstruct.CWC_NotToCreate);

                        return(emptyInstance);
                    }
Example #15
0
 private AttributeQuery(AttributeQuery other) : base(other)
 {
     _onAttribute = other._onAttribute;
 }
 private AttributeQuery(AttributeQuery other) : base(other) {
     this.onAttribute = other.onAttribute;
 }
Example #17
0
        public static void Main(string[] args)
        {
            /******************* REQUEST VARIABLES*******************************/

            string host      = "esqa.moneris.com";
            string store_id  = "moneris";
            string api_token = "hurgle";

            /****************** TRANSACTION VARIABLES *****************************/

            string order_id;                    //will prompt user for input
            string service_type = "session";

            Console.Write("Please enter an order ID: ");
            order_id = Console.ReadLine();

            AttributeQuery aq = new AttributeQuery(order_id, service_type);

            aq.setDeviceId("");
            aq.setAccountLogin("13195417-8CA0-46cd-960D-14C158E4DBB2");
            aq.setPasswordHash("489c830f10f7c601d30599a0deaf66e64d2aa50a");
            aq.setAccountNumber("3E17A905-AC8A-4c8d-A417-3DADA2A55220");
            aq.setAccountName("4590FCC0-DF4A-44d9-A57B-AF9DE98B84DD");
            aq.setAccountEmail("*****@*****.**");
            //aq.setCCNumberHash("4242424242424242");
            //aq.setIPAddress("192.168.0.1");
            //aq.setIPForwarded("192.168.1.0");
            aq.setAccountAddressStreet1("3300 Bloor St W");
            aq.setAccountAddressStreet2("4th Flr West Tower");
            aq.setAccountAddressCity("Toronto");
            aq.setAccountAddressState("Ontario");
            aq.setAccountAddressCountry("Canada");
            aq.setAccountAddressZip("M8X2X2");
            aq.setShippingAddressStreet1("3300 Bloor St W");
            aq.setShippingAddressStreet2("4th Flr West Tower");
            aq.setShippingAddressCity("Toronto");
            aq.setShippingAddressState("Ontario");
            aq.setShippingAddressCountry("Canada");
            aq.setShippingAddressZip("M8X2X2");


            HttpsPostRequest mpgReq =
                new HttpsPostRequest(host, store_id, api_token, aq);

            try
            {
                Receipt receipt = mpgReq.GetReceipt();

                Hashtable results = new Hashtable();
                string[]  rules;

                Console.WriteLine("ResponseCode = " + receipt.GetResponseCode());
                Console.WriteLine("Message = " + receipt.GetMessage());
                Console.WriteLine("TxnNumber = " + receipt.GetTxnNumber());

                results = receipt.GetResult();

                //Iterate through the response
                IDictionaryEnumerator r = results.GetEnumerator();
                while (r.MoveNext())
                {
                    Console.WriteLine(r.Key.ToString() + " = " + r.Value.ToString());
                }


                //Iterate through the rules that were fired
                rules = receipt.GetRules();

                for (int i = 0; i < rules.Length; i++)
                {
                    Console.WriteLine("RuleName = " + rules[i]);
                    Console.WriteLine("RuleCode = " + receipt.GetRuleCode(rules[i]));
                    Console.WriteLine("RuleMessageEn = " + receipt.GetRuleMessageEn(rules[i]));
                    Console.WriteLine("RuleMessageFr = " + receipt.GetRuleMessageFr(rules[i]));
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
Example #18
0
        /// <summary>
        /// Processes a successful SAML response and redirect to the requested URL.
        /// </summary>
        /// <param name="page">The page object.</param>
        /// <param name="samlResponse">The SAML response object.</param>
        /// <param name="relayState">The relay state.</param>
        public static void SamlSuccessRedirect(Page page, ComponentPro.Saml2.Response samlResponse, string relayState)
        {
            // Get the previously loaded certificate.
            X509Certificate2 x509Certificate = (X509Certificate2)page.Application[Global.SpCertKey];

            Assertion samlAssertion;

            // Check assertions.
            if (samlResponse.GetAssertions().Count > 0)
            {
                // Extract the first assertion.
                samlAssertion = samlResponse.GetAssertions()[0];
            }
            else if (samlResponse.GetEncryptedAssertions().Count > 0)
            {
                // Extract the first assertion.
                samlAssertion = samlResponse.GetEncryptedAssertions()[0].Decrypt(x509Certificate.PrivateKey, null);
            }
            else
            {
                throw new ApplicationException("No assertions in response");
            }

            string userName;

            // Get the subject name identifier.
            if (samlAssertion.Subject.NameId != null)
            {
                //userName = samlAssertion.Subject.NameId.NameIdentifier;
                userName = samlAssertion.GetAttributeValueByFriendlyName("eduPersonPrincipalName");

                System.Collections.Generic.Dictionary<string, string> dict = new System.Collections.Generic.Dictionary<string, string>();

                foreach (ComponentPro.Saml2.Attribute attribute in samlAssertion.AttributeStatements[0].Attributes)
                {
                    dict.Add(attribute.FriendlyName, attribute.Values[0].ToString());
                    System.Diagnostics.Trace.WriteLine(attribute.FriendlyName + ":" + attribute.Values[0].ToString());
                }
                HttpContext.Current.Session.Add("samlAttributes", dict);
            }
            else if (samlAssertion.Subject.EncryptedId != null)
            {
                NameId nameId = samlAssertion.Subject.EncryptedId.Decrypt(x509Certificate.PrivateKey, null);
                userName = nameId.NameIdentifier;
            }
            else
            {
                throw new ApplicationException("No name in subject");
            }


            try
            {
                string aaURL = "https://idp.testshib.org:8443/idp/profile/SAML2/SOAP/AttributeQuery";
                //Testing subject
                NameId subje = new NameId(userName,null,null,SamlNameIdentifierFormat.Unspecified,aaURL);
                
                //Testing subject
                Subject subject = new Subject(new NameId(userName));
                SubjectConfirmation subjectConfirmation = new SubjectConfirmation(SamlSubjectConfirmationMethod.Bearer);
                SubjectConfirmationData subjectConfirmationData = new SubjectConfirmationData();
                subjectConfirmationData.Recipient = aaURL;
                subjectConfirmation.SubjectConfirmationData = subjectConfirmationData;
                subject.SubjectConfirmations.Add(subjectConfirmation);

                AttributeQuery attributeQuery = new AttributeQuery();
                //attributeQuery.Subject = subject;
                attributeQuery.Destination = aaURL;
                attributeQuery.Issuer = new Issuer(Global.entityId);
                attributeQuery.Attributes.Add(new ComponentPro.Saml2.Attribute() { FriendlyName = "givenName" });
                attributeQuery.Subject = new Subject(samlAssertion.Subject.NameId);
                
                
                attributeQuery.Sign(x509Certificate);
                System.Diagnostics.Trace.WriteLine("Trying to get attributes from AA");
                System.Diagnostics.Trace.WriteLine("AA query " + attributeQuery.GetXml().OuterXml);
                System.Diagnostics.Trace.WriteLine("AA Subject " + attributeQuery.Subject.ToString());

                ArtifactResponse artifactResponse = ArtifactResponse.SendSamlMessageReceiveAftifactResponse(aaURL, attributeQuery);

                Response attrResponse;
                attrResponse = new ComponentPro.Saml2.Response(artifactResponse.Message);
                System.Diagnostics.Trace.WriteLine("AA reponse " + attrResponse.GetXml().OuterXml);

            }
            catch (Exception e)
            {
                System.Diagnostics.Trace.WriteLine("Execption: " + e.ToString());
                //throw;
            }
            // Get the originally requested resource URL from the relay state.
            string resourceUrl = (string)SamlSettings.CacheProvider.Remove(relayState);
            if (resourceUrl == null)
            {
                throw new ApplicationException("Invalid relay state");
            }

            // Create a login context for the asserted identity.
            FormsAuthentication.SetAuthCookie(userName, false);
            

            // Redirect to the originally requested resource URL.
            page.Response.Redirect(resourceUrl, false);
        }