java-将and​​roid连接到openLDAP服务器

java-将and​​roid连接到openLDAP服务器,第1张

概述我已经分配了一个任务,要从android连接到LDAP服务器.从android执行身份验证过程.我正在使用openLDAP.我是完全陌生的.有人可以帮我看看显示android与LDAP服务器连接并进行身份验证的代码或演示代码.该Portno-389SSLPort-636IPAddress-LGSPC3username-->cn=name,cn

我已经分配了一个任务,要从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

先感谢您

解决方法:

我用来成功连接到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;@OverrIDeprotected 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);}@OverrIDepublic boolean onCreateOptionsMenu(Menu menu) {    getMenuInflater().inflate(R.menu.activity_main, menu);    return true;}@Suppresslint("SimpleDateFormat") @OverrIDepublic 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();           }   }}}

希望对您有帮助.

总结

以上是内存溢出为你收集整理的java-将and​​roid连接到openLDAP服务器全部内容,希望文章能够帮你解决java-将and​​roid连接到openLDAP服务器所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1095919.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-28
下一篇2022-05-28

发表评论

登录后才能评论

评论列表(0条)

    保存