您应该能够从ldap上下文中获取环境,对其进行克隆,然后将要检查的用户的主体和凭据放入:
@Resource(name = "ldap/users")private LdapContext ldapContext;Hashtable environment = ldapContext.getEnvironment().clone();environment.put(Context.SECURITY_PRINCIPAL, userDN);environment.put(Context.SECURITY_CREDENTIALS, userPassword);DirContext dirContext = new InitialDirContext(environment);



