Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to import attribute change in directory through LDIF File by java program  RSS feed

 
shivam chauhan
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys

New to ranch

Please help me out, i have a code which connects to LDAP Directory ,and performs an attribute change for a single user Dn.
I am unable to do so ,for a ldif which contains bulk user accounts modify ldif.

LDIF:
version:1

dn: uid=DummyTest,ou=people,dc=Org,dc=com
changetype: modify
replace: userPassword
userPassword: ******

dn: uid=DummyTest1,ou=people,dc=Org,dc=com
changetype: modify
replace: userPassword
userPassword: *******

dn: uid=DummyTest2,ou=people,dc=Org,dc=com
changetype: modify
replace: userPassword
userPassword: ********





Java Program:



LDAPConnection ldapConnection = new LDAPConnection() ;
try {


ldapConnection.connect("ldap://hostname", port,"uid=admin", "secret");


} catch (LDAPException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return ldapConnection!=null ? ldapConnection:null;

}





InputStream file2 = new FileInputStream(new File(
"Filelocation"));


LdifReader ldifReader = new LdifReader(file2);
for (LdifEntry entry : ldifReader) //here is the problem i guess

{
switch (entry.getChangeType()) {
case Modify:

String C = LDIFseter.generatePassword();

String EntryDN = entry.getDn().toString();
LDAPAttribute password = new LDAPAttribute( "userPassword",C);
System.out.println(C);
LDAPModification singleChange = new LDAPModification( LDAPModification.REPLACE, password);
ldapConnection.modify( EntryDN, singleChange );
LDAPAttribute cmpThisAttr = new LDAPAttribute( "userPassword",C );

boolean hasValue = ldapConnection.compare( EntryDN, cmpThisAttr );
if ( hasValue ) {
System.out.println( "Attribute and value found in entry." );
} else {

LDAPAttribute attr1 = new LDAPAttribute( "userPassword",C );
LDAPAttributeSet myAttrs = new LDAPAttributeSet();
myAttrs.add( attr1 );
/*Can add many more attributes to the Object like email ,address,ph no */


}




break;
default:
throw new IllegalArgumentException(
"Unknown change type in LdifEntry: "
+ entry.getChangeType().toString());
}
}





  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!