ldap认证支持android吗,connect android to openLDAP server

问题

I have been assigned a task to, connect to a LDAP server from android.Perform the authetication process from android.I am using openLDAP. I am completely new to this.Can anyone help me out with some piece of code or demo code showing android connecting with LDAP server and authenticating.

The

Port no-389

SSL Port-636

IP Address-LGSPC3

username-->cn=name,cn=users,dc=mydeomain,dc=com

serverlist-ldap://server1

Thank you in advance

回答1:

The code I used to connect to LDAP server successfully is as follow:

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();

}

}

}

}

Hope it helps you.

来源:https://stackoverflow.com/questions/13801282/connect-android-to-openldap-server

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值