开发者

Using Web Service to authenticate on LDAP

开发者 https://www.devze.com 2023-01-10 01:24 出处:网络
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 Ser

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 ?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消