Source Code Cross Referenced for J2eeProjectHelper.java in  » IDE-Netbeans » identity.kit » org » netbeans » modules » identity » profile » ui » support » 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 » IDE Netbeans » identity.kit » org.netbeans.modules.identity.profile.ui.support 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*
0002:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
0003:         *
0004:         * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
0005:         *
0006:         * The contents of this file are subject to the terms of either the GNU
0007:         * General Public License Version 2 only ("GPL") or the Common
0008:         * Development and Distribution License("CDDL") (collectively, the
0009:         * "License"). You may not use this file except in compliance with the
0010:         * License. You can obtain a copy of the License at
0011:         * http://www.netbeans.org/cddl-gplv2.html
0012:         * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
0013:         * specific language governing permissions and limitations under the
0014:         * License.  When distributing the software, include this License Header
0015:         * Notice in each file and include the License file at
0016:         * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
0017:         * particular file as subject to the "Classpath" exception as provided
0018:         * by Sun in the GPL Version 2 section of the License file that
0019:         * accompanied this code. If applicable, add the following below the
0020:         * License Header, with the fields enclosed by brackets [] replaced by
0021:         * your own identifying information:
0022:         * "Portions Copyrighted [year] [name of copyright owner]"
0023:         *
0024:         * Contributor(s):
0025:         *
0026:         * The Original Software is NetBeans. The Initial Developer of the Original
0027:         * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
0028:         * Microsystems, Inc. All Rights Reserved.
0029:         *
0030:         * If you wish your version of this file to be governed by only the CDDL
0031:         * or only the GPL Version 2, indicate your decision by adding
0032:         * "[Contributor] elects to include this software in this distribution
0033:         * under the [CDDL or GPL Version 2] license." If you do not indicate a
0034:         * single choice of license, a recipient has the option to distribute
0035:         * your version of this file under either the CDDL, the GPL Version 2 or
0036:         * to extend the choice of license to its licensees as provided above.
0037:         * However, if you add GPL Version 2 code and therefore, elected the GPL
0038:         * Version 2 license, then the option applies only if the new code is
0039:         * made subject to such option by the copyright holder.
0040:         */
0041:
0042:        package org.netbeans.modules.identity.profile.ui.support;
0043:
0044:        import java.io.BufferedReader;
0045:        import java.io.BufferedWriter;
0046:        import java.io.ByteArrayOutputStream;
0047:        import java.io.File;
0048:        import java.io.FileNotFoundException;
0049:        import java.io.FileReader;
0050:        import java.io.FileWriter;
0051:        import java.io.IOException;
0052:        import java.io.OutputStreamWriter;
0053:        import java.io.Writer;
0054:        import java.net.URI;
0055:        import java.util.ArrayList;
0056:        import java.util.Enumeration;
0057:        import java.util.List;
0058:        import org.netbeans.api.project.FileOwnerQuery;
0059:        import org.netbeans.api.project.Project;
0060:        import org.netbeans.modules.j2ee.api.ejbjar.EjbJar;
0061:        import org.netbeans.modules.j2ee.dd.api.common.ServiceRef;
0062:        import org.netbeans.modules.j2ee.dd.api.ejb.Ejb;
0063:        import org.netbeans.modules.j2ee.dd.api.ejb.EnterpriseBeans;
0064:        import org.netbeans.modules.j2ee.dd.api.web.Servlet;
0065:        import org.netbeans.modules.j2ee.dd.api.web.WebApp;
0066:        import org.netbeans.modules.j2ee.dd.api.webservices.PortComponent;
0067:        import org.netbeans.modules.j2ee.dd.api.webservices.WebserviceDescription;
0068:        import org.netbeans.modules.j2ee.dd.api.webservices.Webservices;
0069:        import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule;
0070:        import org.netbeans.modules.j2ee.deployment.devmodules.spi.J2eeModuleProvider;
0071:        import org.netbeans.modules.web.api.webmodule.WebModule;
0072:        import org.netbeans.modules.websvc.api.jaxws.project.config.Client;
0073:        import org.netbeans.modules.websvc.api.jaxws.project.config.Service;
0074:        import org.netbeans.modules.websvc.api.jaxws.project.config.JaxWsModel;
0075:        import org.netbeans.spi.project.support.ant.GeneratedFilesHelper;
0076:        import org.openide.ErrorManager;
0077:        import org.openide.filesystems.FileObject;
0078:        import org.openide.loaders.DataObject;
0079:        import org.openide.nodes.Node;
0080:        import org.netbeans.modules.identity.profile.api.bridgeapi.RuntimeBridge;
0081:        import org.netbeans.modules.identity.profile.api.configurator.ConfiguratorException;
0082:        import org.netbeans.modules.identity.profile.api.configurator.ServerProperties;
0083:        import org.netbeans.modules.j2ee.api.ejbjar.Car;
0084:        import org.netbeans.modules.j2ee.dd.api.client.AppClient;
0085:        import org.netbeans.modules.j2ee.dd.api.client.AppClientMetadata;
0086:        import org.netbeans.modules.j2ee.dd.api.common.RootInterface;
0087:        import org.netbeans.modules.j2ee.dd.api.common.SecurityRole;
0088:        import org.netbeans.modules.j2ee.dd.api.ejb.EjbJarMetadata;
0089:        import org.netbeans.modules.j2ee.dd.api.web.AuthConstraint;
0090:        import org.netbeans.modules.j2ee.dd.api.web.DDProvider;
0091:        import org.netbeans.modules.j2ee.dd.api.web.SecurityConstraint;
0092:        import org.netbeans.modules.j2ee.dd.api.web.WebAppMetadata;
0093:        import org.netbeans.modules.j2ee.dd.api.web.WebResourceCollection;
0094:        import org.netbeans.modules.j2ee.dd.api.webservices.WebservicesMetadata;
0095:        import org.openide.filesystems.FileUtil;
0096:        import org.netbeans.modules.j2ee.metadata.model.api.MetadataModel;
0097:        import org.netbeans.modules.j2ee.metadata.model.api.MetadataModelAction;
0098:        import org.netbeans.modules.websvc.wsitconf.api.WSITConfigProvider;
0099:        import org.netbeans.modules.websvc.wsitconf.spi.SecurityCheckerRegistry;
0100:        import org.openide.filesystems.FileLock;
0101:        import org.openide.filesystems.FileSystem;
0102:        import org.openide.filesystems.Repository;
0103:        import org.openide.loaders.DataFolder;
0104:
0105:        /**
0106:         * Helper class for working with J2EE projects.
0107:         *
0108:         * Created on July 18, 2006, 11:36 PM
0109:         *
0110:         * @author ptliu
0111:         * @author Srividhya Narayanan
0112:         */
0113:        public class J2eeProjectHelper {
0114:
0115:            private static final String SERVICE_REF_NAME_PREFIX = "service/"; //NOI18N
0116:
0117:            private static final String AM_DEPLOY_XML_PATH = "nbproject/am-deploy.xml"; //NOI18N
0118:
0119:            private static final String AM_DEPLOY_XSL = "resources/am-deploy.xsl"; //NOI18N
0120:
0121:            private static final String BUILD_SCRIPT = "/build.xml"; //NOI18N
0122:
0123:            private static final String BACKUP_EXT = ".bak"; //NOI18N
0124:
0125:            private static final String IMPORT_AM_DEPLOY_XML = "<import file=\"nbproject/am-deploy.xml\"/>"; //NOI18N
0126:
0127:            private static final String IMPORT_TAG = "<import"; //NOI18N
0128:
0129:            private static final String AM_CONSTRAINT_DISPLAY_NAME = "Access Manager Security Constraint"; //NOI18N
0130:
0131:            private static final String AM_WEB_RESOURCE_NAME = "AUTHENTICATED_RESOURCE"; //NOI18N
0132:
0133:            private static final String AM_URL_PATTERN = "/*"; //NOI18N
0134:
0135:            private static final String AM_ROLE_NAME = "AUTHENTICATED_USERS"; //NOI18N
0136:
0137:            private static final String DEFAULT_ENCODING = "UTF-8"; // NOI18N;
0138:
0139:            private static final String EJB_WSDL_LOC = "META-INF"; // NOI18N;
0140:
0141:            private static final String WEB_WSDL_LOC = "WEB-INF"; // NOI18N;
0142:
0143:            private static final String CLIENT_WSDL_LOC = "META-INF"; // NOI18N;
0144:
0145:            private static final String SUN_WEB_XML = "sun-web"; //NOI18N
0146:
0147:            private static final String SUN_WEB_TEMPLATE = "Templates/Identity/SunDD/sun-web.xml"; //NOI18N
0148:
0149:            private static final String SUN_EJB_JAR_TEMPLATE = "Templates/Identity/SunDD/sun-ejb-jar.xml"; //NOI18N
0150:
0151:            private static final String SUN_EJB_JAR_XML = "sun-ejb-jar"; //NOI18N
0152:
0153:            private static final String SUN_APPLICATION_CLIENT_TEMPLATE = "Templates/Identity/SunDD/sun-application-client.xml"; //NOI18N
0154:
0155:            private static final String SUN_APPLICATION_CLIENT_XML = "sun-application-client"; //NOI18N
0156:
0157:            private static final String XML_EXT = "xml"; //NOI18N
0158:
0159:            private static final String WEB_FOLDER = "web"; //NOI18N
0160:
0161:            private static final String WEB_INF_FOLDER = "WEB-INF"; //NOI18N
0162:
0163:            private static final String CONF_FOLDER = "conf"; //NOI18N
0164:
0165:            private static SecurityCheckerImpl securityChecker;
0166:
0167:            static {
0168:                securityChecker = new SecurityCheckerImpl();
0169:
0170:                SecurityCheckerRegistry.getDefault().register(securityChecker);
0171:            }
0172:
0173:            public enum ProjectType {
0174:                WEB, EJB, CLIENT, UNKNOWN
0175:            };
0176:
0177:            public enum Version {
0178:                VERSION_1_4, VERSION_1_5, UNKNOWN
0179:            };
0180:
0181:            private Node node;
0182:            private JaxWsModel model;
0183:            private ProjectType projectType;
0184:            private Version version;
0185:            private File sunDD;
0186:            private String endpointName;
0187:            private List<String> endpointUri;
0188:            private String portComponentName;
0189:            private String serviceDescriptionName;
0190:            private List<String> serviceRefNames;
0191:            private List<WsdlData> wsdlData;
0192:            private List<String> serviceNames;
0193:
0194:            public static J2eeProjectHelper newInstance(Node node,
0195:                    JaxWsModel model) {
0196:                J2eeProjectHelper helper = new J2eeProjectHelper(node, model);
0197:
0198:                //if (helper.getVersion() == Version.VERSION_1_5) {
0199:                //    return new J2ee15ProjectHelper(node, model);
0200:                //}
0201:
0202:                return helper;
0203:            }
0204:
0205:            /** Creates a new instance of J2eeProjectHelper */
0206:            protected J2eeProjectHelper(Node node, JaxWsModel model) {
0207:                this .node = node;
0208:                this .model = model;
0209:            }
0210:
0211:            public boolean isSecurable() {
0212:                if (getProject() == null || getProvider() == null)
0213:                    return false;
0214:
0215:                if (isServer()) {
0216:                    if (getPortComponentName() != null
0217:                            && getServiceDescriptionName() != null)
0218:                        return true;
0219:                } else {
0220:                    // We don't support 1.4 appclient.
0221:                    if (getProjectType() == ProjectType.CLIENT
0222:                            && getVersion() == Version.VERSION_1_4) {
0223:                        return false;
0224:                    }
0225:
0226:                    if (!getAllServiceRefNames().isEmpty()) {
0227:                        return true;
0228:                    }
0229:                }
0230:
0231:                return false;
0232:            }
0233:
0234:            public boolean noServiceRefExists() {
0235:                if (!isServer()) {
0236:                    if (getProjectType() == ProjectType.CLIENT
0237:                            && getVersion() == Version.VERSION_1_4)
0238:                        return false;
0239:
0240:                    if (getAllServiceRefNames().isEmpty())
0241:                        return true;
0242:                }
0243:
0244:                return false;
0245:            }
0246:
0247:            public boolean isServer() {
0248:                return (getService() != null);
0249:            }
0250:
0251:            public boolean isAMInstalled() {
0252:                try {
0253:                    ServerProperties.getInstance(getServerID());
0254:                    return true;
0255:                } catch (Exception ex) {
0256:                    return false;
0257:                }
0258:            }
0259:
0260:            public String getServerID() {
0261:                return getProvider().getServerInstanceID();
0262:            }
0263:
0264:            public void refreshBuildScript() {
0265:                String buildScript = FileUtil.toFile(getProjectDirectory())
0266:                        .getPath()
0267:                        + BUILD_SCRIPT;
0268:
0269:                //System.out.println("buildScript = " + buildScript);
0270:
0271:                BufferedReader reader = null;
0272:                BufferedWriter writer = null;
0273:                String line = null;
0274:                boolean added = false;
0275:
0276:                // First check to see if our import statement has already been added.
0277:                try {
0278:                    reader = new BufferedReader(new FileReader(buildScript));
0279:
0280:                    while ((line = reader.readLine()) != null) {
0281:                        if (line.indexOf(IMPORT_AM_DEPLOY_XML) != -1) {
0282:                            added = true;
0283:                            break;
0284:                        }
0285:                    }
0286:                } catch (FileNotFoundException ex) {
0287:                    ErrorManager.getDefault().notify(
0288:                            ErrorManager.INFORMATIONAL, ex);
0289:                } catch (IOException ex) {
0290:                    ErrorManager.getDefault().notify(
0291:                            ErrorManager.INFORMATIONAL, ex);
0292:                } finally {
0293:                    if (reader != null) {
0294:                        try {
0295:                            reader.close();
0296:                        } catch (IOException ex) {
0297:                            ErrorManager.getDefault().notify(
0298:                                    ErrorManager.INFORMATIONAL, ex);
0299:                        }
0300:                    }
0301:                }
0302:
0303:                // If our import statement has not been added, add it now.
0304:                if (!added) {
0305:                    try {
0306:                        // Rename the original to build.xml.bak
0307:                        File backupBuildScript = new File(buildScript);
0308:                        backupBuildScript.renameTo(new File(buildScript
0309:                                + BACKUP_EXT));
0310:
0311:                        reader = new BufferedReader(new FileReader(buildScript
0312:                                + BACKUP_EXT));
0313:                        writer = new BufferedWriter(new FileWriter(buildScript));
0314:                        added = false;
0315:                        int index = 0;
0316:
0317:                        while ((line = reader.readLine()) != null) {
0318:                            if (!added
0319:                                    && (index = line.indexOf(IMPORT_TAG)) != -1) {
0320:                                StringBuffer buf = new StringBuffer(line);
0321:                                buf = buf.replace(index, line.length(),
0322:                                        IMPORT_AM_DEPLOY_XML);
0323:                                writer.write(buf.toString());
0324:                                writer.newLine();
0325:                                added = true;
0326:                            }
0327:
0328:                            writer.write(line);
0329:                            writer.newLine();
0330:                        }
0331:                    } catch (FileNotFoundException ex) {
0332:                        ErrorManager.getDefault().notify(
0333:                                ErrorManager.INFORMATIONAL, ex);
0334:                    } catch (IOException ex) {
0335:                        ErrorManager.getDefault().notify(
0336:                                ErrorManager.INFORMATIONAL, ex);
0337:                    } finally {
0338:                        try {
0339:                            if (writer != null) {
0340:                                writer.flush();
0341:                                writer.close();
0342:                            }
0343:
0344:                            if (reader != null) {
0345:                                reader.close();
0346:                            }
0347:                        } catch (IOException ex) {
0348:                            ErrorManager.getDefault().notify(
0349:                                    ErrorManager.INFORMATIONAL, ex);
0350:                        }
0351:                    }
0352:                }
0353:
0354:                // Now refresh the am-deploy.xml itself.
0355:                GeneratedFilesHelper genFilesHelper = new GeneratedFilesHelper(
0356:                        getProjectDirectory());
0357:
0358:                try {
0359:                    genFilesHelper.refreshBuildScript(AM_DEPLOY_XML_PATH,
0360:                            J2eeProjectHelper.class.getResource(AM_DEPLOY_XSL),
0361:                            false);
0362:                } catch (IOException e) {
0363:                    ErrorManager.getDefault().notify(e);
0364:                }
0365:            }
0366:
0367:            public ProjectType getProjectType() {
0368:                if (projectType == null) {
0369:                    Object moduleType = getProvider().getJ2eeModule()
0370:                            .getModuleType();
0371:
0372:                    if (J2eeModule.WAR.equals(moduleType)) {
0373:                        projectType = ProjectType.WEB;
0374:                    } else if (J2eeModule.EJB.equals(moduleType)) {
0375:                        projectType = ProjectType.EJB;
0376:                    } else if (J2eeModule.CLIENT.equals(moduleType)) {
0377:                        projectType = ProjectType.CLIENT;
0378:                    } else {
0379:                        projectType = ProjectType.UNKNOWN;
0380:                    }
0381:                }
0382:
0383:                return projectType;
0384:            }
0385:
0386:            public Version getVersion() {
0387:                if (version == null) {
0388:                    String versionString = ""; //NOI18N
0389:
0390:                    switch (getProjectType()) {
0391:                    case WEB:
0392:                        versionString = getWebModule().getJ2eePlatformVersion();
0393:                        break;
0394:                    case EJB:
0395:                        versionString = getEjbModule().getJ2eePlatformVersion();
0396:                        break;
0397:                    case CLIENT:
0398:                        versionString = getClientModule()
0399:                                .getJ2eePlatformVersion();
0400:                        break;
0401:                    default:
0402:                        break;
0403:                    }
0404:
0405:                    if (versionString.equals("1.4")) { //NOI18N
0406:                        version = Version.VERSION_1_4;
0407:                    } else if (versionString.equals("1.5")) { //NOI18N
0408:                        version = Version.VERSION_1_5;
0409:                    } else {
0410:                        version = Version.UNKNOWN;
0411:                    }
0412:                }
0413:
0414:                return version;
0415:            }
0416:
0417:            //    protected FileObject getSunDDFO() {
0418:            //        FileObject[] fobjs = getProvider().getConfigurationFiles();
0419:            //
0420:            //        if (fobjs.length > 0) {
0421:            //            return fobjs[0];
0422:            //        }
0423:            //
0424:            //        return null;
0425:            //    }
0426:
0427:            public String getEndpointName() {
0428:                if (!isServer())
0429:                    return null;
0430:
0431:                if (endpointName == null) {
0432:                    Version version = getVersion();
0433:
0434:                    if (version == Version.VERSION_1_4) {
0435:                        String javaClassName = getJavaSourceName();
0436:
0437:                        switch (getProjectType()) {
0438:                        case WEB:
0439:                            endpointName = getEndpointNameFromWebApp(javaClassName);
0440:                            break;
0441:                        case EJB:
0442:                            endpointName = getEndpointNameFromEjbJar(javaClassName);
0443:                        default:
0444:                            break;
0445:                        }
0446:                    } else if (version == Version.VERSION_1_5) {
0447:                        Service service = getService();
0448:                        if (service != null) {
0449:                            if (service.getWsdlUrl() == null) {
0450:                                endpointName = service.getName();
0451:                            } else {
0452:                                endpointName = service.getServiceName();
0453:                            }
0454:                        }
0455:                    }
0456:                }
0457:
0458:                //System.out.println("endpointName = " + endpointName);
0459:                return endpointName;
0460:            }
0461:
0462:            private String getEndpointNameFromWebApp(final String javaClassName) {
0463:                MetadataModel<WebAppMetadata> model = getJ2eeModule()
0464:                        .getMetadataModel(WebAppMetadata.class);
0465:                String name = null;
0466:
0467:                try {
0468:                    name = model
0469:                            .runReadAction(new MetadataModelAction<WebAppMetadata, String>() {
0470:                                public String run(WebAppMetadata metadata) {
0471:                                    WebApp webApp = metadata.getRoot();
0472:
0473:                                    for (Servlet s : webApp.getServlet()) {
0474:                                        if (s.getServletClass().equals(
0475:                                                javaClassName)) {
0476:                                            return s.getServletName();
0477:                                        }
0478:                                    }
0479:
0480:                                    return null;
0481:                                }
0482:                            });
0483:                } catch (Exception ex) {
0484:                    ErrorManager.getDefault().notify(
0485:                            ErrorManager.INFORMATIONAL, ex);
0486:                }
0487:
0488:                return name;
0489:            }
0490:
0491:            private String getEndpointNameFromEjbJar(final String javaClassName) {
0492:                MetadataModel<EjbJarMetadata> model = getJ2eeModule()
0493:                        .getMetadataModel(EjbJarMetadata.class);
0494:                String name = null;
0495:
0496:                try {
0497:                    name = model
0498:                            .runReadAction(new MetadataModelAction<EjbJarMetadata, String>() {
0499:                                public String run(EjbJarMetadata metadata) {
0500:                                    org.netbeans.modules.j2ee.dd.api.ejb.EjbJar ejbJar = metadata
0501:                                            .getRoot();
0502:                                    EnterpriseBeans eb = ejbJar
0503:                                            .getEnterpriseBeans();
0504:
0505:                                    if (eb != null) {
0506:                                        for (Ejb ejb : eb.getEjbs()) {
0507:                                            // Unlike servlets, the generated ejb name is
0508:                                            // the same as the web service name.
0509:                                            String ejbName = ejb.getEjbName();
0510:                                            if (ejbName != null
0511:                                                    && ejbName.length() > 0
0512:                                                    && ejb
0513:                                                            .getEjbClass()
0514:                                                            .equals(
0515:                                                                    javaClassName)) {
0516:                                                return ejbName;
0517:                                            }
0518:                                        }
0519:                                    }
0520:
0521:                                    return null;
0522:                                }
0523:                            });
0524:                } catch (Exception ex) {
0525:                    ErrorManager.getDefault().notify(
0526:                            ErrorManager.INFORMATIONAL, ex);
0527:                }
0528:
0529:                return name;
0530:            }
0531:
0532:            private void getServiceInfo() {
0533:                MetadataModel<WebservicesMetadata> webServicesModel = getJ2eeModule()
0534:                        .getMetadataModel(WebservicesMetadata.class);
0535:
0536:                try {
0537:                    webServicesModel
0538:                            .runReadAction(new MetadataModelAction<WebservicesMetadata, String>() {
0539:                                public String run(WebservicesMetadata metadata) {
0540:                                    Webservices webServices = metadata
0541:                                            .getRoot();
0542:
0543:                                    String endpointName = getEndpointName();
0544:                                    ProjectType projectType = getProjectType();
0545:
0546:                                    try {
0547:                                        for (WebserviceDescription desc : webServices
0548:                                                .getWebserviceDescription()) {
0549:                                            for (PortComponent pc : desc
0550:                                                    .getPortComponent()) {
0551:                                                String linkName = ""; //NOI18N
0552:
0553:                                                if (projectType == ProjectType.WEB) {
0554:                                                    linkName = pc
0555:                                                            .getServiceImplBean()
0556:                                                            .getServletLink();
0557:                                                } else if (projectType == ProjectType.EJB) {
0558:                                                    linkName = pc
0559:                                                            .getServiceImplBean()
0560:                                                            .getEjbLink();
0561:                                                }
0562:
0563:                                                if (linkName
0564:                                                        .equals(endpointName)) {
0565:                                                    portComponentName = pc
0566:                                                            .getPortComponentName();
0567:                                                    serviceDescriptionName = desc
0568:                                                            .getWebserviceDescriptionName();
0569:                                                }
0570:                                            }
0571:                                        }
0572:                                    } catch (Exception excp) {
0573:                                        ErrorManager.getDefault().notify(
0574:                                                ErrorManager.INFORMATIONAL,
0575:                                                excp);
0576:                                    }
0577:                                    return portComponentName;
0578:                                }
0579:                            });
0580:
0581:                } catch (Exception ex) {
0582:                    ErrorManager.getDefault().notify(
0583:                            ErrorManager.INFORMATIONAL, ex);
0584:                }
0585:            }
0586:
0587:            public String getPortComponentName() {
0588:                if (!isServer())
0589:                    return null;
0590:
0591:                if (portComponentName == null) {
0592:                    getServiceInfo();
0593:                }
0594:
0595:                //System.out.println("portComponentName = " + portComponentName);
0596:                return portComponentName;
0597:            }
0598:
0599:            public String getServiceDescriptionName() {
0600:                if (serviceDescriptionName == null) {
0601:                    if (isServer()) {
0602:                        getServiceInfo();
0603:                    } else {
0604:                        serviceDescriptionName = getServiceName();
0605:                    }
0606:                }
0607:
0608:                //System.out.println("serviceDescriptionName = " + serviceDescriptionName);
0609:                return serviceDescriptionName;
0610:            }
0611:
0612:            public List<String> getAllServiceRefNames() {
0613:                if (isServer())
0614:                    return null;
0615:
0616:                if (serviceRefNames == null) {
0617:                    switch (getProjectType()) {
0618:                    case WEB:
0619:                        serviceRefNames = getAllServiceRefNamesFromWebApp();
0620:                        break;
0621:                    case CLIENT:
0622:                        serviceRefNames = getAllServiceRefNamesFromAppClient();
0623:                        break;
0624:                    case EJB:
0625:                        serviceRefNames = getAllServiceRefNamesFromEjbJar();
0626:                        break;
0627:                    }
0628:                }
0629:                return serviceRefNames;
0630:            }
0631:
0632:            private List<String> getAllServiceRefNamesFromWebApp() {
0633:                MetadataModel<WebAppMetadata> model = getJ2eeModule()
0634:                        .getMetadataModel(WebAppMetadata.class);
0635:                List<String> refNames = null;
0636:
0637:                try {
0638:                    refNames = model
0639:                            .runReadAction(new MetadataModelAction<WebAppMetadata, List<String>>() {
0640:                                public List<String> run(WebAppMetadata metadata) {
0641:                                    WebApp webApp = metadata.getRoot();
0642:                                    List<String> refNames = new ArrayList<String>();
0643:                                    Version version = getVersion();
0644:
0645:                                    try {
0646:                                        for (ServiceRef s : webApp
0647:                                                .getServiceRef()) {
0648:                                            if (version == Version.VERSION_1_4) {
0649:                                                if (s
0650:                                                        .getServiceRefName()
0651:                                                        .equalsIgnoreCase(
0652:                                                                getServiceRefName()))
0653:                                                    refNames
0654:                                                            .add(s
0655:                                                                    .getServiceRefName());
0656:                                            } else if (version == Version.VERSION_1_5) {
0657:                                                if (isThisTheServiceRef(s)) {
0658:                                                    refNames
0659:                                                            .add(s
0660:                                                                    .getServiceRefName());
0661:                                                }
0662:                                            }
0663:                                        }
0664:                                    } catch (Exception ex) {
0665:                                        ErrorManager.getDefault().notify(
0666:                                                ErrorManager.INFORMATIONAL, ex);
0667:                                    }
0668:
0669:                                    return refNames;
0670:                                }
0671:                            });
0672:                } catch (Exception ex) {
0673:                    ErrorManager.getDefault().notify(
0674:                            ErrorManager.INFORMATIONAL, ex);
0675:                }
0676:
0677:                return refNames;
0678:            }
0679:
0680:            private List<String> getAllServiceRefNamesFromAppClient() {
0681:                MetadataModel<AppClientMetadata> model = getJ2eeModule()
0682:                        .getMetadataModel(AppClientMetadata.class);
0683:                List<String> refNames = null;
0684:
0685:                try {
0686:                    refNames = model
0687:                            .runReadAction(new MetadataModelAction<AppClientMetadata, List<String>>() {
0688:                                public List<String> run(
0689:                                        AppClientMetadata metadata) {
0690:                                    AppClient appClient = metadata.getRoot();
0691:                                    List<String> refNames = new ArrayList<String>();
0692:                                    Version version = getVersion();
0693:
0694:                                    try {
0695:                                        for (ServiceRef s : appClient
0696:                                                .getServiceRef()) {
0697:                                            if (version == Version.VERSION_1_4) {
0698:                                                if (s
0699:                                                        .getServiceRefName()
0700:                                                        .equalsIgnoreCase(
0701:                                                                getServiceRefName()))
0702:                                                    refNames
0703:                                                            .add(s
0704:                                                                    .getServiceRefName());
0705:                                            } else if (version == Version.VERSION_1_5) {
0706:                                                //if (isThisTheServiceRef(s))
0707:                                                refNames.add(s
0708:                                                        .getServiceRefName());
0709:                                            }
0710:                                        }
0711:                                    } catch (Exception ex) {
0712:                                        ErrorManager.getDefault().notify(
0713:                                                ErrorManager.INFORMATIONAL, ex);
0714:                                    }
0715:
0716:                                    return refNames;
0717:                                }
0718:                            });
0719:                } catch (Exception ex) {
0720:                    ErrorManager.getDefault().notify(
0721:                            ErrorManager.INFORMATIONAL, ex);
0722:                }
0723:
0724:                return refNames;
0725:            }
0726:
0727:            private List<String> getAllServiceRefNamesFromEjbJar() {
0728:                MetadataModel<EjbJarMetadata> model = getJ2eeModule()
0729:                        .getMetadataModel(EjbJarMetadata.class);
0730:                List<String> refNames = null;
0731:
0732:                try {
0733:                    refNames = model
0734:                            .runReadAction(new MetadataModelAction<EjbJarMetadata, List<String>>() {
0735:                                public List<String> run(EjbJarMetadata metadata) {
0736:                                    List<String> refNames = new ArrayList<String>();
0737:                                    org.netbeans.modules.j2ee.dd.api.ejb.EjbJar ejbJar = metadata
0738:                                            .getRoot();
0739:                                    EnterpriseBeans eb = ejbJar
0740:                                            .getEnterpriseBeans();
0741:                                    Version version = getVersion();
0742:
0743:                                    if (eb != null) {
0744:                                        for (Ejb ejb : eb.getEjbs()) {
0745:                                            try {
0746:                                                for (ServiceRef s : ejb
0747:                                                        .getServiceRef()) {
0748:                                                    if (isThisTheServiceRef(s))
0749:                                                        refNames
0750:                                                                .add(s
0751:                                                                        .getServiceRefName());
0752:                                                }
0753:                                            } catch (Exception ex) {
0754:                                                ErrorManager
0755:                                                        .getDefault()
0756:                                                        .notify(
0757:                                                                ErrorManager.INFORMATIONAL,
0758:                                                                ex);
0759:                                            }
0760:                                        }
0761:                                    }
0762:
0763:                                    return refNames;
0764:                                }
0765:                            });
0766:                } catch (Exception ex) {
0767:                    ErrorManager.getDefault().notify(
0768:                            ErrorManager.INFORMATIONAL, ex);
0769:                }
0770:
0771:                return refNames;
0772:            }
0773:
0774:            private boolean isThisTheServiceRef(ServiceRef s) {
0775:                String wsdlFile = getWsdlFO().getPath();
0776:
0777:                //System.out.println("wsdlfile from client node " + wsdlFile);
0778:                //System.out.println("wsdlfo name from client node " + getWsdlFO().getName());
0779:                //System.out.println("wsdlfo path from client node " + getWsdlFO().getPath());
0780:                URI wsdlUri = s.getWsdlFile();
0781:
0782:                //System.out.println("wsdlfile from service-ref " + wsdlUri.toString());
0783:                //System.out.println("wsdlfile from service-ref " + wsdlUri.getPath());
0784:                //System.out.println("wsdlfile from service-ref " + wsdlUri.getSchemeSpecificPart());
0785:
0786:                String path = wsdlUri.getPath();
0787:                int idx = 0;
0788:
0789:                if (path.startsWith(EJB_WSDL_LOC)) {
0790:                    idx = EJB_WSDL_LOC.length();
0791:                } else if (path.startsWith(WEB_WSDL_LOC)) {
0792:                    idx = WEB_WSDL_LOC.length();
0793:                } else if (path.startsWith(CLIENT_WSDL_LOC)) {
0794:                    idx = CLIENT_WSDL_LOC.length();
0795:                }
0796:
0797:                path = path.substring(idx, path.length());
0798:                //System.out.println("extracted path " + path);
0799:                if (wsdlFile != null && wsdlUri != null
0800:                        && wsdlFile.contains(path)) {
0801:                    return true;
0802:                }
0803:
0804:                return false;
0805:            }
0806:
0807:            public List<WsdlData> getWsdlData() {
0808:                if (isServer())
0809:                    return null;
0810:
0811:                if (wsdlData == null) {
0812:                    wsdlData = new ArrayList<WsdlData>();
0813:                    FileObject wsdlFO = getWsdlFO();
0814:
0815:                    if (wsdlFO != null) {
0816:                        try {
0817:                            List<String> svcNames = getAllServiceNames();
0818:                            for (String s : svcNames) {
0819:                                wsdlData.add(WsdlParser.parseWSDLFile(FileUtil
0820:                                        .toFile(wsdlFO), s));
0821:                            }
0822:                        } catch (IOException ioex) {
0823:                            ErrorManager.getDefault().notify(
0824:                                    ErrorManager.INFORMATIONAL, ioex);
0825:                        }
0826:                    }
0827:                }
0828:
0829:                return wsdlData;
0830:            }
0831:
0832:            protected FileObject getWsdlFO() {
0833:                if (getVersion() == Version.VERSION_1_4) {
0834:
0835:                    switch (getProjectType()) {
0836:                    case WEB:
0837:                        return getWsdlFOFromWebApp(getServiceRefName());
0838:                    case CLIENT:
0839:                        return getWsdlFOFromAppClient(getServiceRefName());
0840:                    case EJB:
0841:                        // Not applicable?
0842:                        break;
0843:                    }
0844:                } else if (getVersion() == Version.VERSION_1_5) {
0845:                    Client client = getClient();
0846:                    String wsdl = client.getLocalWsdlFile();
0847:                    Enumeration e = getProject().getProjectDirectory()
0848:                            .getFolders(true);
0849:                    while (e.hasMoreElements()) {
0850:                        FileObject fo = (FileObject) e.nextElement();
0851:                        FileObject wsdlFo = fo.getFileObject(wsdl);
0852:                        if (wsdlFo != null)
0853:                            return wsdlFo;
0854:                    }
0855:                }
0856:
0857:                return null;
0858:            }
0859:
0860:            private FileObject getWsdlFOFromWebApp(final String refName) {
0861:                MetadataModel<WebAppMetadata> model = getJ2eeModule()
0862:                        .getMetadataModel(WebAppMetadata.class);
0863:                FileObject fobj = null;
0864:
0865:                try {
0866:                    fobj = model
0867:                            .runReadAction(new MetadataModelAction<WebAppMetadata, FileObject>() {
0868:                                public FileObject run(WebAppMetadata metadata) {
0869:                                    WebApp webApp = metadata.getRoot();
0870:                                    try {
0871:                                        for (ServiceRef s : webApp
0872:                                                .getServiceRef()) {
0873:                                            if (s.getServiceRefName()
0874:                                                    .equalsIgnoreCase(refName)) {
0875:                                                return getProjectDirectory()
0876:                                                        .getFileObject(
0877:                                                                "web/"
0878:                                                                        + s
0879:                                                                                .getWsdlFile()
0880:                                                                                .getPath()); //NOI18N
0881:                                            }
0882:                                        }
0883:                                    } catch (Exception ex) {
0884:                                        ErrorManager.getDefault().notify(
0885:                                                ErrorManager.INFORMATIONAL, ex);
0886:                                    }
0887:
0888:                                    return null;
0889:                                }
0890:                            });
0891:                } catch (Exception ex) {
0892:                    ErrorManager.getDefault().notify(
0893:                            ErrorManager.INFORMATIONAL, ex);
0894:                }
0895:
0896:                return fobj;
0897:            }
0898:
0899:            private FileObject getWsdlFOFromAppClient(final String refName) {
0900:                MetadataModel<AppClientMetadata> model = getJ2eeModule()
0901:                        .getMetadataModel(AppClientMetadata.class);
0902:                FileObject fobj = null;
0903:
0904:                try {
0905:                    fobj = model
0906:                            .runReadAction(new MetadataModelAction<AppClientMetadata, FileObject>() {
0907:                                public FileObject run(AppClientMetadata metadata) {
0908:                                    AppClient appClient = metadata.getRoot();
0909:                                    try {
0910:                                        for (ServiceRef s : appClient
0911:                                                .getServiceRef()) {
0912:                                            if (s.getServiceRefName()
0913:                                                    .equalsIgnoreCase(refName)) {
0914:                                                return getProjectDirectory()
0915:                                                        .getFileObject(
0916:                                                                "src/conf/"
0917:                                                                        + s
0918:                                                                                .getWsdlFile()
0919:                                                                                .getPath()
0920:                                                                                .substring(
0921:                                                                                        9)); //NOI18N
0922:                                            }
0923:                                        }
0924:                                    } catch (Exception ex) {
0925:                                        ErrorManager.getDefault().notify(
0926:                                                ErrorManager.INFORMATIONAL, ex);
0927:                                    }
0928:
0929:                                    return null;
0930:                                }
0931:                            });
0932:                } catch (Exception ex) {
0933:                    ErrorManager.getDefault().notify(
0934:                            ErrorManager.INFORMATIONAL, ex);
0935:                }
0936:
0937:                return fobj;
0938:            }
0939:
0940:            public boolean isAppServerSun() {
0941:                return RuntimeBridge.isAppServerSun(getProvider());
0942:            }
0943:
0944:            public boolean providerExists() {
0945:                return false;
0946:            }
0947:
0948:            public boolean isSecurityEnabled() {
0949:                SunDDHelper helper = new SunDDHelper(getSunDDFO(),
0950:                        getProjectType());
0951:
0952:                if (isServer()) {
0953:                    return helper
0954:                            .isServiceSecurityEnabled(
0955:                                    getServiceDescriptionName(),
0956:                                    getPortComponentName());
0957:                } else {
0958:                    for (WsdlData wsdlData : getWsdlData()) {
0959:                        String namespace = wsdlData.getTargetNameSpace();
0960:                        String localPart = wsdlData.getPort();
0961:
0962:                        for (String name : getAllServiceRefNames()) {
0963:                            if (helper.isClientSecurityEnabled(name, namespace,
0964:                                    localPart)) {
0965:                                return true;
0966:                            }
0967:                        }
0968:                    }
0969:                }
0970:
0971:                return false;
0972:            }
0973:
0974:            protected void enableMessageLevelSecurity(String providerId) {
0975:                SunDDHelper helper = new SunDDHelper(getSunDDFO(),
0976:                        getProjectType());
0977:
0978:                if (isServer()) {
0979:                    helper.setServiceMessageSecurityBinding(
0980:                            getServiceDescriptionName(),
0981:                            getPortComponentName(), providerId);
0982:                } else {
0983:                    for (WsdlData wsdlData : getWsdlData()) {
0984:                        String namespace = wsdlData.getTargetNameSpace();
0985:                        String localPart = wsdlData.getPort();
0986:
0987:                        for (String name : getAllServiceRefNames()) {
0988:                            helper.setServiceRefMessageSecurityBinding(name,
0989:                                    namespace, localPart);
0990:                        }
0991:                    }
0992:                }
0993:            }
0994:
0995:            protected void disableMessageLevelSecurity() {
0996:                SunDDHelper helper = new SunDDHelper(getSunDDFO(),
0997:                        getProjectType());
0998:
0999:                if (isServer()) {
1000:                    helper
1001:                            .removeServiceMessageSecurityBinding(
1002:                                    getServiceDescriptionName(),
1003:                                    getPortComponentName());
1004:                } else {
1005:                    for (WsdlData wsdlData : getWsdlData()) {
1006:                        String namespace = wsdlData.getTargetNameSpace();
1007:                        String localPart = wsdlData.getPort();
1008:
1009:                        for (String name : getAllServiceRefNames()) {
1010:                            helper.removeServiceRefMessageSecurityBinding(name,
1011:                                    namespace, localPart);
1012:                        }
1013:                    }
1014:                }
1015:            }
1016:
1017:            public FileObject getSunDDFO() {
1018:                FileObject conf = getConfRoot();
1019:                String sunDDName = getSunDDName();
1020:                FileObject fobj = conf.getFileObject(sunDDName, XML_EXT);
1021:
1022:                if (fobj == null) {
1023:                    String template = getSunDDTemplate();
1024:
1025:                    try {
1026:                        fobj = createSunDDFromTemplate(template, conf,
1027:                                sunDDName);
1028:                    } catch (IOException ex) {
1029:                        ex.printStackTrace();
1030:                    }
1031:                }
1032:
1033:                return fobj;
1034:            }
1035:
1036:            private String getSunDDName() {
1037:                switch (getProjectType()) {
1038:                case EJB:
1039:                    return SUN_EJB_JAR_XML;
1040:                case WEB:
1041:                    return SUN_WEB_XML;
1042:                case CLIENT:
1043:                    return SUN_APPLICATION_CLIENT_XML;
1044:                }
1045:
1046:                return null;
1047:            }
1048:
1049:            private String getSunDDTemplate() {
1050:                switch (getProjectType()) {
1051:                case EJB:
1052:                    return SUN_EJB_JAR_TEMPLATE;
1053:                case WEB:
1054:                    return SUN_WEB_TEMPLATE;
1055:                case CLIENT:
1056:                    return SUN_APPLICATION_CLIENT_TEMPLATE;
1057:                }
1058:
1059:                return null;
1060:            }
1061:
1062:            private FileObject getConfRoot() {
1063:                FileObject[] sourceRoots = getProvider().getSourceRoots();
1064:
1065:                for (FileObject root : sourceRoots) {
1066:                    String name = root.getName();
1067:
1068:                    if (getProjectType() == ProjectType.WEB) {
1069:                        if (name.equals(WEB_FOLDER)) {
1070:                            return root.getFileObject(WEB_INF_FOLDER);
1071:                        }
1072:                    } else {
1073:                        if (name.equals(CONF_FOLDER)) { //NOI18N
1074:                            return root;
1075:                        }
1076:                    }
1077:                }
1078:                return null;
1079:            }
1080:
1081:            private FileObject createSunDDFromTemplate(String template,
1082:                    FileObject folder, String sunDDName) throws IOException {
1083:                assert template != null;
1084:                assert folder != null;
1085:
1086:                FileSystem defaultFS = Repository.getDefault()
1087:                        .getDefaultFileSystem();
1088:                FileObject templateFO = defaultFS.findResource(template);
1089:                DataObject templateDO = DataObject.find(templateFO);
1090:                DataFolder dataFolder = DataFolder.findFolder(folder);
1091:                DataObject dataObj = templateDO.createFromTemplate(dataFolder,
1092:                        sunDDName);
1093:
1094:                return dataObj.getPrimaryFile();
1095:            }
1096:
1097:            //    public boolean providerExists() {
1098:            //        File sunDD = getSunDD();
1099:            //
1100:            //        if (isServer()) {
1101:            //            String pcName = getPortComponentName();
1102:            //            String descName = getServiceDescriptionName();
1103:            //
1104:            //            if (SunDDBridge.doesEndPointMSBExist(sunDD, descName, pcName) &&
1105:            //                    !(SunDDBridge.isEndPointMSBAMProvider(sunDD, descName, pcName)))
1106:            //                return true;
1107:            //        } else {
1108:            //            List<String> refNames = getAllServiceRefNames();
1109:            //            String s = refNames.get(0);
1110:            //            List<WsdlData> wsdlInfo = getWsdlData();
1111:            //            if (!wsdlInfo.isEmpty()) {
1112:            //                WsdlData w = wsdlInfo.get(0);
1113:            //                String namespace = w.getTargetNameSpace();
1114:            //                String localPart = w.getPort();
1115:            //                if (SunDDBridge.doesSvcRefMSBExist(sunDD, s, namespace, localPart) &&
1116:            //                        !(SunDDBridge.isSvcRefMSBAMProvider(sunDD, s, namespace, localPart)))
1117:            //                    return true;
1118:            //            }
1119:            //        }
1120:            //        return false;
1121:            //    }
1122:            //
1123:            //    public boolean isSecurityEnabled() {
1124:            //        File sunDD = getSunDD();
1125:            //        String pcName = getPortComponentName();
1126:            //        String descName = getServiceDescriptionName();
1127:            //        List<String> refNames = getAllServiceRefNames();
1128:            //
1129:            //        if (isServer()) {
1130:            //            if (SunDDBridge.doesEndPointMSBExist(sunDD, descName, pcName) &&
1131:            //                    SunDDBridge.isEndPointMSBAMProvider(sunDD, descName, pcName))
1132:            //                return true;
1133:            //        } else {
1134:            //            String s = refNames.get(0);
1135:            //            List<WsdlData> wsdlInfo = getWsdlData();
1136:            //
1137:            //            if (!wsdlInfo.isEmpty()) {
1138:            //                WsdlData w = wsdlInfo.get(0);
1139:            //                String namespace = w.getTargetNameSpace();
1140:            //                String localPart = w.getPort();
1141:            //
1142:            //                if (SunDDBridge.doesSvcRefMSBExist(sunDD, s, namespace, localPart) &&
1143:            //                        SunDDBridge.isSvcRefMSBAMProvider(sunDD, s, namespace, localPart))
1144:            //                    return true;
1145:            //            }
1146:            //        }
1147:            //        return false;
1148:            //    }
1149:
1150:            public boolean isWsitSecurityEnabled() {
1151:                return WSITConfigProvider.getDefault().isWsitSecurityEnabled(
1152:                        node, model);
1153:            }
1154:
1155:            public void setTransientState(boolean isEnabled) {
1156:                securityChecker.setTransientState(isEnabled);
1157:            }
1158:
1159:            public void clearTransientState() {
1160:                securityChecker.clearTransientState();
1161:            }
1162:
1163:            public void enableWSPSecurity(String providerId) {
1164:                enableMessageLevelSecurity(providerId);
1165:            }
1166:
1167:            public void disableWSPSecurity() {
1168:                disableMessageLevelSecurity();
1169:            }
1170:
1171:            public void enableWSCSecurity(boolean isLiberty) {
1172:                if (getProjectType().equals(ProjectType.WEB)) {
1173:                    if (isLiberty) {
1174:                        enableLiberty();
1175:                    } else {
1176:                        disableLiberty();
1177:                    }
1178:                }
1179:
1180:                enableMessageLevelSecurity(null);
1181:            }
1182:
1183:            public void disableWSCSecurity() {
1184:                if (getProjectType().equals(ProjectType.WEB)) {
1185:                    disableLiberty();
1186:                }
1187:                disableMessageLevelSecurity();
1188:            }
1189:
1190:            //    protected void enableMessageLevelSecurity(String providerId) {
1191:            //        File sunDD = getSunDD();
1192:            //        String pcName = getPortComponentName();
1193:            //        String descName = getServiceDescriptionName();
1194:            //        List<String> refNames = getAllServiceRefNames();
1195:            //
1196:            //        if (isServer()) {
1197:            //            //            System.out.println("descname: portcompname: " + descName +
1198:            //            //                    " : " + pcName);
1199:            //            if (!SunDDBridge.setEndPointMSB(sunDD, descName, pcName, providerId)){
1200:            //                ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL,
1201:            //                        new Exception("Failed during SunDD changes")); // NOI18N
1202:            //            }
1203:            //        } else {
1204:            //            List<WsdlData> wsdlInfo = getWsdlData();
1205:            //            int i = 0;
1206:            //            assert(wsdlInfo.size() >= refNames.size());
1207:            //            for (String s : refNames) {
1208:            //                if (wsdlInfo.get(i) != null) {
1209:            //                    String namespace = wsdlInfo.get(i).getTargetNameSpace();
1210:            //                    String localPart = wsdlInfo.get(i).getPort();
1211:            //                    //                    System.out.println("refName : namespace: localpart: " + s +
1212:            //                    //                            " : " + namespace + " : " + localPart);
1213:            //                    if (!SunDDBridge.setSvceRefMSB(sunDD, s, namespace, localPart)) {
1214:            //                        ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL,
1215:            //                                new Exception("Failed during SunDD changes")); // NOI18N
1216:            //                    }
1217:            //                }
1218:            //                i++;
1219:            //            }
1220:            //        }
1221:            //    }
1222:
1223:            //    protected void disableMessageLevelSecurity() {
1224:            //        //if (!isSecurityEnabled()) return;
1225:            //
1226:            //        File sunDD = getSunDD();
1227:            //        String pcName = getPortComponentName();
1228:            //        String descName = getServiceDescriptionName();
1229:            //        List<String> refNames = getAllServiceRefNames();
1230:            //
1231:            //        if (isServer()) {
1232:            //            //            System.out.println("Into delete -- descname: portcompname: " + descName +
1233:            //            //                    " : " + pcName);
1234:            //            if (!SunDDBridge.deleteEndPointMSB(sunDD, descName, pcName)){
1235:            //                ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL,
1236:            //                        new Exception("Failed during SunDD changes")); // NOI18N
1237:            //            }
1238:            //        } else {
1239:            //            List<WsdlData> wsdlInfo = getWsdlData();
1240:            //            int i = 0;
1241:            //            assert(wsdlInfo.size() >= refNames.size());
1242:            //            for (String s : refNames) {
1243:            //                if (wsdlInfo.get(i) != null) {
1244:            //                    String namespace = wsdlInfo.get(i).getTargetNameSpace();
1245:            //                    String localPart = wsdlInfo.get(i).getPort();
1246:            //                    //                    System.out.println("Into delete -- refName : namespace: localpart: " + s +
1247:            //                    //                            " : " + namespace + " : " + localPart);
1248:            //                    if (!SunDDBridge.deleteSvcRefMSB(sunDD, s, namespace, localPart)) {
1249:            //                        ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL,
1250:            //                                new Exception("Failed during SunDD changes")); // NOI18N
1251:            //                    }
1252:            //                }
1253:            //                i++;
1254:            //            }
1255:            //        }
1256:            //    }
1257:
1258:            private void enableLiberty() {
1259:                addAMSecurityConstraint();
1260:                SunDDHelper helper = new SunDDHelper(getSunDDFO(),
1261:                        getProjectType());
1262:                helper.addSecurityRoleMapping();
1263:            }
1264:
1265:            private void disableLiberty() {
1266:                removeAMSecurityConstraint();
1267:                SunDDHelper helper = new SunDDHelper(getSunDDFO(),
1268:                        getProjectType());
1269:                helper.removeSecurityRoleMapping();
1270:            }
1271:
1272:            private void addAMSecurityConstraint() {
1273:                boolean isModified = false;
1274:                WebApp webApp = getWebApp();
1275:                SecurityRole amRole = getAMSecurityRole(webApp);
1276:
1277:                try {
1278:                    if (amRole == null) {
1279:                        amRole = (SecurityRole) webApp
1280:                                .createBean("SecurityRole"); //NOI18N
1281:                        amRole.setRoleName(AM_ROLE_NAME);
1282:                        webApp.addSecurityRole(amRole);
1283:                        isModified = true;
1284:                    }
1285:                } catch (ClassNotFoundException ex) {
1286:                    ErrorManager.getDefault().notify(
1287:                            ErrorManager.INFORMATIONAL, ex);
1288:                }
1289:
1290:                SecurityConstraint amConstraint = getAMSecurityConstraint(webApp);
1291:
1292:                try {
1293:                    if (amConstraint == null) {
1294:                        amConstraint = (SecurityConstraint) webApp
1295:                                .createBean("SecurityConstraint"); //NOI18n
1296:                        amConstraint.setDisplayName(AM_CONSTRAINT_DISPLAY_NAME);
1297:                        webApp.addSecurityConstraint(amConstraint);
1298:
1299:                        WebResourceCollection wrc = (WebResourceCollection) amConstraint
1300:                                .createBean("WebResourceCollection"); //NOI18N
1301:                        wrc.setWebResourceName(AM_WEB_RESOURCE_NAME);
1302:                        wrc.setUrlPattern(new String[] { AM_URL_PATTERN });
1303:                        amConstraint
1304:                                .setWebResourceCollection(new WebResourceCollection[] { wrc });
1305:
1306:                        AuthConstraint authConstraint = (AuthConstraint) amConstraint
1307:                                .createBean("AuthConstraint"); //NOI18N
1308:                        authConstraint
1309:                                .setRoleName(new String[] { AM_ROLE_NAME }); //NOI18N
1310:                        amConstraint.setAuthConstraint(authConstraint);
1311:                        isModified = true;
1312:                    }
1313:                } catch (ClassNotFoundException ex) {
1314:                    ErrorManager.getDefault().notify(
1315:                            ErrorManager.INFORMATIONAL, ex);
1316:                }
1317:
1318:                if (isModified)
1319:                    saveDD(webApp);
1320:            }
1321:
1322:            private void removeAMSecurityConstraint() {
1323:                boolean isModified = false;
1324:                WebApp webApp = getWebApp();
1325:                SecurityRole amRole = getAMSecurityRole(webApp);
1326:
1327:                if (amRole != null) {
1328:                    webApp.removeSecurityRole(amRole);
1329:                    isModified = true;
1330:                }
1331:
1332:                SecurityConstraint amConstraint = getAMSecurityConstraint(webApp);
1333:
1334:                if (amConstraint != null) {
1335:                    webApp.removeSecurityConstraint(amConstraint);
1336:                    isModified = true;
1337:                }
1338:
1339:                if (isModified)
1340:                    saveDD(webApp);
1341:            }
1342:
1343:            private SecurityRole getAMSecurityRole(WebApp webApp) {
1344:                SecurityRole[] roles = webApp.getSecurityRole();
1345:
1346:                for (SecurityRole role : roles) {
1347:                    if (role.getRoleName().equals(AM_ROLE_NAME)) {
1348:                        return role;
1349:                    }
1350:                }
1351:
1352:                return null;
1353:            }
1354:
1355:            private SecurityConstraint getAMSecurityConstraint(WebApp webApp) {
1356:                SecurityConstraint[] constraints = webApp
1357:                        .getSecurityConstraint();
1358:
1359:                for (SecurityConstraint constraint : constraints) {
1360:                    if (constraint.getDefaultDisplayName().equals(
1361:                            AM_CONSTRAINT_DISPLAY_NAME)) {
1362:                        return constraint;
1363:                    }
1364:                }
1365:
1366:                return null;
1367:            }
1368:
1369:            private void saveDD(RootInterface model) {
1370:                try {
1371:                    ByteArrayOutputStream out = new ByteArrayOutputStream();
1372:                    model.write(out);
1373:                    out.close();
1374:
1375:                    FileObject webDD = getWebModule().getDeploymentDescriptor();
1376:                    FileLock lock = webDD.lock();
1377:                    Writer writer = new OutputStreamWriter(webDD
1378:                            .getOutputStream(lock));
1379:                    writer.write(out.toString(DEFAULT_ENCODING));
1380:                    writer.flush();
1381:                    writer.close();
1382:                    lock.releaseLock();
1383:                } catch (IOException e) {
1384:                    ErrorManager.getDefault().notify(
1385:                            org.openide.ErrorManager.INFORMATIONAL, e);
1386:                } catch (IllegalStateException e) {
1387:                    ErrorManager.getDefault().notify(
1388:                            org.openide.ErrorManager.INFORMATIONAL, e);
1389:                }
1390:            }
1391:
1392:            public String getConfigPath() {
1393:                return FileUtil.toFile(getProjectDirectory()).getPath()
1394:                        + File.separator + "src" + File.separator + "conf"; //NOI18N
1395:            }
1396:
1397:            private String getServiceRefName() {
1398:                return SERVICE_REF_NAME_PREFIX + getServiceName(); //NOI18N
1399:            }
1400:
1401:            public List<String> getAllServiceNames() {
1402:                if (serviceNames == null) {
1403:                    serviceNames = new ArrayList<String>();
1404:
1405:                    FileObject wsdlFO = getWsdlFO();
1406:
1407:                    if (wsdlFO != null) {
1408:                        try {
1409:                            serviceNames = WsdlParser.getWsdlSvcNames(FileUtil
1410:                                    .toFile(wsdlFO));
1411:                        } catch (IOException ioex) {
1412:                            ErrorManager.getDefault().notify(
1413:                                    ErrorManager.INFORMATIONAL, ioex);
1414:                        }
1415:                    }
1416:                }
1417:
1418:                return serviceNames;
1419:            }
1420:
1421:            public List<String> getEndpointURI() {
1422:                if (endpointUri == null) {
1423:                    endpointUri = new ArrayList<String>();
1424:
1425:                    if (isServer()) {
1426:                        endpointUri.add(getServiceDescriptionName());
1427:                    } else {
1428:                        endpointUri = getAllServiceNames();
1429:                    }
1430:                }
1431:                return endpointUri;
1432:            }
1433:
1434:            private String getServiceName() {
1435:                if (isServer()) {
1436:                    //TODO: Need to implement
1437:                    return null;
1438:                } else {
1439:                    // Currently just using node's name to get the info.
1440:                    // Need a proper API for that.
1441:                    return node.getName();
1442:                }
1443:            }
1444:
1445:            protected J2eeModuleProvider getProvider() {
1446:                Project project = getProject();
1447:
1448:                if (project != null)
1449:                    return (J2eeModuleProvider) project.getLookup().lookup(
1450:                            J2eeModuleProvider.class);
1451:
1452:                return null;
1453:            }
1454:
1455:            protected Project getProject() {
1456:                return FileOwnerQuery.getOwner(getFileObject());
1457:            }
1458:
1459:            protected FileObject getProjectDirectory() {
1460:                return getProject().getProjectDirectory();
1461:            }
1462:
1463:            private FileObject getFileObject() {
1464:                FileObject source = getJavaSource();
1465:
1466:                if (source != null)
1467:                    return source;
1468:
1469:                FileObject fo = (FileObject) node.getLookup().lookup(
1470:                        FileObject.class);
1471:
1472:                if (fo != null)
1473:                    return fo;
1474:
1475:                DataObject dobj = (DataObject) node.getLookup().lookup(
1476:                        DataObject.class);
1477:
1478:                return dobj.getPrimaryFile();
1479:            }
1480:
1481:            protected FileObject getJavaSource() {
1482:                return (FileObject) node.getLookup().lookup(FileObject.class);
1483:            }
1484:
1485:            protected String getJavaSourceName() {
1486:                return getService().getImplementationClass();
1487:            }
1488:
1489:            protected Client getClient() {
1490:                return (Client) node.getLookup().lookup(Client.class);
1491:            }
1492:
1493:            protected Service getService() {
1494:                return (Service) node.getLookup().lookup(Service.class);
1495:            }
1496:
1497:            protected WebModule getWebModule() {
1498:                return WebModule.getWebModule(getProjectDirectory());
1499:            }
1500:
1501:            protected EjbJar getEjbModule() {
1502:                return EjbJar.getEjbJar(getProjectDirectory());
1503:            }
1504:
1505:            protected Car getClientModule() {
1506:                return Car.getCar(getProjectDirectory());
1507:            }
1508:
1509:            protected J2eeModule getJ2eeModule() {
1510:                return getProvider().getJ2eeModule();
1511:            }
1512:
1513:            protected WebApp getWebApp() {
1514:                FileObject conf = getConfRoot();
1515:                FileObject fobj = conf.getFileObject("web", XML_EXT);
1516:
1517:                try {
1518:                    WebApp webApp = DDProvider.getDefault().getDDRoot(fobj);
1519:
1520:                    return webApp;
1521:                } catch (Exception ex) {
1522:                    ErrorManager.getDefault().notify(
1523:                            org.openide.ErrorManager.INFORMATIONAL, ex);
1524:                }
1525:
1526:                return null;
1527:            }
1528:        }
w_w_w___.__ja_v_a2__s_._c_o___m__ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.