Novell.Directory.Ldap.LdapConstraints.setControls C# (CSharp) Method

setControls() public method

Sets a single control to be sent to the server.
public setControls ( LdapControl control ) : void
control LdapControl A single control to be sent to the server or /// null if none. ///
return void
        public virtual void setControls(LdapControl control)
        {
            if (control == null)
            {
                this.controls = null;
                return ;
            }
            this.controls = new LdapControl[1];
            this.controls[0] = (LdapControl) control.Clone();
            return ;
        }

Usage Example

示例#1
0
    public static void Main( String[] args )
    {
        if (args.Length != 6)
        {
            Console.Error.WriteLine("Usage:   mono SimplePassword <host Name> "
                + "<port number> <login dn> <password> <user dn>"
                + " <new user password>");
            Console.Error.WriteLine("\n Example: mono SimplePassword Acme.com 389"
                + " \"cn=Admin,o=Acme\" secret\n"
                + "         \"cn=JSmith,ou=sales,o=Acme\" userPWD");
            Environment.Exit(1);
        }

        int    ldapVersion = LdapConnection.Ldap_V3;
        String ldapHost    = args[0];
        int    ldapPort    = int.Parse(args[1]);
        String loginDN     = args[2];
        String password    = args[3];
        String userDN      = args[4];
        String userPWD     = args[5];

        /* Simple Password control.  There is no value  associated with this control,
         * just an OID and criticality. Setting the criticality to TRUE means the
         * server will return an error if it does not recognize or is unable to
         * perform the control.
         */

        LdapControl cont = new LdapControl(simplePassOID,
            true,
            null);
        LdapConstraints lcons = new LdapConstraints();
        lcons.setControls(cont);

        LdapConnection lc  = new LdapConnection();

        try
        {
            // connect to the server
            lc.Connect( ldapHost, ldapPort );
            // bind to the server
            lc.Bind( ldapVersion, loginDN, password );

            //  Modify the 'userpassword' attribute, with the Simple
            // Password control.
            LdapModification[] modifications = new LdapModification[1];
            LdapAttribute sPassword = new LdapAttribute( "userPassword",userPWD);
            modifications[0] =
                new LdapModification( LdapModification.REPLACE, sPassword);

            lc.Modify( userDN, modifications,lcons);

            Console.WriteLine("Your Simple password has been modified.");

            lc.Disconnect();
        }
        catch( LdapException e )
        {
            Console.Error.WriteLine("SimplePassword example failed");
            Console.Error.WriteLine( "Error: " + e.ToString() );
            Environment.Exit(1);
        }
        catch( Exception e )
        {
            Console.WriteLine( "Error: " + e.ToString() );
        }
        Environment.Exit(0);
    }