使用java代码从ldap中删除用户

时间:2015-08-24 08:46:54

标签: java ldap websphere ldap-query tivoli

如何从LDAP中删除用户?我需要通过非管理员用户名登录Websphere门户。我已经在下面提到的代码中传递了管理凭据,但是我收到了这个错误:

 javax.naming.NoPermissionException: [LDAP: error code 50 - Insufficient Access Rights]; Remaining name: 'uid=LM00828-00,cn=users,o=dealers,dc=india,dc=company,dc=com'

Java代码如下:

public void deactivate{
String proUrl = "ldap://hostname:portnumber" ;
String connectiontype = "simple" ;

String AdminDn = "uid=portaladmin,cn=users,o=admins,dc=india,dc=comapny,dc=com" ;
String password = "password" ;

Hashtable<String, String> environmentVar = new Hashtable<String, String>() ;

environmentVar.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.ldap.LdapCtxFactory");
environmentVar.put(Context.PROVIDER_URL,  proUrl) ;
environmentVar.put(Context.SECURITY_AUTHENTICATION,  connectiontype) ;
environmentVar.put(Context.SECURITY_PRINCIPAL,  AdminDn ) ;
environmentVar.put(Context.SECURITY_CREDENTIALS,  password) ;
DirContext dirContext = new InitialDirContext(environmentVar) ;  
deleteUser(dirContext);
}

public void deleteUser(DirContext context) {

try {
context.destroySubcontext("uid=LM00828-00,cn=users,o=dealers,dc=india,dc=company,dc=com");
NamingEnumeration list = context.list("");

// Go through each item in list
while (list.hasMore()) {
NameClassPair nc = (NameClassPair)list.next();
ApplicationLogger.debug(nc);
}

// Close the context when we're done
context.close();

} catch (NamingException e) {
ApplicationLogger.error(e);
}

}

0 个答案:

没有答案