Source Code Cross Referenced for NetletProvider.java in  » Portal » Open-Portal » com » sun » portal » providers » netlet » 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 » Portal » Open Portal » com.sun.portal.providers.netlet 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /**
0002:         * Copyright 2002 Sun Microsystems, Inc. All
0003:         * rights reserved. Use of this product is subject
0004:         * to license terms. Federal Acquisitions:
0005:         * Commercial Software -- Government Users
0006:         * Subject to Standard License Terms and
0007:         * Conditions.
0008:         *
0009:         * Sun, Sun Microsystems, the Sun logo, and Sun ONE
0010:         * are trademarks or registered trademarks of Sun Microsystems,
0011:         * Inc. in the United States and other countries.
0012:         *
0013:         * Functionality:
0014:         *  1. Gets ths contents of the Netlet channel. (getContent() method).
0015:         *  2. Gets the contents of the Netlet provider. (getEdit() method).
0016:         *  3. Processed the contents of the Netlet provider and stores to the backend (processEdit() method).
0017:         */package com.sun.portal.providers.netlet;
0018:
0019:        import com.iplanet.am.util.SystemProperties;
0020:        import com.sun.portal.log.common.PortalLogger;
0021:        import com.iplanet.sso.SSOException;
0022:        import com.iplanet.sso.SSOToken;
0023:        import com.iplanet.sso.SSOTokenManager;
0024:        import com.sun.portal.desktop.DesktopException;
0025:        import com.sun.portal.desktop.context.ContextException;
0026:        import com.sun.portal.desktop.util.I18n;
0027:        import com.sun.portal.desktop.util.ParameterMap;
0028:        import com.sun.portal.desktop.util.Target;
0029:        import com.sun.portal.netlet.util.NetletConstants;
0030:        import com.sun.portal.netlet.util.UrlEncoder;
0031:        import com.sun.portal.netlet.util.UserAttributes;
0032:        import com.sun.portal.providers.ProfileProviderAdapter;
0033:        import com.sun.portal.providers.ProviderException;
0034:        import com.sun.portal.providers.context.ProviderContextException;
0035:        import com.sun.portal.log.common.PortalLogger;
0036:
0037:        import javax.servlet.http.HttpServletRequest;
0038:        import javax.servlet.http.HttpServletResponse;
0039:        import java.io.IOException;
0040:        import java.io.DataOutputStream;
0041:        import java.net.HttpURLConnection;
0042:        import java.net.URL;
0043:        import java.net.URLEncoder;
0044:        import java.util.*;
0045:        import java.util.logging.Logger;
0046:        import java.util.logging.Level;
0047:
0048:        /*
0049:         * Provider class to retrieve and store the contents of Netlet channel and provider.
0050:         */
0051:
0052:        public class NetletProvider extends ProfileProviderAdapter implements 
0053:                NetletConstants {
0054:
0055:            private ResourceBundle bundle = null;
0056:            private final String NC_NAME = "/NetletConfig";
0057:            private final String NC_STARTURL = "?func=makepage";
0058:            private final String NC_JNLP_STARTURL = "?func=makeJnlpPage&startNetlet=true";
0059:            private String editContainer = null;
0060:            private String container = null;
0061:            private String statusMsg = null;
0062:            private String netletStatus = null;
0063:
0064:            private String ruleName;
0065:            private String newHostString;
0066:            private String clientBindIPAddress;
0067:            private String netletLaunchMode;
0068:            private String browserProxyType;
0069:            private String browserProxyHost;
0070:            private String browserProxyPort;
0071:            private String browserProxyOverrideList;
0072:
0073:            // Create a logger for this class
0074:            private static Logger debugLogger = PortalLogger
0075:                    .getLogger(NetletProvider.class);
0076:
0077:            /*
0078:             *  Initialize the provider and get the resource bundle
0079:             */
0080:            public void init(String n, HttpServletRequest req)
0081:                    throws ProviderException {
0082:                super .init(n, req);
0083:                bundle = getResourceBundle(NetletConstants.NETLET_PROVIDER_RES_BUNDLE);
0084:            }
0085:
0086:            /*
0087:             * Default constructor
0088:             */
0089:            public NetletProvider() {
0090:            }
0091:
0092:            /*
0093:             * Returns the URI of NetletConfig (Netlet servlet)
0094:             */
0095:            public String getNetletConfigURI(HttpServletRequest req) {
0096:                String cp = req.getContextPath();
0097:                String ncuri = (cp + NC_NAME);
0098:                return ncuri;
0099:            }
0100:
0101:            /*
0102:             * Invokes NetletConfig servlet using URLConnection.
0103:             * @ Returns the response code of the Servlet.
0104:             */
0105:            private int callNetletConfig(String func, HttpServletRequest httpreq)
0106:                    throws IOException, ContextException, SSOException {
0107:                String psNetletHeader = httpreq
0108:                        .getHeader(NetletConstants.NETLET_HEADER);
0109:                String host = httpreq.getServerName();
0110:                int port = httpreq.getServerPort();
0111:                String proto = httpreq.getScheme();
0112:                // iDSAME Migration for cookies
0113:                //String cookieName = SystemProperties.get("portal.cookie.name","iPlanetDirectoryPro");
0114:                String cookieName = SystemProperties.get(
0115:                        NetletConstants.IS_COOKIE_KEY,
0116:                        NetletConstants.IS_DEFAULT_COOKIE_NAME);
0117:                // EOC : iDSAME Migration for cookies
0118:
0119:                String ncURI = getNetletConfigURI(httpreq);
0120:                String ncURL = proto + "://" + host + ":" + port + ncURI;
0121:
0122:                URL nc = new URL(ncURL + "?func=" + func);
0123:                HttpURLConnection ncc = (HttpURLConnection) nc.openConnection();
0124:                ncc.setDoOutput(true);
0125:                ncc.setDoInput(true);
0126:                ncc.setUseCaches(false);
0127:                ncc.setRequestProperty("Cookie", cookieName
0128:                        + "="
0129:                        + URLEncoder.encode(SSOTokenManager.getInstance()
0130:                                .createSSOToken(httpreq).getTokenID()
0131:                                .toString()));
0132:                if (psNetletHeader != null) {
0133:                    ncc.setRequestProperty(NetletConstants.NETLET_HEADER,
0134:                            psNetletHeader);
0135:                }
0136:                int response = ncc.getResponseCode();
0137:                ncc.disconnect();
0138:                return response;
0139:            }
0140:
0141:            /*
0142:             * Returns true if the reAuthentication is enabled for the user.
0143:             */
0144:            private boolean isReauthEnabled(HttpServletRequest httpreq) {
0145:                UserAttributes attrs = getNetletUserAttributes(httpreq);
0146:                return attrs == null ? false : attrs.getBoolean(
0147:                        NetletConstants.NETLET_DO_REAUTH, false);
0148:            }
0149:
0150:            /*
0151:             *  Returns true if there is atleast one static rule, false otherwise
0152:             */
0153:            private boolean hasStaticRule(List netletRules) {
0154:                if (netletRules == null || netletRules.isEmpty()) {
0155:                    return false;
0156:                }
0157:                boolean hasStatic = false;
0158:                for (int x = 0; x < netletRules.size(); x++) {
0159:                    String nr = (String) netletRules.get(x);
0160:                    if (nr.endsWith(NetletConstants.NETLET_EXTEND_SESSION))
0161:                        nr = nr.substring(0, nr.lastIndexOf("|"));
0162:                    StringTokenizer tok = new StringTokenizer(nr, "|");
0163:                    boolean isTarget = false;
0164:                    try {
0165:                        String func = (String) tok.nextElement();
0166:                        String tmp = (String) tok.nextElement(); // url
0167:                        tmp = (String) tok.nextElement(); // loopback
0168:                        while (tok.hasMoreElements() && !isTarget) {
0169:                            tmp = (String) tok.nextElement(); // local port
0170:                            tmp = (String) tok.nextElement(); // dest host
0171:                            if (tmp.equals(NetletConstants.NETLET_TARGET_HOST)) {
0172:                                isTarget = true;
0173:                            }
0174:                            tmp = (String) tok.nextElement(); // dest port
0175:                        }
0176:                    } catch (NoSuchElementException nsee) {
0177:                        continue; // skip non-parsable rules
0178:                    }
0179:                    if (!isTarget) {
0180:                        hasStatic = true;
0181:                    }
0182:                }
0183:                return hasStatic;
0184:            }
0185:
0186:            /*
0187:             * Returns true if netletRules contain a dynamic rule with the given ruleName
0188:             */
0189:            private boolean hasDynamicRule(List netletRules, String ruleName) {
0190:                if (netletRules == null || netletRules.isEmpty()) {
0191:                    return false;
0192:                }
0193:                for (int x = 0; x < netletRules.size(); x++) {
0194:                    String nr = (String) netletRules.get(x);
0195:                    if (nr.endsWith(NetletConstants.NETLET_EXTEND_SESSION))
0196:                        nr = nr.substring(0, nr.lastIndexOf("|"));
0197:                    StringTokenizer tok = new StringTokenizer(nr, "|");
0198:                    boolean isTarget = false;
0199:                    try {
0200:                        String func = (String) tok.nextElement();
0201:                        StringTokenizer tempTok = new StringTokenizer(func, "^");
0202:                        func = tempTok.nextToken();
0203:                        if (ruleName != null && ruleName.trim().length() != 0
0204:                                && func.equals(ruleName)) {
0205:                            String tmp = (String) tok.nextElement(); // url
0206:                            tmp = (String) tok.nextElement(); // loopback
0207:                            while (tok.hasMoreElements() && !isTarget) {
0208:                                tmp = (String) tok.nextElement(); // local port
0209:                                tmp = (String) tok.nextElement(); // dest host
0210:                                if (tmp
0211:                                        .equals(NetletConstants.NETLET_TARGET_HOST)) {
0212:                                    return true;
0213:                                }
0214:                                tmp = (String) tok.nextElement(); // dest port
0215:                            }
0216:                        }
0217:                    } catch (NoSuchElementException nsee) {
0218:                        continue; // skip non-parsable rules
0219:                    }
0220:                }
0221:                return false;
0222:            }
0223:
0224:            /*
0225:             * Returns true if netletRules has atleast one dynamic rule
0226:             */
0227:            private boolean hasDynamicRule(List netletRules) {
0228:                if (netletRules == null || netletRules.isEmpty()) {
0229:                    return false;
0230:                }
0231:                for (int x = 0; x < netletRules.size(); x++) {
0232:                    String nr = (String) netletRules.get(x);
0233:                    if (nr.endsWith(NetletConstants.NETLET_EXTEND_SESSION))
0234:                        nr = nr.substring(0, nr.lastIndexOf("|"));
0235:                    StringTokenizer tok = new StringTokenizer(nr, "|");
0236:                    boolean isTarget = false;
0237:                    try {
0238:                        String func = (String) tok.nextElement();
0239:                        String tmp = (String) tok.nextElement(); // url
0240:                        tmp = (String) tok.nextElement(); // loopback
0241:                        while (tok.hasMoreElements() && !isTarget) {
0242:                            tmp = (String) tok.nextElement(); // local port
0243:                            tmp = (String) tok.nextElement(); // dest host
0244:                            if (tmp.equals(NetletConstants.NETLET_TARGET_HOST)) {
0245:                                return true;
0246:                            }
0247:                            tmp = (String) tok.nextElement(); // dest port
0248:                        }
0249:                    } catch (NoSuchElementException nsee) {
0250:                        continue; // skip non-parsable rules
0251:                    }
0252:                }
0253:                return false;
0254:            }
0255:
0256:            /*
0257:             * Trims the hostName list separated by '+'
0258:             */
0259:            private String trimHostNamesList(String hostNames) {
0260:                String newHostNameList = null;
0261:                StringTokenizer st = new StringTokenizer(hostNames, "+");
0262:                try {
0263:                    newHostNameList = st.nextToken().trim();
0264:                    while (st.hasMoreTokens()) {
0265:                        newHostNameList += "+";
0266:                        newHostNameList += st.nextToken().trim();
0267:                    }
0268:                } catch (NoSuchElementException nse) {
0269:                    debugLogger.log(Level.INFO, "PSSR_CSPPN0001", nse);
0270:                }
0271:                return newHostNameList;
0272:            }
0273:
0274:            /*
0275:             * Update the Targets configured by the user to reflect the changes
0276:             * made to the Netlet rules
0277:             * @ Resturns updated Target list.
0278:             */
0279:            private List updateTargets(List currentTargets, List currentRules) {
0280:                if (currentTargets == null || currentTargets.isEmpty()) {
0281:                    return currentTargets;
0282:                }
0283:                List newTargets = new ArrayList();
0284:                for (int i = 0; i < currentTargets.size(); i++) {
0285:                    Target target = new Target((String) currentTargets.get(i));
0286:                    if (hasDynamicRule(currentRules, target.getName())) {
0287:                        newTargets.add(currentTargets.get(i));
0288:                    }
0289:                }
0290:                return newTargets;
0291:            }
0292:
0293:            /*
0294:             * Main method to get the Netlet channel contents.
0295:             * This method is invoked by DesktopServlet
0296:             */
0297:            public StringBuffer getContent(HttpServletRequest req,
0298:                    HttpServletResponse res) throws ProviderException {
0299:                StringBuffer content = new StringBuffer();
0300:                StringBuffer targetsToSet = new StringBuffer(100);
0301:
0302:                UserAttributes attrs = getNetletUserAttributes(req);
0303:
0304:                String launchModeStr = attrs
0305:                        .getString(NetletConstants.NETLET_LAUNCH_MODE);
0306:                boolean jwsMode = false;
0307:                if (launchModeStr != null
0308:                        && launchModeStr.equalsIgnoreCase("Java Web Start")) {
0309:                    jwsMode = true;
0310:                }
0311:
0312:                List netletRules = attrs
0313:                        .getStringList(NetletConstants.NETLET_RULES);
0314:
0315:                boolean serviceEnabled = attrs.isAllowed();
0316:
0317:                boolean noNetletRules = (netletRules == null || netletRules
0318:                        .isEmpty()) ? true : false;
0319:
0320:                /**
0321:                 * Check whether the request is via the Gateway and whether the netlet is enabled.
0322:                 */
0323:                boolean openPortal = true;
0324:                boolean netletDisabled = true;
0325:                String psNetletHeader = req
0326:                        .getHeader(NetletConstants.NETLET_HEADER);
0327:                debugLogger.log(Level.FINER, "PSSR_CSPPN0002", psNetletHeader);
0328:                if (psNetletHeader != null) {
0329:                    openPortal = false;
0330:                    StringTokenizer tokenizer = new StringTokenizer(
0331:                            psNetletHeader, ";");
0332:                    if (tokenizer.hasMoreTokens()) {
0333:                        String token = tokenizer.nextToken().trim();
0334:                        if ("enabled=true".equals(token)) {
0335:                            netletDisabled = false;
0336:                        }
0337:                    }
0338:                }
0339:
0340:                /*
0341:                 *  Return appropriate error messages.
0342:                 */
0343:                if (!serviceEnabled || noNetletRules || openPortal
0344:                        || netletDisabled) {
0345:                    content.append("<table><tr><td>\n").append("<font FACE=\"")
0346:                            .append(getStringProperty("fontFace1")).append(
0347:                                    "\" size=\"-1\">\n");
0348:                    if (openPortal) {
0349:                        content.append(bundle.getString("noGateway"));
0350:                    } else if (netletDisabled) {
0351:                        content.append(bundle.getString("netletDisabled"));
0352:                    } else if (!serviceEnabled) {
0353:                        content.append(bundle.getString("noService"));
0354:                    } else if (noNetletRules) {
0355:                        content.append(bundle.getString("noRules"));
0356:                    }
0357:                    content.append("</font></td></tr></table>\n");
0358:                    /*
0359:                       try {
0360:                           getProviderContext().setBooleanProperty(getName(), "isEditable", false);
0361:                       } catch (ProviderContextException pce) {
0362:                           getProviderContext().debugError("NetletProvider: Unable to set isEditable property of Netlet channel", pce);
0363:                       }
0364:                     */
0365:                    return content;
0366:                } else {
0367:                    /*
0368:                       try {
0369:                           if (getProviderContext().getBooleanProperty(getName(), "isEditable") == false)
0370:                               getProviderContext().setBooleanProperty(getName(), "isEditable", true);
0371:                       } catch (ProviderContextException pce) {
0372:                           getProviderContext().debugError("NetletProvider: Unable to set isEditable property of Netlet channel", pce);
0373:                       }
0374:                     */
0375:                }
0376:
0377:                String ncURI = getNetletConfigURI(req);
0378:                String ncStartURL = ncURI + NC_STARTURL;
0379:                String ncJNLPStartURL = ncURI + NC_JNLP_STARTURL;
0380:                List targets = null;
0381:                try {
0382:                    Map l = getProviderContext().getCollectionProperty(
0383:                            getName(), "targets");
0384:                    if (l != null || !l.isEmpty()) {
0385:                        targets = new ArrayList(l.values());
0386:                    }
0387:                } catch (ProviderContextException pce) {
0388:                    debugLogger.log(Level.INFO, "PSSR_CSPPN0003", pce);
0389:                    targets = null;
0390:                }
0391:
0392:                /*
0393:                 * Display only those targets for which Netlet rule is defined.
0394:                 */
0395:                targets = updateTargets(targets, netletRules);
0396:                //getProviderContext().setCollectionProperty(getName(),"targets", targets);
0397:                boolean hasTargets = (targets == null || targets.isEmpty()) ? false
0398:                        : true;
0399:                boolean hasDynamicRule = hasDynamicRule(netletRules);
0400:                /*
0401:                 *  Check whether the Netlet should be started on login
0402:                 */
0403:                boolean startNetlet = hasStaticRule(netletRules);
0404:
0405:                if (!startNetlet) {
0406:                    String macload = req.getParameter("macload");
0407:                    String agent = req.getHeader("user-agent");
0408:                    if ((macload != null && macload.equals("dynamic"))
0409:                            || (agent != null
0410:                                    && agent.indexOf("Mac_PowerPC") != -1 && agent
0411:                                    .indexOf("MSIE") != -1)) {
0412:                        startNetlet = true;
0413:                    }
0414:                }
0415:
0416:                content.append("<table><tr><td>\n").append(
0417:                        "<font FACE=\"[tag:iwtDesktop-fontFace1]\" ").append(
0418:                        "size=\"-1\">\n");
0419:
0420:                if (!hasTargets && hasDynamicRule) {
0421:                    content.append(bundle.getString("noTargets"));
0422:                } else {
0423:                    // set the appropriate message in the channel
0424:                    String wait = "";
0425:                    if (startNetlet) {
0426:                        wait = bundle.getString("wait");
0427:                    } else {
0428:                        wait = bundle.getString("targets");
0429:                    }
0430:                    content.append(wait);
0431:                }
0432:                content.append("</font>\n");
0433:
0434:                // no static rules, >0 dynamic, mac MSIE gets started now
0435:                // because it ignores NO_CONTENT response and reloads, so
0436:                // mac netlet always loads if any (static/dynamic) rules exist
0437:
0438:                if (startNetlet) {
0439:                    int response = 0;
0440:                    try {
0441:                        response = callNetletConfig("isLoaded", req);
0442:                        if (response == HttpServletResponse.SC_NO_CONTENT) {
0443:                            callNetletConfig("setLoading", req);
0444:                            if (jwsMode) {
0445:                                content.append(
0446:                                        "<script language=\"JavaScript\">\n")
0447:                                        .append("launchJWS(\"").append(
0448:                                                ncJNLPStartURL).append(
0449:                                                "\", null );\n").append(
0450:                                                "</script>\n");
0451:                            } else {
0452:                                content.append(
0453:                                        "<script language=\"JavaScript\">\n")
0454:                                        .append("netletWinOpen(\"").append(
0455:                                                ncStartURL).append(
0456:                                                "\", true );\n").append(
0457:                                                "</script>\n");
0458:                            }
0459:                        }
0460:                    } catch (IOException mue) {
0461:                        debugLogger.log(Level.INFO, "PSSR_CSPPN0004", mue);
0462:                        throw new ProviderException(
0463:                                "invalid netlet config url", mue);
0464:                    } catch (ContextException ce) {
0465:                        debugLogger.log(Level.INFO, "PSSR_CSPPN0004", ce);
0466:                        throw new ProviderException(
0467:                                "error calling netlet config", ce);
0468:                    } catch (SSOException ssoe) {
0469:                        debugLogger.log(Level.INFO, "PSSR_CSPPN0004", ssoe);
0470:                        throw new ProviderException(
0471:                                "error calling netlet config", ssoe);
0472:                    }
0473:                }
0474:                content.append("<br><hr></td></tr>\n");
0475:
0476:                if (hasTargets) {
0477:                    for (int x = 0; x < targets.size(); x++) {
0478:                        String targ = (String) targets.get(x);
0479:                        Target target = new Target(targ);
0480:
0481:                        String trimmedValue = trimHostNamesList(target
0482:                                .getValue());
0483:
0484:                        StringBuffer url = new StringBuffer().append(ncURI)
0485:                                .append("?func=").append(
0486:                                        UrlEncoder.encode(target.getName()))
0487:                                .append("&machine=").append(trimmedValue);
0488:
0489:                        // For JNLP
0490:                        targetsToSet.append(target.getName()).append("=")
0491:                                .append(trimmedValue).append("|");
0492:
0493:                        StringTokenizer st = new StringTokenizer(target
0494:                                .getValue(), "+");
0495:                        String displayName = "";
0496:
0497:                        if (st.countTokens() == 1) {
0498:                            displayName = target.getValue().trim();
0499:                        } else {// Has multiple host-names
0500:                            try {
0501:                                displayName = "[ " + st.nextToken().trim();
0502:                                while (st.hasMoreElements()) {
0503:                                    displayName += ", ";
0504:                                    displayName += (String) st.nextToken()
0505:                                            .trim();
0506:                                }
0507:                                displayName += " ]";
0508:                            } catch (NoSuchElementException nse) {
0509:                                debugLogger.log(Level.INFO, "PSSR_CSPPN0005",
0510:                                        nse);
0511:                            }
0512:                        }
0513:
0514:                        StringBuffer href = new StringBuffer()
0515:                                .append("<a href=\"#");
0516:                        if (jwsMode) {
0517:                            href.append("\" onClick=\"launchJWS(");
0518:                            if (startNetlet) {
0519:                                // if netlet already started (static/auto launch mode), no need to invoke start url.
0520:                                // TODO : issue - when jws window is closed desktop need to be refreshed, so that links can be updated.
0521:                                href.append("null, '");
0522:                            } else {
0523:                                href.append("'" + ncJNLPStartURL + "', '");
0524:                            }
0525:                        } else {
0526:                            href.append("\" onClick=\"netletConfigOpen('")
0527:                                    .append(ncStartURL + "', '");
0528:                        }
0529:                        href
0530:                                .append(url.toString())
0531:                                .append("'); return false;\">")
0532:                                .append(target.getName())
0533:                                .append(
0534:                                        " "
0535:                                                + bundle
0536:                                                        .getString("NameHostSeparator")
0537:                                                + " ").append(displayName)
0538:                                .append("</a>\n");
0539:
0540:                        StringBuffer row = new StringBuffer()
0541:                                .append(
0542:                                        "<tr><td><font FACE=\"[tag:iwtDesktop-fontFace1]\" ")
0543:                                .append("size=\"-1\">").append(href.toString())
0544:                                .append("</font></td></tr>\n");
0545:
0546:                        content.append(row.toString());
0547:                    }
0548:                }
0549:                content.append("</table>\n");
0550:
0551:                Hashtable tagTable = new Hashtable();
0552:                tagTable.put("content", content.toString());
0553:                tagTable.put("iwtDesktop-fontFace1",
0554:                        getStringProperty("fontFace1"));
0555:
0556:                content = getTemplate("display.template", tagTable);
0557:                return content;
0558:            }
0559:
0560:            /*
0561:             * Method to get the contents of Netlet Edit Provider.
0562:             * Invoked by DesktopServlet.
0563:             */
0564:            public StringBuffer getEdit(HttpServletRequest req,
0565:                    HttpServletResponse res) throws ProviderException {
0566:                StringBuffer content = new StringBuffer();
0567:                StringBuffer targetList = new StringBuffer("");
0568:                editContainer = req.getParameter("provider");
0569:                container = req.getParameter("containerName");
0570:                List targets = null;
0571:                UserAttributes attrs = getNetletUserAttributes(req);
0572:                List netletRules = attrs
0573:                        .getStringList(NetletConstants.NETLET_RULES);
0574:                try {
0575:                    Map l = getProviderContext().getCollectionProperty(
0576:                            getName(), "targets");
0577:                    if (l != null || !l.isEmpty())
0578:                        targets = new ArrayList(l.values());
0579:                } catch (ProviderContextException pce) {
0580:                    debugLogger.log(Level.INFO, "PSSR_CSPPN0006", pce);
0581:                    targets = null;
0582:                }
0583:                targets = updateTargets(targets, netletRules);
0584:                boolean hasTargets = (targets == null || targets.isEmpty()) ? false
0585:                        : true;
0586:
0587:                int count = 0;
0588:                /*
0589:                for (Enumeration e = targets.elements(); e.hasMoreElements(); ) {
0590:                 */
0591:                if (hasTargets) {
0592:                    for (int x = 0; x < targets.size(); x++) {
0593:                        String targ = (String) targets.get(x);
0594:                        Target target = new Target(targ);
0595:                        targetList
0596:                                .append(
0597:                                        "<TR><TD><CENTER><INPUT TYPE=\"CHECKBOX\" ")
0598:                                .append("VALUE=\"1\" NAME=\"remove")
0599:                                .append(count)
0600:                                .append("\"></CENTER></TD>\n")
0601:                                .append(
0602:                                        "<TD><FONT FACE=\"[tag:iwtDesktop-fontFace1]\" ")
0603:                                .append("SIZE=\"+0\">\n").append(
0604:                                        genRuleSelect("rule" + count, target
0605:                                                .getName(), req)).append(
0606:                                        "\n</FONT></TD>\n").append(
0607:                                        "<TD><FONT FACE=").append(
0608:                                        "\"[tag:iwtDesktop-fontFace1]\" ")
0609:                                .append("SIZE=\"+0\"><INPUT TYPE=\"TEXT\" ")
0610:                                .append("RPROXY-NOPARSE VALUE=\"").append(
0611:                                        trimHostNamesList(target.getValue()))
0612:                                .append("\" SIZE=\"30\" NAME=\"host").append(
0613:                                        count).append("\"></FONT></TD></TR>\n");
0614:
0615:                        count++;
0616:                    }
0617:                }
0618:
0619:                String invalidHost = bundle == null ? null : bundle
0620:                        .getString("invalidHost");
0621:                // If localized string is unavailable, display in English.
0622:                if (invalidHost == null || invalidHost.trim().length() == 0)
0623:                    invalidHost = new String(
0624:                            "You must enter a valid host name(s).");
0625:
0626:                Hashtable tagTable = new Hashtable();
0627:
0628:                String targetCount = Integer.toString(count);
0629:                tagTable.put("targetCount", targetCount);
0630:                tagTable.put("targetList", targetList.toString());
0631:                tagTable.put("invalidHostName", invalidHost);
0632:                tagTable.put("iwtDesktop-fontFac/e1",
0633:                        getStringProperty("fontFace1"));
0634:
0635:                if ((statusMsg != null) && (statusMsg.trim().length() != 0)) {
0636:                    tagTable.put("errorMsg", statusMsg);
0637:                    statusMsg = null;
0638:
0639:                    tagTable.put("newHostString", newHostString);
0640:                    tagTable.put("newRuleSelect", genRuleSelect("newRule",
0641:                            ruleName, req));
0642:                    tagTable.put("clientBindIP", clientBindIPAddress);
0643:                    tagTable.put("launchModeSelect", genLaunchModeSelect(
0644:                            "launchMode", netletLaunchMode, req));
0645:                    tagTable.put("newAlgorithmSelect", genAlgorithmSelect(req));
0646:                    tagTable.put("browserProxyType", genBrowserProxyType(
0647:                            "browserProxyType", browserProxyType, req));
0648:                    tagTable.put("browserProxyHost", browserProxyHost);
0649:                    tagTable.put("browserProxyPort", browserProxyPort);
0650:                    tagTable.put("browserProxyOverriseList",
0651:                            browserProxyOverrideList);
0652:                } else {
0653:                    tagTable.put("newHostString", "");
0654:                    tagTable.put("newRuleSelect", genRuleSelect("newRule",
0655:                            null, req));
0656:                    tagTable.put("launchModeSelect", genLaunchModeSelect(
0657:                            "launchMode", null, req));
0658:                    tagTable.put("newAlgorithmSelect", genAlgorithmSelect(req));
0659:                    tagTable.put("clientBindIP", attrs.getString(
0660:                            NetletConstants.NETLET_CLIENT_BIND_IP,
0661:                            NetletConstants.NETLET_DEFAULT_CLIENT_BIND_IP));
0662:                    tagTable.put("browserProxyType", genBrowserProxyType(
0663:                            "browserProxyType", null, req));
0664:                    tagTable.put("browserProxyHost", attrs.getString(
0665:                            NetletConstants.NETLET_PROXY_HOST, ""));
0666:                    tagTable.put("browserProxyPort", attrs.getString(
0667:                            NetletConstants.NETLET_PROXY_PORT, ""));
0668:                    tagTable.put("browserProxyOverriseList", attrs.getString(
0669:                            NetletConstants.NETLET_PROXY_OVERRIDE, ""));
0670:                }
0671:
0672:                if (isReauthEnabled(req)) {
0673:                    Hashtable changePasswordTagTable = new Hashtable();
0674:                    if ((statusMsg != null) && (statusMsg.trim().length() != 0)) {
0675:                        changePasswordTagTable
0676:                                .put("changePasswdMsg", statusMsg);
0677:                        statusMsg = null;
0678:                    }
0679:
0680:                    changePasswordTagTable.put("changeNetletPasswordLabel",
0681:                            bundle.getString("changeNetletPasswordLabel"));
0682:                    changePasswordTagTable.put("oldPasswordLabel", bundle
0683:                            .getString("oldPasswordLabel"));
0684:                    changePasswordTagTable.put("newPasswordLabel", bundle
0685:                            .getString("newPasswordLabel"));
0686:                    changePasswordTagTable.put("confirmPasswordLabel", bundle
0687:                            .getString("confirmPasswordLabel"));
0688:
0689:                    StringBuffer changePasswordTemplate = getTemplate(
0690:                            "changepassword.template", changePasswordTagTable);
0691:                    tagTable.put("changePasswordTemplate",
0692:                            changePasswordTemplate);
0693:                }
0694:
0695:                tagTable.put("addNewTargetLabel", bundle
0696:                        .getString("addNewTargetLabel"));
0697:                tagTable
0698:                        .put("ruleNameLabel", bundle.getString("ruleNameLabel"));
0699:                tagTable.put("hostsLabel", bundle.getString("hostsLabel"));
0700:                tagTable.put("multipleEntries", bundle
0701:                        .getString("multipleEntries"));
0702:                tagTable.put("editExistingTargetLabel", bundle
0703:                        .getString("editExistingTargetLabel"));
0704:                tagTable.put("removeLabel", bundle.getString("removeLabel"));
0705:                tagTable.put("ruleLabel", bundle.getString("ruleLabel"));
0706:                tagTable.put("hostLabel", bundle.getString("hostLabel"));
0707:                tagTable.put("changeAlgorithmLabel", bundle
0708:                        .getString("changeAlgorithmLabel"));
0709:                tagTable.put("changeIPAddressLabel", bundle
0710:                        .getString("changeIPAddressLabel"));
0711:                tagTable.put("clientIPAddressLabel", bundle
0712:                        .getString("clientIPAddressLabel"));
0713:                tagTable.put("changeNetletLaunchModeLabel", bundle
0714:                        .getString("changeNetletLaunchModeLabel"));
0715:                tagTable.put("netletLaunchModeLabel", bundle
0716:                        .getString("netletLaunchModeLabel"));
0717:                tagTable.put("switchModeMessage", bundle
0718:                        .getString("switchModeMessage"));
0719:                tagTable.put("changeProxySettingsLabel", bundle
0720:                        .getString("changeProxySettingsLabel"));
0721:                tagTable.put("browserProxyTypeLabel", bundle
0722:                        .getString("browserProxyTypeLabel"));
0723:                tagTable.put("browserProxyHostLabel", bundle
0724:                        .getString("browserProxyHostLabel"));
0725:                tagTable.put("browserProxyPortLabel", bundle
0726:                        .getString("browserProxyPortLabel"));
0727:                tagTable.put("browserProxyOverrideListLabel", bundle
0728:                        .getString("browserProxyOverrideListLabel"));
0729:
0730:                content = getTemplate("edit.template", tagTable);
0731:                return content;
0732:            }
0733:
0734:            public Vector getExistingTargets(ParameterMap params,
0735:                    boolean ignoreRemove) {
0736:                int targetCount = params.getInt("targetCount");
0737:                Vector targets = new Vector();
0738:                boolean removeFlag = false;
0739:                for (int i = 0; i < targetCount; i++) {
0740:                    if (!ignoreRemove) {
0741:                        String checkBoxValue = params.getString("remove" + i);
0742:                        removeFlag = checkBoxValue == null ? false
0743:                                : checkBoxValue.trim().equals("1") ? true
0744:                                        : false;
0745:                    }
0746:                    if (!removeFlag) {
0747:                        String ruleString = "rule" + i;
0748:                        String hostString = "host" + i;
0749:                        String rule = params.getString(ruleString);
0750:                        String host = params.getString(hostString);
0751:                        if (!I18n.isAscii(host)) {
0752:                            debugLogger.info("PSSR_CSPPN0007");
0753:                        } else if (host == null || host.trim().equals("")) {
0754:                            debugLogger.info("PSSR_CSPPN0008");
0755:                        } else {
0756:                            Target target = new Target(rule, host);
0757:                            targets.add(target.toString());
0758:                        }
0759:                    }
0760:                }
0761:                return targets;
0762:            }
0763:
0764:            /*
0765:             * Creates a new SSOToken ans returns the same.
0766:             */
0767:            private SSOToken getSSOToken(HttpServletRequest req) {
0768:                SSOToken ssoToken = null;
0769:                try {
0770:                    ssoToken = SSOTokenManager.getInstance()
0771:                            .createSSOToken(req);
0772:                    ssoToken = SSOTokenManager.getInstance()
0773:                            .createSSOToken(req);
0774:                } catch (SSOException ssoe) {
0775:                    debugLogger.log(Level.INFO, "PSSR_CSPPN0009", ssoe);
0776:                }
0777:                return ssoToken;
0778:            }
0779:
0780:            /*
0781:             * Returns the Netlet User Attributes.
0782:             */
0783:            private UserAttributes getNetletUserAttributes(
0784:                    HttpServletRequest req) {
0785:                SSOToken ssoToken = getSSOToken(req);
0786:                UserAttributes netletuserAttrs = new UserAttributes(ssoToken);
0787:                try {
0788:                    if (ssoToken != null)
0789:                        netletStatus = ssoToken.getProperty("ClientStatus");
0790:                } catch (SSOException e) {
0791:                    debugLogger.log(Level.INFO, "PSSR_CSPPN0004", e);
0792:                }
0793:                return netletuserAttrs;
0794:            }
0795:
0796:            /*
0797:             * Returns the page parameter map
0798:             */
0799:            private ParameterMap getParameterMap(HttpServletRequest req) {
0800:                ParameterMap map = null;
0801:                try {
0802:                    map = new ParameterMap(getProviderContext().getCharset(),
0803:                            req, true);
0804:                    for (Enumeration e = req.getParameterNames(); e
0805:                            .hasMoreElements();) {
0806:                        String name = (String) e.nextElement();
0807:                        String[] val = req.getParameterValues(name);
0808:                        map.put(name, val);
0809:                    }
0810:                } catch (DesktopException de) {
0811:                    debugLogger.log(Level.INFO, "PSSR_CSPPN0010", de);
0812:                }
0813:                return map;
0814:            }
0815:
0816:            /*
0817:             * Return the Netlet Provider URL
0818:             */
0819:            private URL getNetletProviderURL(HttpServletRequest req) {
0820:                URL netletProviderURL = null;
0821:                try {
0822:                    netletProviderURL = new URL(getProviderContext()
0823:                            .getDesktopURL(req)
0824:                            + "?action=edit&provider="
0825:                            + URLEncoder.encode(editContainer)
0826:                            + "&targetprovider="
0827:                            + URLEncoder.encode(getName())
0828:                            + "&containerName=" + URLEncoder.encode(container));
0829:                } catch (java.net.MalformedURLException e) {
0830:                }
0831:                return netletProviderURL;
0832:            }
0833:
0834:            /*
0835:             * Processes the Values of the Netlet Edit Provider and stores the values to the backend.
0836:             */
0837:            public URL processEdit(HttpServletRequest req,
0838:                    HttpServletResponse res) throws ProviderException {
0839:                ParameterMap params = getParameterMap(req);
0840:                if (params == null)
0841:                    return null;
0842:
0843:                setProcessParameters(params);
0844:
0845:                editContainer = req.getParameter("provider");
0846:                container = req.getParameter("containerName");
0847:                UserAttributes netletuserAttrs = getNetletUserAttributes(req);
0848:                Vector targets = null;
0849:                String addMore = params.getString("add_more");
0850:                String changePassword = params.getString("change_password");
0851:
0852:                validateParams(req);
0853:                if (statusMsg != null)
0854:                    return getNetletProviderURL(req);
0855:
0856:                if ((addMore != null) && (addMore.length() > 0)) {
0857:                    try {
0858:                        targets = new Vector(getProviderContext()
0859:                                .getCollectionProperty(getName(), "targets")
0860:                                .values());
0861:                    } catch (ProviderContextException pce) {
0862:                        debugLogger.log(Level.INFO, "PSSR_CSPPN0006", pce);
0863:                    }
0864:
0865:                    addTarget(params, targets);
0866:                    return getNetletProviderURL(req);
0867:                } else if ((changePassword != null)
0868:                        && (changePassword.trim().length() > 0)) {
0869:                    changePassword(params, netletuserAttrs);
0870:                    return getNetletProviderURL(req);
0871:                } else {
0872:                    targets = getExistingTargets(params, false);
0873:                    processFinished(params, targets, netletuserAttrs);
0874:                    super .processEdit(params);
0875:                }
0876:                return null;
0877:            }
0878:
0879:            private void setProcessParameters(ParameterMap params) {
0880:                ruleName = params.getString("newRule");
0881:                newHostString = params.getString("newHost");
0882:                clientBindIPAddress = params.getString("clientBindIP");
0883:                netletLaunchMode = params.getString("launchMode");
0884:                browserProxyType = params.getString("browserProxyType");
0885:                browserProxyHost = params.getString("browserProxyHost");
0886:                browserProxyPort = params.getString("browserProxyPort");
0887:                browserProxyOverrideList = params
0888:                        .getString("browserProxyOverriseList");
0889:            }
0890:
0891:            private void validateParams(HttpServletRequest req) {
0892:                ParameterMap params = getParameterMap(req);
0893:                UserAttributes netletuserAttrs = getNetletUserAttributes(req);
0894:                String addMore = params.getString("add_more");
0895:                String changePassword = params.getString("change_password");
0896:
0897:                if ((addMore != null) && (addMore.length() > 0)) {
0898:                    try {
0899:                        Vector targets = new Vector(getProviderContext()
0900:                                .getCollectionProperty(getName(), "targets")
0901:                                .values());
0902:                        if (targets != null && !targets.isEmpty()) {
0903:                            if (newHostString != null
0904:                                    && !newHostString.trim().equals("")) {
0905:                                if (!I18n.isAscii(newHostString)) {
0906:                                    debugLogger.info("PSSR_CSPPN0007");
0907:                                    statusMsg = bundle
0908:                                            .getString("nonAsciiHostname");
0909:                                    return;
0910:                                }
0911:                            }
0912:                        }
0913:                    } catch (ProviderContextException pce) {
0914:                        debugLogger.log(Level.INFO, "PSSR_CSPPN0006", pce);
0915:                    }
0916:                }
0917:
0918:                validateIP(clientBindIPAddress);
0919:
0920:                if (!I18n.isAscii(newHostString))
0921:                    statusMsg = bundle.getString("nonAsciiHostname");
0922:
0923:                validatePort(browserProxyPort);
0924:
0925:                if (!I18n.isAscii(browserProxyHost))
0926:                    statusMsg = bundle.getString("nonAsciiHostname");
0927:
0928:                if ((changePassword != null)
0929:                        && (changePassword.trim().length() > 0)) {
0930:                    String password = netletuserAttrs.getString(
0931:                            NetletConstants.NETLET_PASSWORD,
0932:                            NetletConstants.NETLET_DEFAULT_PASSWORD);
0933:                    String oldPassword = params.getString("oldPassword");
0934:                    String newPassword = params.getString("newPassword");
0935:                    String confirmNewPassword = params
0936:                            .getString("confirmNewPassword");
0937:                    if (!(password.equals(oldPassword)))
0938:                        statusMsg = bundle.getString("authError");
0939:                    else {
0940:                        if ((newPassword == null)
0941:                                || (newPassword.length() == 0))
0942:                            statusMsg = bundle.getString("emptyPasswd");
0943:                        else if (!newPassword.equals(confirmNewPassword))
0944:                            statusMsg = bundle.getString("checkFailed");
0945:                    }
0946:                }
0947:            }
0948:
0949:            /*
0950:             * Process the 'Finished' button request
0951:             */
0952:            private void processFinished(ParameterMap params, Vector targets,
0953:                    UserAttributes netletuserAttrs) {
0954:                addTarget(params, targets);
0955:
0956:                if (netletStatus == null
0957:                        || netletStatus.trim().equals("UNLOADED"))
0958:                    changeLaunchMode(params, netletuserAttrs);
0959:
0960:                changeAlgorithm(params, netletuserAttrs);
0961:                changeClientBindIP(params, netletuserAttrs);
0962:                changeAttribute(NetletConstants.NETLET_PROXY_TYPE,
0963:                        "browserProxyType", params, netletuserAttrs);
0964:                changeAttribute(NetletConstants.NETLET_PROXY_HOST,
0965:                        "browserProxyHost", params, netletuserAttrs);
0966:                changeAttribute(NetletConstants.NETLET_PROXY_PORT,
0967:                        "browserProxyPort", params, netletuserAttrs);
0968:                changeAttribute(NetletConstants.NETLET_PROXY_OVERRIDE,
0969:                        "browserProxyOverriseList", params, netletuserAttrs);
0970:            }
0971:
0972:            /*
0973:             * Get the newTarget, add it to the list of targets
0974:             * and store it to the user profile
0975:             */
0976:            private void addTarget(ParameterMap params, Vector targets) {
0977:                if (targets == null)
0978:                    targets = new Vector();
0979:
0980:                String newHost = params.getString("newHost");
0981:                if (newHost != null && !newHost.trim().equals("")) {
0982:                    String newRule = params.getString("newRule");
0983:                    Target target = new Target(newRule, newHost);
0984:                    targets.add(target.toString());
0985:                }
0986:                try {
0987:                    getProviderContext().setCollectionProperty(getName(),
0988:                            "targets", targets);
0989:                } catch (ProviderContextException pce) {
0990:                    debugLogger.log(Level.INFO, "PSSR_CSPPN0011", pce);
0991:                }
0992:            }
0993:
0994:            /*
0995:             * Get the old and new password, validate.
0996:             * Store it to the profile if verification succeeds.
0997:             */
0998:            private void changePassword(ParameterMap params,
0999:                    UserAttributes netletuserAttrs) {
1000:                String newPassword = params.getString("newPassword");
1001:                netletuserAttrs.setString(NetletConstants.NETLET_PASSWORD,
1002:                        newPassword);
1003:            }
1004:
1005:            /*
1006:             * Read the ciphers selected by the user, and store it to the profile.
1007:             */
1008:            private void changeAlgorithm(ParameterMap params,
1009:                    UserAttributes netletuserAttrs) {
1010:                List netletRules = netletuserAttrs
1011:                        .getStringList(NetletConstants.NETLET_RULES);
1012:                ArrayList userCiphers = new ArrayList();
1013:                for (int x = 0; x < netletRules.size(); x++) {
1014:                    String nr = (String) netletRules.get(x);
1015:                    if (nr.endsWith(NetletConstants.NETLET_EXTEND_SESSION))
1016:                        nr = nr.substring(0, nr.lastIndexOf("|"));
1017:                    StringTokenizer tok = new StringTokenizer(nr, "|");
1018:                    boolean isTarget = false;
1019:
1020:                    try {
1021:                        String func = (String) tok.nextElement();
1022:                        tok = new StringTokenizer(func, "^");
1023:
1024:                        String rulename = (String) tok.nextElement();
1025:
1026:                        StringBuffer sbuffer = new StringBuffer();
1027:                        sbuffer.append(rulename);
1028:
1029:                        String[] algos = params.getArray(rulename);
1030:                        if (algos != null) {
1031:                            boolean algoAppended = false;
1032:                            for (int i = 0; i < algos.length; i++) {
1033:                                if (algos[i].trim().length() != 0) {
1034:                                    sbuffer.append("|" + algos[i]);
1035:                                    algoAppended = true;
1036:                                }
1037:                            }
1038:                            if (algoAppended) {
1039:                                userCiphers.add(sbuffer.toString());
1040:                            }
1041:                        }
1042:                    } catch (NoSuchElementException nsee) {
1043:                        debugLogger.log(Level.INFO, "PSSR_CSPPN0004", nsee);
1044:                        continue;
1045:                    }
1046:                }
1047:                netletuserAttrs.setStringList(
1048:                        NetletConstants.NETLET_USER_CIPHER, (List) userCiphers);
1049:            }
1050:
1051:            /*
1052:             * Read the client bind IP selected by the user, and store it to the profile.
1053:             */
1054:            private void changeClientBindIP(ParameterMap params,
1055:                    UserAttributes netletuserAttrs) {
1056:                String clientBindIP = netletuserAttrs.getString(
1057:                        NetletConstants.NETLET_CLIENT_BIND_IP,
1058:                        NetletConstants.NETLET_DEFAULT_CLIENT_BIND_IP);
1059:                String newClientBindIP = params.getString("clientBindIP");
1060:                if (clientBindIP != null
1061:                        && !clientBindIP.equals(newClientBindIP))
1062:                    netletuserAttrs.setString(
1063:                            NetletConstants.NETLET_CLIENT_BIND_IP,
1064:                            newClientBindIP);
1065:            }
1066:
1067:            private void validatePort(String port) {
1068:                try {
1069:                    if (port != null && port.trim().length() > 0) {
1070:                        int portInt = Integer.parseInt(port);
1071:                        if ((portInt < 1025) || (portInt > 65535))
1072:                            statusMsg = bundle.getString("portOutOfRange");
1073:                    }
1074:                } catch (NumberFormatException nfe) {
1075:                    statusMsg = bundle.getString("invalidPort");
1076:                }
1077:            }
1078:
1079:            private void validateIP(String ip) {
1080:                if (ip != null && ip.trim().length() > 0) {
1081:                    try {
1082:                        StringTokenizer st = new StringTokenizer(ip, ".");
1083:                        if (st.countTokens() < 4) {
1084:                            statusMsg = bundle.getString("invalidIP");
1085:                            return;
1086:                        }
1087:                        while (st.hasMoreTokens()) {
1088:                            String token = st.nextToken();
1089:                            if (token == null && token.trim().length() == 0) {
1090:                                statusMsg = bundle.getString("invalidIP");
1091:                                return;
1092:                            }
1093:
1094:                            int addressValue = Integer.parseInt(token);
1095:                            if (addressValue < 0 || addressValue > 255) {
1096:                                statusMsg = bundle.getString("invalidIP");
1097:                                return;
1098:                            }
1099:                        }
1100:                    } catch (NumberFormatException nfe) {
1101:                        statusMsg = bundle.getString("invalidIP");
1102:                    }
1103:                }
1104:            }
1105:
1106:            private void changeLaunchMode(ParameterMap params,
1107:                    UserAttributes netletuserAttrs) {
1108:                String launchMode = netletuserAttrs
1109:                        .getString(NetletConstants.NETLET_LAUNCH_MODE);
1110:                String newLaunchMode = params.getString("launchMode");
1111:                if (launchMode != null && !launchMode.equals(newLaunchMode)) {
1112:                    netletuserAttrs.setString(
1113:                            NetletConstants.NETLET_LAUNCH_MODE, newLaunchMode);
1114:                }
1115:            }
1116:
1117:            private String genLaunchModeSelect(String name,
1118:                    String selectedOption, HttpServletRequest httpreq) {
1119:                StringBuffer ruleSelect = new StringBuffer();
1120:                ruleSelect.append("<select name=\"").append(name).append(
1121:                        "\">\n");
1122:
1123:                UserAttributes attrs = getNetletUserAttributes(httpreq);
1124:                String launchModeStr = attrs
1125:                        .getString(NetletConstants.NETLET_LAUNCH_MODE);
1126:                if (selectedOption == null || selectedOption.length() == 0)
1127:                    selectedOption = launchModeStr;
1128:
1129:                ruleSelect.append("<option selected>").append(selectedOption)
1130:                        .append("</option>\n");
1131:                if (launchModeStr != null
1132:                        && launchModeStr.equalsIgnoreCase("Applet")) {
1133:                    ruleSelect.append("<option>").append("Java Web Start")
1134:                            .append("</option>\n");
1135:                } else {
1136:                    ruleSelect.append("<option>").append("Applet").append(
1137:                            "</option>\n");
1138:                }
1139:
1140:                ruleSelect.append("</select>\n");
1141:                return ruleSelect.toString();
1142:            }
1143:
1144:            /*
1145:             * Generates the contents of "Rule" list box
1146:             * of "Edit an Existing target" block and selects one.
1147:             */
1148:            private String genRuleSelect(String name, String selected,
1149:                    HttpServletRequest httpreq) {
1150:                StringBuffer ruleSelect = new StringBuffer(512);
1151:                ruleSelect.append("<select name=\"").append(name).append(
1152:                        "\">\n");
1153:
1154:                UserAttributes attrs = getNetletUserAttributes(httpreq);
1155:                List netletRules = attrs
1156:                        .getStringList(NetletConstants.NETLET_RULES);
1157:
1158:                for (int x = 0; x < netletRules.size(); x++) {
1159:                    String nr = (String) netletRules.get(x);
1160:                    if (nr.endsWith(NetletConstants.NETLET_EXTEND_SESSION))
1161:                        nr = nr.substring(0, nr.lastIndexOf("|"));
1162:                    StringTokenizer tok = new StringTokenizer(nr, "|");
1163:                    boolean isTarget = false;
1164:                    try {
1165:                        String func = (String) tok.nextElement();
1166:                        String tmp = (String) tok.nextElement(); // url
1167:                        tmp = (String) tok.nextElement(); // loopback
1168:                        while (tok.hasMoreElements() && !isTarget) {
1169:                            tmp = (String) tok.nextElement(); // local port
1170:                            tmp = (String) tok.nextElement(); // dest host
1171:                            if (tmp.equals(NetletConstants.NETLET_TARGET_HOST))
1172:                                isTarget = true;
1173:                            tmp = (String) tok.nextElement(); // dest port
1174:                        }
1175:                        if (!isTarget)
1176:                            continue; // skip non-TARGET rules
1177:                        // Added to Netlet Algorithm enhancement for Lihue
1178:                        tok = new StringTokenizer(func, "^");
1179:                        func = (String) tok.nextElement();
1180:                        if (func.equals(selected)) {
1181:                            ruleSelect.append("<option selected>").append(func)
1182:                                    .append("</option>\n");
1183:                        } else {
1184:                            ruleSelect.append("<option>").append(func).append(
1185:                                    "</option>\n");
1186:                        }
1187:                    } catch (NoSuchElementException nsee) {
1188:                        continue; // skip non-parsable rules
1189:                    }
1190:                }
1191:                ruleSelect.append("</select>\n");
1192:                return ruleSelect.toString();
1193:            }
1194:
1195:            private String genBrowserProxyType(String name,
1196:                    String selectedOption, HttpServletRequest httpreq) {
1197:                StringBuffer tempSelect = new StringBuffer();
1198:                tempSelect.append("<select name=\"").append(name).append(
1199:                        "\">\n");
1200:
1201:                UserAttributes attrs = getNetletUserAttributes(httpreq);
1202:                String proxyType = attrs
1203:                        .getString(NetletConstants.NETLET_PROXY_TYPE);
1204:                if (selectedOption == null || selectedOption.length() == 0)
1205:                    selectedOption = proxyType;
1206:
1207:                if (proxyType == null || proxyType.trim().equalsIgnoreCase(""))
1208:                    proxyType = "DIRECT";
1209:
1210:                tempSelect.append("<option selected>").append(selectedOption)
1211:                        .append("</option>\n");
1212:                if (proxyType != null && proxyType.equalsIgnoreCase("MANUAL"))
1213:                    tempSelect.append("<option>").append("DIRECT").append(
1214:                            "</option>\n");
1215:                else
1216:                    tempSelect.append("<option>").append("MANUAL").append(
1217:                            "</option>\n");
1218:
1219:                tempSelect.append("</select>\n");
1220:                return tempSelect.toString();
1221:            }
1222:
1223:            /*
1224:             * Generates contents of "Change algorithm" list boxes
1225:             * and selects the appripriate algo for a rule.
1226:             */
1227:            private String genAlgorithmSelect(HttpServletRequest httpreq) {
1228:                StringBuffer algorithmSelect = new StringBuffer();
1229:                UserAttributes netletuserAttrs = getNetletUserAttributes(httpreq);
1230:                List netletRules = netletuserAttrs
1231:                        .getStringList(NetletConstants.NETLET_RULES);
1232:                List netletUserciphers = netletuserAttrs
1233:                        .getStringList(NetletConstants.NETLET_USER_CIPHER);
1234:
1235:                for (int x = 0; x < netletRules.size(); x++) {
1236:                    String nr = (String) netletRules.get(x);
1237:                    if (nr.endsWith(NetletConstants.NETLET_EXTEND_SESSION))
1238:                        nr = nr.substring(0, nr.lastIndexOf("|"));
1239:                    StringTokenizer tok = new StringTokenizer(nr, "|");
1240:
1241:                    boolean isTarget = false;
1242:
1243:                    try {
1244:                        String func = (String) tok.nextElement();
1245:                        tok = new StringTokenizer(func, "^");
1246:                        String rulename = (String) tok.nextElement();
1247:                        Vector selectAlgo = new Vector();
1248:                        if (!tok.hasMoreElements()) { // Use the default algorithm
1249:                            selectAlgo
1250:                                    .add(netletuserAttrs
1251:                                            .getString(
1252:                                                    NetletConstants.NETLET_KSSL_DEFAULT_CIPHER,
1253:                                                    NetletConstants.NETLET_KSSL_DEFAULT_CIPHER_VALUE));
1254:                            selectAlgo
1255:                                    .add(netletuserAttrs
1256:                                            .getString(
1257:                                                    NetletConstants.NETLET_JSSE_DEFAULT_CIPHER,
1258:                                                    NetletConstants.NETLET_JSSE_DEFAULT_CIPHER_VALUE));
1259:                        } else {
1260:                            selectAlgo.add((String) tok.nextElement());
1261:                        }
1262:
1263:                        algorithmSelect.append("<tr>");
1264:                        algorithmSelect.append("<td align=right width=35%>");
1265:                        algorithmSelect
1266:                                .append("<font face=\"[tag:iwtDesktop-fontFace1]\" size=+0>");
1267:                        algorithmSelect.append("<b>");
1268:                        algorithmSelect.append(rulename);
1269:                        algorithmSelect.append(": </b></font></td>");
1270:                        algorithmSelect.append("<td>");
1271:                        algorithmSelect
1272:                                .append("<font face=\"[tag:iwtDesktop-fontFace1]\" size=+0>");
1273:                        algorithmSelect
1274:                                .append("<select multiple size=\"8\" name=\""
1275:                                        + rulename + "\">");
1276:
1277:                        if (tok.hasMoreElements()) {
1278:                            selectAlgo = new Vector();
1279:                            // Get the algorithm selected by the user for this rulename
1280:                            for (int i = 0; i < netletUserciphers.size(); i++) {
1281:                                String algoString = (String) netletUserciphers
1282:                                        .get(i);
1283:                                StringTokenizer tmp_st = new StringTokenizer(
1284:                                        algoString, "|");
1285:                                String tmp_rulename = tmp_st.nextToken();
1286:                                if (rulename.equals(tmp_rulename)) {
1287:                                    while (tmp_st.hasMoreTokens()) {
1288:                                        selectAlgo.add(tmp_st.nextToken());
1289:                                    }
1290:                                    break;
1291:                                }
1292:                            }
1293:                            tok = new StringTokenizer((String) tok
1294:                                    .nextElement(), "+");
1295:                            while (tok.hasMoreElements()) {
1296:                                String algo = (String) tok.nextElement();
1297:                                if (selectAlgo.contains(algo)) {
1298:                                    algorithmSelect
1299:                                            .append("<option selected value=\""
1300:                                                    + algo + "\">" + algo);
1301:                                } else {
1302:                                    algorithmSelect.append("<option value=\""
1303:                                            + algo + "\">" + algo);
1304:                                }
1305:                            }
1306:                        } else {
1307:                            for (Iterator iter = selectAlgo.iterator(); iter
1308:                                    .hasNext();) {
1309:                                String algo = (String) iter.next();
1310:                                algorithmSelect
1311:                                        .append("<option selected value=\""
1312:                                                + algo + "\">" + algo);
1313:                            }
1314:                        }
1315:                        algorithmSelect
1316:                                .append("<option value=\"\">__________________________________________________</option>");
1317:                        algorithmSelect.append("</select></font></td></tr>");
1318:                        algorithmSelect.append("<tr><td></td></tr>");
1319:                    } catch (NoSuchElementException nsee) {
1320:                        //algorithmSelect = new StringBuffer("");
1321:                        debugLogger.log(Level.INFO, "PSSR_CSPPN0004", nsee);
1322:                        continue;
1323:                    } catch (Exception ex) { // May be profile exception
1324:                        debugLogger.log(Level.INFO, "PSSR_CSPPN0004", ex);
1325:                        continue;
1326:                    }
1327:                }
1328:                return algorithmSelect.toString();
1329:            }
1330:
1331:            private void changeAttribute(String attrName, String attr,
1332:                    ParameterMap params, UserAttributes netletuserAttrs) {
1333:                String value = netletuserAttrs.getString(attrName);
1334:                String newValue = params.getString(attr);
1335:                if (value != null && !value.equals(newValue)) {
1336:                    netletuserAttrs.setString(attrName, newValue);
1337:                }
1338:            }
1339:
1340:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.