【发布时间】:2010-07-30 10:42:47
【问题描述】:
由于在我的 BlackBerry 应用程序上显然无法使用 LDAP 进行身份验证,因此我正在尝试使用一种解决方法。我不想直接在 LDAP 服务器上进行身份验证,而是想在两者之间使用 Web 服务。所以它看起来像这样
App --calls--> Web Service --calls--> LDAP Server
因此,Web 服务应该从应用程序中获取用户名和密码,并将其发送到 LDAP 服务器。如果可以登录,Web 服务会得到一个 TRUE 作为响应并将其转发给应用程序。
它应该是这样工作的。但是目前,当我从应用程序调用 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 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;
}
到目前为止我发现了什么: 似乎网络服务没有收到用户名和密码属性。当我打印它们时,我得到:
`CN=null, OU=employee, OU=...`
就像我在这篇文章中读到的Web service recieves null parameters from application using ksoap method 一样,ksoap 的冒号似乎有问题。我改变了我的 NAMESPACE 但没有任何成功。也许我也需要更改我的网址。但是当我仍然需要使用 localhost 时,我该怎么做呢?
【问题讨论】:
标签: web-services blackberry ldap connection