Java Mobile Ms Aduser to the specified OU

Source: Internet
Author: User

Java mobile msaduser to the specified OU

Recently do OA system automation, so applied to a number of development, the previous article we introduced the use of Java to create Ms Aduser, change password, etc., but after the creation, we also have the separation of automation, we leave the user to disable the user first, and then move to the specified OU, Then the deletion is performed once a month via PowerShell or VBS scripts, rather than the direct deletion of the separation user account, so we need to do two steps for the above requirements, first to disable, For disabling users, we typically modify the user's Useracountcontrol property to operate, and we'll cover the properties of the ad user in the next article. Today we mainly demonstrate the use of Java programs to move users to the specified OU.

In our environment Oadi this user under the Ixm Adm OU, we need to move to the IXM users OU

650) this.width=650; "title=" image "style=" Margin:0px;background-image:none; "border=" 0 "alt=" image "src="/http S3.51cto.com/wyfs02/m00/a6/9b/wkiol1nu21va0295aafsexqx6ti472.png "height=" 359 "/>

Configuring Java-related agents

/** * moveuser.java * 5 july 2001 * sample jndi application  to move an object in the active directory. *  */import  java.util.Hashtable;import javax.naming.*;import javax.naming.ldap.*;import  Javax.naming.directory.*;p ublic class moveuser     {      public static void main  (String[] args)      {                hashtable env  = new hashtable ();          string  adminname =  "Cn=administrator,cn=users,dc=ixmsoft,dc=com";           String adminPassword =  "123";            string olduserpath =  "Cn=aodi,ou=ixm adm,ou=imxsoft users,dc=ixmsoft,dc=com";           String newUserpath =  "Cn=aodi,ou=ixm users,ou=imxsoft  users,dc=ixmsoft,dc=com ";           string ldapurl  =  "ldap://192.168.5.20:389";                     env.put (Context.initial_context_factory, " Com.sun.jndi.ldap.LdapCtxFactory ");                //set security credentials, note using simple cleartext  Authentication          env.put (Context.SECURITY_ Authentication, "simple");           env.put (Context.SECURITY_ Principal,adminname);            env.put (Context.security_credentials,adminpassword);                                //connect to my domain controller           env.put (Context.provider_url,ldapurl);                                try {                // Create the initial directory  Context               ldapcontext  ctx = new initialldapcontext (env,null);                // move the user                ctx.rename (Olduserpath,newuserpath);                system.out.println ("Moved user");                                ctx.close ();           }           catch  (Namingexception e)  {                System.err.println ("problem moving object: "  + e);           }     }}

We define the new, old user road strength

650) this.width=650; "title=" image "style=" Margin:0px;background-image:none; "border=" 0 "alt=" image "src="/http S3.51cto.com/wyfs02/m02/07/e9/wkiom1nu26eggnu3aah1sjcyjpi475.png "height=" 378 "/>

Start execution

650) this.width=650; "title=" image "style=" Margin:0px;background-image:none; "border=" 0 "alt=" image "src="/http S3.51cto.com/wyfs02/m00/07/e9/wkiom1nu26mqse1jaagunq3fjqu461.png "height=" 338 "/>

Successful execution

650) this.width=650; "title=" image "style=" Margin:0px;background-image:none; "border=" 0 "alt=" image "src="/http S3.51cto.com/wyfs02/m01/07/e9/wkiom1nu26zhsb1eaakorjyzbsu673.png "height=" 477 "/>

We view ad information

650) this.width=650; "title=" image "style=" Margin:0px;background-image:none; "border=" 0 "alt=" image "src="/http S3.51cto.com/wyfs02/m00/a6/9b/wkiol1nu22paerupaahj9r-is8w809.png "height=" 451 "/>

We finally made it easy to define a UserPath CN user value as a variable for easy value transfer

/** * moveuser.java * 5 july 2001 * sample jndi application  to move an object in the active directory. *  */import  java.util.Hashtable;import javax.naming.*;import javax.naming.ldap.*;import  Javax.naming.directory.*;p ublic class moveuser     {      public static void main  (String[] args)      {                hashtable env  = new hashtable ();          string  Adaccount= "Aodi";           string adminname =   "Cn=administrator,cn=users,dc=ixmsoft,dc=com";           String adminPassword =  "123 ";           string olduserpath = " CN= " +adaccount+ "," + "ou=ixm adm,ou=imxsoft users,dc=ixmsoft,dc=com";           String newUserpath =  "cn=" +adaccount+ "," + "Ou=ixm users,ou=imxsoft  users,dc=ixmsoft,dc=com ";           string ldapurl  =  "ldap://192.168.5.20:389";                     env.put (Context.initial_context_factory, " Com.sun.jndi.ldap.LdapCtxFactory ");                //set security credentials, note using simple cleartext  Authentication          env.put (Context.SECURITY_ Authentication, "simple");    &nbsP;      env.put (Context.security_principal,adminname);           env.put (Context.security_credentials,adminpassword);                                //connect to my domain controller           env.put (Context.provider_url,ldapurl);                                try {                // create the initial directory  context                Ldapcontext ctx = new&nbSp;initialldapcontext (env,null);                // Move the user                ctx.rename (Olduserpath,newuserpath);                system.out.println ("Moved user:" +ADAccount);                system.out.println ("NewUserpath:" + Newuserpath);                Ctx.close ();          }            catch  (namingexception e)  {                system.err.println ("Problem moving object:   " + e");           }     }} 

650) this.width=650; "Src=" https://s1.51cto.com/wyfs02/M01/07/EC/wKiom1nVlviQey3UAAJWzSHHAiI422.jpg-wh_500x0-wm_ 3-wmp_4-s_2972007918.jpg "title=" 1.jpg "alt=" Wkiom1nvlviqey3uaajwzshhaii422.jpg-wh_50 "/>

This article from "Gao Wenrong" blog, declined reprint!

Java Mobile Ms Aduser to the specified OU

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.