1 | package com.heuristiclab.okb.wsclient.handler;
|
---|
2 |
|
---|
3 | import java.io.IOException;
|
---|
4 | import java.io.InputStream;
|
---|
5 | import java.security.KeyStore;
|
---|
6 | import java.security.KeyStoreException;
|
---|
7 | import java.security.NoSuchAlgorithmException;
|
---|
8 | import java.security.cert.CertificateException;
|
---|
9 | import java.util.Iterator;
|
---|
10 | import java.util.Map;
|
---|
11 | import java.util.logging.Level;
|
---|
12 | import java.util.logging.Logger;
|
---|
13 |
|
---|
14 | import javax.security.auth.callback.Callback;
|
---|
15 | import javax.security.auth.callback.CallbackHandler;
|
---|
16 | import javax.security.auth.callback.UnsupportedCallbackException;
|
---|
17 |
|
---|
18 | import com.sun.xml.wss.impl.callback.KeyStoreCallback;
|
---|
19 |
|
---|
20 |
|
---|
21 | public 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 | }
|
---|