Free cookie consent management tool by TermsFeed Policy Generator

source: branches/OKBJavaConnector/src/main/java/com/heuristiclab/okb/wsclient/handler/TrustStoreCallbackHandler.java @ 5673

Last change on this file since 5673 was 5673, checked in by bfarka, 13 years ago

added and mirgrated old java connector project

Added 4 new WSDL Files #1441

File size: 3.4 KB
Line 
1package com.heuristiclab.okb.wsclient.handler;
2
3import java.io.IOException;
4import java.io.InputStream;
5import java.security.KeyStore;
6import java.security.KeyStoreException;
7import java.security.NoSuchAlgorithmException;
8import java.security.cert.CertificateException;
9import java.util.Iterator;
10import java.util.Map;
11import java.util.logging.Level;
12import java.util.logging.Logger;
13
14import javax.security.auth.callback.Callback;
15import javax.security.auth.callback.CallbackHandler;
16import javax.security.auth.callback.UnsupportedCallbackException;
17
18import com.sun.xml.wss.impl.callback.KeyStoreCallback;
19
20
21public class TrustStoreCallbackHandler implements CallbackHandler {
22
23    KeyStore keyStore = null;
24    String password = "changeit";
25    public TrustStoreCallbackHandler() {
26            System.out.println("Truststore CBH.CTOR Called..........");
27            InputStream is = null;
28            try {
29                keyStore = KeyStore.getInstance("JKS");
30                //String keystoreURL = "C:\\Users\\HolperM\\.netbeans\\6.9\\config\\GF3\\domain1\\config\\cacerts.jks";
31                //String keystoreURL = "C:\\Users\\HolperM\\.netbeans\\6.9\\config\\GF3\\domain1\\config\\keystoreHL.jks";
32                //FIXME
33                is = this.getClass().getClassLoader().getResourceAsStream("HLOKB_KeystoreLocalhost.jks");
34                //is = new FileInputStream(keystoreURL);//keystoreURL);
35                //keyStore.load(is, "changeit".toCharArray());
36                keyStore.load(is, "mh2404".toCharArray());
37            } catch (IOException ex) {
38                Logger.getLogger(TrustStoreCallbackHandler.class.getName()).log(Level.SEVERE, null, ex);
39                 throw new RuntimeException(ex);
40            } catch (NoSuchAlgorithmException ex) {
41                Logger.getLogger(TrustStoreCallbackHandler.class.getName()).log(Level.SEVERE, null, ex);
42                 throw new RuntimeException(ex);
43            } catch (CertificateException ex) {
44                Logger.getLogger(TrustStoreCallbackHandler.class.getName()).log(Level.SEVERE, null, ex);
45                 throw new RuntimeException(ex);
46            } catch (KeyStoreException ex) {
47                Logger.getLogger(TrustStoreCallbackHandler.class.getName()).log(Level.SEVERE, null, ex);
48                 throw new RuntimeException(ex);
49            } finally {
50                try {
51                  if (is!=null)
52                    is.close();
53                } catch (IOException ex) {
54                    Logger.getLogger(TrustStoreCallbackHandler.class.getName()).log(Level.SEVERE, null, ex);
55                }
56            }
57    }
58    public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
59        System.out.println("Truststore CBH.handle() Called..........");
60         for (int i = 0; i < callbacks.length; i++) {
61            if (callbacks[i] instanceof KeyStoreCallback) {
62                KeyStoreCallback cb = (KeyStoreCallback) callbacks[i];
63                print(cb.getRuntimeProperties());
64                cb.setKeystore(keyStore);
65            } else {
66                throw new UnsupportedCallbackException(callbacks[i]);
67            }
68        }
69    }
70    private void print(Map context) {
71         Iterator it = context.keySet().iterator();
72         while (it.hasNext()) {
73             System.out.println("Prop " + it.next());
74         }
75     }
76}
Note: See TracBrowser for help on using the repository browser.