Exemplo n.º 1
0
        /// <summary>
        /// Get the singleton instance of the <see cref="ConnectorServer" />.
        /// </summary>
        public static ConnectorServer NewInstance()
        {
            SafeType <ConnectorServer> type =
                SafeType <ConnectorServer> .ForRawType(Type.GetType(IMPL_NAME, true));

            return(type.CreateInstance());
        }
        ///// End of From Groovy

        //[Test]
        //[Category("Update")]
        //public void TestUpdate0()
        //{
        //    Uid uid = GetFacade().Update(ObjectClass.ACCOUNT, new Uid("Foo"), GetTestCreateConnectorObject("Foo"), null);
        //    Assert.NotNull(uid, "The Uid is null");
        //}

        //[Test]
        //[Category("Update")]
        //[ExpectedException(typeof(UnknownUidException))]
        //public void TestUpdate1()
        //{
        //    GetFacade().Update(Test, new Uid("TEST1"), GetTestUpdateConnectorObject("TEST1"), null);
        //}

        //[Test]
        //[Category("Update")]
        //[ExpectedException(typeof(InvalidAttributeValueException))]
        //public void TestUpdate2()
        //{
        //    GetFacade().Update(Test, new Uid("TEST2"), GetTestUpdateConnectorObject("TEST2"), null);
        //}

        //[Test]
        //[Category("Update")]
        //[ExpectedException(typeof(ArgumentException))]
        //public void TestUpdate3()
        //{
        //    GetFacade().Update(Test, new Uid("TEST3"), GetTestUpdateConnectorObject("TEST3"), null);
        //}

        //[Test]
        //[Category("Update")]
        //[ExpectedException(typeof(PreconditionFailedException))]
        //public void TestUpdate4()
        //{
        //    GetFacade().Update(Test, new Uid("TEST4"), GetTestUpdateConnectorObject("TEST4"), null);
        //}

        //[Test]
        //[Category("Update")]
        //[ExpectedException(typeof(PreconditionRequiredException))]
        //public void TestUpdate5()
        //{
        //    GetFacade().Update(Test, new Uid("TEST5"), GetTestUpdateConnectorObject("TEST5"), null);
        //}

        //[Test]
        //[Category("Update")]
        //[ExpectedException(typeof(RuntimeException))]
        //public void TestUpdate7()
        //{
        //    GetFacade().Update(ObjectClass.GROUP, new Uid("Group1"), GetTestUpdateConnectorObject("Group1"), null);
        //}

        protected ConnectorFacade GetFacade()
        {
            var f = CreateConnectorFacade(SafeType <Connector> .ForRawType(typeof(MsPowerShellConnector)));

            Assert.NotNull(f, "The Facade Creation fails");
            return(f);
        }
        public ConnectorFacade CreateConnectorFacade(SafeType <Connector> clazz)
        {
            if (null == _facade)
            {
                PropertyBag propertyBag = TestHelpers.GetProperties(clazz.RawType);

                string assemblyFolder         = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
                string testModulePath         = Path.GetFullPath(Path.Combine(assemblyFolder, "..\\..\\..\\Samples\\Tests\\TestModule.psm1"));
                string objectChacheModulePath = typeof(ObjectCacheLibrary).Assembly.Location;

                var importModules = new string[] { testModulePath, objectChacheModulePath };


                APIConfiguration impl = TestHelpers.CreateTestConfiguration(clazz, propertyBag, "configuration");
                impl.ConfigurationProperties.SetPropertyValue("PsModulesToImport", importModules);
                //
                impl.ProducerBufferSize = 0;
                impl.ResultsHandlerConfiguration.EnableAttributesToGetSearchResultsHandler = false;
                impl.ResultsHandlerConfiguration.EnableCaseInsensitiveFilter     = false;
                impl.ResultsHandlerConfiguration.EnableFilteredResultsHandler    = false;
                impl.ResultsHandlerConfiguration.EnableNormalizingResultsHandler = false;

                //We timeout after 10s
                impl.SetTimeout(SafeType <APIOperation> .ForRawType(typeof(CreateApiOp)), 10000);
                impl.SetTimeout(SafeType <APIOperation> .ForRawType(typeof(UpdateApiOp)), 10000);
                impl.SetTimeout(SafeType <APIOperation> .ForRawType(typeof(DeleteApiOp)), 10000);
                _facade = ConnectorFacadeFactory.GetInstance().NewInstance(impl);
            }
            return(_facade);
        }
Exemplo n.º 4
0
 public ConnectorClassAttribute(String connectorDisplayNameKey, String connectorCategoryKey,
                                Type connectorConfigurationClass)
 {
     _connectorDisplayNameKey     = connectorDisplayNameKey;
     _connectorCategoryKey        = connectorCategoryKey;
     _connectorConfigurationClass = SafeType <Configuration> .ForRawType(connectorConfigurationClass);
 }
        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)));
            //}
        }
Exemplo n.º 6
0
        public void TestSafeType()
        {
            //compile-time type safe
            SafeType <APIOperation> op =
                SafeType <APIOperation> .Get <ScriptOnResourceApiOp>();

            Assert.AreEqual(typeof(ScriptOnResourceApiOp), op.RawType);
            //runtime type safe. needed for marshalling code, etc
            op =
                SafeType <APIOperation> .ForRawType(typeof(SchemaApiOp));

            Assert.AreEqual(typeof(SchemaApiOp), op.RawType);
        }
Exemplo n.º 7
0
        public virtual Schema Schema()
        {
            if (null == _schema)
            {
                var builder = new SchemaBuilder(SafeType <Connector> .Get(this));
                // Account
                var accountInfoBuilder = new ObjectClassInfoBuilder();
                accountInfoBuilder.AddAttributeInfo(Name.INFO);
                accountInfoBuilder.AddAttributeInfo(OperationalAttributeInfos.PASSWORD);
                accountInfoBuilder.AddAttributeInfo(PredefinedAttributeInfos.GROUPS);
                accountInfoBuilder.AddAttributeInfo(ConnectorAttributeInfoBuilder.Build("firstName"));
                accountInfoBuilder.AddAttributeInfo(
                    ConnectorAttributeInfoBuilder.Define("lastName").SetRequired(true).Build());
                builder.DefineObjectClass(accountInfoBuilder.Build());

                // Group
                var groupInfoBuilder = new ObjectClassInfoBuilder();
                groupInfoBuilder.ObjectType = ObjectClass.GROUP_NAME;
                groupInfoBuilder.AddAttributeInfo(Name.INFO);
                groupInfoBuilder.AddAttributeInfo(PredefinedAttributeInfos.DESCRIPTION);
                groupInfoBuilder.AddAttributeInfo(
                    ConnectorAttributeInfoBuilder.Define("members")
                    .SetCreatable(false)
                    .SetUpdateable(false)
                    .SetMultiValued(true)
                    .Build());

                // Only the CRUD operations
                builder.DefineObjectClass(groupInfoBuilder.Build(), SafeType <SPIOperation> .Get <CreateOp>(),
                                          SafeType <SPIOperation> .ForRawType(typeof(SearchOp <>)), SafeType <SPIOperation> .Get <UpdateOp>(),
                                          SafeType <SPIOperation> .Get <DeleteOp>());

                // Operation Options
                builder.DefineOperationOption(OperationOptionInfoBuilder.BuildAttributesToGet(),
                                              SafeType <SPIOperation> .ForRawType(typeof(SearchOp <>)));

                // Support paged Search
                builder.DefineOperationOption(OperationOptionInfoBuilder.BuildPageSize(),
                                              SafeType <SPIOperation> .ForRawType(typeof(SearchOp <>)));
                builder.DefineOperationOption(OperationOptionInfoBuilder.BuildPagedResultsCookie(),
                                              SafeType <SPIOperation> .ForRawType(typeof(SearchOp <>)));

                // Support to execute operation with provided credentials
                builder.DefineOperationOption(OperationOptionInfoBuilder.BuildRunAsUser());
                builder.DefineOperationOption(OperationOptionInfoBuilder.BuildRunWithPassword());

                _schema = builder.Build();
            }
            return(_schema);
        }
Exemplo n.º 8
0
        private LocalConnectorInfoImpl CreateConnectorInfo(Assembly assembly,
                                                           Type rawConnectorClass,
                                                           ConnectorClassAttribute attribute)
        {
            String fileName = assembly.Location;

            if (!typeof(Connector).IsAssignableFrom(rawConnectorClass))
            {
                String MSG = ("File " + fileName +
                              " declares a connector " + rawConnectorClass +
                              " that does not implement Connector.");
                throw new ConfigurationException(MSG);
            }
            SafeType <Connector> connectorClass =
                SafeType <Connector> .ForRawType(rawConnectorClass);

            SafeType <Configuration> connectorConfigurationClass = attribute.ConnectorConfigurationType;

            if (connectorConfigurationClass == null)
            {
                String MSG = ("File " + fileName +
                              " contains a ConnectorInfo attribute " +
                              "with no connector configuration class.");
                throw new ConfigurationException(MSG);
            }
            String connectorDisplayNameKey =
                attribute.ConnectorDisplayNameKey;

            if (connectorDisplayNameKey == null)
            {
                String MSG = ("File " + fileName +
                              " contains a ConnectorInfo attribute " +
                              "with no connector display name.");
                throw new ConfigurationException(MSG);
            }
            ConnectorKey key =
                new ConnectorKey(assembly.GetName().Name,
                                 assembly.GetName().Version.ToString(),
                                 connectorClass.RawType.Namespace + "." + connectorClass.RawType.Name);
            LocalConnectorInfoImpl rv = new LocalConnectorInfoImpl();

            rv.ConnectorClass = connectorClass;
            rv.ConnectorConfigurationClass = connectorConfigurationClass;
            rv.ConnectorDisplayNameKey     = connectorDisplayNameKey;
            rv.ConnectorKey            = key;
            rv.DefaultAPIConfiguration = CreateDefaultAPIConfiguration(rv);
            rv.Messages = LoadMessages(assembly, rv, attribute.MessageCatalogPaths);
            return(rv);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Loads a class from the FrameworkInternal module
        /// </summary>
        /// <param name="typeName"></param>
        /// <returns></returns>
        public static SafeType <T> LoadType <T>(String typeName) where T : class
        {
            Assembly assembly;

            lock (LOCK)
            {
                if (_assembly == null)
                {
                    AssemblyName assemName = new AssemblyName();
                    assemName.Name = "FrameworkInternal";
                    _assembly      = Assembly.Load(assemName);
                }
                assembly = _assembly;
            }

            return(SafeType <T> .ForRawType(assembly.GetType(typeName, true)));
        }
Exemplo n.º 10
0
        static FrameworkUtil()
        {
            IDictionary <SafeType <SPIOperation>, SafeType <APIOperation> > temp =
                new Dictionary <SafeType <SPIOperation>, SafeType <APIOperation> >();

            temp[SafeType <SPIOperation> .Get <AuthenticateOp>()] =
                SafeType <APIOperation> .Get <AuthenticationApiOp>();

            temp[SafeType <SPIOperation> .Get <ResolveUsernameOp>()] =
                SafeType <APIOperation> .Get <ResolveUsernameApiOp>();

            temp[SafeType <SPIOperation> .Get <CreateOp>()] =
                SafeType <APIOperation> .Get <CreateApiOp>();

            temp[SafeType <SPIOperation> .Get <DeleteOp>()] =
                SafeType <APIOperation> .Get <DeleteApiOp>();

            temp[SafeType <SPIOperation> .ForRawType(typeof(SearchOp <>))] =
                SafeType <APIOperation> .Get <SearchApiOp>();

            temp[SafeType <SPIOperation> .Get <UpdateOp>()] =
                SafeType <APIOperation> .Get <UpdateApiOp>();

            temp[SafeType <SPIOperation> .Get <UpdateAttributeValuesOp>()] =
                SafeType <APIOperation> .Get <UpdateApiOp>();

            temp[SafeType <SPIOperation> .Get <SchemaOp>()] =
                SafeType <APIOperation> .Get <SchemaApiOp>();

            temp[SafeType <SPIOperation> .Get <TestOp>()] =
                SafeType <APIOperation> .Get <TestApiOp>();

            temp[SafeType <SPIOperation> .Get <ScriptOnConnectorOp>()] =
                SafeType <APIOperation> .Get <ScriptOnConnectorApiOp>();

            temp[SafeType <SPIOperation> .Get <ScriptOnResourceOp>()] =
                SafeType <APIOperation> .Get <ScriptOnResourceApiOp>();

            temp[SafeType <SPIOperation> .Get <SyncOp>()] =
                SafeType <APIOperation> .Get <SyncApiOp>();

            SPI_TO_API = CollectionUtil.NewReadOnlyDictionary(temp);

            CONFIG_SUPPORTED_TYPES = CollectionUtil.NewReadOnlySet <Type>
                                     (
                typeof(string),
                typeof(long),
                typeof(long?),
                typeof(char),
                typeof(char?),
                typeof(double),
                typeof(double?),
                typeof(float),
                typeof(float?),
                typeof(int),
                typeof(int?),
                typeof(bool),
                typeof(bool?),
                typeof(Uri),
                typeof(FileName),
                typeof(GuardedByteArray),
                typeof(GuardedString),
                typeof(Script)
                                     );
            ATTR_SUPPORTED_TYPES = CollectionUtil.NewReadOnlySet <Type>
                                   (
                typeof(string),
                typeof(long),
                typeof(long?),
                typeof(char),
                typeof(char?),
                typeof(double),
                typeof(double?),
                typeof(float),
                typeof(float?),
                typeof(int),
                typeof(int?),
                typeof(bool),
                typeof(bool?),
                typeof(byte),
                typeof(byte?),
                typeof(byte[]),
                typeof(BigDecimal),
                typeof(BigInteger),
                typeof(GuardedByteArray),
                typeof(GuardedString),
                typeof(IDictionary <object, object>)
                                   );
        }