public void Init()
        {
            try
            {
                ConnectorFramework serverConnectorFramework = new ConnectorFramework();
                ConnectorServerService.ConnectorServerService.InitializeConnectors(serverConnectorFramework.LocalManager);

                foreach (var connectorInfo in serverConnectorFramework.LocalManager.ConnectorInfos)
                {
                    Trace.TraceInformation("Found Connector {0}", connectorInfo.ConnectorKey);
                }

                int freePort = FreePort;
                EndpointAddress serviceAddress =
                    new EndpointAddress(String.Format("http://localhost:{0}/openicf", freePort));

                var secureString = new GuardedString();
                "changeit".ToCharArray().ToList().ForEach(p => secureString.AppendChar(p));

                ClientAuthenticationValidator validator = new ClientAuthenticationValidator();
                validator.Add(new SingleTenantPrincipal(serverConnectorFramework), secureString.GetBase64SHA1Hash());

                _close = Start(validator, serviceAddress);
                _close += () => serverConnectorFramework.Dispose();

                // ----------

                _clientConnectorFramework = new ConnectorFramework();

                _connectionInfo = new RemoteWSFrameworkConnectionInfo
                {
                    RemoteUri = new Uri(String.Format("http://localhost.fiddler:{0}/openicf", freePort)),
                    Principal = ConnectionPrincipal.DefaultName,
                    Password = secureString
                };
            }
            catch (Exception e)
            {
                TraceUtil.TraceException("Failed", e);
                throw;
            }
        }
 public SingleTenantPrincipal(ConnectorFramework connectorFramework)
     : this(new OpenICFServerAdapter(connectorFramework, connectorFramework.LocalManager, false))
 {
     _connectorFramework = connectorFramework;
 }
        protected override void OnStart(string[] args)
        {
            try
            {
                ConnectorFramework connectorFramework = new ConnectorFramework();
                InitializeConnectors(connectorFramework.LocalManager);

                NameValueCollection settings = ConfigurationManager.AppSettings;

                String keyHash = settings.Get(PropKey);
                if (keyHash == null)
                {
                    throw new Org.IdentityConnectors.Framework.Common.Exceptions.ConfigurationException(
                        "Missing required configuration property: " + PropKey);
                }

                ClientAuthenticationValidator validator = new ClientAuthenticationValidator();
                validator.Add(new SingleTenantPrincipal(connectorFramework), keyHash);

                String facadeLifeTimeStr = settings.Get(PropFacadeLifetime);
                if (facadeLifeTimeStr != null)
                {
                    // _server.MaxFacadeLifeTime = Int32.Parse(facedeLifeTimeStr);
                }

                String disableWcf = settings.Get("disableWcf");
                OperatingSystem os = Environment.OSVersion;
                if (disableWcf == null && (os.Platform == PlatformID.Win32NT) &&
                    ((os.Version.Major > 6) || ((os.Version.Major == 6) && (os.Version.Minor >= 2))))
                {
                    ServiceHost host = new ConnectorServiceHost(validator);
                    host.Open();

                    _closeAction = () => host.Close();
                    Trace.TraceInformation("Started WCF connector server");
                }
                else
                {
                    Uri[] endpointUri = ExtractEndPoint();
                    if (endpointUri == null)
                    {
                        throw new Org.IdentityConnectors.Framework.Common.Exceptions.ConfigurationException(
                            "Missing required baseAddress");
                    }
                    VtortConnectorServiceHost host = new VtortConnectorServiceHost(validator, endpointUri);
                    host.Open();

                    _closeAction = () => host.Close();
                    Trace.TraceInformation("Started WebSocketListener connector server");
                }
            }
            catch (Exception e)
            {
                TraceUtil.TraceException("Exception occured starting connector server", e);
                throw;
            }
        }