KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ofbiz > base > util > AliasKeyManager


1 /*
2  * $Id: AliasKeyManager.java 5462 2005-08-05 18:35:48Z jonesde $
3  *
4  * Copyright (c) 2003 The Open For Business Project - www.ofbiz.org
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, including without limitation
9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  * and/or sell copies of the Software, and to permit persons to whom the
11  * Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included
14  * in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
21  * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
22  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  *
24  */

25 package org.ofbiz.base.util;
26
27 import java.security.Principal JavaDoc;
28 import java.security.PrivateKey JavaDoc;
29 import java.security.cert.X509Certificate JavaDoc;
30 import java.net.Socket JavaDoc;
31
32 import javax.net.ssl.X509KeyManager;
33
34 /**
35  * AliasKeyManager - KeyManager used to specify a certificate alias
36  *
37  * @author <a HREF="mailto:jaz@ofbiz.org">Andy Zeneski</a>
38  * @version $Rev: 5462 $
39  * @since 3.0
40  */

41 public class AliasKeyManager implements X509KeyManager {
42
43     protected X509KeyManager keyManager = null;
44     protected String JavaDoc alias = null;
45
46     protected AliasKeyManager() {}
47
48     public AliasKeyManager(X509KeyManager keyManager, String JavaDoc alias) {
49         this.keyManager = keyManager;
50         this.alias = alias;
51     }
52
53     // this is where the customization comes in
54
public String JavaDoc chooseClientAlias(String JavaDoc[] keyType, Principal JavaDoc[] issuers, Socket JavaDoc socket) {
55       for (int i = 0; i < keyType.length; i++) {
56           String JavaDoc[] aliases = keyManager.getClientAliases(keyType[i], issuers);
57           if (aliases != null && aliases.length > 0) {
58               for (int x = 0; x < aliases.length; x++) {
59                   if (alias.equals(aliases[i])) {
60                       return alias;
61                   }
62               }
63           }
64       }
65       return null;
66     }
67
68     // these just pass through the keyManager
69
public String JavaDoc chooseServerAlias(String JavaDoc keyType, Principal JavaDoc[] issuers, Socket JavaDoc socket) {
70       return keyManager.chooseServerAlias(keyType, issuers, socket);
71     }
72
73     public X509Certificate JavaDoc[] getCertificateChain(String JavaDoc alias) {
74       return keyManager.getCertificateChain(alias);
75     }
76
77     public String JavaDoc[] getClientAliases(String JavaDoc keyType, Principal JavaDoc[] issuers) {
78       return keyManager.getClientAliases(keyType, issuers);
79     }
80
81     public PrivateKey JavaDoc getPrivateKey(String JavaDoc alias) {
82       return keyManager.getPrivateKey(alias);
83     }
84
85     public String JavaDoc[] getServerAliases(String JavaDoc keyType, Principal JavaDoc[] issuers) {
86       return keyManager.getServerAliases(keyType, issuers);
87     }
88 }
89
Popular Tags