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:

    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 rawpw() As Byte
       rawpw = System.Text.UTF8Encoding().GetBytes(pw)
       csentry("userPassword").Values.Add(rawpw)
    End Sub
    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[] rawpw = System.Text.UTF8Encoding.UTF8.GetBytes(pw)
        csentry["userPassword"].Values.Add(rawpw);
        return;
    }

Send comments about this topic to Microsoft

Build date: 2/16/2009