public Object Invoke(Object proxy, MethodInfo method, Object[] args) { //don't proxy toString, hashCode, or equals if (method.DeclaringType.Equals(typeof(object))) { return(method.Invoke(this, args)); } //partition arguments into arguments that can //be simply marshalled as part of the request and //those that are response handlers IList <Object> simpleMarshallArgs = CollectionUtil.NewList(args); ObjectStreamHandler streamHandlerArg = ExtractStreamHandler(ReflectionUtil.GetParameterTypes(method), simpleMarshallArgs); //build the request object RemoteConnectorInfoImpl connectorInfo = (RemoteConnectorInfoImpl)_configuration.ConnectorInfo; RemoteFrameworkConnectionInfo connectionInfo = connectorInfo.RemoteConnectionInfo; OperationRequest request = new OperationRequest( connectorInfo.ConnectorKey, _configuration, _operation, method.Name, simpleMarshallArgs); //create the connection RemoteFrameworkConnection connection = new RemoteFrameworkConnection(connectionInfo); try { connection.WriteObject(CultureInfo.CurrentUICulture); connection.WriteObject(connectionInfo.Key); //send the request connection.WriteObject(request); //now process each response stream (if any) if (streamHandlerArg != null) { HandleStreamResponse(connection, streamHandlerArg); } //finally return the actual return value OperationResponsePart response = (OperationResponsePart)connection.ReadObject(); if (response.Exception != null) { throw response.Exception; } return(response.Result); } finally { connection.Dispose(); } }
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); }
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(); } }
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); }
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)); } }
/// <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); }
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 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); } }
public RemoteFrameworkConnection(RemoteFrameworkConnectionInfo info) { Init(info); }
public RemoteManagerKey(RemoteFrameworkConnectionInfo info) { _host = info.Host; _port = info.Port; }