Microsoft Identity Integration Server 2003 Developer Reference

Example: Setting an Initial Password in Sun and Netscape Directory Servers

When you add a user to Sun and Netscape directory servers, you can set an initial password for the newly created user. To set the initial password, set the userPassword attribute to a value. You can set the initial password of a user by implementing the IMVSynchronization.Provision method of your management agent rules extension.

The following example shows how to set the initial password of a user in Sun and Netscape directory servers:

[Visual Basic .NET]
Public Sub Provision( _
ByVal mventry As MVEntry) _
Implements IMVSynchronization.Provision

	Dim ManagementAgent As ConnectedMA
	Dim Connectors As Integer
	Dim dn As ReferenceValue
	Dim container As String
	Dim rdn As String

	ManagementAgent = mventry.ConnectedMAs("iPlanet MA")
	Connectors = ManagementAgent.Connectors.Count

	If 0 = Connectors Then
		rdn = "CN=" & mventry("cn").Value
		container = "ou=people,o=fabrikam.com"
		dn = ManagementAgent.EscapeDNComponent(rdn).Concat(container)

		Dim oc As ValueCollection
		oc = Utils.ValueCollection("top")
		oc.Add("person")
		oc.Add("organizationalPerson")
		oc.Add("inetOrgPerson")

		Dim csentry As CSEntry
		csentry = ManagementAgent.Connectors.StartNewConnector("inetOrgPerson", oc)
		csentry.CommitNewConnector()
		SetIPlanetPW(csentry, mventry("employeeID").Value)
   End If
End Sub

Private Sub SetIPlanetPW(ByRef csentry As CSEntry, _
						ByVal pw As String)
   Dim password() As Byte
   password = New System.Text.UTF8Encoding(False, False).GetBytes(pw)
   ReDim Preserve password(UBound(password) + 2)
   csentry("userPassword").Values.Add(password)
End Sub
[C#]
void IMVSynchronization.Provision (MVEntry mventry)
{
	ConnectedMA ManagementAgent;
	int Connectors;
	ReferenceValue dn;
	string container;
	string rdn;

	ManagementAgent = mventry.ConnectedMAs["iPlanet MA"];
	Connectors = ManagementAgent.Connectors.Count;

	if(0 == Connectors)
	{
		rdn = "CN=" + mventry["cn"].Value;
		container = "ou=people,o=fabrikam.com";
		dn = ManagementAgent.EscapeDNComponent(rdn).Concat(container);
		ValueCollection oc;
		oc = Utils.ValueCollection("top");
		oc.Add("person");
		oc.Add("organizationalPerson");
		oc.Add("inetOrgPerson");

		CSEntry csentry;
		csentry = ManagementAgent.Connectors.StartNewConnector("inetOrgPerson", oc);
		csentry.CommitNewConnector();
		SetIPlanetPW(csentry, mventry["employeeID"].Value);
}
}

void SetIPlanetPW(CSEntry csentry, string pw)
{
	byte[] password = new byte[0];
	password = System.Text.UTF8Encoding.UTF8.GetBytes(pw);
	byte[] ExtendedPassword = new byte[password.Length+2];
	for(int x=0;x<password.Length;++x)
	{
		ExtendedPassword[x] = password[x];
}
	csentry["userPassword"].Values.Add(ExtendedPassword);
	return;
}