Active Directory change password
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Anonymous
Posted On:   Tuesday, November 18, 2003 07:31 PM

Hi, 1) I am trying to change the password of a user at MS ActiveDirectory, from a Java Application. Is it possible?, because I heard to cheange password, we need to connect via SSL. Is it right? 2) I connected to ActiveDirectory from application, and listed the contents of Users. My AD is created in this way: AAA |_Users | |_Domain Users | Contains All user names and active dir folders |_Computers I could list the contents of Users, Computers etc (First level) Now how could I access the details of a user? Please help. Hashtable env = new Hashtable(); env.put(Con   More>>

Hi,

1) I am trying to change the password of a user at MS ActiveDirectory, from a Java Application. Is it possible?,
because I heard to cheange password, we need to connect via SSL. Is it right?



2) I connected to ActiveDirectory from application, and listed the contents of Users.

My AD is created in this way:

AAA

|_Users

| |_Domain Users

| Contains All user names and active dir folders

|_Computers

I could list the contents of Users, Computers etc (First level)

Now how could I access the details of a user?

Please help.





Hashtable env = new Hashtable();

env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");

env.put(Context.PROVIDER_URL, "ldap://192.168.0.3:389");

//env.put(Context.SECURITY_PROTOCOL, "ssl");

env.put(Context.SECURITY_AUTHENTICATION, "simple"); // Create the initial context

//env.put(Context.SECURITY_PRINCIPAL, "cn=kk,dc=mydomain,dc=m3");

env.put(Context.SECURITY_PRINCIPAL, "kk@mydomain.net");

String strPwd = "kk";

env.put(Context.SECURITY_CREDENTIALS, strPwd);



String str="kkg@mydomain.net";

//env.put(Context.SECURITY_PRINCIPAL, str);

//env.put(Context.SECURITY_PRINCIPAL, "CN=kk");



try {

System.out.println("11Is it binding..................");

DirContext ctx = new InitialDirContext(env);

System.out.println("Is it binding..................");



NamingEnumeration contentsEnum = ctx.list("CN=Users, DC=mydomain,DC=net ");



// Working perfect- lists the contents of 'Users' directory

while (contentsEnum.hasMore()){

NameClassPair ncp = (NameClassPair) contentsEnum.next();

String userName = ncp.getName();

System.out.println("User: "+userName);

}



// Remaining is not working



// javax.naming.directory.Attributes atts = ctx.getAttributes ("CN=Users/Domain Users/kk, DC=mydomain,DC=net");

// System.out.println("SIZE="+atts.toString());



SearchControls ctls = new SearchControls();

System.out.println("SearchControls ctls = new SearchControls()");

ctls.setSearchScope(SearchControls.OBJECT_SCOPE);

System.out.println("ctls.setSearchScope(SearchControls.OBJECT_SCOPE)");



String uid = "Users"; // Set up the environment for creating the initial context



//NamingEnumeration results = ctx.search("", "(CN="+ uid +")", ctls);

NamingEnumeration results = ctx.search("Users@mydomain.net", "DC=mydomain, DC=net", ctls);

System.out.println("NamingEnumeration");

SearchResult sr = (SearchResult)results.nextElement();

String dn = sr.getName(); //

//String mycon = ((SearchResult)answer.next()).getName();

System.out.println("DN-" + dn+"-"); // ... do something useful with ctx

if(dn != null)

{



System.out.println("ads");

}


ctx.close();

}

catch (Exception e)

{

//System.err.println("Problem getting attribute:" + e);

e.printStackTrace();

}

   <<Less
About | Sitemap | Contact