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

时间:2010-07-30 10:42:47

标签: web-services blackberry ldap connection

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

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

因此,Web Service应该获取应用程序提供的用户名和密码,并将其发送到LDAP服务器。如果可以登录,则Web服务将获得TRUE作为响应并将其转发给App。

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

  

SoapFault - faultcode: 'S:Server' faultstring: 'java.lang.NullPointerException' faultactor: 'null' detail: 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;

    }

到目前为止我发现了什么: 似乎webservice没有收到用户名和密码属性。当我打印出来时,我得到:

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

就像我在这篇文章Web service recieves null parameters from application using ksoap method上看到的那样,ksoap似乎有冒号问题。我改变了我的NAMESPACE但没有任何成功。也许我也需要更改我的URL。但是,当我仍然需要使用localhost时,我该怎么做呢?

1 个答案:

答案 0 :(得分:1)

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