01: /*
02: * $Id: AliasKeyManager.java,v 1.1 2003/10/29 21:21:58 ajzeneski Exp $
03: *
04: * Copyright (c) 2003 The Open For Business Project - www.ofbiz.org
05: *
06: * Permission is hereby granted, free of charge, to any person obtaining a
07: * copy of this software and associated documentation files (the "Software"),
08: * to deal in the Software without restriction, including without limitation
09: * 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;
28: import java.security.PrivateKey;
29: import java.security.cert.X509Certificate;
30: import java.net.Socket;
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 $Revision: 1.1 $
39: * @since 3.0
40: */
41: public class AliasKeyManager implements X509KeyManager {
42:
43: protected X509KeyManager keyManager = null;
44: protected String alias = null;
45:
46: protected AliasKeyManager() {
47: }
48:
49: public AliasKeyManager(X509KeyManager keyManager, String alias) {
50: this .keyManager = keyManager;
51: this .alias = alias;
52: }
53:
54: // this is where the customization comes in
55: public String chooseClientAlias(String[] keyType,
56: Principal[] issuers, Socket socket) {
57: for (int i = 0; i < keyType.length; i++) {
58: String[] aliases = keyManager.getClientAliases(keyType[i],
59: issuers);
60: if (aliases != null && aliases.length > 0) {
61: for (int x = 0; x < aliases.length; x++) {
62: if (alias.equals(aliases[i])) {
63: return alias;
64: }
65: }
66: }
67: }
68: return null;
69: }
70:
71: // these just pass through the keyManager
72: public String chooseServerAlias(String keyType,
73: Principal[] issuers, Socket socket) {
74: return keyManager.chooseServerAlias(keyType, issuers, socket);
75: }
76:
77: public X509Certificate[] getCertificateChain(String alias) {
78: return keyManager.getCertificateChain(alias);
79: }
80:
81: public String[] getClientAliases(String keyType, Principal[] issuers) {
82: return keyManager.getClientAliases(keyType, issuers);
83: }
84:
85: public PrivateKey getPrivateKey(String alias) {
86: return keyManager.getPrivateKey(alias);
87: }
88:
89: public String[] getServerAliases(String keyType, Principal[] issuers) {
90: return keyManager.getServerAliases(keyType, issuers);
91: }
92: }
|