這個案例是對方已經有寫好的webService驗證,我們只要去打他的ws就可以了

在pathList那邊應該要從設定檔或是DB取出ws路徑,(在這邊我new一個List<Map<String,Object>>做示範)

因為有可能跨國企業,會有需要在不同路徑做驗證的問題

 

checkPath是ws路徑,session_id是登入驗證資訊

 

image

 

文字如下:

 

    public static boolean checkEIPAuth(String sessionId) throws Exception {
        boolean result = false;
        
        if(sessionId.isEmpty()){
            return result;
        }
        
        // 取得EIP驗證ws path
        List<Map<String, Object>> pathList = new ArrayList<Map<String, Object>>();
        for(Map<String,Object> map : pathList){
            
            String eipCheckPath = map.get("checkPath") + "session_id=";
            LOG.debug("LoginAction eipCheckPath=" + eipCheckPath);
            CloseableHttpClient client = null;
            CloseableHttpResponse response = null;
            
            try {
                // 建立CloseableHttpClient
                HttpClientBuilder builder = HttpClientBuilder.create();
                client = builder.build();
                // 執行
                HttpUriRequest httpGet = new HttpGet(eipCheckPath + sessionId);

                response = client.execute(httpGet);
                // 請求傳送成功,並得到響應
                if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
                    // 讀取伺服器返回過來的資料
                    HttpEntity entity = response.getEntity();

                    if (entity != null) {
                        result = Boolean.parseBoolean(EntityUtils.toString(entity));
                        if(result == true){
                            break;
                        }
                    } 
                }

            } catch (Exception e) {
                LOG.debug("LoginAction checkEIPAuthPath Exception = " + e.getMessage());

            } finally {
                if (response != null)
                    response.close();
                if (client != null)
                    client.close();

            }
        }
        LOG.debug("LoginAction eipCheckPath result" + result);
        return result;
    }

 

 

 

arrow
arrow
    文章標籤
    JAVA 登入驗證
    全站熱搜

    我的暱稱 發表在 痞客邦 留言(0) 人氣()