/// <summary>
        /// helper method for searching object in AD by UID
        /// </summary>
        /// <param name="uid">Uid of the searched </param>
        /// <param name="oclass">Object class</param>
        /// <param name="options">Operation options</param>
        /// <returns>Connector object found by the Uid</returns>
        private ConnectorObject ADSearchByUid(Uid uid, ObjectClass oclass, OperationOptions options)
        {
            ExchangeUtility.NullCheck(uid, "uid", this.configuration);
            ExchangeUtility.NullCheck(oclass, "oclass", this.configuration);
            if (options == null)
            {
                options = new OperationOptionsBuilder().Build();
            }

            ConnectorObject ret        = null;
            Filter          filter     = FilterBuilder.EqualTo(uid);
            var             translator = base.CreateFilterTranslator(oclass, options);
            IList <string>  queries    = translator.Translate(filter);

            if (queries.Count == 1)
            {
                ResultsHandler handler = delegate(ConnectorObject cobject)
                {
                    ret = cobject;
                    return(false);
                };
                base.ExecuteQuery(oclass, queries[0], handler, options);
            }

            return(ret);
        }
        public void TestSearchByteAttributes()
        {
            OperationOptionsBuilder builder = new OperationOptionsBuilder();

            builder.AttributesToGet = new[] { "attributeByte", "attributeByteMultivalue", "attributeByteArray", "attributeByteArrayMultivalue" };
            var co = GetFacade().GetObject(Test, new Uid("UID01"), builder.Build());

            Assert.IsNotNull(co);

            IList <Object> value = co.GetAttributeByName("attributeByte").Value;

            Assert.AreEqual(1, value.Count);
            Assert.IsInstanceOf(typeof(byte), value[0]);

            value = co.GetAttributeByName("attributeByteMultivalue").Value;
            Assert.AreEqual(2, value.Count);
            Assert.IsInstanceOf(typeof(byte), value[0]);
            Assert.IsInstanceOf(typeof(byte), value[1]);

            value = co.GetAttributeByName("attributeByteArray").Value;
            Assert.AreEqual(1, value.Count);
            Assert.IsInstanceOf(typeof(byte[]), value[0]);

            value = co.GetAttributeByName("attributeByteArrayMultivalue").Value;
            Assert.AreEqual(2, value.Count);
            Assert.IsInstanceOf(typeof(byte[]), value[0]);
            Assert.IsInstanceOf(typeof(byte[]), value[1]);
        }
Exemple #3
0
        /// <summary>
        /// Performs a raw, unfiltered search at the SPI level,
        /// eliminating duplicates from the result set.
        /// </summary>
        /// <param name="search">The search SPI</param>
        /// <param name="oclass">The object class - passed through to
        /// connector so it may be null if the connecor
        /// allowing it to be null. (This is convenient for
        /// unit tests, but will not be the case in general)</param>
        /// <param name="filter">The filter to search on</param>
        /// <param name="handler">The result handler</param>
        /// <param name="options">The options - may be null - will
        /// be cast to an empty OperationOptions</param>
        public SearchResult Search <T>(SearchOp <T> search,
                                       ObjectClass objectClass,
                                       Filter filter,
                                       ResultsHandler handler,
                                       OperationOptions options) where T : class
        {
            Assertions.NullCheck(objectClass, "objectClass");
            if (ObjectClass.ALL.Equals(objectClass))
            {
                throw new System.NotSupportedException("Operation is not allowed on __ALL__ object class");
            }
            Assertions.NullCheck(handler, "handler");
            //convert null into empty
            if (options == null)
            {
                options = new OperationOptionsBuilder().Build();
            }

            SearchResult result = null;

            RawSearcherImpl <T> .RawSearch(search, objectClass, filter, new SearchResultsHandler()
            {
                Handle = obj =>
                {
                    return(handler.Handle(obj));
                },
                HandleResult = obj =>
                {
                    result = obj;
                }
            }, options);

            return(result != null ? result : new SearchResult());
        }
 public virtual void SyncAllCallFailPattern()
 {
     TestCallPattern(new TestOperationPattern()
     {
         MakeCall = facade =>
         {
             // create an empty results handler..
             SyncResultsHandler rh = new SyncResultsHandler()
             {
                 Handle = obj =>
                 {
                     return(true);
                 }
             };
             // call the sync method..
             var builder = new OperationOptionsBuilder();
             builder.Options["FAIL_DELETE"] = true;
             facade.Sync(ObjectClass.ALL, new SyncToken(1), rh, builder.Build());
         },
         CheckCalls = calls =>
         {
             Assert.AreEqual("Sync", GetAndRemoveMethodName(calls));
         }
     });
 }
        // TODO move to appropriate place
        /// <summary>
        /// helper method for searching object in AD by UID
        /// </summary>
        /// <param name="uid">Uid of the searched </param>
        /// <param name="oclass">Object class</param>
        /// <param name="options">Operation options</param>
        /// <returns>Connector object found by the Uid</returns>
        internal ConnectorObject ADSearchByUid(ExchangeConnector connector, Uid uid, ObjectClass oclass, OperationOptions options)
        {
            ExchangeConfiguration configuration = connector.Configuration;

            ExchangeUtility.NullCheck(uid, "uid", configuration);
            ExchangeUtility.NullCheck(oclass, "oclass", configuration);
            if (options == null)
            {
                options = new OperationOptionsBuilder().Build();
            }

            ConnectorObject ret        = null;
            Filter          filter     = FilterBuilder.EqualTo(uid);
            var             translator = connector.ActiveDirectoryConnector.CreateFilterTranslator(oclass, options);
            IList <string>  queries    = translator.Translate(filter);

            if (queries.Count == 1)
            {
                ResultsHandler handler = new ResultsHandler()
                {
                    Handle = cobject =>
                    {
                        ret = cobject;
                        return(false);
                    }
                };
                connector.ActiveDirectoryConnector.ExecuteQuery(oclass, queries[0], handler, options);
            }

            return(ret);
        }
        public void TestTimeout()
        {
            ConnectorInfoManager manager = GetConnectorInfoManager();
            ConnectorInfo        info1   = FindConnectorInfo(manager, "1.0.0.0", "org.identityconnectors.testconnector.TstConnector");

            Assert.IsNotNull(info1);

            APIConfiguration config = info1.CreateDefaultAPIConfiguration();

            config.SetTimeout(SafeType <APIOperation> .ForRawType(typeof(CreateApiOp)), 5000);
            config.SetTimeout(SafeType <APIOperation> .ForRawType(typeof(SearchApiOp)), 5000);
            ConfigurationProperties props    = config.ConfigurationProperties;
            ConfigurationProperty   property = props.GetProperty("numResults");

            // 1000 is several times the remote size between pauses
            property.Value = 2;
            OperationOptionsBuilder opBuilder = new OperationOptionsBuilder();

            opBuilder.SetOption("delay", 10000);

            ConnectorFacade facade1 = ConnectorFacadeFactory.GetInstance().NewInstance(config);

            ICollection <ConnectorAttribute> attrs = CollectionUtil.NewReadOnlySet <ConnectorAttribute>();

            try
            {
                facade1.Create(ObjectClass.ACCOUNT, attrs, opBuilder.Build()).GetUidValue();
                Assert.Fail("expected timeout");
            }
            catch (OperationTimeoutException)
            {
                // expected
            }
            //catch (RemoteWrappedException e)
            //{
            //    Assert.IsTrue(e.Is(typeof(OperationTimeoutException)));
            //}

            try
            {
                facade1.Search(ObjectClass.ACCOUNT, null, new ResultsHandler()
                {
                    Handle = obj =>
                    {
                        return(true);
                    }
                }, opBuilder.Build());
                Assert.Fail("expected timeout");
            }
            catch (OperationTimeoutException)
            {
                // expected
            }
            //catch (RemoteWrappedException e)
            //{
            //    Assert.IsTrue(e.Is(typeof(OperationTimeoutException)));
            //}
        }
        /// <summary>
        /// Implementation of SearchOp.ExecuteQuery
        /// </summary>
        /// <param name="oclass">Object class</param>
        /// <param name="query">Query to execute</param>
        /// <param name="handler">Results handler</param>
        /// <param name="options">Operation options</param>
        public override void ExecuteQuery(
            ObjectClass oclass, string query, ResultsHandler handler, OperationOptions options)
        {
            ExchangeUtility.NullCheck(oclass, "oclass", this.configuration);

            // we handle accounts only
            if (!oclass.Is(ObjectClass.ACCOUNT_NAME))
            {
                base.ExecuteQuery(oclass, query, handler, options);
                return;
            }

            ICollection <string> attsToGet = null;

            if (options != null && options.AttributesToGet != null)
            {
                attsToGet = CollectionUtil.NewList(options.AttributesToGet);
            }

            // delegate to get the exchange attributes if requested
            ResultsHandler filter = delegate(ConnectorObject cobject)
            {
                ConnectorObject filtered = ExchangeUtility.ReplaceAttributes(
                    cobject, attsToGet, AttMapFromAD);
                filtered = this.AddExchangeAttributes(oclass, filtered, attsToGet);
                return(handler(filtered));
            };

            ResultsHandler   handler2use = handler;
            OperationOptions options2use = options;

            if (options != null && options.AttributesToGet != null)
            {
                if (attsToGet.Contains(AttDatabase) || attsToGet.Contains(AttExternalMail) ||
                    attsToGet.Contains(AttRecipientType))
                {
                    // replace Exchange attributes with AD names
                    var newAttsToGet = ExchangeUtility.FilterReplace(attsToGet, AttMap2AD);

                    // we have to remove recipient type, as it is unknown to AD
                    newAttsToGet.Remove(AttRecipientType);

                    // build new op options
                    var      builder         = new OperationOptionsBuilder(options);
                    string[] attributesToGet = new string[newAttsToGet.Count];
                    newAttsToGet.CopyTo(attributesToGet, 0);
                    builder.AttributesToGet = attributesToGet;
                    options2use             = builder.Build();
                    handler2use             = filter;
                }
            }

            base.ExecuteQuery(oclass, query, handler2use, options2use);
        }
        public void TestCreateTestRunAs()
        {
            ICollection <ConnectorAttribute> createAttributes = GetTestCreateConnectorObject("TEST5");
            var builder = new OperationOptionsBuilder();

            builder.RunAsUser       = "******";
            builder.RunWithPassword = new GuardedString(GetSecure(Password));
            Uid uid = GetFacade().Create(Test, createAttributes, builder.Build());

            Assert.AreEqual(uid.GetUidValue(), "TEST5");
        }
        public void TestConnectionPooling()
        {
            ConnectorPoolManager.Dispose();
            ConnectorInfoManager manager =
                GetConnectorInfoManager();
            ConnectorInfo info1 =
                FindConnectorInfo(manager,
                                  "1.0.0.0",
                                  "org.identityconnectors.testconnector.TstConnector");

            Assert.IsNotNull(info1);
            //reset connection count
            {
                //trigger TstConnection.init to be called
                APIConfiguration config2 =
                    info1.CreateDefaultAPIConfiguration();
                config2.ConfigurationProperties.GetProperty("resetConnectionCount").Value = (true);
                ConnectorFacade facade2 =
                    ConnectorFacadeFactory.GetInstance().NewInstance(config2);
                facade2.Schema(); //force instantiation
            }

            APIConfiguration config =
                info1.CreateDefaultAPIConfiguration();

            config.ConnectorPoolConfiguration.MinIdle = (0);
            config.ConnectorPoolConfiguration.MaxIdle = (0);

            ConnectorFacade facade1 =
                ConnectorFacadeFactory.GetInstance().NewInstance(config);

            OperationOptionsBuilder builder = new OperationOptionsBuilder();

            builder.SetOption("testPooling", "true");
            OperationOptions options = builder.Build();
            ICollection <ConnectorAttribute> attrs = CollectionUtil.NewReadOnlySet <ConnectorAttribute>();

            Assert.AreEqual("1", facade1.Create(ObjectClass.ACCOUNT, attrs, options).GetUidValue());
            Assert.AreEqual("2", facade1.Create(ObjectClass.ACCOUNT, attrs, options).GetUidValue());
            Assert.AreEqual("3", facade1.Create(ObjectClass.ACCOUNT, attrs, options).GetUidValue());
            Assert.AreEqual("4", facade1.Create(ObjectClass.ACCOUNT, attrs, options).GetUidValue());
            config =
                info1.CreateDefaultAPIConfiguration();
            config.ConnectorPoolConfiguration.MinIdle = (1);
            config.ConnectorPoolConfiguration.MaxIdle = (2);
            facade1 =
                ConnectorFacadeFactory.GetInstance().NewInstance(config);
            Assert.AreEqual("5", facade1.Create(ObjectClass.ACCOUNT, attrs, options).GetUidValue());
            Assert.AreEqual("5", facade1.Create(ObjectClass.ACCOUNT, attrs, options).GetUidValue());
            Assert.AreEqual("5", facade1.Create(ObjectClass.ACCOUNT, attrs, options).GetUidValue());
            Assert.AreEqual("5", facade1.Create(ObjectClass.ACCOUNT, attrs, options).GetUidValue());
        }
        public void TestOperationOptions()
        {
            OperationOptionsBuilder builder = new OperationOptionsBuilder();

            builder.SetOption("foo", "bar");
            builder.SetOption("foo2", "bar2");
            OperationOptions v1 = builder.Build();
            OperationOptions v2 = (OperationOptions)CloneObject(v1);

            Assert.AreEqual(2, v2.Options.Count);
            Assert.AreEqual("bar", v2.Options["foo"]);
            Assert.AreEqual("bar2", v2.Options["foo2"]);
        }
Exemple #11
0
 /// <summary>
 /// Performs a raw, unfiltered search at the SPI level,
 /// eliminating duplicates from the result set.
 /// </summary>
 /// <param name="search">The search SPI</param>
 /// <param name="oclass">The object class - passed through to
 /// connector so it may be null if the connecor
 /// allowing it to be null. (This is convenient for
 /// unit tests, but will not be the case in general)</param>
 /// <param name="filter">The filter to search on</param>
 /// <param name="handler">The result handler</param>
 /// <param name="options">The options - may be null - will
 /// be cast to an empty OperationOptions</param>
 public void Search <T>(SearchOp <T> search,
                        ObjectClass oclass,
                        Filter filter,
                        ResultsHandler handler,
                        OperationOptions options) where T : class
 {
     if (options == null)
     {
         options = new OperationOptionsBuilder().Build();
     }
     RawSearcherImpl <T> .RawSearch(
         search, oclass, filter, handler, options);
 }
        public void TestSearchAttributes()
        {
            OperationOptionsBuilder builder = new OperationOptionsBuilder();

            builder.AttributesToGet = new[] { "attributeString", "attributeMap" };
            GetFacade().Search(Test, null, new ResultsHandler
            {
                Handle = connectorObject =>
                {
                    Assert.AreEqual(4, connectorObject.GetAttributes().Count);
                    return(true);
                }
            }, builder.Build());
        }
        public void TestCreateTestRunAsFailed()
        {
            ICollection <ConnectorAttribute> createAttributes = GetTestCreateConnectorObject("TEST5");
            var builder = new OperationOptionsBuilder();

            builder.RunAsUser = "******";
            var secret = new SecureString();

            "__FAKE__".ToCharArray().ToList().ForEach(secret.AppendChar);
            builder.RunWithPassword = new GuardedString(secret);
            Uid uid = GetFacade().Create(Test, createAttributes, builder.Build());

            Assert.AreEqual(uid.GetUidValue(), "TEST5");
        }
Exemple #14
0
        /// <summary>
        /// Builds new Operation options and add the specified attribute names as
        /// AttributesToGet (add to existing AttributesToGet)
        /// </summary>
        /// <param name="options">Existing Operation Options</param>
        /// <param name="attNames">attribute names to be add to AttributeToGet</param>
        /// <returns>New Operation Options</returns>
        internal static OperationOptions AddAttributeToOptions(OperationOptions options, params string[] attNames)
        {
            OperationOptionsBuilder optionsBuilder = new OperationOptionsBuilder(options);
            List <string>           attsToGet      = new List <string>();

            if (options.AttributesToGet != null)
            {
                attsToGet.AddRange(options.AttributesToGet);
            }

            foreach (string attName in attNames)
            {
                attsToGet.Add(attName);
            }

            optionsBuilder.AttributesToGet = attsToGet.ToArray();
            return(optionsBuilder.Build());
        }
        public virtual void TestSearch2()
        {
            ConnectorFacade search = GetFacade();

            for (int i = 0; i < 100; i++)
            {
                ICollection <ConnectorAttribute> co = GetTestCreateConnectorObject(string.Format("TEST{0:D5}", i));
                co.Add(ConnectorAttributeBuilder.Build("sortKey", i));
                search.Create(ObjectClass.ACCOUNT, co, null);
            }

            OperationOptionsBuilder builder = new OperationOptionsBuilder {
                PageSize = 10, SortKeys = new[] { new SortKey("sortKey", false) }
            };
            SearchResult result = null;

            ICollection <ConnectorObject> resultSet = new HashSet <ConnectorObject>();
            int pageIndex = 0;
            int index     = 101;

            while ((result = search.Search(ObjectClass.ACCOUNT, FilterBuilder.StartsWith(ConnectorAttributeBuilder.Build(Name.NAME, "TEST")), new ResultsHandler()
            {
                Handle = connectorObject =>
                {
                    int?idx = ConnectorAttributeUtil.GetIntegerValue(connectorObject.GetAttributeByName("sortKey"));
                    Assert.IsTrue(idx < index);
                    if (idx != null)
                    {
                        index = (int)idx;
                    }
                    resultSet.Add(connectorObject);
                    return(true);
                }
            }, builder.Build())).PagedResultsCookie != null)
            {
                builder = new OperationOptionsBuilder(builder.Build())
                {
                    PagedResultsCookie = result.PagedResultsCookie
                };
                Assert.AreEqual(10 * ++pageIndex, resultSet.Count);
            }
            Assert.AreEqual(9, pageIndex);
            Assert.AreEqual(100, resultSet.Count);
        }
        public void TestPagedSearch()
        {
            ConnectorPoolManager.Dispose();
            ConnectorInfoManager manager = GetConnectorInfoManager();
            ConnectorInfo        info1   = FindConnectorInfo(manager, "1.0.0.0", "org.identityconnectors.testconnector.TstStatefulPoolableConnector");

            Assert.IsNotNull(info1);

            APIConfiguration config = info1.CreateDefaultAPIConfiguration();

            config.ProducerBufferSize = 0;

            config.ConnectorPoolConfiguration.MinIdle = 1;
            config.ConnectorPoolConfiguration.MaxIdle = 2;
            config.ResultsHandlerConfiguration.FilteredResultsHandlerInValidationMode = true;           // for paged searches, the filtered results handler should be either disabled or put into validation mode

            ConnectorFacade facade1 = ConnectorFacadeFactory.GetInstance().NewInstance(config);

            OperationOptionsBuilder builder = new OperationOptionsBuilder();

            builder.PageSize = 10;
            builder.SetSortKeys(new ICF.SortKey(Name.NAME, true));

            SearchResult searchResult = null;
            ISet <Uid>   UIDs         = new HashSet <Uid>();

            int iteration = 0;

            do
            {
                if (null != searchResult)
                {
                    builder.PagedResultsCookie = searchResult.PagedResultsCookie;
                }

                int size = 0;
                searchResult = facade1.Search(ObjectClass.ACCOUNT, null, new ResultsHandler()
                {
                    Handle = obj =>
                    {
                        if (size >= 10)
                        {
                            Assert.Fail("More then 10 objects was handled!");
                        }
                        size++;
                        if (UIDs.Contains(obj.Uid))
                        {
                            Assert.Fail("Duplicate Entry in results");
                        }
                        return(UIDs.Add(obj.Uid));
                    }
                }, builder.Build());
                iteration++;
                Assert.IsNotNull(searchResult);
                Assert.AreEqual(searchResult.RemainingPagedResults, 100 - (iteration * 10));
            } while (searchResult.PagedResultsCookie != null);

            // Search with paged results offset

            builder                    = new OperationOptionsBuilder();
            builder.PageSize           = 10;
            builder.PagedResultsOffset = 5;
            builder.SetSortKeys(new ICF.SortKey(Name.NAME, true));

            searchResult = null;

            UIDs.Clear();
            Filter filter = FilterBuilder.EqualTo(ConnectorAttributeBuilder.BuildEnabled(true));

            iteration = 0;
            do
            {
                if (null != searchResult)
                {
                    builder.PagedResultsCookie = searchResult.PagedResultsCookie;
                }

                int size = 0;
                searchResult = facade1.Search(ObjectClass.ACCOUNT, filter, new ResultsHandler()
                {
                    Handle = obj =>
                    {
                        if (size >= 10)
                        {
                            Assert.Fail("More then 10 objects was handled!");
                        }
                        size++;
                        if (UIDs.Contains(obj.Uid))
                        {
                            Assert.Fail("Duplicate Entry in results");
                        }
                        return(UIDs.Add(obj.Uid));
                    }
                }, builder.Build());
                iteration++;
                Assert.IsNotNull(searchResult);
                Assert.AreEqual(searchResult.RemainingPagedResults, Math.Max(50 - (iteration * 15), 0));
            } while (searchResult.PagedResultsCookie != null);
        }