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


001:        package com.sun.portal.netlet.eproxy;
002:
003:        /*
004:         *  Groups all Netlet traffic associated with a user Session into
005:         *  a single manageable entity. Creates and starts a thread
006:         *  for Activating the session.
007:         *  @ see com.sun.portal.netlet.eproxyy.KeepSessionAlive
008:         *  @ see com.sun.portal.netlet.eproxyy.NetletGroupManager
009:         *
010:         *  @ created  31-08-2001
011:         *  @ Author  Rajesh T
012:         */
013:
014:        import java.util.*;
015:        import java.util.logging.Level;
016:        import java.util.logging.Logger;
017:
018:        import com.iplanet.sso.SSOException;
019:        import com.iplanet.sso.SSOToken;
020:        import com.iplanet.sso.SSOTokenEvent;
021:        import com.iplanet.sso.SSOTokenID;
022:        import com.iplanet.sso.SSOTokenListener;
023:        import com.iplanet.sso.SSOTokenManager;
024:        import com.sun.portal.log.common.PortalLogger;
025:        import com.sun.portal.netlet.econnection.ReaderWriter;
026:        import com.sun.portal.netlet.econnection.ReaderWriterLock;
027:        import com.sun.portal.netlet.monitoring.util.EProxyEvent;
028:        import com.sun.portal.rproxy.configservlet.client.NetletProfile;
029:        import com.sun.portal.rproxy.monitoring.MonitoringSubsystem;
030:
031:        public class NetletGroup implements  SSOTokenListener {
032:
033:            private List userNetlets = new ArrayList();
034:            private SSOToken ssoToken = null;
035:
036:            private NetletGroupManager manager;
037:
038:            private boolean netletRunUponLogout = false;
039:
040:            private NetletProfile netletUserattrs = null;
041:
042:            /*
043:             * Added for Netlet PRD 1.8.1 for Lihue
044:             */
045:            private Hashtable appletSrcPorts = null;
046:
047:            private Vector srcPorts = null;
048:
049:            private static final HashMap srcPortVsRuleName = new HashMap();
050:            /*
051:             * @ added by bshankar@sun.com for bug 4680712 - Netlet should not not
052:             * continue after Max session time.
053:             */
054:            private long userLoginTime; // in millisecs
055:
056:            private long maxSessionTime; // in millisecs
057:
058:            private static Logger logger = PortalLogger
059:                    .getLogger(NetletGroup.class);
060:
061:            public NetletGroup(NetletGroupManager ngm, SSOToken s)
062:                    throws SSOException {
063:                ssoToken = s;
064:                manager = ngm;
065:                appletSrcPorts = new Hashtable();
066:                srcPorts = new Vector();
067:                getNetletProfile();
068:                setSrcPorts();
069:                setNetletRunUponLogout();
070:                ssoToken.addSSOTokenListener(this );
071:                userLoginTime = System.currentTimeMillis()
072:                        - (ssoToken.getMaxSessionTime() * 60 - ssoToken
073:                                .getTimeLeft()) * 1000 + 10000;
074:                maxSessionTime = ssoToken.getMaxSessionTime() * 60000;
075:            }
076:
077:            public NetletGroup(NetletGroupManager ngm, SSOTokenID ssoTokenID)
078:                    throws SSOException {
079:                SSOTokenManager ssoTokenManager = SSOTokenManager.getInstance();
080:                ssoToken = ssoTokenManager
081:                        .createSSOToken(ssoTokenID.toString());
082:                manager = ngm;
083:                appletSrcPorts = new Hashtable();
084:                srcPorts = new Vector();
085:                getNetletProfile();
086:                setSrcPorts();
087:                setNetletRunUponLogout();
088:                ssoToken.addSSOTokenListener(this );
089:                userLoginTime = System.currentTimeMillis()
090:                        - (ssoToken.getMaxSessionTime() * 60 - ssoToken
091:                                .getTimeLeft()) * 1000 + 10000;
092:                maxSessionTime = ssoToken.getMaxSessionTime() * 60000;
093:            }
094:
095:            public NetletGroup(NetletGroupManager ngm, String tokenID)
096:                    throws SSOException {
097:                SSOTokenManager ssoTokenManager = SSOTokenManager.getInstance();
098:                ssoToken = ssoTokenManager.createSSOToken(tokenID);
099:                manager = ngm;
100:                appletSrcPorts = new Hashtable();
101:                srcPorts = new Vector();
102:                getNetletProfile();
103:                setSrcPorts();
104:                setNetletRunUponLogout();
105:                ssoToken.addSSOTokenListener(this );
106:                userLoginTime = System.currentTimeMillis()
107:                        - (ssoToken.getMaxSessionTime() * 60 - ssoToken
108:                                .getTimeLeft()) * 1000 + 10000;
109:                maxSessionTime = ssoToken.getMaxSessionTime() * 60000;
110:            }
111:
112:            /*
113:             * Added for Netlet PRD 1.8.1 for Lihue. @ retriives netlet user profile
114:             * using ssoToken and stores in a member variable.
115:             */
116:            public void getNetletProfile() {
117:                try {
118:                    netletUserattrs = new NetletProfile(ssoToken.getTokenID()
119:                            .toString());
120:                    // // logger.info("netletUserAttributes = " +
121:                    // netletUserattrs.toString());
122:                    Object[] params0 = { netletUserattrs.toString() };
123:                    logger.log(Level.INFO, "PSSRNTLT_CSPNEPROX000", params0);
124:                } catch (Exception e) {
125:                    // logger.log(Level.SEVERE, "NetletGroup: unable to retrieve netlet
126:                    // user attributes from service schema");
127:                    logger.log(Level.SEVERE, "PSSRNTLT_CSPNEPROX001");
128:                    netletUserattrs = null;
129:                }
130:            }
131:
132:            public void setNetletRunUponLogout() {
133:                if (netletUserattrs != null) {
134:                    try {
135:                        netletRunUponLogout = !(netletUserattrs.getBoolean(
136:                                "TerminateAtLogout", true));
137:                    } catch (Exception e) {
138:                        // logger.log(Level.SEVERE, "NetletGroup: Cannot read
139:                        // TerminateAtLogout attribute from srapNetletService schema");
140:                        logger.log(Level.SEVERE, "PSSRNTLT_CSPNEPROX002");
141:                        netletRunUponLogout = false;
142:                    }
143:                } else {
144:                    // logger.log(Level.SEVERE, "NetletGroup: Netlet user attributes
145:                    // unavailable");
146:                    logger.log(Level.SEVERE, "PSSRNTLT_CSPNEPROX003");
147:                    netletRunUponLogout = false;
148:                }
149:            }
150:
151:            public boolean getNetletRunUponLogout() {
152:                return netletRunUponLogout;
153:            }
154:
155:            /*
156:             * Added for Netlet PRD 1.8.1 for Lihue @ reads all the source ports from
157:             * the netlet rules and stores those source ports in the srcPorts list which
158:             * have EXTEND in their rule
159:             */
160:            private void setSrcPorts() {
161:                String tempRule;
162:                if (netletUserattrs != null) {
163:                    List rules = netletUserattrs.getStringList("Rules");
164:                    for (int x = 0; x < rules.size(); x++) {
165:                        String rule = (String) rules.get(x);
166:                        boolean isExtend = rule.endsWith("EXTEND");
167:                        if (isExtend) {
168:                            rule = rule.substring(0, rule.lastIndexOf("|"));
169:                            String es = "false";
170:                            StringTokenizer st = new StringTokenizer(rule, "|");
171:                            String tmp = st.nextToken(); // Rulename
172:                            tempRule = tmp;
173:                            tmp = st.nextToken(); // URL
174:                            tmp = st.nextToken(); // Download Applet
175:
176:                            while (st.hasMoreElements()) {
177:                                tmp = st.nextToken(); // SourcePort
178:                                int sp = Integer.parseInt(tmp);
179:                                srcPorts.add(new Integer(sp));
180:                                srcPortVsRuleName.put(tmp, tempRule);
181:                                tmp = st.nextToken(); // target host
182:                                tmp = st.nextToken(); // target port
183:                            }
184:                        }
185:                    }
186:                } else {
187:                    // logger.log(Level.SEVERE, "NetletGroup: Netlet user attributes
188:                    // unavailable");
189:                    logger.log(Level.SEVERE, "PSSRNTLT_CSPNEPROX004");
190:                }
191:            }
192:
193:            /*
194:             * Added for Nelet PRD 1.8.1 for Lihue Adds the SourcePort associated with
195:             * ReaderWriterLock to the Hashtable with ReaderWriterLock as key
196:             */
197:
198:            public void addAppletSrcPort(ReaderWriterLock r) {
199:                try {
200:                    appletSrcPorts.put(r, new Integer(r.getAppletSrcPort()));
201:                } catch (NullPointerException ne) {
202:                    // logger.log(Level.SEVERE, "NetletGroup: Unable to add source port
203:                    // to NetletGroup -> " + ne);
204:                    logger.log(Level.SEVERE, "PSSRNTLT_CSPNEPROX005", ne);
205:                }
206:            }
207:
208:            /*
209:             * Added for Nelet PRD 1.8.1 for Lihue Removes the SourcePort associated
210:             * with ReaderWriterLock from the Hashtable with ReaderWriterLock as key
211:             */
212:
213:            public void removeAppletSrcPort(ReaderWriterLock r) {
214:                appletSrcPorts.remove(r);
215:            }
216:
217:            /*
218:             * Adds a ReaderWriterGroup of the user represented by this classes user
219:             * Session @ see com.sun.portal.netlet.econnection.ReaderWriterLock
220:             */
221:
222:            public synchronized void add(ReaderWriterLock r) {
223:                userNetlets.add(r);
224:                MonitoringSubsystem.handleEvent(EProxyEvent.NETLET_ADDED,
225:                        new Object[] { r, this  });
226:                addAppletSrcPort(r);
227:            }
228:
229:            /*
230:             * Removes a ReaderWriterGroup associated with the session of the user @ see
231:             * com.sun.portal.netlet.econnection.ReaderWriterLock
232:             */
233:
234:            public synchronized void remove(ReaderWriter r) {
235:                userNetlets.remove(r);
236:                MonitoringSubsystem.handleEvent(EProxyEvent.NETLET_REMOVED,
237:                        this );
238:            }
239:
240:            /*
241:             * Added for Nelet PRD 1.8.1 for Lihue Removes the SourcePort associated
242:             * with ReaderWriterLock from the Hashtables with ReaderWriterLock as key
243:             */
244:            public synchronized void remove(ReaderWriterLock r) {
245:                removeAppletSrcPort(r);
246:                userNetlets.remove(r);
247:                MonitoringSubsystem.handleEvent(EProxyEvent.NETLET_REMOVED,
248:                        this );
249:            }
250:
251:            /*
252:             * Returns the user Session associated with this group @ see
253:             * com.iplanet.sso.SSOToken
254:             */
255:
256:            public SSOToken getSSOToken() {
257:                return ssoToken;
258:            }
259:
260:            /*
261:             * Returns the number of ReaderWriters associated with this group
262:             */
263:
264:            public int activeGroupCount() {
265:                return userNetlets.size();
266:            }
267:
268:            /*
269:             * Unregisters itself from the NetletGroupManager called when there is no
270:             * more netlet traffic associated with this user Session @ see
271:             * com.sun.portal.netlet.eproxy.NetletGroupManager
272:             */
273:
274:            public synchronized void clean() {
275:                ReaderWriterLock rwl = null;
276:                for (int i = 0; i < userNetlets.size(); i++) {
277:                    rwl = (ReaderWriterLock) userNetlets.get(i);
278:                    if (rwl != null) {
279:                        rwl.stopAll();
280:                    }
281:                }
282:            }
283:
284:            /*
285:             * Obtaines the latest of the netlet activity that the user has performed
286:             * over his group of Netlets @ see
287:             * com.sun.portal.netlet.econnection.ReaderWriterLock
288:             */
289:
290:            public long getLastActivityTime() {
291:                long lastActivityTime = 0;
292:                try {
293:                    Object rws[] = null;
294:                    lastActivityTime = System.currentTimeMillis()
295:                            - ((ssoToken.getMaxIdleTime() * 60000) + 10000);
296:                    long holdlastActivityTime = 0;
297:
298:                    synchronized (userNetlets) {
299:                        rws = new Object[userNetlets.size()];
300:                        rws = userNetlets.toArray();
301:                    }
302:
303:                    ReaderWriterLock rw;
304:
305:                    for (int i = 0; i < rws.length; i++) {
306:                        rw = (ReaderWriterLock) rws[i];
307:                        if (rw != null) {
308:                            try {
309:                                holdlastActivityTime = rw.getLastActivityTime();
310:                                /*
311:                                 * Check whether the connection is left idle for "MAX
312:                                 * IDLE TIME"
313:                                 */
314:                                if ((System.currentTimeMillis() - holdlastActivityTime) >= (ssoToken
315:                                        .getMaxIdleTime() * 60000)) {
316:                                    rw.stopAll();
317:                                    remove(rw);
318:                                    continue;
319:                                }
320:                            } catch (NullPointerException ne) {
321:                                remove(rw);
322:                                continue;
323:                            }
324:                            if (lastActivityTime < holdlastActivityTime) {
325:                                lastActivityTime = holdlastActivityTime;
326:                            }
327:                        }
328:                    }
329:                    return lastActivityTime;
330:                } catch (Throwable e) {
331:                    // logger.log(Level.SEVERE, "NetletGroup: Unable to get the Netlet
332:                    // Groups last user activity -> " + e);
333:                    logger.log(Level.SEVERE, "PSSRNTLT_CSPNEPROX006", e);
334:                }
335:
336:                try {
337:                    lastActivityTime = (System.currentTimeMillis() - ((ssoToken
338:                            .getMaxIdleTime() * 60000) + 1000));
339:                } catch (SSOException se) {
340:                    // logger.log(Level.SEVERE, "NetletGroup: Unable to get the Netlet
341:                    // Groups last user activity -> " + se);
342:                    logger.log(Level.SEVERE, "PSSRNTLT_CSPNEPROX007", se);
343:                }
344:                return lastActivityTime;
345:            }
346:
347:            /* Whenever the ssoToken changes this method is invoked */
348:            public void ssoTokenChanged(SSOTokenEvent evt) {
349:                // logger.info("NetletGroup: Gateway gets session notification");
350:                logger.info("PSSRNTLT_CSPNEPROX008");
351:                SSOToken token = null;
352:                try {
353:                    token = evt.getToken();
354:                    /*
355:                     * getType() throws SSOException if Event type is not one of these:
356:                     * SSO_TOKEN_IDLE_TIMEOUT, SSO_TOKEN_AMX_TIMEOUT, SSO_TOKEN_DESTROY
357:                     */
358:                    int evtType = evt.getType();
359:                } catch (SSOException ssoe) {
360:                    /*
361:                     * No need to close the netlet connection if the event is none of
362:                     * the above, so just return
363:                     */
364:                    // logger.log(Level.SEVERE, "NetletGroup: Unknown SSOToken event ->
365:                    // " + ssoe);
366:                    logger.log(Level.SEVERE, "PSSRNTLT_CSPNEPROX009", ssoe);
367:                    return;
368:                }
369:
370:                String tokenID = token.getTokenID().toString();
371:                String ssoTokenID = ssoToken.getTokenID().toString();
372:                if (ssoTokenID.equals(tokenID)) {
373:                    if (!getNetletRunUponLogout()) {
374:                        NetletGroupManager.unregister(ssoTokenID.toString());
375:                    }
376:                }
377:            }
378:
379:            /*
380:             * Returns true if any ReaderWriter of this group belongs to the Netlet rule
381:             * which has the "Extend session" set, false otherwise
382:             */
383:            public boolean needToExtend() {
384:                boolean needtoextend = false;
385:                Enumeration enumeration = appletSrcPorts.keys();
386:                Collection currentSrcPorts = appletSrcPorts.values();
387:                Iterator iter = currentSrcPorts.iterator();
388:                while (iter.hasNext()) {
389:                    Integer currentSrcPort = (Integer) iter.next();
390:                    if (currentSrcPort.intValue() == -1) {
391:                        currentSrcPort = new Integer(30021); // Special Case for FTP
392:                        // - Data channel
393:                    }
394:                    if (srcPorts.contains(currentSrcPort)) {
395:                        needtoextend = true;
396:                        break;
397:                    }
398:                }
399:                return needtoextend;
400:            }
401:
402:            /*
403:             * @ added by bshankar@sun.com for bug 4680712 - Netlet should not not
404:             * continue after Max session time. Returns the time (in millisecs) at which
405:             * the user has logged into the portal server.
406:             */
407:            public long getUserLoginTime() {
408:                return userLoginTime;
409:            }
410:
411:            /*
412:             * @ added by bshankar@sun.com for bug 4680712 - Netlet should not not
413:             * continue after Max session time. Returns the maximum session time (in
414:             * millisecs)
415:             */
416:            public long getMaxSessionTime() {
417:                return maxSessionTime;
418:            }
419:
420:            public static String getRulenameForPort(Integer port) {
421:                String rule = (String) srcPortVsRuleName.get(String
422:                        .valueOf(port.intValue()));
423:                return (rule == null ? "Unknown rule" : rule);
424:            }
425:
426:            public String getUserName() {
427:                try {
428:                    return ssoToken.getPrincipal().getName();
429:                } catch (SSOException e) {
430:                    return "UNKNOWN";
431:                }
432:            }
433:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.