【问题标题】:connect android to openLDAP server将android连接到openLDAP服务器
【发布时间】:2012-11-27 21:15:46
【问题描述】:

我被分配了一个任务,从 android 连接到 LDAP 服务器。从 android 执行身份验证过程。我正在使用 openLDAP。我对此完全陌生。任何人都可以帮助我使用一些代码或演示代码来显示 android 与 LDAP 服务器连接并进行身份验证。

  Port no-389
  SSL Port-636
  IP Address-LGSPC3
  username-->cn=name,cn=users,dc=mydeomain,dc=com

  serverlist-ldap://server1

提前谢谢你

【问题讨论】:

    标签: java android httpclient openldap unboundid-ldap-sdk


    【解决方案1】:

    我用来成功连接LDAP服务器的代码如下:

    import java.sql.Date;
    import java.text.SimpleDateFormat;
    
    import android.annotation.SuppressLint;
    import android.app.Activity;
    import android.os.Bundle;
    import android.view.Menu;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.widget.Button;
    import android.widget.Toast;
    
    import com.unboundid.ldap.sdk.AddRequest;
    import com.unboundid.ldap.sdk.LDAPConnection;
    import com.unboundid.ldap.sdk.LDAPException;
    
    public class MainActivity extends Activity implements OnClickListener {
    
    //String address="ldap://server1.mydomain.com" ;
    String address="xxx.xxx.xxx.xxx";
    int port=389;
    //String bindDN="CN=name,CN=users,DC=mydomain,DC=com";
    String bindDN="cn=Manager,dc=maxcrc,dc=com";
    String password="secret";
    boolean login_flag=true;
    
    LDAPConnection c ;
    AddRequest addRequest;
    @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);
    }
    
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }
    
    @SuppressLint("SimpleDateFormat") @Override
    public void onClick(View arg0) {
    
           try {
               c= new LDAPConnection(address,port,bindDN,password);
               c.setConnectionName("Demo Connection");
               String con_name=c.getConnectionName();
               long time=c.getConnectTime();
               SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yy HH:mm:ss");
               String dateString = formatter.format(new Date(time));
               Toast.makeText(getBaseContext(),"Connected to LDAP server....connection_name="+con_name+" at time"+dateString, Toast.LENGTH_LONG).show();
    
          } catch (LDAPException e) {
              login_flag=false;
              e.printStackTrace();
              Toast.makeText(getBaseContext(),"No connection was established" , Toast.LENGTH_LONG).show();
        } catch(Exception e) {
               e.printStackTrace();
        } finally{
               if(login_flag){
                     c.close();
                     Toast.makeText(getBaseContext(), "Connection Closed successfully", Toast.LENGTH_LONG).show();
               }
       }
    
    
    }
    
    }
    

    希望对您有所帮助。

    【讨论】:

      猜你喜欢
      • 2013-12-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-11
      • 2013-01-11
      • 2015-11-08
      • 1970-01-01
      相关资源
      最近更新 更多