Saturday, February 5, 2011

تغيير اسم مستخدم عن طريق جافا

حاليا اعمل على برنامج لادارة الهوية Oracle Identity Manager وكان مطلوبا تغيير اسم المستخدم في اكتف دايركتورى وعندما حاولت التغيير بالطرية المعتادة فوجئت بالخطأ canot_on_rdn. سبب الخطأ أن اسم المستخدم أو خاصية cn في الاكتف دايركتوري هي خاصية مميزة للمستخدم relative distinguished name RDN ولا يمكن تعديلها كباقي الخصائص الحل هو اعادة تسمية المستخدم كالتالي:

 Paste your source here:  
 Add new lines after "{" and before "}"  
 Add new lines before "{"  
 Remove empty lines.  
 Add comment lines before function.  
 Add new lines after ";"  
 Add new lines after "}" (For .css) (Thanks David)  
 Remove new lines (useful only if you add them again with the other functions above)  
 Add new lines after ";" but not in for loops (Don't check "Remove new lines" but do check "Remove empty lines")(Thanks Chris) (Experimental, uses a heuristic that might fail )  
 Add new lines after ";" but not in for loops and skip quotes (Don't check "Remove new lines" but do check "Remove empty lines") (Thanks Chris) (Experimental, uses a heuristic that might fail )  
 Reduce whitespace  
 Put the code again in the input box above after submit.  
 Skip HTML, give me plain code! (Use Save-As function of your browser)        
 import javax.naming.*;  
 import javax.naming.directory.*;  
 import java.util.ArrayList;  
 import java.util.HashMap;  
 import java.util.Hashtable;  
 import java.util.List;  
 import java.util.Map;  
 public class renameCN  
 {  
   public static void renameCN(String oldCN, String newCN)  
   {  
     Hashtable env = new Hashtable();  
     env.put(Context.INITIAL_CONTEXT_FACTORY, “com.sun.jndi.ldap.LdapCtxFactory”);  
     env.put(Context.SECURITY_PROTOCOL, “ssl”);  
     env.put(Context.PROVIDER_URL, “ldaps://173.xxx.xxx.xxx:636/”);  
     env.put(Context.SECURITY_PRINCIPAL, “cn=administrator,cn=users,dc=hs2003uat,dc=com”);  
     env.put(Context.SECURITY_CREDENTIALS, “Passw0rd”);  
     try  
     {  
       DirContext cmtx = new InitialDirContext(env);  
       String OldCN=”CN=” +oldCN+”,CN=Users,DC=xxxxxx,DC=COM”;  
       System.out.println(“Old CN:”+OldCN);  
       String NewCN=”CN=:+newCN+”,CN=Users,DC=xxxx,DC=COM”;  
       System.out.println(“New CN:”+NewCN);  
       System.out.println(“Starting Modify DN “);  
       cmtx.rename(OldCN, NewCN);  
       cmtx.close();  
     }  
     catch (Exception e)  
     {  
       System.out.println(“Ended Modify DN with Error…”);  
       rtnval=”ERROR : “+e.getMessage();  
       e.printStackTrace();  
     }  
   }  
 }   

No comments:

Post a Comment