Source Code Cross Referenced for SecurityInstallConfig.java in  » ESB » open-esb » com » sun » jbi » internal » security » config » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » ESB » open esb » com.sun.jbi.internal.security.config 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*
0002:         * BEGIN_HEADER - DO NOT EDIT
0003:         *
0004:         * The contents of this file are subject to the terms
0005:         * of the Common Development and Distribution License
0006:         * (the "License").  You may not use this file except
0007:         * in compliance with the License.
0008:         *
0009:         * You can obtain a copy of the license at
0010:         * https://open-esb.dev.java.net/public/CDDLv1.0.html.
0011:         * See the License for the specific language governing
0012:         * permissions and limitations under the License.
0013:         *
0014:         * When distributing Covered Code, include this CDDL
0015:         * HEADER in each file and include the License file at
0016:         * https://open-esb.dev.java.net/public/CDDLv1.0.html.
0017:         * If applicable add the following below this CDDL HEADER,
0018:         * with the fields enclosed by brackets "[]" replaced with
0019:         * your own identifying information: Portions Copyright
0020:         * [year] [name of copyright owner]
0021:         */
0022:
0023:        /*
0024:         * @(#)SecurityInstallConfig.java
0025:         * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
0026:         *
0027:         * END_HEADER - DO NOT EDIT
0028:         */
0029:        /**
0030:         *  SecurityInstallConfig.java
0031:         *
0032:         *  SUN PROPRIETARY/CONFIDENTIAL.
0033:         *  This software is the proprietary information of Sun Microsystems, Inc.
0034:         *  Use is subject to license terms.
0035:         *
0036:         *  Created on December 16, 2004, 2:49 PM
0037:         */package com.sun.jbi.internal.security.config;
0038:
0039:        import com.sun.jbi.StringTranslator;
0040:        import com.sun.jbi.internal.security.Constants;
0041:        import com.sun.jbi.internal.security.LocalStringConstants;
0042:        import com.sun.jbi.internal.security.https.HttpConstants;
0043:        import com.sun.jbi.management.common.GenericConfigurationMBean;
0044:
0045:        import java.util.Enumeration;
0046:        import java.util.HashMap;
0047:        import java.util.Iterator;
0048:        import java.util.Properties;
0049:        import java.util.logging.Logger;
0050:        import java.util.regex.Pattern;
0051:
0052:        import javax.jbi.JBIException;
0053:        import javax.xml.parsers.DocumentBuilderFactory;
0054:        import javax.xml.transform.Transformer;
0055:        import javax.xml.transform.TransformerFactory;
0056:        import org.w3c.dom.Document;
0057:        import org.w3c.dom.Element;
0058:        import org.w3c.dom.Text;
0059:        import org.w3c.dom.Node;
0060:        import org.w3c.dom.NodeList;
0061:
0062:        /**
0063:         * Class which encapsulates the installation configuration for the
0064:         * Security Service.
0065:         *
0066:         * Remember : modifiers should be synchronized.
0067:         *
0068:         * @author Sun Microsystems, Inc.
0069:         */
0070:        public class SecurityInstallConfig implements 
0071:                com.sun.jbi.internal.security.config.SecurityConfiguration {
0072:            /**
0073:             * Missing Property String.
0074:             */
0075:            private final String mMissingProperty = "PROPERTY_NOT_FOUND";
0076:
0077:            /** 
0078:             * The User Domains map. This map contains the UserDomain information keyed by the
0079:             * name of the domain. The Value is a Properties object that has all the attributes
0080:             * specified for the domain
0081:             */
0082:            private HashMap mUserDomains;
0083:
0084:            /** 
0085:             * The KeyStoreManagers map. This map contains the KeyStoreManager information Keyed 
0086:             * by the name of the manager. The Value is a Properties object that has all the 
0087:             * attributes specified for the manager.
0088:             */
0089:            private HashMap mKeyStoreManagers;
0090:
0091:            /** 
0092:             * The SSL Context.
0093:             */
0094:            private Properties mTransportSecurityContext;
0095:
0096:            /** Default UserDomain */
0097:            private String mDefUD;
0098:
0099:            /** Default Security Context */
0100:            private String mDefSecCtx;
0101:
0102:            /** Default KeyStore Manager */
0103:            private String mDefKSMgr;
0104:
0105:            /** The String Translator to use. */
0106:            private StringTranslator mTranslator;
0107:
0108:            /** The Logger. */
0109:            private Logger mLogger;
0110:
0111:            /** Flag indicating if the Security Configuration has changed. */
0112:            private boolean mIsDirty;
0113:
0114:            /** The DOM form of this configuration. */
0115:            private Document mDom;
0116:
0117:            /** Dot Pattern. */
0118:            private static final String DOT_PATTERN = "\\x2E";
0119:
0120:            /** UD Prefix. */
0121:            private static final String UD_PREFIX = "uds.ud";
0122:
0123:            /** UD pattern. */
0124:            private static final String UD_PATTERN = "uds" + DOT_PATTERN + "ud";
0125:
0126:            /** KM Prefix. */
0127:            private static final String KM_PREFIX = "kms.km";
0128:
0129:            /** KM pattern. */
0130:            private static final String KM_PATTERN = "kms" + DOT_PATTERN + "km";
0131:
0132:            /** Transport Prefix. */
0133:            private static final String TRANSPORT_PREFIX = "transports";
0134:
0135:            /** Default Suffix. */
0136:            private static final String DEFAULT_SUFFIX = ".default";
0137:
0138:            /** Generic Pattern. */
0139:            private static final String ANY_PATTERN = ".*";
0140:
0141:            /** Default User Domain Property. */
0142:            private static final String DEF_UD_KEY = UD_PREFIX + DEFAULT_SUFFIX;
0143:
0144:            /** Default Key Store Manager Property. */
0145:            private static final String DEF_KM_KEY = KM_PREFIX + DEFAULT_SUFFIX;
0146:
0147:            /** Name suffix. */
0148:            private static final String NAME_SUFFIX = ".name";
0149:
0150:            /** Domain suffix. */
0151:            private static final String DOMAIN_SUFFIX = ".domain";
0152:
0153:            /** Param suffix. */
0154:            private static final String PARAM_SUFFIX = ".param";
0155:
0156:            /** Param Pattern. */
0157:            private static final String PARAM_PATTERN = "[[" + DOT_PATTERN
0158:                    + "]param]";
0159:
0160:            /** Param suffix. */
0161:            private static final String VALUE_SUFFIX = ".value";
0162:
0163:            /** Manager suffix. */
0164:            private static final String MANAGER_SUFFIX = ".manager";
0165:
0166:            /** 
0167:             * Creates a new instance of SecurityInstallConfig.
0168:             *
0169:             * @param translator is the StringTranslator.
0170:             */
0171:            public SecurityInstallConfig(StringTranslator translator) {
0172:                mTranslator = translator;
0173:                mLogger = Logger
0174:                        .getLogger(com.sun.jbi.internal.security.Constants.PACKAGE);
0175:                mUserDomains = new HashMap();
0176:                mKeyStoreManagers = new HashMap();
0177:                createDefaultTransportSecurityCtx();
0178:                mIsDirty = true;
0179:                mDom = null;
0180:            }
0181:
0182:            /**
0183:             * As the name suggests generate a DOM from the Configuration data this object holds.
0184:             *
0185:             * @return a DOM based on the state of this object.
0186:             * @throws JBIException on errors.
0187:             */
0188:            public synchronized org.w3c.dom.Document generateDocument()
0189:                    throws JBIException {
0190:                if (!mIsDirty) {
0191:                    return mDom;
0192:                }
0193:
0194:                try {
0195:                    validate();
0196:
0197:                    // -- Create a New Document
0198:                    mDom = DocumentBuilderFactory.newInstance()
0199:                            .newDocumentBuilder().newDocument();
0200:
0201:                    // -- Add the root element
0202:                    Element root = mDom
0203:                            .createElement(Constants.ELEMENT_SECURITY_CONFIGURATION);
0204:                    mDom.appendChild(root);
0205:
0206:                    // -- Add the UserDomains
0207:                    addUserDomains(mDom);
0208:
0209:                    // -- Add the KeyStoreManagers
0210:                    addKeyStoreManagers(mDom);
0211:
0212:                    // -- Add the Security Contexts
0213:                    addSecurityContexts(mDom);
0214:
0215:                } catch (Exception ex) {
0216:                    throw new JBIException(ex);
0217:                }
0218:                return mDom;
0219:            }
0220:
0221:            /**
0222:             * @param dom Document to which this element is to be added.
0223:             * @throws Exception on errors.
0224:             * 
0225:             */
0226:            private void addUserDomains(Document dom) throws Exception {
0227:                Element uds = dom.createElement(Constants.ELEMENT_USER_DOMAINS);
0228:                Element defUd = dom.createElement(Constants.ELEMENT_DEFAULT);
0229:                Text txtDefUd = dom.createTextNode(getDefaultUserDomainName());
0230:                defUd.appendChild(txtDefUd);
0231:                uds.appendChild(defUd);
0232:
0233:                Iterator itr = getUserDomainContexts().keySet().iterator();
0234:
0235:                while (itr.hasNext()) {
0236:                    Element ud = dom
0237:                            .createElement(Constants.ELEMENT_USER_DOMAIN);
0238:
0239:                    String name = (String) itr.next();
0240:                    Element elName = dom.createElement(Constants.ELEMENT_NAME);
0241:                    Text txtName = dom.createTextNode(name);
0242:                    elName.appendChild(txtName);
0243:
0244:                    Element domain = dom
0245:                            .createElement(Constants.ELEMENT_DOMAIN);
0246:
0247:                    Properties udProps = (Properties) getUserDomainContexts()
0248:                            .get(name);
0249:
0250:                    for (Enumeration e = udProps.propertyNames(); e
0251:                            .hasMoreElements();) {
0252:
0253:                        String key = (String) e.nextElement();
0254:                        String value = (String) udProps.getProperty(key);
0255:
0256:                        if (Constants.DOMAIN.equals(key)) {
0257:                            Text text = dom.createTextNode(value);
0258:                            domain.appendChild(text);
0259:                            ud.insertBefore(domain, ud.getFirstChild());
0260:                        } else {
0261:                            addParameter(dom, ud, key, value);
0262:                        }
0263:                    }
0264:                    ud.insertBefore(elName, ud.getFirstChild());
0265:                    uds.appendChild(ud);
0266:                }
0267:                dom.getDocumentElement().appendChild(uds);
0268:            }
0269:
0270:            /**
0271:             * Add a parameter to a Element
0272:             *
0273:             * @param dom is the main Document to which the elements are added.
0274:             * @param parent is the parent element to which the parameter is to be added.
0275:             * @param key is the paramname.
0276:             * @param value is the paramvalue.
0277:             */
0278:            private void addParameter(Document dom, Element parent, String key,
0279:                    String value) {
0280:                Element param = dom.createElement(Constants.ELEMENT_PARAM);
0281:                Element paramname = dom
0282:                        .createElement(Constants.ELEMENT_PARAM_NAME);
0283:                Element paramvalue = dom
0284:                        .createElement(Constants.ELEMENT_PARAM_VALUE);
0285:
0286:                Text txtName = dom.createTextNode(key);
0287:                Text txtValue = dom.createTextNode(value);
0288:
0289:                paramname.appendChild(txtName);
0290:                paramvalue.appendChild(txtValue);
0291:
0292:                param.appendChild(paramname);
0293:                param.appendChild(paramvalue);
0294:
0295:                parent.appendChild(param);
0296:            }
0297:
0298:            /**
0299:             * @param dom Document to which this element is to be added.
0300:             * @throws Exception on errors
0301:             * 
0302:             */
0303:            private void addKeyStoreManagers(Document dom) throws Exception {
0304:                Element kms = dom
0305:                        .createElement(Constants.ELEMENT_KEYSTORE_MANAGERS);
0306:                Element defKm = dom.createElement(Constants.ELEMENT_DEFAULT);
0307:                Text txtDefKm = dom
0308:                        .createTextNode(getDefaultKeyStoreManagerName());
0309:                defKm.appendChild(txtDefKm);
0310:                kms.appendChild(defKm);
0311:
0312:                Iterator itr = getKeyStoreContexts().keySet().iterator();
0313:
0314:                while (itr.hasNext()) {
0315:                    Element ks = dom
0316:                            .createElement(Constants.ELEMENT_KEYSTORE_MANAGER);
0317:
0318:                    String name = (String) itr.next();
0319:                    Element elName = dom.createElement(Constants.ELEMENT_NAME);
0320:                    Text txtName = dom.createTextNode(name);
0321:                    elName.appendChild(txtName);
0322:
0323:                    Element manager = dom
0324:                            .createElement(Constants.ELEMENT_MANAGER);
0325:
0326:                    Properties ksProps = (Properties) getKeyStoreContexts()
0327:                            .get(name);
0328:
0329:                    for (Enumeration e = ksProps.propertyNames(); e
0330:                            .hasMoreElements();) {
0331:
0332:                        String key = (String) e.nextElement();
0333:                        String value = (String) ksProps.getProperty(key);
0334:
0335:                        if (Constants.MANAGER.equals(key)) {
0336:                            Text text = dom.createTextNode(value);
0337:                            manager.appendChild(text);
0338:                            ks.insertBefore(manager, ks.getFirstChild());
0339:                        } else {
0340:                            addParameter(dom, ks, key, value);
0341:                        }
0342:                    }
0343:                    ks.insertBefore(elName, ks.getFirstChild());
0344:                    kms.appendChild(ks);
0345:                }
0346:                dom.getDocumentElement().appendChild(kms);
0347:            }
0348:
0349:            /**
0350:             * @param dom Document to which this element is to be added.
0351:             */
0352:            public void addSecurityContexts(Document dom) {
0353:
0354:                Element ts = dom
0355:                        .createElement(Constants.ELEMENT_TRANSPORT_SECURITY);
0356:                Element server = dom.createElement(Constants.ELEMENT_SERVER);
0357:                Element client = dom.createElement(Constants.ELEMENT_CLIENT);
0358:
0359:                // -- Add the client Child elements
0360:                client.appendChild(createTextElement(dom,
0361:                        Constants.ELEMENT_SSL_USE_DEFAULT, Boolean
0362:                                .toString(getSSLClientUseDefault())));
0363:                client
0364:                        .appendChild(createTextElement(dom,
0365:                                Constants.ELEMENT_SSL_PROTOCOL,
0366:                                getSSLClientProtocol()));
0367:                client
0368:                        .appendChild(createTextElement(dom,
0369:                                Constants.ELEMENT_SSL_CLIENT_ALIAS,
0370:                                getSSLClientAlias()));
0371:
0372:                // -- Add the server Child Elements
0373:                server.appendChild(createTextElement(dom,
0374:                        Constants.ELEMENT_SSL_REQ_CLIENT_AUTH, Boolean
0375:                                .toString(getSSLServerRequireClientAuth())));
0376:
0377:                ts.appendChild(server);
0378:                ts.appendChild(client);
0379:
0380:                dom.getDocumentElement().appendChild(ts);
0381:
0382:            }
0383:
0384:            /**
0385:             * create an Element with the Text value
0386:             *
0387:             * @param dom is the parent document.
0388:             * @param elName is the Element Name.
0389:             * @param textValue is the textValue
0390:             * @return the created Element
0391:             */
0392:            private Element createTextElement(Document dom, String elName,
0393:                    String textValue) {
0394:                Element el = dom.createElement(elName);
0395:                Text txt = dom.createTextNode(textValue);
0396:                el.appendChild(txt);
0397:                return el;
0398:            }
0399:
0400:            /**
0401:             * Validate the State of this Object.
0402:             *
0403:             * @throws JBIException if the state is invalid. The Message in the exception
0404:             * should give an indication of the errorenous state.
0405:             */
0406:            public void validate() throws JBIException {
0407:                // -- There should be atleast one of each User Domain, KeyStore Manager 
0408:                // -- && Security Context defined.
0409:                if (mUserDomains.size() < 1) {
0410:                    String msg = mTranslator.getString(
0411:                            LocalStringConstants.BC_ERR_MISSING_CONFIG_ELEMENT,
0412:                            mTranslator
0413:                                    .getString(LocalStringConstants.CONST_UD));
0414:                    throw new JBIException(msg);
0415:                }
0416:
0417:                if (mKeyStoreManagers.size() < 1) {
0418:                    String msg = mTranslator.getString(
0419:                            LocalStringConstants.BC_ERR_MISSING_CONFIG_ELEMENT,
0420:                            mTranslator
0421:                                    .getString(LocalStringConstants.CONST_KM));
0422:                    throw new JBIException(msg);
0423:                }
0424:
0425:                // -- Check if all the defaults exist.
0426:                if (!mUserDomains.containsKey(getDefaultUserDomainName())) {
0427:                    String msg = mTranslator
0428:                            .getString(
0429:                                    LocalStringConstants.BC_ERR_DEFAULT_CONFIG_ELEMENT_MISSING,
0430:                                    mTranslator
0431:                                            .getString(LocalStringConstants.CONST_UD),
0432:                                    getDefaultUserDomainName());
0433:                    throw new JBIException(msg);
0434:                }
0435:
0436:                if (!mKeyStoreManagers
0437:                        .containsKey(getDefaultKeyStoreManagerName())) {
0438:                    String msg = mTranslator
0439:                            .getString(
0440:                                    LocalStringConstants.BC_ERR_DEFAULT_CONFIG_ELEMENT_MISSING,
0441:                                    mTranslator
0442:                                            .getString(LocalStringConstants.CONST_KM),
0443:                                    getDefaultKeyStoreManagerName());
0444:                    throw new JBIException(msg);
0445:                }
0446:
0447:            }
0448:
0449:            /*-------------------------------------------------------------------------------*\
0450:             *                     Accessors and Mutators                                    *
0451:            \*-------------------------------------------------------------------------------*/
0452:
0453:            // -- Set the Defaults
0454:            /**
0455:             * @param defUserDomain is the default User Domain.
0456:             */
0457:            public synchronized void setDefaultUserDomainName(
0458:                    String defUserDomain) {
0459:                mIsDirty = true;
0460:                mDefUD = defUserDomain;
0461:            }
0462:
0463:            /**
0464:             * @param defKSMgr is the default KeyStore Manager.
0465:             */
0466:            public synchronized void setDefaultKeyStoreManagerName(
0467:                    String defKSMgr) {
0468:                mIsDirty = true;
0469:                mDefKSMgr = defKSMgr;
0470:            }
0471:
0472:            /**
0473:             * Add a new User Domain. If a User Domain by the specified name exists, it is
0474:             * overwritten with the new one.
0475:             *
0476:             * @param name of the domain.
0477:             * @param domain is the implementation class that implements the UserDomain interface.
0478:             */
0479:            public synchronized void addUserDomain(String name, String domain) {
0480:                mIsDirty = true;
0481:                Properties props = new Properties();
0482:                props.setProperty(Constants.DOMAIN, domain);
0483:
0484:                mUserDomains.put(name, props);
0485:            }
0486:
0487:            /**
0488:             * Remove a User Domain. 
0489:             *
0490:             * @param name of the domain.
0491:             */
0492:            public synchronized void removeUserDomain(String name) {
0493:                mIsDirty = true;
0494:                mUserDomains.remove(name);
0495:            }
0496:
0497:            /**
0498:             * Add a parameter to a User Domain, if the domain does not exist, the parameter is
0499:             * not added.
0500:             *
0501:             * @param domain name of the UserDomain.
0502:             * @param name is the name of the parameter.
0503:             * @param value is the value for the parameter.
0504:             */
0505:            public synchronized void addParameterToUserDomain(String domain,
0506:                    String name, String value) {
0507:                mIsDirty = true;
0508:                if (mUserDomains.containsKey(domain)) {
0509:                    Properties props = (Properties) mUserDomains.get(domain);
0510:                    props.setProperty(name, value);
0511:                    mUserDomains.put(domain, props);
0512:                } else {
0513:                    mLogger
0514:                            .warning(mTranslator
0515:                                    .getString(
0516:                                            LocalStringConstants.BC_WRN_FAILED_TO_ADD_PARAM,
0517:                                            new String[] {
0518:                                                    name,
0519:                                                    value,
0520:                                                    mTranslator
0521:                                                            .getString(LocalStringConstants.CONST_UD),
0522:                                                    domain, }));
0523:                }
0524:            }
0525:
0526:            /**
0527:             * Remove a parameter to a User Domain.
0528:             *
0529:             * @param domain name of the UserDomain.
0530:             * @param name is the name of the parameter.
0531:             */
0532:            public synchronized void removeParameterFromUserDomain(
0533:                    String domain, String name) {
0534:                mIsDirty = true;
0535:                if (mUserDomains.containsKey(domain)) {
0536:                    Properties props = (Properties) mUserDomains.get(domain);
0537:                    props.remove(name);
0538:                }
0539:            }
0540:
0541:            /**
0542:             * Add a new KeyStore Manager. If a KeyStoreManager by the specified name exists, 
0543:             * it is overwritten with the new one.
0544:             *
0545:             * @param name of the manager.
0546:             * @param manager is the implementation class that implements the KeyStoreManager 
0547:             * interface.
0548:             */
0549:            public synchronized void addKeyStoreManager(String name,
0550:                    String manager) {
0551:                mIsDirty = true;
0552:                Properties props = new Properties();
0553:                props.setProperty(Constants.MANAGER, manager);
0554:
0555:                mKeyStoreManagers.put(name, props);
0556:            }
0557:
0558:            /**
0559:             * Remove a KeyStore Manager. 
0560:             *
0561:             * @param name of the manager.
0562:             */
0563:            public synchronized void removeKeyStoreManager(String name) {
0564:                mIsDirty = true;
0565:                mKeyStoreManagers.remove(name);
0566:            }
0567:
0568:            /**
0569:             * Add a parameter to a KeyStoreManager, if it does not exist, the parameter is
0570:             * not added.
0571:             *
0572:             * @param manager is the name of the KeyStoreManager.
0573:             * @param name is the name of the parameter.
0574:             * @param value is the value for the parameter.
0575:             */
0576:            public synchronized void addParameterToKeyStoreManager(
0577:                    String manager, String name, String value) {
0578:                mIsDirty = true;
0579:                if (mKeyStoreManagers.containsKey(manager)) {
0580:                    Properties props = (Properties) mKeyStoreManagers
0581:                            .get(manager);
0582:                    props.setProperty(name, value);
0583:                } else {
0584:                    mLogger
0585:                            .warning(mTranslator
0586:                                    .getString(
0587:                                            LocalStringConstants.BC_WRN_FAILED_TO_ADD_PARAM,
0588:                                            new String[] {
0589:                                                    name,
0590:                                                    value,
0591:                                                    mTranslator
0592:                                                            .getString(LocalStringConstants.CONST_KM),
0593:                                                    manager, }));
0594:                }
0595:            }
0596:
0597:            /**
0598:             * Remove a parameter from the KeyStoreManager.
0599:             *
0600:             * @param manager is the name of the KeyStoreManager.
0601:             * @param name is the name of the parameter.
0602:             */
0603:            public synchronized void removeParameterFromKeyStoreManager(
0604:                    String manager, String name) {
0605:                mIsDirty = true;
0606:                if (mKeyStoreManagers.containsKey(manager)) {
0607:                    Properties props = (Properties) mKeyStoreManagers
0608:                            .get(manager);
0609:                    props.remove(name);
0610:                }
0611:            }
0612:
0613:            // -- Accessors
0614:
0615:            /**
0616:             * @return the default User Domain name.
0617:             */
0618:            public String getDefaultUserDomainName() {
0619:                return mDefUD;
0620:            }
0621:
0622:            /**
0623:             * @return the default KeyStore Manager.
0624:             */
0625:            public String getDefaultKeyStoreManagerName() {
0626:                return mDefKSMgr;
0627:            }
0628:
0629:            /**
0630:             * Get a Map of User Domain Contexts by their name.
0631:             * [ Key = Name (string) : Value = UserDomain Contexts (Properties) ]
0632:             * @return a Map of User Domain Contexts by their name
0633:             */
0634:            public HashMap getUserDomainContexts() {
0635:                return mUserDomains;
0636:            }
0637:
0638:            /**
0639:             * Get a Map of KeyStore Services keyed by their name.
0640:             *
0641:             * [ Key = Name (string) : Value = KeyStoreContexts (Properties) ]
0642:             * @return a Map of KeyStore Manager keyed by their name.
0643:             */
0644:            public HashMap getKeyStoreContexts() {
0645:                return mKeyStoreManagers;
0646:            }
0647:
0648:            /*---------------------------------------------------------------------------------*\
0649:             *                     Create a Security Config from the dom                       *
0650:            \*---------------------------------------------------------------------------------*/
0651:
0652:            /**
0653:             * Constructor to create SecurityConfiguration from DOM.
0654:             *
0655:             * @param translator is the StringTranslator
0656:             * @param dom is the dom for the Security Config data.
0657:             * @throws JBIException on Errors.
0658:             */
0659:            public SecurityInstallConfig(Document dom,
0660:                    StringTranslator translator) throws JBIException {
0661:                mTranslator = translator;
0662:                mLogger = Logger
0663:                        .getLogger(com.sun.jbi.internal.security.Constants.PACKAGE);
0664:                mUserDomains = new HashMap();
0665:                mKeyStoreManagers = new HashMap();
0666:                createDefaultTransportSecurityCtx();
0667:                createSecurityConfiguration(dom);
0668:                mDom = dom;
0669:                mIsDirty = false;
0670:            }
0671:
0672:            /** 
0673:             * Create a TransportSecurityContext with default values.
0674:             * 
0675:             */
0676:            private void createDefaultTransportSecurityCtx() {
0677:                mTransportSecurityContext = new Properties();
0678:
0679:                setSSLClientAlias(HttpConstants.DEFAULT_CLIENT_ALIAS);
0680:                setSSLClientUseDefault(true);
0681:                setSSLClientProtocol(HttpConstants.DEFAULT_SSL_PROTOCOL);
0682:
0683:                setSSLServerRequireClientAuth(HttpConstants.DEFAULT_SSL_REQ_CLIENT_AUTH);
0684:            }
0685:
0686:            /**
0687:             * Create a SecurityConfiguration object from the dom.
0688:             *
0689:             * @param dom is the dom for the Security Config data.
0690:             * @throws JBIException on Errors.
0691:             */
0692:            public void createSecurityConfiguration(Document dom)
0693:                    throws JBIException {
0694:                getUserDomainsFromDom(this , dom.getDocumentElement());
0695:                getKeyStoreManagersFromDom(this , dom.getDocumentElement());
0696:                getTransportSecurityContextFromDom(this , dom
0697:                        .getDocumentElement());
0698:            }
0699:
0700:            /**
0701:             * @param config is the SecurityInstallConfig to update.
0702:             * @param parent is the parent SecurityConfiguration element for the data.
0703:             * @throws JBIException on Errors
0704:             */
0705:            private void getUserDomainsFromDom(SecurityInstallConfig config,
0706:                    Element parent) throws JBIException {
0707:                try {
0708:                    // -- Should use XPath stuff from J2SE 1.5
0709:                    Element uds = (Element) parent.getElementsByTagName(
0710:                            Constants.ELEMENT_USER_DOMAINS).item(0);
0711:
0712:                    config.setDefaultUserDomainName(((Text) uds
0713:                            .getElementsByTagName(Constants.ELEMENT_DEFAULT)
0714:                            .item(0).getFirstChild()).getData());
0715:
0716:                    NodeList udList = uds
0717:                            .getElementsByTagName(Constants.ELEMENT_USER_DOMAIN);
0718:
0719:                    for (int i = 0; i < udList.getLength(); i++) {
0720:                        Element ud = (Element) udList.item(i);
0721:                        String name = ((Text) ud.getElementsByTagName(
0722:                                Constants.ELEMENT_NAME).item(0).getFirstChild())
0723:                                .getData();
0724:                        String domain = ((Text) ud.getElementsByTagName(
0725:                                Constants.ELEMENT_DOMAIN).item(0)
0726:                                .getFirstChild()).getData();
0727:                        config.addUserDomain(name, domain);
0728:
0729:                        NodeList params = ud
0730:                                .getElementsByTagName(Constants.ELEMENT_PARAM);
0731:
0732:                        for (int p = 0; p < params.getLength(); p++) {
0733:                            Element param = (Element) params.item(0);
0734:                            String paramname = ((Text) param
0735:                                    .getElementsByTagName(
0736:                                            Constants.ELEMENT_PARAM_NAME).item(
0737:                                            0).getFirstChild()).getData();
0738:                            String paramvalue = ((Text) param
0739:                                    .getElementsByTagName(
0740:                                            Constants.ELEMENT_PARAM_VALUE)
0741:                                    .item(0).getFirstChild()).getData();
0742:
0743:                            config.addParameterToUserDomain(name, paramname,
0744:                                    paramvalue);
0745:                        }
0746:                    }
0747:                } catch (Exception ex) {
0748:                    throw new JBIException(ex.toString(), ex);
0749:                }
0750:            }
0751:
0752:            /**
0753:             * @param config is the SecurityInstallConfig to update.
0754:             * @param parent is the parent SecurityConfiguration element for the data.
0755:             * @throws JBIException on Errors
0756:             */
0757:            private void getKeyStoreManagersFromDom(
0758:                    SecurityInstallConfig config, Element parent)
0759:                    throws JBIException {
0760:                try {
0761:                    // -- Should use XPath stuff from J2SE 1.5
0762:                    Element kms = (Element) parent.getElementsByTagName(
0763:                            Constants.ELEMENT_KEYSTORE_MANAGERS).item(0);
0764:
0765:                    config.setDefaultKeyStoreManagerName(((Text) kms
0766:                            .getElementsByTagName(Constants.ELEMENT_DEFAULT)
0767:                            .item(0).getFirstChild()).getData());
0768:
0769:                    NodeList kmList = kms
0770:                            .getElementsByTagName(Constants.ELEMENT_KEYSTORE_MANAGER);
0771:
0772:                    for (int i = 0; i < kmList.getLength(); i++) {
0773:                        Element km = (Element) kmList.item(i);
0774:                        String name = ((Text) km.getElementsByTagName(
0775:                                Constants.ELEMENT_NAME).item(0).getFirstChild())
0776:                                .getData();
0777:                        String manager = ((Text) km.getElementsByTagName(
0778:                                Constants.ELEMENT_MANAGER).item(0)
0779:                                .getFirstChild()).getData();
0780:                        config.addKeyStoreManager(name, manager);
0781:
0782:                        NodeList params = km
0783:                                .getElementsByTagName(Constants.ELEMENT_PARAM);
0784:
0785:                        for (int p = 0; p < params.getLength(); p++) {
0786:                            Element param = (Element) params.item(0);
0787:                            String paramname = ((Text) param
0788:                                    .getElementsByTagName(
0789:                                            Constants.ELEMENT_PARAM_NAME).item(
0790:                                            0).getFirstChild()).getData();
0791:                            String paramvalue = ((Text) param
0792:                                    .getElementsByTagName(
0793:                                            Constants.ELEMENT_PARAM_VALUE)
0794:                                    .item(0).getFirstChild()).getData();
0795:
0796:                            config.addParameterToKeyStoreManager(name,
0797:                                    paramname, paramvalue);
0798:                        }
0799:                    }
0800:                } catch (Exception ex) {
0801:                    throw new JBIException(ex.toString(), ex);
0802:                }
0803:            }
0804:
0805:            /**
0806:             * @param config is the SecurityInstallConfig to update.
0807:             * @param parent is the parent SecurityConfiguration element for the data.
0808:             * @throws JBIException on Errors
0809:             */
0810:            private void getTransportSecurityContextFromDom(
0811:                    SecurityInstallConfig config, Element parent)
0812:                    throws JBIException {
0813:                try {
0814:                    // -- Should use XPath stuff from J2SE 1.5
0815:                    Element transportSec = (Element) parent
0816:                            .getElementsByTagName(
0817:                                    Constants.ELEMENT_TRANSPORT_SECURITY).item(
0818:                                    0);
0819:
0820:                    if (transportSec != null) {
0821:                        Element client = (Element) transportSec
0822:                                .getElementsByTagName(Constants.ELEMENT_CLIENT)
0823:                                .item(0);
0824:
0825:                        // -- SSL Protocol value
0826:                        Element sslProtocol = (Element) client
0827:                                .getElementsByTagName(
0828:                                        Constants.ELEMENT_SSL_PROTOCOL).item(0);
0829:                        if (sslProtocol != null) {
0830:                            setSSLClientProtocol(((Text) sslProtocol
0831:                                    .getFirstChild()).getData());
0832:                        }
0833:
0834:                        // -- Use Default
0835:                        Element useDef = (Element) client.getElementsByTagName(
0836:                                Constants.ELEMENT_SSL_USE_DEFAULT).item(0);
0837:                        if (useDef != null) {
0838:                            setSSLClientUseDefault(new Boolean(((Text) useDef
0839:                                    .getFirstChild()).getData()).booleanValue());
0840:                        }
0841:
0842:                        // -- Client Alias
0843:                        Element clientAlias = (Element) client
0844:                                .getElementsByTagName(
0845:                                        Constants.ELEMENT_SSL_CLIENT_ALIAS)
0846:                                .item(0);
0847:                        if (clientAlias != null) {
0848:                            setSSLClientAlias(((Text) clientAlias
0849:                                    .getFirstChild()).getData());
0850:                        }
0851:
0852:                        Element server = (Element) transportSec
0853:                                .getElementsByTagName(Constants.ELEMENT_SERVER)
0854:                                .item(0);
0855:
0856:                        if (server != null) {
0857:                            // -- Require Client Auth value
0858:                            Element reqClientAuth = (Element) server
0859:                                    .getElementsByTagName(
0860:                                            Constants.ELEMENT_SSL_REQ_CLIENT_AUTH)
0861:                                    .item(0);
0862:                            if (reqClientAuth != null) {
0863:                                setSSLServerRequireClientAuth(new Boolean(
0864:                                        ((Text) reqClientAuth.getFirstChild())
0865:                                                .getData()).booleanValue());
0866:                            }
0867:                        }
0868:                    }
0869:                } catch (Exception ex) {
0870:                    throw new JBIException(ex.toString(), ex);
0871:                }
0872:
0873:            }
0874:
0875:            /*---------------------------------------------------------------------------------*\
0876:             *   Helper Methods which aid in the creation of a                                 *
0877:             *   SecurityInstallConfig from properties and vice-versa                          *
0878:            \*---------------------------------------------------------------------------------*/
0879:
0880:            /**
0881:             * Create a SecurityInstallConfig from a GenericConfigurationMBean.
0882:             * @param configMBean is the GenericConfigurationMBean which has the Properties 
0883:             * to be used for the creation of the SecurityInstallConfig object
0884:             * @param translator is the StringTranslator
0885:             * @throws JBIException if the configuration data is not sufficient/valid to
0886:             * create the SecurityConfiguration information.
0887:             * @return the created SecurityInstallConfig
0888:             */
0889:            public static SecurityInstallConfig createSecurityInstallConfig(
0890:                    GenericConfigurationMBean configMBean,
0891:                    StringTranslator translator) throws JBIException {
0892:                SecurityInstallConfig secInstCfg = new SecurityInstallConfig(
0893:                        translator);
0894:
0895:                secInstCfg.setDefaultUserDomainName(configMBean
0896:                        .getProperty(DEF_UD_KEY));
0897:                secInstCfg.setDefaultKeyStoreManagerName(configMBean
0898:                        .getProperty(DEF_KM_KEY));
0899:
0900:                secInstCfg.updateUserDomains(configMBean);
0901:                secInstCfg.updateKeyStoreManagers(configMBean);
0902:                secInstCfg.updateTransportSecurityContext(configMBean);
0903:                secInstCfg.validate();
0904:
0905:                return secInstCfg;
0906:            }
0907:
0908:            /**
0909:             * @param configMBean is the GenericConfigurationMBean which has the cofig data
0910:             */
0911:            private void updateUserDomains(GenericConfigurationMBean configMBean) {
0912:                mIsDirty = true;
0913:                for (int i = 1; true; i++) {
0914:                    // -- Get all the parameters for a domain
0915:                    String currentDomainKey = UD_PREFIX + i;
0916:
0917:                    Properties udProps = SecurityInstallConfig
0918:                            .filterProperties(Pattern.compile(UD_PATTERN + i
0919:                                    + DOT_PATTERN + ANY_PATTERN), configMBean);
0920:
0921:                    if (udProps.size() == 0) {
0922:                        break;
0923:                    }
0924:
0925:                    // -- Create the UserDomain entry
0926:                    String name = configMBean.getProperty(currentDomainKey
0927:                            + NAME_SUFFIX);
0928:                    String domain = configMBean.getProperty(currentDomainKey
0929:                            + DOMAIN_SUFFIX);
0930:
0931:                    addUserDomain(name, domain);
0932:
0933:                    // -- Add parameters to the entry if any are specified
0934:                    String udParamKey = currentDomainKey + PARAM_SUFFIX;
0935:                    for (int j = 1; true; j++) {
0936:                        String currentUdParamKey = udParamKey + j;
0937:
0938:                        Properties udParams = SecurityInstallConfig
0939:                                .filterProperties(Pattern.compile(UD_PATTERN
0940:                                        + i + DOT_PATTERN + ANY_PATTERN
0941:                                        + PARAM_PATTERN + j + DOT_PATTERN
0942:                                        + ANY_PATTERN), udProps);
0943:
0944:                        if ((udParams.size() == 0) || (udParams.size() != 2)) {
0945:                            break;
0946:                        }
0947:
0948:                        addParameterToUserDomain(name, configMBean
0949:                                .getProperty(currentUdParamKey + NAME_SUFFIX),
0950:                                configMBean.getProperty(currentUdParamKey
0951:                                        + VALUE_SUFFIX));
0952:                    }
0953:                }
0954:
0955:            }
0956:
0957:            /**
0958:             * @param configMBean is the GenericConfigurationMBean which has the cofig data
0959:             * @throws JBIException on errors
0960:             */
0961:            private void updateKeyStoreManagers(
0962:                    GenericConfigurationMBean configMBean) throws JBIException {
0963:                mIsDirty = true;
0964:                for (int i = 1; true; i++) {
0965:                    // -- Get all the parameters for a domain
0966:                    String currentManagerKey = KM_PREFIX + i;
0967:
0968:                    Properties kmProps = SecurityInstallConfig
0969:                            .filterProperties(Pattern.compile(KM_PATTERN + i
0970:                                    + DOT_PATTERN + ANY_PATTERN), configMBean);
0971:
0972:                    if (kmProps.size() == 0) {
0973:                        break;
0974:                    }
0975:
0976:                    // -- Create the UserDomain entry
0977:                    String name = configMBean.getProperty(currentManagerKey
0978:                            + NAME_SUFFIX);
0979:                    String manager = configMBean.getProperty(currentManagerKey
0980:                            + MANAGER_SUFFIX);
0981:
0982:                    addKeyStoreManager(name, manager);
0983:
0984:                    // -- Add parameters to the entry if any are specified
0985:                    String kmParamKey = currentManagerKey + PARAM_SUFFIX;
0986:                    for (int j = 1; true; j++) {
0987:                        String currentKmParamKey = kmParamKey + j;
0988:
0989:                        Properties kmParams = SecurityInstallConfig
0990:                                .filterProperties(Pattern.compile(KM_PATTERN
0991:                                        + i + DOT_PATTERN + ANY_PATTERN
0992:                                        + PARAM_PATTERN + j + DOT_PATTERN
0993:                                        + ANY_PATTERN), kmProps);
0994:
0995:                        if ((kmParams.size() == 0) || (kmParams.size() != 2)) {
0996:                            break;
0997:                        }
0998:
0999:                        addParameterToKeyStoreManager(name, configMBean
1000:                                .getProperty(currentKmParamKey + NAME_SUFFIX),
1001:                                configMBean.getProperty(currentKmParamKey
1002:                                        + VALUE_SUFFIX));
1003:                    }
1004:                }
1005:            }
1006:
1007:            /**
1008:             * @param configMBean is the GenericConfigurationMBean which has the cofig data
1009:             */
1010:            private void updateTransportSecurityContext(
1011:                    GenericConfigurationMBean configMBean) {
1012:                mIsDirty = true;
1013:                if (!mMissingProperty.equals(configMBean
1014:                        .getProperty(TRANSPORT_PREFIX
1015:                                + HttpConstants.PARAM_SSL_CLIENT_ALIAS))) {
1016:                    setSSLClientAlias(configMBean.getProperty(TRANSPORT_PREFIX
1017:                            + HttpConstants.PARAM_SSL_CLIENT_ALIAS));
1018:                }
1019:
1020:                if (!mMissingProperty.equals(configMBean
1021:                        .getProperty(TRANSPORT_PREFIX
1022:                                + HttpConstants.PARAM_SSL_USE_DEFAULT))) {
1023:                    setSSLClientUseDefault(new Boolean(configMBean
1024:                            .getProperty(TRANSPORT_PREFIX
1025:                                    + HttpConstants.PARAM_SSL_USE_DEFAULT))
1026:                            .booleanValue());
1027:                }
1028:
1029:                if (!mMissingProperty.equals(configMBean
1030:                        .getProperty(TRANSPORT_PREFIX
1031:                                + HttpConstants.PARAM_SSL_PROTOCOL))) {
1032:                    setSSLClientProtocol(configMBean
1033:                            .getProperty(TRANSPORT_PREFIX
1034:                                    + HttpConstants.PARAM_SSL_PROTOCOL));
1035:                }
1036:
1037:                if (!mMissingProperty.equals(configMBean
1038:                        .getProperty(TRANSPORT_PREFIX
1039:                                + HttpConstants.PARAM_SSL_REQ_CLIENT_AUTH))) {
1040:                    setSSLServerRequireClientAuth(new Boolean(configMBean
1041:                            .getProperty(TRANSPORT_PREFIX
1042:                                    + HttpConstants.PARAM_SSL_REQ_CLIENT_AUTH))
1043:                            .booleanValue());
1044:                }
1045:            }
1046:
1047:            /**
1048:             * Filter Property keys with the specified prefix.
1049:             *
1050:             * @param pattern is the pattern to be matched
1051:             * @param configMBean is the source of the Properties
1052:             * @return filtered Properties which start with the specified pattern.
1053:             */
1054:            public static Properties filterProperties(Pattern pattern,
1055:                    GenericConfigurationMBean configMBean) {
1056:                Properties props = new Properties();
1057:
1058:                String[] keys = configMBean.getPropertyKeys();
1059:                for (int i = 0; i < keys.length; i++) {
1060:                    if (pattern.matcher(keys[i]).matches()) {
1061:                        props.setProperty(keys[i], configMBean
1062:                                .getProperty(keys[i]));
1063:                    }
1064:                }
1065:                return props;
1066:            }
1067:
1068:            /**
1069:             * Filter Property keys with the specified prefix.
1070:             *
1071:             * @param pattern is the pattern to be matched.
1072:             * @param srcProps are the Properties to search for a match.
1073:             * @return filtered Properties which start with the specified pattern.
1074:             */
1075:            public static Properties filterProperties(Pattern pattern,
1076:                    Properties srcProps) {
1077:                Properties props = new Properties();
1078:
1079:                for (Enumeration keys = srcProps.propertyNames(); keys
1080:                        .hasMoreElements();) {
1081:                    String key = (String) keys.nextElement();
1082:                    if (pattern.matcher(key).matches()) {
1083:                        props.setProperty(key, srcProps.getProperty(key));
1084:                    }
1085:                }
1086:                return props;
1087:            }
1088:
1089:            /**
1090:             * Convert this SecurityInstallConfig instance to GenericConfigurationMBean 
1091:             * Properties. This would ideally be called before the Configuration MBean is asked 
1092:             * to save the data or before a the getPropertyKeys() is invoked.
1093:             *
1094:             * @param configMBean is the GenericConfigurationMBean which is to be updated.
1095:             */
1096:            public void updateConfigMBean(GenericConfigurationMBean configMBean) {
1097:                configMBean.setProperty(DEF_UD_KEY, getDefaultUserDomainName());
1098:                configMBean.setProperty(DEF_KM_KEY,
1099:                        getDefaultKeyStoreManagerName());
1100:
1101:                updateUserDomainProperties(configMBean);
1102:                updateKeyStoreManagerProperties(configMBean);
1103:                updateTransportSecurityCtxProperties(configMBean);
1104:
1105:            }
1106:
1107:            /**
1108:             * @param configMBean is the Configuration MBean to be updated.
1109:             */
1110:            public void updateUserDomainProperties(
1111:                    GenericConfigurationMBean configMBean) {
1112:                HashMap uds = getUserDomainContexts();
1113:
1114:                int i = 1;
1115:                for (Iterator udNames = uds.keySet().iterator(); udNames
1116:                        .hasNext(); i++) {
1117:                    String currentUdPattern = UD_PREFIX + i;
1118:                    String udName = (String) udNames.next();
1119:                    configMBean.setProperty(currentUdPattern + NAME_SUFFIX,
1120:                            udName);
1121:                    Properties udProps = (Properties) uds.get(udName);
1122:
1123:                    int j = 1;
1124:                    for (Enumeration params = udProps.propertyNames(); params
1125:                            .hasMoreElements();) {
1126:                        String paramname = (String) params.nextElement();
1127:                        String paramvalue = udProps.getProperty(paramname);
1128:
1129:                        if (paramname.equals(Constants.DOMAIN)) {
1130:                            configMBean.setProperty(currentUdPattern
1131:                                    + DOMAIN_SUFFIX, paramvalue);
1132:                        } else {
1133:                            configMBean
1134:                                    .setProperty(currentUdPattern
1135:                                            + PARAM_SUFFIX + j + NAME_SUFFIX,
1136:                                            paramname);
1137:                            configMBean.setProperty(currentUdPattern
1138:                                    + PARAM_SUFFIX + j++ + VALUE_SUFFIX,
1139:                                    paramvalue);
1140:                        }
1141:                    }
1142:                }
1143:            }
1144:
1145:            /**
1146:             * @param configMBean is the Configuration MBean to be updated.
1147:             */
1148:            public void updateKeyStoreManagerProperties(
1149:                    GenericConfigurationMBean configMBean) {
1150:                HashMap kms = getKeyStoreContexts();
1151:
1152:                int i = 1;
1153:                for (Iterator kmNames = kms.keySet().iterator(); kmNames
1154:                        .hasNext(); i++) {
1155:                    String currentKmPattern = KM_PREFIX + i;
1156:                    String kmName = (String) kmNames.next();
1157:                    configMBean.setProperty(currentKmPattern + NAME_SUFFIX,
1158:                            kmName);
1159:                    Properties kmProps = (Properties) kms.get(kmName);
1160:
1161:                    int j = 1;
1162:                    for (Enumeration params = kmProps.propertyNames(); params
1163:                            .hasMoreElements();) {
1164:                        String paramname = (String) params.nextElement();
1165:                        String paramvalue = kmProps.getProperty(paramname);
1166:
1167:                        if (paramname.equals(Constants.MANAGER)) {
1168:                            configMBean.setProperty(currentKmPattern
1169:                                    + MANAGER_SUFFIX, paramvalue);
1170:                        } else {
1171:                            configMBean
1172:                                    .setProperty(currentKmPattern
1173:                                            + PARAM_SUFFIX + j + NAME_SUFFIX,
1174:                                            paramname);
1175:                            configMBean.setProperty(currentKmPattern
1176:                                    + PARAM_SUFFIX + j++ + VALUE_SUFFIX,
1177:                                    paramvalue);
1178:                        }
1179:                    }
1180:                }
1181:            }
1182:
1183:            /**
1184:             * @param configMBean is the Configuration MBean to be updated.
1185:             */
1186:            public void updateTransportSecurityCtxProperties(
1187:                    GenericConfigurationMBean configMBean) {
1188:
1189:                configMBean.setProperty(TRANSPORT_PREFIX
1190:                        + HttpConstants.PARAM_SSL_CLIENT_ALIAS,
1191:                        getSSLClientAlias());
1192:                configMBean.setProperty(TRANSPORT_PREFIX
1193:                        + HttpConstants.PARAM_SSL_PROTOCOL,
1194:                        getSSLClientProtocol());
1195:                configMBean.setProperty(TRANSPORT_PREFIX
1196:                        + HttpConstants.PARAM_SSL_USE_DEFAULT, Boolean
1197:                        .toString((getSSLClientUseDefault())));
1198:
1199:                configMBean.setProperty(TRANSPORT_PREFIX
1200:                        + HttpConstants.PARAM_SSL_REQ_CLIENT_AUTH, Boolean
1201:                        .toString(getSSLServerRequireClientAuth()));
1202:            }
1203:
1204:            /*-------------------------------------------------------------------------------*\
1205:             *         Operations to display Configuration information                       *
1206:             * The GenericConfigurationMBean delegates all queries for information to this   *
1207:             * class, the following methods return an XML string for the config information. *
1208:            \*-------------------------------------------------------------------------------*/
1209:
1210:            /**
1211:             * Get an XML String which has the meta-data for a particular user domain
1212:             * User Domain.
1213:             *
1214:             * @param name is the logical name of the UserDomain. If there is no such UserDomain
1215:             * or the name is null then a empty string "" is returned.
1216:             * @return an XML String with information for a particular UserDomain.
1217:             */
1218:            public String getUserDomainCtx(String name) {
1219:                if (name == null || "".equals(name)) {
1220:                    return "";
1221:                }
1222:
1223:                return getNamedNodeString(Constants.ELEMENT_USER_DOMAINS,
1224:                        Constants.ELEMENT_USER_DOMAIN, name.trim());
1225:            }
1226:
1227:            /**
1228:             * Get an XML String listing all the UserDomains and their meta-data.
1229:             *
1230:             * @return an XML String with information for all the UserDomains.
1231:             */
1232:            public String getUserDomainCtxs() {
1233:
1234:                try {
1235:                    Node uds = generateDocument().getElementsByTagName(
1236:                            Constants.ELEMENT_USER_DOMAINS).item(0);
1237:
1238:                    return getString(uds);
1239:
1240:                } catch (Exception ex) {
1241:                    return "";
1242:                }
1243:            }
1244:
1245:            /**
1246:             * Get an XML String which has the meta-data for a particular key store manager.
1247:             *
1248:             * @param name is the logical name of the KeyStoreManager. If there is no such 
1249:             * KeyStoreManager or the name is null then a empty string "" is returned.
1250:             * @return an XML String with information for a particular KeyStoreManager.
1251:             */
1252:            public String getKeyStoreCtx(String name) {
1253:                if (name == null || "".equals(name)) {
1254:                    return "";
1255:                }
1256:
1257:                return getNamedNodeString(Constants.ELEMENT_KEYSTORE_MANAGERS,
1258:                        Constants.ELEMENT_KEYSTORE_MANAGER, name.trim());
1259:            }
1260:
1261:            /**
1262:             * Get an XML String listing all the KeyStoreManagers and their meta-data.
1263:             *
1264:             * @return an XML String with information for all the KeyStoreManagers.
1265:             */
1266:            public String getKeyStoreCtxs() {
1267:                try {
1268:                    Node kms = generateDocument().getElementsByTagName(
1269:                            Constants.ELEMENT_KEYSTORE_MANAGERS).item(0);
1270:
1271:                    return getString(kms);
1272:
1273:                } catch (Exception ex) {
1274:                    return "";
1275:                }
1276:            }
1277:
1278:            /**
1279:             * Get an XML String for the TransportSecurityContext.
1280:             *
1281:             * @return an XML String with information for the TransportSecurity Context.
1282:             */
1283:            public String getTransportSecurityConfig() {
1284:                try {
1285:                    Node ts = generateDocument().getElementsByTagName(
1286:                            Constants.ELEMENT_TRANSPORT_SECURITY).item(0);
1287:
1288:                    return getString(ts);
1289:
1290:                } catch (Exception ex) {
1291:                    return "";
1292:                }
1293:            }
1294:
1295:            /**
1296:             * @return an XML String for the dom rooted at the given node
1297:             * @param node is the root node for the XML document.
1298:             */
1299:            private String getString(Node node) {
1300:                java.io.StringWriter strWriter = new java.io.StringWriter();
1301:                try {
1302:                    Transformer xformer = TransformerFactory.newInstance()
1303:                            .newTransformer();
1304:                    xformer.setOutputProperty(
1305:                            javax.xml.transform.OutputKeys.INDENT, "yes");
1306:                    xformer.transform(new javax.xml.transform.dom.DOMSource(
1307:                            node), new javax.xml.transform.stream.StreamResult(
1308:                            strWriter));
1309:                } catch (Exception ex) {
1310:                    return "";
1311:                }
1312:                return strWriter.toString();
1313:            }
1314:
1315:            /**
1316:             *
1317:             * @param collectionElementName is the collections element ( i.e User Domains, 
1318:             * Key Store Managers, Security Contexts ).
1319:             * @param elementName is the name of the sub-element ( User Domain, KeyStoreManager,
1320:             * Security Context ).
1321:             * @param searchName is the desired element name .
1322:             * @return an XML String for the element whose name attribute is equal to the 
1323:             * specified name.
1324:             * the named element
1325:             */
1326:            private String getNamedNodeString(String collectionElementName,
1327:                    String elementName, String searchName) {
1328:                try {
1329:                    Element main = (Element) generateDocument()
1330:                            .getElementsByTagName(collectionElementName)
1331:                            .item(0);
1332:
1333:                    NodeList ctxs = main.getElementsByTagName(elementName);
1334:
1335:                    for (int i = 0; i < ctxs.getLength(); i++) {
1336:                        Node name = ((Element) ctxs.item(i))
1337:                                .getElementsByTagName(Constants.ELEMENT_NAME)
1338:                                .item(0);
1339:                        if (searchName.equals(((Text) name.getFirstChild())
1340:                                .getData())) {
1341:                            return getString(ctxs.item(i));
1342:                        }
1343:                    }
1344:                    return "";
1345:                } catch (Exception ex) {
1346:                    return "";
1347:                }
1348:            }
1349:
1350:            // -- Set / Get the Client Alias from the TransportSecurity Context.
1351:            /**
1352:             * @param alias is the SSL Client alias.
1353:             */
1354:            public synchronized void setSSLClientAlias(java.lang.String alias) {
1355:                mTransportSecurityContext.setProperty(
1356:                        HttpConstants.PARAM_SSL_CLIENT_ALIAS, alias);
1357:
1358:            }
1359:
1360:            /**
1361:             * @return the SSL Client alias.
1362:             */
1363:            public String getSSLClientAlias() {
1364:                return mTransportSecurityContext
1365:                        .getProperty(HttpConstants.PARAM_SSL_CLIENT_ALIAS);
1366:            }
1367:
1368:            // -- Set / Get the Client SSL Protocol  from the TransportSecurity Context.
1369:            /**
1370:             * @param protocol is the SSL Client protocol, allowed values are SSLv3, 
1371:             * TLS and TLSv1
1372:             */
1373:            public synchronized void setSSLClientProtocol(String protocol) {
1374:                if (protocol == null) {
1375:                    throw new IllegalArgumentException(protocol);
1376:                }
1377:
1378:                protocol = protocol.trim();
1379:
1380:                if (HttpConstants.SSLV3.equals(protocol)
1381:                        || HttpConstants.TLSV1.equals(protocol)
1382:                        || HttpConstants.TLS.equals(protocol)) {
1383:                    mTransportSecurityContext.setProperty(
1384:                            HttpConstants.PARAM_SSL_PROTOCOL, protocol);
1385:                } else {
1386:                    throw new IllegalArgumentException(protocol);
1387:                }
1388:            }
1389:
1390:            /**
1391:             * @return the SSL Client Protocol.
1392:             */
1393:            public String getSSLClientProtocol() {
1394:                return mTransportSecurityContext
1395:                        .getProperty(HttpConstants.PARAM_SSL_PROTOCOL);
1396:            }
1397:
1398:            // -- Get / Set the SSL Client Use Default parameter
1399:
1400:            /**
1401:             * @param flag - true/false inducates whether to use the
1402:             * default Application Server SSL context or not.
1403:             */
1404:            public synchronized void setSSLClientUseDefault(boolean flag) {
1405:                mTransportSecurityContext.setProperty(
1406:                        HttpConstants.PARAM_SSL_USE_DEFAULT, Boolean
1407:                                .toString(flag));
1408:            }
1409:
1410:            /**
1411:             * @return true/false inducates whether the
1412:             * default Application Server SSL context is being used or not.
1413:             */
1414:            public boolean getSSLClientUseDefault() {
1415:                return new Boolean(mTransportSecurityContext
1416:                        .getProperty(HttpConstants.PARAM_SSL_USE_DEFAULT))
1417:                        .booleanValue();
1418:            }
1419:
1420:            // -- Set / Get the SSL Server Req. Client Auth value
1421:
1422:            /**
1423:             * @param flag - true/false inducates whether Client Auth 
1424:             * is required by default.
1425:             */
1426:            public synchronized void setSSLServerRequireClientAuth(boolean flag) {
1427:                mTransportSecurityContext.setProperty(
1428:                        HttpConstants.PARAM_SSL_REQ_CLIENT_AUTH, Boolean
1429:                                .toString(flag));
1430:            }
1431:
1432:            /**
1433:             * @return true/false inducates whether Client Auth 
1434:             * is required by default.
1435:             */
1436:            public boolean getSSLServerRequireClientAuth() {
1437:                return new Boolean(mTransportSecurityContext
1438:                        .getProperty(HttpConstants.PARAM_SSL_REQ_CLIENT_AUTH))
1439:                        .booleanValue();
1440:            }
1441:
1442:            /**
1443:             *
1444:             * @return the Transport Security Properties as a Property Set.
1445:             */
1446:            public Properties getTransportSecurityContext() {
1447:                return mTransportSecurityContext;
1448:            }
1449:
1450:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.