2013-04-02 56 views
0

我每天都需要執行例程,連接到遠程地址,使用智能卡進行身份驗證,然後在此遠程地址檢查我的用戶名的任何新信息。Java智能卡HttpClient身份驗證

我想做這個例程自動,創建一個Java應用程序,將連接到該地址,用智能卡進行身份驗證,然後檢查是否有任何新的信息。

我試過了,但沒有成功用智能卡設置HttpClient環境,我將卡插在我的機器上並設置Cronjob運行,它返回了沒有插入卡的警告。

的代碼如下:

HttpClient httpClient = new DefaultHttpClient(); 
      // Secure Protocol implementation. 
      SSLContext ctx = SSLContext.getInstance("SSL"); 
      // Implementation of a trust manager for X509 certificates 
      X509TrustManager tm = new X509TrustManager() { 

       public java.security.cert.X509Certificate[] getAcceptedIssuers() { 
        return null; 
       } 

       public void checkClientTrusted(java.security.cert.X509Certificate[] arg0, String arg1) throws java.security.cert.CertificateException { 
        // TODO Auto-generated method stub 
       } 

       @Override 
       public void checkServerTrusted(
         java.security.cert.X509Certificate[] arg0, String arg1) 
         throws java.security.cert.CertificateException { 
        // TODO Auto-generated method stub 

       } 
      }; 
      ctx.init(null, new TrustManager[] { tm }, null); 
      SSLSocketFactory ssf = new SSLSocketFactory(ctx); 

      ClientConnectionManager ccm = httpClient.getConnectionManager(); 
      // register https protocol in httpclient's scheme registry 
      SchemeRegistry sr = ccm.getSchemeRegistry(); 
      sr.register(new Scheme("https", 443, ssf)); 

      HttpGet httpget = new HttpGet("http://remoteserver.com/login.seam"); 
      HttpParams params = httpclient.getParams(); 

      params.setParameter("param1", "paramValue1"); 

      httpget.setParams(params); 
      System.out.println("REQUEST:" + httpget.getURI()); 
      ResponseHandler responseHandler = new BasicResponseHandler(); 
      String responseBody; 

      responseBody = httpclient.execute(httpget, responseHandler); 

      System.out.println(responseBody); 

是否有任何與它的幫助嗎?我搜索了很多,但我無法連接使用智能卡...

在此先感謝和抱歉我的英語不好。

回答

1

我們沒有看到關於智能卡讀卡器的代碼。 第一次你必須從你的智能卡獲取信息。 嘗試查看如何使用smartcardio庫。 然後將所有信息從您的應用程序發送到網站。

我認爲它可以幫助你,如果我明白你的問題。