Specifying an LDAP directory

The following sample is taken from the code presented above in Verifying Signed Messages. It demonstrates runtime addition of a cache-related colleague using PKIFv2 objects and functions.

Supported Languages

C++

void AssociatingAnLDAPDirectoryWithAMediator()
{
      //Create a mediator object
      IPKIFMediatorPtr mediator = MakeDefaultMediator(); 

      //Create three LDAP objects
      CPKIFLDAPRepositoryPtr ldap1(new CPKIFLDAPRepository());
      ldap1->SetHost("192.168.0.1");
      ldap1->Set_Port(789);               //non-standard port
 

      CPKIFLDAPRepositoryPtr ldap2(new CPKIFLDAPRepository());
      ldap2->SetHost("192.168.0.2");      //use standard port 389

 

      CPKIFLDAPRepositoryPtr ldap3(new CPKIFLDAPRepository());
      ldap3->SetHost("192.168.0.3");      //use standard port 389

 

      //Access the cache mediator directly. 
      CPKIFCacheMediator2* cacheMediator = mediator->GetMediator<CPKIFCacheMediator2>();
      cacheMediator->AddColleague(dynamic_pointer_cast<IPKIFColleague, CPKIFLDAPRepository>(ldap1));
      cacheMediator->AddColleague(dynamic_pointer_cast<IPKIFColleague, CPKIFLDAPRepository>(ldap2));
      cacheMediator->AddColleague(dynamic_pointer_cast<IPKIFColleague, CPKIFLDAPRepository>(ldap3));
}

 

C#

public void AssociatingAnLDAPDirectoryWithAMediator()
{
    //Create a mediator object
    IPKIFColleaguePtr mediator = pkif_module.MakeDefaultMediator(); 

    //Create three LDAP objects
    IPKIFColleaguePtr ldap1Col = pkif_module.make_NewCPKIFLDAPRepository();
    CPKIFLDAPRepositoryPtr ldap1 = pkif_module.cast_ToCPKIFLDAPRepository(ldap1Col);
    ldap1.SetHost("192.168.0.1");
    ldap1.Set_Port(789);                  //non-standard port
 

    IPKIFColleaguePtr ldap2Col = pkif_module.make_NewCPKIFLDAPRepository();
    CPKIFLDAPRepositoryPtr ldap2 = pkif_module.cast_ToCPKIFLDAPRepository(ldap2Col);
    ldap2.SetHost("192.168.0.2");   //use standard port 389

    IPKIFColleaguePtr ldap3Col = pkif_module.make_NewCPKIFLDAPRepository();
    CPKIFLDAPRepositoryPtr ldap3 = pkif_module.cast_ToCPKIFLDAPRepository(ldap3Col);
    ldap3.SetHost("192.168.0.3");   //use standard port 389

 

    //Access the cache mediator directly.  In this case,
    //the application can elect to surrender the cache object
    //to the mediator for purposes of memory cleanup or can
    //manage the lifetime of the object manually.
    CPKIFCacheMediator2 cacheMediator = pkif_module.Get_CacheMediator(mediator);
    cacheMediator.AddColleague(ldap1Col);
    cacheMediator.AddColleague(ldap2Col);
    cacheMediator.AddColleague(ldap3Col);
}

 

JAVA

public void AssociatingAnLDAPDirectoryWithAMediator()
{
   
//Create a mediator object
    IPKIFColleaguePtr mediator = pkif_module.MakeDefaultMediator(); 

    //Create three LDAP objects
    IPKIFColleaguePtr ldap1Col = pkif_module.make_NewCPKIFLDAPRepository();
    CPKIFLDAPRepositoryPtr ldap1 = pkif_module.cast_ToCPKIFLDAPRepository(ldap1Col);
    ldap1.SetHost(
"192.168.0.1");
    ldap1.Set_Port(789);                 
//non-standard port 

    IPKIFColleaguePtr ldap2Col = pkif_module.make_NewCPKIFLDAPRepository();
    CPKIFLDAPRepositoryPtr ldap2 = pkif_module.cast_ToCPKIFLDAPRepository(ldap2Col);
    ldap2.SetHost(
"192.168.0.2");   //use standard port 389 

    IPKIFColleaguePtr ldap3Col = pkif_module.make_NewCPKIFLDAPRepository();
    CPKIFLDAPRepositoryPtr ldap3 = pkif_module.cast_ToCPKIFLDAPRepository(ldap3Col);
    ldap3.SetHost(
"192.168.0.3");   //use standard port 389 

    //Access the cache mediator directly.  In this case,
    //the application can elect to surrender the cache object
    //to the mediator for purposes of memory cleanup or can
    //manage the lifetime of the object manually.
    CPKIFCacheMediator2 cacheMediator = pkif_module.Get_CacheMediator(mediator);
    cacheMediator.AddColleague(ldap1Col);
    cacheMediator.AddColleague(ldap2Col);
    cacheMediator.AddColleague(ldap3Col);
}