protected override Action Start(ClientAuthenticationValidator validator, EndpointAddress serviceAddress)
        {
            VtortConnectorServiceHost host = new VtortConnectorServiceHost(validator, serviceAddress.Uri);
            host.Open();

            return () => host.Close();
        }
        public ConnectorServiceHost(ClientAuthenticationValidator validator, params Uri[] baseAddresses)
            : base(typeof(WcfWebsocket), baseAddresses)
        {
            if (validator == null)
            {
                throw new ArgumentNullException("validator");
            }

            // Add a custom authentication validator
            Credentials.UserNameAuthentication.UserNamePasswordValidationMode = UserNamePasswordValidationMode.Custom;
            Credentials.UserNameAuthentication.CustomUserNamePasswordValidator = validator;

            // Add a custom authorization policy
            var policies = new List<IAuthorizationPolicy> { validator };
            Authorization.PrincipalPermissionMode = PrincipalPermissionMode.Custom;
            Authorization.ExternalAuthorizationPolicies = policies.AsReadOnly();

            /*
            foreach (var cd in ImplementedContracts.Values)
            {
                cd.Behaviors.Add(new WebSocketServiceInstanceProvider());
            }*/
        }
        public ConnectorServiceHostFactory()
        {
            NameValueCollection settings = ConfigurationManager.AppSettings;
            String authenticatorType = settings.Get(typeof(ClientAuthenticationValidator).FullName);
            if (String.IsNullOrEmpty(authenticatorType))
            {
                throw new Exception("Missing required app configuration: " +
                                    typeof(ClientAuthenticationValidator).FullName);
            }

            var type = AppDomain.CurrentDomain.GetAssemblies()
                .Where(a => !a.IsDynamic)
                .SelectMany(a => a.GetTypes())
                .FirstOrDefault(t => t.FullName.Equals(authenticatorType));
            if (type != null)
            {
                _authenticator = (ClientAuthenticationValidator)Activator.CreateInstance(type);
                //Add Principal and SharedKey
                String keyHash = settings.Get(PropKey);
                if (null != keyHash)
                {
                    _authenticator.Add(new SingleTenantPrincipal(new ConnectorFramework()), keyHash);
                }
            }
            else
            {
                Trace.TraceWarning("Type not found: " + authenticatorType);
            }

            if (null == _authenticator)
            {
                throw new ArgumentNullException(authenticatorType);
            }
        }
 public ConnectorServiceHostFactory(ClientAuthenticationValidator authenticator)
 {
     if (authenticator == null)
     {
         throw new ArgumentNullException("authenticator");
     }
     _authenticator = authenticator;
 }
 protected override Action Start(ClientAuthenticationValidator validator, EndpointAddress serviceAddress)
 {
     return null;
 }
        protected override Action Start(ClientAuthenticationValidator validator, EndpointAddress serviceAddress)
        {
            ServiceHost host = new ConnectorServiceHost(validator, serviceAddress.Uri);

            CustomBinding binding = new CustomBinding();
            binding.Elements.Add(new ByteStreamMessageEncodingBindingElement());

            HttpTransportBindingElement transport = new HttpTransportBindingElement
            {
                WebSocketSettings =
                {
                    TransportUsage = WebSocketTransportUsage.Always,
                    CreateNotificationOnConnection = true,
                    SubProtocol = "v1.openicf.forgerock.org"
                },
                Realm = "openicf",
                AuthenticationScheme = AuthenticationSchemes.Basic,
            };

            binding.Elements.Add(transport);
            host.AddServiceEndpoint(typeof (IWebSocketService), binding, "");

            host.Open();

            return () => { host.Close(); };
        }
 protected abstract Action Start(ClientAuthenticationValidator validator, EndpointAddress serviceAddress);
        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 VtortConnectorServiceHost(ClientAuthenticationValidator validator, params Uri[] baseAddresses)
 {
     _validator = validator;
     _endPointUri = baseAddresses[0];
 }
        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;
            }
        }