使用 Web 服务在 LDAP 上进行身份验证

发布于 2024-09-11 23:42:01 字数 3884 浏览 1 评论 0原文

由于显然无法在我的 BlackBerry 应用程序上使用 LDAP 进行身份验证,因此我尝试使用一种解决方法。我不想直接在 LDAP 服务器上进行身份验证,而是想在两者之间使用 Web 服务。所以它看起来像这样

App --calls--> Web Service --calls--> LDAP Server

所以 Web 服务应该获取应用程序给出的用户名和密码并将其发送到 LDAP 服务器。如果可以登录,Web 服务会收到 TRUE 作为响应并将其转发到应用程序。

这就是它应该如何运作的。但目前,当我从应用程序调用 Web 服务时,出现以下错误:

SoapFault - 故障代码:'S:Server' 故障字符串: 'java.lang.NullPointerException' 故障因素:'null' 详细信息: org.kxml2.kdom.Node@21e05a11

似乎是服务器问题,但我不知道在哪里:(
嗯,这就是我正在使用的 Web 服务:

import javax.ejb.Stateless;  
import javax.jws.WebService;  

import com.novell.ldap.LDAPConnection;  
import com.novell.ldap.LDAPException;  

@Stateless  
@WebService()  
public class ldapServiceBean implements ldapService {

    @Override
    public String error() {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public boolean ldapLogin(String username, String password) {
         int ldapPort = LDAPConnection.DEFAULT_PORT;
         int ldapVersion = LDAPConnection.LDAP_V3;
         String ldapHost = "dc1.somehost ";
         String loginDN =
         "CN="+username+",OU=employee,OU=user,DC=somehost";

         byte[] passwordBytes = password.getBytes();
         LDAPConnection lc = new LDAPConnection();

         try {
             // connect to the server
             lc.connect( ldapHost, ldapPort );

             // authenticate to the server
             lc.bind( ldapVersion, loginDN, passwordBytes );
             System.out.println("Bind successful");

             return true;
         }
         catch( LDAPException e ) {
             if ( e.getResultCode() == LDAPException.NO_SUCH_OBJECT ) {
                 System.err.println( "Error: No such entry" );
             } else if ( e.getResultCode() ==
                 LDAPException.NO_SUCH_ATTRIBUTE ) {
                 System.err.println( "Error: No such attribute" );
             } else {
                 System.err.println( "Error: " + e.toString() );
             }
         }
        return false;
    }

这就是调用 Web 服务的方法

private static final String SOAP_ACTION = "";  
    private static final String METHOD_NAME = "ldapLogin";  
    private static final String NAMESPACE = "http://ldapproxy.somehost/";  
    private static final String URL = "http://myIP:8080/LDAPProxy/ldapServiceBeanService";  

...  


public boolean login(String username, String password) {


        SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); 

        //SoapObject
        request.addProperty("username", username);
        request.addProperty("password", password);

        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
        //envelope.dotNet = true;
        //envelope.bodyOut = request;
        envelope.setOutputSoapObject(request);       

        HttpTransport httpTransport = new HttpTransport(URL);
        try
        {

            httpTransport.call(SOAP_ACTION, envelope);

            System.out.println("request: " + httpTransport.requestDump);
            resultsRequestSOAP = (SoapObject) envelope.getResponse();

            return true;

        }catch(SoapFault sF){
            String error = sF.toString();
            Dialog.alert(error);
        }
        catch (Exception aE)
        {
            Dialog.alert("Connection failed");
            aE.printStackTrace ();
        }
        return false;

    }

到目前为止我发现了什么: 网络服务似乎没有接收用户名和密码属性。当我打印它们时,我得到:

`CN=null, OU=employee, OU=...`

就像我在这篇文章中读到的那样 Web 服务使用 ksoap 方法从应用程序接收空参数 看来 ksoap 有冒号问题。我更改了我的命名空间但没有成功。也许我也需要更改我的网址。但是当我仍然需要使用 localhost 时我该怎么做?

Since it' apparently not possible to authenticate with LDAP on my BlackBerry App, I'm trying to use a kind of workaround. Instead of authenticate directly on the LDAP Server, I want to use a Web Service in between. So it looks like this

App --calls--> Web Service --calls--> LDAP Server

So the Web Service should take the username and password given from the Application and send it to the LDAP Server. If its possible to sign in, the Web Service gets a TRUE as response and forward it to the App.

That's how it should work. But at the moment, when I call the Web Service from the App, I get following error:

SoapFault - faultcode: 'S:Server' faultstring:
'java.lang.NullPointerException' faultactor: 'null' detail:
org.kxml2.kdom.Node@21e05a11

Seems like a Server problem but I don't know where :(
Well, that's the Web Service I'm using:

import javax.ejb.Stateless;  
import javax.jws.WebService;  

import com.novell.ldap.LDAPConnection;  
import com.novell.ldap.LDAPException;  

@Stateless  
@WebService()  
public class ldapServiceBean implements ldapService {

    @Override
    public String error() {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public boolean ldapLogin(String username, String password) {
         int ldapPort = LDAPConnection.DEFAULT_PORT;
         int ldapVersion = LDAPConnection.LDAP_V3;
         String ldapHost = "dc1.somehost ";
         String loginDN =
         "CN="+username+",OU=employee,OU=user,DC=somehost";

         byte[] passwordBytes = password.getBytes();
         LDAPConnection lc = new LDAPConnection();

         try {
             // connect to the server
             lc.connect( ldapHost, ldapPort );

             // authenticate to the server
             lc.bind( ldapVersion, loginDN, passwordBytes );
             System.out.println("Bind successful");

             return true;
         }
         catch( LDAPException e ) {
             if ( e.getResultCode() == LDAPException.NO_SUCH_OBJECT ) {
                 System.err.println( "Error: No such entry" );
             } else if ( e.getResultCode() ==
                 LDAPException.NO_SUCH_ATTRIBUTE ) {
                 System.err.println( "Error: No such attribute" );
             } else {
                 System.err.println( "Error: " + e.toString() );
             }
         }
        return false;
    }

And that's the method calling the Web Service

private static final String SOAP_ACTION = "";  
    private static final String METHOD_NAME = "ldapLogin";  
    private static final String NAMESPACE = "http://ldapproxy.somehost/";  
    private static final String URL = "http://myIP:8080/LDAPProxy/ldapServiceBeanService";  

...  


public boolean login(String username, String password) {


        SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); 

        //SoapObject
        request.addProperty("username", username);
        request.addProperty("password", password);

        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
        //envelope.dotNet = true;
        //envelope.bodyOut = request;
        envelope.setOutputSoapObject(request);       

        HttpTransport httpTransport = new HttpTransport(URL);
        try
        {

            httpTransport.call(SOAP_ACTION, envelope);

            System.out.println("request: " + httpTransport.requestDump);
            resultsRequestSOAP = (SoapObject) envelope.getResponse();

            return true;

        }catch(SoapFault sF){
            String error = sF.toString();
            Dialog.alert(error);
        }
        catch (Exception aE)
        {
            Dialog.alert("Connection failed");
            aE.printStackTrace ();
        }
        return false;

    }

What I found out so far:
It seems that the webservice don't receives the username and password property. As I print them I get:

`CN=null, OU=employee, OU=...`

Like I've read at this post Web service recieves null parameters from application using ksoap method it seems ksoap have a problem with colons. I changed my NAMESPACE but without any success. Maybe I need to change my URL too. But how would I do this while I still need to use localhost ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

初心未许 2024-09-18 23:42:01

与往常一样,以这种方式进行 LDAP 绑定测试时,请记住,标准要求用户名绑定(无密码)是成功的匿名绑定,因此您必须在登录尝试时验证这种情况(空密码)。

As always when doing LDAP bind testing this way, recall that the standard requires that a bind of a username, no password, is a successful Anonymous bind, so therefore you MUST validate for this case (empty password) on login attempts.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文