KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > servicemix > soap > handlers > security > KeystoreInstanceCrypto


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17 package org.apache.servicemix.soap.handlers.security;
18
19 import java.security.KeyStoreException JavaDoc;
20 import java.security.PrivateKey JavaDoc;
21 import java.security.cert.Certificate JavaDoc;
22 import java.util.ArrayList JavaDoc;
23 import java.util.Arrays JavaDoc;
24 import java.util.List JavaDoc;
25
26 import org.apache.servicemix.jbi.security.keystore.KeystoreInstance;
27 import org.apache.servicemix.jbi.security.keystore.KeystoreManager;
28
29 public class KeystoreInstanceCrypto extends BaseCrypto {
30
31     private KeystoreInstance keystore;
32     
33     public KeystoreInstanceCrypto() {
34     }
35     
36     public KeystoreInstanceCrypto(KeystoreInstance keystore) {
37         this.keystore = keystore;
38     }
39     
40     public KeystoreInstanceCrypto(KeystoreManager keystoreManager, String JavaDoc keystore) {
41         this.keystore = keystoreManager.getKeystore(keystore);
42     }
43     
44     /**
45      * @return the keystore
46      */

47     public KeystoreInstance getKeystore() {
48         return keystore;
49     }
50
51     /**
52      * @param keystore the keystore to set
53      */

54     public void setKeystore(KeystoreInstance keystore) {
55         this.keystore = keystore;
56     }
57
58     protected String JavaDoc[] getAliases() throws KeyStoreException JavaDoc {
59         String JavaDoc[] pks = keystore.listPrivateKeys();
60         String JavaDoc[] tcs = keystore.listTrustCertificates();
61         List JavaDoc aliases = new ArrayList JavaDoc();
62         aliases.addAll(Arrays.asList(pks));
63         aliases.addAll(Arrays.asList(tcs));
64         return (String JavaDoc[]) aliases.toArray(new String JavaDoc[aliases.size()]);
65     }
66
67     protected Certificate JavaDoc getCertificate(String JavaDoc alias) throws KeyStoreException JavaDoc {
68         return keystore.getCertificate(alias);
69     }
70
71     protected String JavaDoc getCertificateAlias(Certificate JavaDoc cert) throws KeyStoreException JavaDoc {
72         return keystore.getCertificateAlias(cert);
73     }
74
75     protected Certificate JavaDoc[] getCertificateChain(String JavaDoc alias) throws KeyStoreException JavaDoc {
76         return keystore.getCertificateChain(alias);
77     }
78
79     public PrivateKey JavaDoc getPrivateKey(String JavaDoc alias, String JavaDoc password) throws Exception JavaDoc {
80         return keystore.getPrivateKey(alias);
81     }
82
83     protected String JavaDoc[] getTrustCertificates() throws KeyStoreException JavaDoc {
84         return keystore.listTrustCertificates();
85     }
86
87 }
88
Popular Tags