0
我正在爲我的數據庫構建一個LDAP接口。當一個客戶端請求bind()時,它將在數據庫中搜索並檢查它是否有效。UnboundID:如何封裝processBindRequest返回值?
public class Main {
LDAPListener listener ;
Main() {}
public static void main(String[] args) {
Main main = new Main();
int port = main.StartServer();
try {
LDAPConnection cn = new LDAPConnection("localhost",port);
System.out.println("."+cn.isConnected()+" "+cn.getConnectedPort());
cn.bind("uid=user,ou=People,dc=example,dc=com", "pass");
cn.close();
main.StopServer();
} catch (Exception e){e.printStackTrace();
main.StopServer();}
}
public int StartServer() {
int listenPort = 0;
RequestHandler requestHandler = new RequestHandler();
LDAPListenerConfig config = new LDAPListenerConfig(listenPort, requestHandler);
listener = new LDAPListener(config);
try {
listener.startListening();
System.out.println(">port "+listener.getListenPort());
} catch (Exception e){System.out.println("e1> "+e.getMessage());}
return listener.getListenPort();
}
public void StopServer(){
System.out.println(">shutdown");
listener.shutDown(true);
}
}
然後,我修改LDAPListenerRequestHandler與數據庫進行通信,得到記錄作爲返回值:
class RequestHandler extends LDAPListenerRequestHandler {
@Override
public LDAPMessage processBindRequest(int arg0, BindRequestProtocolOp arg1,
List<Control> arg2) {
String uid = arg1.getBindDN();
String pass = arg1.getSimplePassword();
System.out.println(">bind: "+ uid);
// Database query: SELECT * FROM user WHERE username='uid' AND password='pass'
// Get the record as return value
return null;
}
}
當我運行它,我從綁定線錯誤消息:
LDAPException(resultCode=80 (other), errorMessage='An unexpected exception was thrown while attempting to process the requested operation: NullPointerException(trace='run(LDAPListenerClientConnection.java:461)', revision=15579)', diagnosticMessage='An unexpected exception was thrown while attempting to process the requested operation: NullPointerException(trace='run(LDAPListenerClientConnection.java:461)', revision=15579)')
at com.unboundid.ldap.sdk.LDAPConnection.bind(LDAPConnection.java:1881)
at com.unboundid.ldap.sdk.LDAPConnection.bind(LDAPConnection.java:1799)
我想,它是由processBindRequest()返回null引起的。如何在我的數據庫記錄中封裝LDAPMessage進程?
感謝您的回答。編輯processBindRequest()後我仍然得到相同的錯誤ResultCode = 80 – vladschwartz
我建議您啓用調試日誌記錄(如com.unboundid.util.Debug類中所述),看看哪裏和什麼異常被拋出。由於您沒有提供完整的代碼,因此很難知道具體問題是什麼。 –