系統開發階段就即將結束,使用者整合是個大問題。期間網上查詢了一翻,各種複製粘貼,冗餘資訊量太多太多,甚感悲痛。。。。
有些成功分享,一是講可以通過修改ofProperty表,將Message Service器中的預設使用者表【ofUser】替換為自訂使用者表,可以是公司原使用者表;
二是按照OPenfire的使用者整合管理Custom Database Integration Guide官網的說明,修改設定檔。
都試了一遍,哎,失敗。。。
還好,發現了作者為Justin Hunt開發了一個外掛程式User Service,用起來還是蠻方便的,這裡做簡單介紹。
第一步,下載userservice.jar,添加到Plugin中,研讀相關說明,講的很詳細,也有樣本;
第二步,設定安全密鑰,在server->server
setting->User service中進行配置,並啟動其服務;
第三步,建立使用者,發送HTTP請求到使用者服務中心【submit
HTTP requests to the userservice service】
/** * init Openfire User via httpRequest dml@2012.9.14 * * @param url */private static void httpExecute(String url) {// 構造HttpClient的執行個體HttpClient httpClient = new HttpClient();// 設定 Http 連線逾時為5秒httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(5000);// 建立GET方法的執行個體GetMethod getMethod = new GetMethod(url);// 設定 get 請求逾時為 5 秒getMethod.getParams().setParameter(HttpMethodParams.SO_TIMEOUT, 5000);// 使用系統提供的預設的恢複策略getMethod.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,new DefaultHttpMethodRetryHandler());try {// 執行getMethodint statusCode = httpClient.executeMethod(getMethod);if (statusCode != HttpStatus.SC_OK) {log.warning("Method failed: " + getMethod.getStatusLine());}// 讀取內容 ,第一種方式擷取byte[] responseBody = getMethod.getResponseBody();// 處理內容log.info(new String(responseBody));} catch (HttpException e) {// 發生致命的異常,可能是協議不對或者返回的內容有問題log.info("Please check your provided http address!");e.printStackTrace();} catch (IOException e) {// 發生網路異常e.printStackTrace();} finally {// 釋放串連getMethod.releaseConnection();}}
以上代碼需匯入HttpClient.jar包,url為傳入參數,自行定義,格式見user service協助【http://example.com:9090/plugins/userService/userservice?type=add&secret=bigsecret&username=kafka&password=drowssap&name=f】
第四步,添加組資訊,組資訊直接添加到ofGroupUser表中即可,這裡不做贅述了。
第五步,重啟openfire伺服器,進行測試。。。