001: /*
002: * BEGIN_HEADER - DO NOT EDIT
003: *
004: * The contents of this file are subject to the terms
005: * of the Common Development and Distribution License
006: * (the "License"). You may not use this file except
007: * in compliance with the License.
008: *
009: * You can obtain a copy of the license at
010: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
011: * See the License for the specific language governing
012: * permissions and limitations under the License.
013: *
014: * When distributing Covered Code, include this CDDL
015: * HEADER in each file and include the License file at
016: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
017: * If applicable add the following below this CDDL HEADER,
018: * with the fields enclosed by brackets "[]" replaced with
019: * your own identifying information: Portions Copyright
020: * [year] [name of copyright owner]
021: */
022:
023: /*
024: * @(#)SecurityConfigImpl.java
025: * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
026: *
027: * END_HEADER - DO NOT EDIT
028: */
029: /**
030: * SecurityConfigImpl.java
031: *
032: * SUN PROPRIETARY/CONFIDENTIAL.
033: * This software is the proprietary information of Sun Microsystems, Inc.
034: * Use is subject to license terms.
035: *
036: * Created on October 26, 2004, 6:40 PM
037: */package com.sun.jbi.internal.security.https.jregress;
038:
039: import com.sun.jbi.internal.security.config.SecurityConfiguration;
040: import com.sun.jbi.internal.security.ContextImpl;
041: import com.sun.jbi.internal.security.Constants;
042:
043: import java.util.HashMap;
044: import java.util.Properties;
045:
046: /**
047: *
048: * @author Sun Microsystems, Inc.
049: */
050: public class SecurityConfigImpl implements SecurityConfiguration {
051:
052: /** The Default Security Configuration */
053: private String mDefaultConfigName;
054:
055: /** The Security Context Map */
056: private Properties mSecurityContext;
057:
058: /** The Default User Domain */
059: private String mDefaultUserDomain;
060:
061: /** The User Domain Map */
062: private HashMap mUserDomains;
063:
064: /** The Default KeyStore Manager */
065: private String mDefaultKeyStoreManager;
066:
067: /** The Key Store Manager Map */
068: private HashMap mKeyStoreMgrCtxs;
069:
070: /** My Instance.*/
071: private static SecurityConfigImpl mInstance = null;
072:
073: /** Hide Constructor. */
074: private SecurityConfigImpl() {
075: // -- This constructor is never called.
076: };
077:
078: /**
079: * Constructor.
080: */
081: private SecurityConfigImpl(String userFileName,
082: String userFileName2, String keystorebase,
083: com.sun.jbi.StringTranslator translator) {
084: mKeyStoreMgrCtxs = new HashMap();
085: mUserDomains = new HashMap();
086:
087: mDefaultKeyStoreManager = "server";
088: mDefaultConfigName = "default";
089:
090: initUserDomains(userFileName, userFileName2);
091: initSecurityContexts(keystorebase);
092: initKeyStoreManagers(keystorebase);
093: }
094:
095: /**
096: * A single shared user domain
097: */
098: private void initUserDomains(String userFile, String userFile2) {
099: Properties[] udProps = new Properties[2];
100:
101: udProps[0] = new Properties();
102:
103: udProps[0].setProperty(Constants.DOMAIN, "JAAS");
104: udProps[0].setProperty(Constants.PARAM_FILE_NAME, userFile);
105: mUserDomains.put("file", udProps[0]);
106:
107: udProps[1] = new Properties();
108: udProps[1].setProperty(Constants.DOMAIN, "JAAS");
109: udProps[1].setProperty(Constants.PARAM_FILE_NAME, userFile2);
110: mUserDomains.put("file2", udProps[1]);
111:
112: }
113:
114: /**
115: * A Single Security Context will be created.
116: */
117: private void initSecurityContexts(String keystorebase) {
118:
119: mSecurityContext = new Properties();
120:
121: }
122:
123: /**
124: * Two KeyStoreManagers are created "server" and "client" for testing purposes.
125: */
126: private void initKeyStoreManagers(String ksbase) {
127:
128: SecurityContextInfo info = new SecurityContextInfo(ksbase);
129:
130: Properties serverKSMgr = new Properties();
131: serverKSMgr.setProperty(Constants.MANAGER, "JavaStandard");
132:
133: serverKSMgr.setProperty(Constants.PARAM_KEYSTORE_LOCATION, info
134: .getServerKeyStoreURL());
135: serverKSMgr.setProperty(Constants.PARAM_KEYSTORE_TYPE, info
136: .getServerKeyStoreType());
137: serverKSMgr.setProperty(Constants.PARAM_KEYSTORE_PASS, info
138: .getClientKeyStorePassword());
139:
140: serverKSMgr.setProperty(Constants.PARAM_TRUSTSTORE_LOCATION,
141: info.getServerTrustStoreURL());
142: serverKSMgr.setProperty(Constants.PARAM_TRUSTSTORE_TYPE, info
143: .getServerTrustStoreType());
144: serverKSMgr.setProperty(Constants.PARAM_TRUSTSTORE_PASS, info
145: .getServerTrustStorePassword());
146: mKeyStoreMgrCtxs.put("server", serverKSMgr);
147:
148: Properties clientKSMgr = new Properties();
149: clientKSMgr.setProperty(Constants.MANAGER, "JavaStandard");
150: clientKSMgr.setProperty(Constants.PARAM_KEYSTORE_LOCATION, info
151: .getClientKeyStoreURL());
152: clientKSMgr.setProperty(Constants.PARAM_KEYSTORE_TYPE, info
153: .getClientKeyStoreType());
154: clientKSMgr.setProperty(Constants.PARAM_KEYSTORE_PASS, info
155: .getClientKeyStorePassword());
156:
157: clientKSMgr.setProperty(Constants.PARAM_TRUSTSTORE_LOCATION,
158: info.getClientTrustStoreURL());
159: clientKSMgr.setProperty(Constants.PARAM_TRUSTSTORE_TYPE, info
160: .getClientTrustStoreType());
161: clientKSMgr.setProperty(Constants.PARAM_TRUSTSTORE_PASS, info
162: .getClientTrustStorePassword());
163: mKeyStoreMgrCtxs.put("client", clientKSMgr);
164: }
165:
166: /**
167: * Get a Map Security Contexts, keyed by their name
168: * [ Key = Name (String) : Value = SecurityContext (Context) ]
169: *
170: * @return the HashMap which has the mappings
171: */
172: public Properties getTransportSecurityContext() {
173: return mSecurityContext;
174: }
175:
176: /**
177: * Get the Name of the default Configuration name
178: *
179: * @param name is the Name of the default configuration
180: */
181: public void setDefaultConfigName(String name) {
182: mDefaultConfigName = name;
183: }
184:
185: /**
186: * Get the Name of the default User Domain
187: *
188: * @return the name of the Default User Domain
189: */
190: public String getDefaultUserDomainName() {
191: return mDefaultUserDomain;
192: }
193:
194: /**
195: * Get a Map of User Domain Contexts by their name
196: * [ Key = Name (string) : Value = UserDomain Contexts (Properties) ]
197: *
198: * @return a map of the User Domain Contexts
199: */
200: public HashMap getUserDomainContexts() {
201: return mUserDomains;
202: }
203:
204: /**
205: * Get the Name of the default KeyStore Service
206: *
207: * @return the name of the default KeyStore.
208: */
209: public String getDefaultKeyStoreManagerName() {
210: return mDefaultKeyStoreManager;
211: }
212:
213: /**
214: * Get a Map of KeyStore Services keyed by their name
215: * [ Key = Name (string) : Value = KeyStoreContexts (Properties) ]
216: *
217: * @return a map of the Key Store Contexts
218: */
219: public HashMap getKeyStoreContexts() {
220: return mKeyStoreMgrCtxs;
221: }
222:
223: /**
224: * Set the Name of the default User Domain
225: *
226: * @param name is the name of the Default User Domain
227: */
228: public void setDefaultUserDomainName(String name) {
229: mDefaultUserDomain = name;
230: }
231:
232: /**
233: * Set the Map of User Domain Contexts by their name.
234: * [ Key = Name (string) : Value = UserDomain Contexts (Properties) ]
235: *
236: * @param map is the UserDomain map
237: */
238: public void setUserDomainContexts(HashMap map) {
239: mUserDomains = map;
240: }
241:
242: /**
243: * Set the Map of the default KeyStore Service.
244: *
245: * @param name is the name of the default KeyStore.
246: */
247: public void setDefaultKeyStoreManagerName(String name) {
248: mDefaultKeyStoreManager = name;
249: }
250:
251: /**
252: * Set the Map of KeyStore Services keyed by their name
253: * [ Key = Name (string) : Value = KeyStoreContexts (Properties) ]
254: *
255: * @param map the KS Manager Context
256: */
257: public void setKeyStoreContexts(HashMap map) {
258: mKeyStoreMgrCtxs = map;
259: }
260:
261: /**
262: * Create a test installation security configuration
263: */
264: public static SecurityConfiguration getTestSecurityConfiguration(
265: String userFileName, String userFileName2,
266: String keystorebase, com.sun.jbi.StringTranslator translator) {
267: if (mInstance == null) {
268: mInstance = new SecurityConfigImpl(userFileName,
269: userFileName2, keystorebase, translator);
270: }
271: return mInstance;
272: }
273:
274: /**
275: *
276: * Not used by the Tests.
277: * @return null, method not used.
278: */
279: public org.w3c.dom.Document generateDocument() {
280: return null;
281: }
282: }
|