LDAPException(resultCode=84 (解码错误)

LDAPException(resultCode=84 (decoding error)

我正在尝试连接到 LDAP 服务器并从我有登录表单(Active Directory 用户名和密码)的简单 Adnroid 应用程序登录,但出现以下错误:

LDAPException(resultCode=84 (decoding error), errorMessage='The connection to server xxx.x.xxx.xx:443 was closed while waiting for a response to a bind request SimpleBindRequest(): Unable to read or decode an LDAP message: Invalid value length of 80 for an ASN.1 integer element. Integer element values must have a length between 1 and 4 bytes., ldapSDKVersion=5.1.4, revision=95121137bbf71bc02638a53c2c8ddf3588c2bcc4')

登录时出现错误,bindDN只用uid可以登录吗?我尝试指定完整的 DN (dn="CN=LastName FirstName,OU=Users,OU=xx,OU=xxx,OU=xxx,DC=xxx,DC=xxx,DC=xxx,DC=xxx,DC=su") 和 (dn="uid=xxx,OU=Users,OU=xx,OU=xxx,OU=xxx,DC=xxx,DC=xxx,DC=xxx,DC=xxx,DC=su"),但得到了同样的错误。

可能是什么问题?提前致谢。

这是我的代码:

public class MainActivity extends Activity implements OnClickListener {

int port=443;
final String dn ="uid=xxx";
final String password ="xxx";
final String hostname = "xxx.x.xxx.xx";
boolean login_flag=true;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Button bt_login=(Button)findViewById(R.id.bt_login);
    bt_login.setOnClickListener(this);
}


@SuppressLint("SimpleDateFormat")
@Override
public void onClick(View view)
{       
    new Thread(new Runnable()
    {
        @Override
        public void run()
        {
            try {
                final BindRequest bindRequest = new SimpleBindRequest(dn,password);
                final SSLUtil sslUtil = new SSLUtil(new TrustAllTrustManager());
                final LDAPConnectionOptions connectionOptions = new LDAPConnectionOptions();
                connectionOptions.setFollowReferrals(true);
                final LDAPConnection ldapConnection = new LDAPConnection(sslUtil.createSSLSocketFactory(),hostname,port);
                final BindResult bindResult = ldapConnection.bind(bindRequest);
                final ResultCode resultCode = bindResult.getResultCode();
                if(resultCode.equals(ResultCode.SUCCESS))
                {
                    System.out.println("success");
                }
            } catch (LDAPException e) {
                login_flag=false;
                e.printStackTrace();
                System.out.println("No connection was established");
            } catch(Exception e) {
                e.printStackTrace();
            } finally{
                if(login_flag){
                    ldapConnection.close();
                    System.out.println("Connection Closed successfully");

                }
            }
        }
    }).start();
}
}

您的配置可能有几个问题。

xxx.x.xxx.xx:443 和 int port=443 表示您正在尝试连接端口 443,这不是使用 Microsoft Active Directory 的 LDAP 可接受的端口。

尝试以下方法之一:

  • 389 - 不安全
  • 636 - 安全
  • 3268 - 不安全
  • 3269 - 安全

您似乎不确定应该使用什么正确的 DN。

在 DC 上,执行:dsquery user -samid jim

将显示与 sAMAccountName 匹配的用户的 DN:“CN=Jim Willeke,CN=Users,DC=mad,DC=willeke,DC=com”

或者您可以将您的值用于 sAMAccountName@yourADDomain (jim@willeke.net)

-吉姆