public override bool Equals(Object o) { if (o is RemoteFrameworkConnectionInfo) { RemoteFrameworkConnectionInfo other = (RemoteFrameworkConnectionInfo)o; if (!Object.Equals(Host, other.Host)) { return(false); } if (Port != other.Port) { return(false); } if (UseSSL != other.UseSSL) { return(false); } if (CertificateValidationCallback == null || other.CertificateValidationCallback == null) { if (CertificateValidationCallback != null || other.CertificateValidationCallback != null) { return(false); } } else { if (!CertificateValidationCallback.Equals (other.CertificateValidationCallback)) { return(false); } } if (!Key.Equals(other.Key)) { return(false); } if (Timeout != other.Timeout) { return(false); } return(true); } return(false); }
public RemoteManagerKey(RemoteFrameworkConnectionInfo info) { _host = info.Host; _port = info.Port; }
public override ConnectorInfoManager GetRemoteManager(RemoteFrameworkConnectionInfo info) { RemoteManagerKey key = new RemoteManagerKey(info); lock (REMOTE_LOCK) { RemoteConnectorInfoManagerImpl rv = CollectionUtil.GetValue(_remoteManagerCache, key, null); if (rv == null) { rv = new RemoteConnectorInfoManagerImpl(info); } _remoteManagerCache[key] = rv; return rv.Derive(info); } }
public abstract ConnectorInfoManager GetRemoteManager(RemoteFrameworkConnectionInfo info);
public RemoteFrameworkConnection(RemoteFrameworkConnectionInfo info) { Init(info); }
private void Init(RemoteFrameworkConnectionInfo connectionInfo) { IPAddress[] addresses = Dns.GetHostAddresses(connectionInfo.Host); TcpClient client = new TcpClient(addresses[0].AddressFamily); client.SendTimeout = connectionInfo.Timeout; client.ReceiveTimeout = connectionInfo.Timeout; client.Connect(addresses[0], connectionInfo.Port); Stream stream; try { stream = client.GetStream(); } catch (Exception) { try { client.Close(); } catch (Exception) { } throw; } try { if (connectionInfo.UseSSL) { if (connectionInfo.CertificateValidationCallback != null) { RemoteCertificateValidationCallback callback = connectionInfo.CertificateValidationCallback; stream = new SslStream( stream, false, callback); } else { stream = new SslStream(stream, false); } ((SslStream)stream).AuthenticateAsClient(connectionInfo.Host, new X509CertificateCollection(new X509Certificate[0]), SslProtocols.Tls, false); } } catch (Exception) { try { stream.Close(); } catch (Exception) { } try { client.Close(); } catch (Exception) { } throw; } Init(client, stream); }
/// <summary> /// Derives another RemoteConnectorInfoManagerImpl with /// a different RemoteFrameworkConnectionInfo but with the /// same metadata /// </summary> /// <param name="info"></param> public RemoteConnectorInfoManagerImpl Derive(RemoteFrameworkConnectionInfo info) { RemoteConnectorInfoManagerImpl rv = new RemoteConnectorInfoManagerImpl(); IList<Object> remoteInfosObj = (IList<Object>)SerializerUtil.CloneObject(_connectorInfo); IList<ConnectorInfo> remoteInfos = CollectionUtil.NewList<object, ConnectorInfo>(remoteInfosObj); foreach (ConnectorInfo remoteInfo in remoteInfos) { ((RemoteConnectorInfoImpl)remoteInfo).RemoteConnectionInfo = (info); } rv._connectorInfo = CollectionUtil.AsReadOnlyList(remoteInfos); return rv; }
public RemoteConnectorInfoManagerImpl(RemoteFrameworkConnectionInfo info) { using (RemoteFrameworkConnection connection = new RemoteFrameworkConnection(info)) { connection.WriteObject(CultureInfo.CurrentUICulture); connection.WriteObject(info.Key); connection.WriteObject(new HelloRequest(HelloRequest.CONNECTOR_INFO)); HelloResponse response = (HelloResponse)connection.ReadObject(); if (response.Exception != null) { throw response.Exception; } IList<RemoteConnectorInfoImpl> remoteInfos = response.ConnectorInfos; //populate transient fields not serialized foreach (RemoteConnectorInfoImpl remoteInfo in remoteInfos) { remoteInfo.RemoteConnectionInfo = info; } _connectorInfo = CollectionUtil.NewReadOnlyList<RemoteConnectorInfoImpl, ConnectorInfo>(remoteInfos); } }
protected override ConnectorInfoManager GetConnectorInfoManager() { TestUtil.InitializeLogging(); GuardedString str = new GuardedString(); str.AppendChar('c'); str.AppendChar('h'); str.AppendChar('a'); str.AppendChar('n'); str.AppendChar('g'); str.AppendChar('e'); str.AppendChar('i'); str.AppendChar('t'); #if DEBUG const int PORT = 58762; #else const int PORT = 58761; #endif /*X509Store store = new X509Store("TestCertificateStore", StoreLocation.CurrentUser); store.Open(OpenFlags.ReadOnly|OpenFlags.OpenExistingOnly); X509Certificate certificate = store.Certificates[0]; store.Close();*/ X509Certificate2 certificate = new X509Certificate2(CERT_PATH, "changeit"); //Trace.TraceInformation("certificate: "+certificate); _server = ConnectorServer.NewInstance(); _server.Port = PORT; _server.KeyHash = str.GetBase64SHA1Hash(); _server.IfAddress = (IOUtil.GetIPAddress("localhost")); _server.UseSSL = true; _server.ServerCertificate = certificate; _server.Start(); //while ( true ) { // Thread.Sleep(1000); //} ConnectorInfoManagerFactory fact = ConnectorInfoManagerFactory.GetInstance(); MyCertificateValidationCallback callback = new MyCertificateValidationCallback(); RemoteFrameworkConnectionInfo connInfo = new RemoteFrameworkConnectionInfo("localhost", PORT, str, true, callback.Validate, 60000); ConnectorInfoManager manager = fact.GetRemoteManager(connInfo); return manager; }
protected override ConnectorInfoManager GetConnectorInfoManager() { TestUtil.InitializeLogging(); GuardedString str = new GuardedString(); str.AppendChar('c'); str.AppendChar('h'); str.AppendChar('a'); str.AppendChar('n'); str.AppendChar('g'); str.AppendChar('e'); str.AppendChar('i'); str.AppendChar('t'); #if DEBUG const int PORT = 58758; #else const int PORT = 58759; #endif _server = ConnectorServer.NewInstance(); _server.Port = PORT; _server.IfAddress = (IOUtil.GetIPAddress("127.0.0.1")); _server.KeyHash = str.GetBase64SHA1Hash(); _server.Start(); //while ( true ) { // Thread.Sleep(1000); //} ConnectorInfoManagerFactory fact = ConnectorInfoManagerFactory.GetInstance(); RemoteFrameworkConnectionInfo connInfo = new RemoteFrameworkConnectionInfo("127.0.0.1", PORT, str); ConnectorInfoManager manager = fact.GetRemoteManager(connInfo); return manager; }
public virtual void TestFacadeEviction() { ConnectorServer server = ConnectorServer.NewInstance(); try { GuardedString str = new GuardedString(); str.AppendChar('c'); str.AppendChar('h'); str.AppendChar('a'); str.AppendChar('n'); str.AppendChar('g'); str.AppendChar('e'); str.AppendChar('i'); str.AppendChar('t'); #if DEBUG const int PORT = 58760; #else const int PORT = 58761; #endif server.MaxFacadeLifeTime = 1; server.Port = PORT; server.IfAddress = (IOUtil.GetIPAddress("127.0.0.1")); server.KeyHash = str.GetBase64SHA1Hash(); server.Start(); RemoteFrameworkConnectionInfo connInfo = new RemoteFrameworkConnectionInfo("127.0.0.1", PORT, str, false, null, 0); ConnectorInfoManager remoteManager = ConnectorInfoManagerFactory.GetInstance().GetRemoteManager(connInfo); ConnectorInfo remoteInfo = FindConnectorInfo(remoteManager, "1.0.0.0", "org.identityconnectors.testconnector.TstConnector"); ConnectorFacade remoteFacade = ConnectorFacadeFactory.GetInstance(). NewInstance(remoteInfo.CreateDefaultAPIConfiguration()); ManagedConnectorFacadeFactoryImpl managedFactory = (ManagedConnectorFacadeFactoryImpl)ConnectorFacadeFactory.GetManagedInstance(); // Assert it's empty Assert.IsNull(managedFactory.Find(remoteFacade.ConnectorFacadeKey)); remoteFacade.Schema(); // Assert it has one item Assert.IsNotNull(managedFactory.Find(remoteFacade.ConnectorFacadeKey)); Thread.Sleep(new TimeSpan(0, 2, 0)); // Assert it's empty Assert.IsNull(managedFactory.Find(remoteFacade.ConnectorFacadeKey)); } finally { server.Stop(); } }