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


001:        /** 
002:         * $Id: NetFileUserProfileHandler.java,v 1.29 2005/11/30 11:26:40 ss150821 Exp $ 
003:         * Copyright 2002 Sun Microsystems, Inc. All 
004:         * rights reserved. Use of this product is subject 
005:         * to license terms. Federal Acquisitions: 
006:         * Commercial Software -- Government Users 
007:         * Subject to Standard License Terms and 
008:         * Conditions. 
009:         * 
010:         * Sun, Sun Microsystems, the Sun logo, and Sun ONE 
011:         * are trademarks or registered trademarks of Sun Microsystems, 
012:         * Inc. in the United States and other countries. 
013:         */package com.sun.portal.netfile.servlet.java2;
014:
015:        /*
016:         * Handles the profile information of the NetFile user.
017:         * Obtains the profile information from the repository using the 
018:         * the NetFileContext. Likewise, saves the information to the
019:         * repository on the user requesting for information to be saved.
020:         *
021:         * Also has helper methods that fetch/create temporary directory.
022:         * Temporary directory is needed for operations with Win hosts
023:         * and for file upload.
024:         *
025:         * @author Suresh Yellamaraju
026:         */
027:
028:        import com.sun.portal.netfile.shared.*;
029:        import com.sun.portal.log.common.PortalLogger;
030:
031:        import com.iplanet.sso.SSOToken;
032:
033:        import com.sun.identity.security.DecryptAction;
034:        import com.sun.identity.security.EncryptAction;
035:
036:        import java.security.AccessController;
037:        import java.util.*;
038:        import java.util.logging.*;
039:        import java.io.File;
040:
041:        class NetFileUserProfileHandler {
042:
043:            private static Logger logger = PortalLogger
044:                    .getLogger(NetFileUserProfileHandler.class);
045:
046:            private SSOToken ssoToken = null;
047:            private NetFileContext nfContext = null;
048:            private NetFileResource nfRes = null;
049:            private NetFileAttributeExtractor nfAttrs = null;
050:
051:            private String[] pathInfo = null;
052:
053:            /*
054:             * Initializes the NetFile user profile handler  
055:             * @param SSOToken the SSOToken of the logged in user
056:             * @param NetFileContext the context of NetFile 
057:             * @param NetFileResource the resource object for access to NetFile properties
058:             */
059:            public NetFileUserProfileHandler(SSOToken token,
060:                    NetFileContext context, NetFileResource res) {
061:
062:                ssoToken = token;
063:                nfContext = context;
064:                nfRes = res;
065:
066:            }
067:
068:            /* 
069:             * Retrieves the user's saved session preferences. Called on the session start up,
070:             * immediately after the applet has downloaded.
071:             *
072:             * @return Hashtable containing user's saved session attributes and 
073:             * NetFile attributes as name-value pairs
074:             *
075:             * @exception NetFileException if a severe exception that prevents retrieving NetFile attributes. 
076:             * If an exception occurs for some of the attributes, then default values are returned.
077:             */
078:            public Hashtable getSessionPreferences() throws NetFileException {
079:
080:                return getNetFileUserAttributes();
081:            }
082:
083:            /*
084:             * Saves the user session's preferences.
085:             *
086:             * @param java.util.List containing the request data, including list of machines, 
087:             * shares, ids, passwords and machine encodings sent from the applet. 
088:             */
089:            public void saveSessionData(java.util.List nfReqData)
090:                    throws NetFileException {
091:
092:                try {
093:                    Hashtable data = (Hashtable) nfReqData.get(4);
094:                    String winsize = (String) data
095:                            .get(NetFileContext.SRAP_NF_WINSIZE);
096:                    String winloc = (String) data
097:                            .get(NetFileContext.SRAP_NF_WINLOC);
098:                    Vector nfVecData = (Vector) data
099:                            .get(NetFileContext.SRAP_NF_USERHOST);
100:
101:                    HashSet hsHostData = new HashSet();
102:
103:                    if (!nfVecData.isEmpty()) {
104:                        Iterator hosts = nfVecData.iterator();
105:                        while (hosts.hasNext())
106:                            hsHostData.add((String) AccessController
107:                                    .doPrivileged(new EncryptAction(
108:                                            (String) hosts.next())));
109:                    }
110:
111:                    HashSet hsWinSize = new HashSet();
112:                    hsWinSize.add(winsize);
113:
114:                    HashSet hsWinLoc = new HashSet();
115:                    hsWinLoc.add(winloc);
116:
117:                    Map prefs = new HashMap();
118:                    prefs.put(NetFileContext.SRAP_NF_USERHOST, hsHostData);
119:                    try {
120:                        nfContext.savePreferences(prefs);
121:                    } catch (Exception ex) {
122:                        //                logger.log(Level.SEVERE, "Exception in saving user host data", ex);
123:                        logger.log(Level.SEVERE, "PSSRNF_CSPNSJ2104");
124:                    }
125:
126:                    prefs.remove(NetFileContext.SRAP_NF_USERHOST);
127:                    prefs.put(NetFileContext.SRAP_NF_WINSIZE, hsWinSize);
128:                    try {
129:                        nfContext.savePreferences(prefs);
130:                    } catch (Exception ex) {
131:                        //                logger.log(Level.SEVERE, "Exception in saving win size", ex);
132:                        logger.log(Level.SEVERE, "PSSRNF_CSPNSJ2105");
133:                    }
134:
135:                    prefs.remove(NetFileContext.SRAP_NF_WINSIZE);
136:                    prefs.put(NetFileContext.SRAP_NF_WINLOC, hsWinLoc);
137:                    try {
138:                        nfContext.savePreferences(prefs);
139:                    } catch (Exception ex) {
140:                        //                logger.log(Level.SEVERE, "Exception in saving win location", ex);
141:                        logger.log(Level.SEVERE, "PSSRNF_CSPNSJ2106");
142:                    }
143:
144:                    nfContext.savePreferences(prefs);
145:                } catch (Exception e) {
146:                    throw new NetFileException(NetFileException.NF_FATAL_ERROR,
147:                            "Exception in saving the session information");
148:                    //TBD: Get the String from Resource Bundle.
149:                }
150:                return;
151:            }
152:
153:            /*
154:             * Retrieves the NetFile user's attributes. Also retrieves the global, 
155:             * organization and other dynamic attributes of the user
156:             */
157:            private Hashtable getNetFileUserAttributes() {
158:
159:                List commonHosts = null;
160:                List mergedHosts = null;
161:                List listOfHosts = null;
162:                List deniedHosts = null;
163:                List allowedHosts = null;
164:                Hashtable htSessionData = new Hashtable();
165:                String szDefaultDomain = "";
166:
167:                try {
168:                    java.security.Principal princi = ssoToken.getPrincipal();
169:                    String userIdentity = princi.getName();
170:                    int startIndex = userIdentity.indexOf('=', 0);
171:                    int endIndex = userIdentity.indexOf(',', 0);
172:
173:                    htSessionData.put("userid", userIdentity.substring(
174:                            startIndex + 1, endIndex));
175:
176:                    Map[] prefs = nfContext.getPreferences();
177:
178:                    this .createNetFileAttributeExtractor(prefs[0]);
179:
180:                    nfContext.loadMailAttributesAsCollection(htSessionData);
181:
182:                    htSessionData.put(NetFileContext.SRAP_NF_NTDOMAIN, nfAttrs
183:                            .getString(NetFileContext.SRAP_NF_NTDOMAIN, ""));
184:
185:                    htSessionData
186:                            .put(NetFileContext.SRAP_NF_WINLOC, nfAttrs
187:                                    .getString(NetFileContext.SRAP_NF_WINLOC,
188:                                            "100|50"));
189:
190:                    htSessionData.put(NetFileContext.SRAP_NF_WINSIZE, nfAttrs
191:                            .getString(NetFileContext.SRAP_NF_WINSIZE,
192:                                    "700|400"));
193:
194:                    htSessionData.put("iplanet-am-user-preferredlocale",
195:                            nfContext.getUserLocale());
196:
197:                    szDefaultDomain = nfAttrs.getString(
198:                            NetFileContext.SRAP_NF_DOMAIN, "");
199:                    htSessionData.put(NetFileContext.SRAP_NF_DOMAIN,
200:                            szDefaultDomain);
201:
202:                    deniedHosts = getDeniedHosts();
203:                    if (deniedHosts != null) {
204:                        //                logger.info("Denied hosts obtained are " + deniedHosts.toString());
205:                        Object[] params3 = { deniedHosts.toString() };
206:                        logger.log(Level.INFO, "PSSRNF_CSPNSJ2107", params3);
207:                    } else
208:                        //                logger.info("Denied host list is empty for this user");
209:                        logger.info("PSSRNF_CSPNSJ2108");
210:
211:                    allowedHosts = getAllowedHosts();
212:                    if (allowedHosts != null) {
213:                        //                logger.info("Allowed hosts obtained are " + allowedHosts.toString());
214:                        Object[] params5 = { allowedHosts.toString() };
215:                        logger.log(Level.INFO, "PSSRNF_CSPNSJ2109", params5);
216:                    } else
217:                        //                logger.info("Allowed host list is empty for this user");
218:                        logger.info("PSSRNF_CSPNSJ2110");
219:
220:                    commonHosts = getCommonHosts();
221:                    /*
222:                     //            if(logger.infoEnabled() && (commonHosts != null)) {            
223:                     if(logger.infoEnabled() && (commonHosts != null)) {            
224:                     //                logger.info("Common data obtained is " + commonHosts.toString());
225:                     Object[] params8 = { commonHosts.toString()};
226:                     logger.log( Level.INFO , "PSSRNF_CSPNSJ2112" , params8 );
227:                     }
228:                     */
229:
230:                    listOfHosts = getUserAddedHosts();
231:                    /*
232:                     //            if(logger.infoEnabled() && (listOfHosts != null)) {                        
233:                     if(logger.infoEnabled() && (listOfHosts != null)) {                        
234:                     //                logger.info("User Hosts are " + listOfHosts.toString());                
235:                     Object[] params10 = { listOfHosts.toString()};
236:                     logger.log( Level.INFO , "PSSRNF_CSPNSJ2114" , params10 );
237:                     }
238:                     */
239:
240:                    NetFileHostDataProcessor nfHostProc = new NetFileHostDataProcessor(
241:                            null, this .nfContext, this .nfRes);
242:                    nfHostProc.setPathInfo(this .pathInfo);
243:                    nfHostProc.setDefaultDomain(szDefaultDomain);
244:
245:                    try {
246:                        if ((commonHosts != null) && (!commonHosts.isEmpty())) {
247:
248:                            if ((listOfHosts == null)
249:                                    || (listOfHosts.isEmpty())) {
250:                                // Merge common hosts and denied hosts
251:                                mergedHosts = nfHostProc
252:                                        .getMergedCommonDeniedHosts(
253:                                                commonHosts, deniedHosts,
254:                                                allowedHosts);
255:                                htSessionData.put(
256:                                        NetFileContext.SRAP_NF_USERCOMHOST,
257:                                        mergedHosts);
258:                                if (!nfHostProc.getInvalidHosts().isEmpty()) {
259:                                    htSessionData.put(
260:                                            NetFileContext.SRAP_NF_INVALIDHOST,
261:                                            nfHostProc.getInvalidHosts());
262:                                }
263:                            } else {
264:                                /* 
265:                                 * Merge common, denied and user-added hosts. Note that if the user
266:                                 * host and a common host match (by name via InetAddress), then the 
267:                                 * preferences of the user override the settings in the common host.
268:                                 * The resultant host info is a merged host and is added to the 
269:                                 * SRAP_NF_USERHOST. All the other common hosts which are valid are 
270:                                 * added as common hosts for the user in SRAP_NF_USERCOMHOST. If a host
271:                                 * is denied, then it is added to the list of SRAP_NF_USERDENYHOST and 
272:                                 * is not added to the SRAP_NF_USERHOST or SRAP_NF_USERCOMHOST.
273:                                 */
274:                                mergedHosts = nfHostProc
275:                                        .getMergedCommonUserHosts(commonHosts,
276:                                                deniedHosts, allowedHosts,
277:                                                listOfHosts);
278:                                htSessionData.put(
279:                                        NetFileContext.SRAP_NF_USERHOST,
280:                                        mergedHosts);
281:                                htSessionData.put(
282:                                        NetFileContext.SRAP_NF_USERCOMHOST,
283:                                        nfHostProc.getNotMergedCommonHosts());
284:                                if (!nfHostProc.getInvalidHosts().isEmpty()) {
285:                                    htSessionData.put(
286:                                            NetFileContext.SRAP_NF_INVALIDHOST,
287:                                            nfHostProc.getInvalidHosts());
288:                                }
289:                            }
290:                        } else {
291:                            if ((listOfHosts == null)
292:                                    || (listOfHosts.isEmpty())) {
293:                                // No common hosts and no user-added hosts. So do nothing.
294:                            } else {
295:                                // Merge denied hosts and user-added hosts
296:                                mergedHosts = nfHostProc.mergeDeniedUserHosts(
297:                                        deniedHosts, allowedHosts, listOfHosts);
298:                                htSessionData.put(
299:                                        NetFileContext.SRAP_NF_USERHOST,
300:                                        mergedHosts);
301:                                if (!nfHostProc.getInvalidHosts().isEmpty()) {
302:                                    htSessionData.put(
303:                                            NetFileContext.SRAP_NF_INVALIDHOST,
304:                                            nfHostProc.getInvalidHosts());
305:                                }
306:                            }
307:                        }
308:                    } catch (Exception e) {
309:                        //                logger.log(Level.SEVERE, "Exception extracting common data or host data or in merging them",e);
310:                        logger.log(Level.SEVERE, "PSSRNF_CSPNSJ2115");
311:                    }
312:
313:                    if (nfHostProc.getCommonHostsAsList() == null)
314:                        htSessionData.put(NetFileContext.SRAP_NF_COMHOST,
315:                                new ArrayList(1));
316:                    else
317:                        htSessionData.put(NetFileContext.SRAP_NF_COMHOST,
318:                                nfHostProc.getCommonHostsAsList());
319:
320:                    if (nfHostProc.getUserDeniedHostsAsList() == null)
321:                        htSessionData.put(NetFileContext.SRAP_NF_USERDENYHOST,
322:                                new ArrayList(1));
323:                    else
324:                        htSessionData.put(NetFileContext.SRAP_NF_USERDENYHOST,
325:                                nfHostProc.getUserDeniedHostsAsList());
326:
327:                    if (deniedHosts == null)
328:                        deniedHosts = new ArrayList(1);
329:                    htSessionData.put(NetFileContext.SRAP_NF_DENYHOST,
330:                            deniedHosts);
331:
332:                    if (allowedHosts == null)
333:                        allowedHosts = new ArrayList(1);
334:                    htSessionData.put(NetFileContext.SRAP_NF_ALLOWEDHOST,
335:                            allowedHosts);
336:
337:                    htSessionData.put(NetFileContext.SRAP_NF_MAXSEARCHDIR,
338:                            nfAttrs.getInt(NetFileContext.SRAP_NF_MAXSEARCHDIR,
339:                                    100));
340:
341:                    htSessionData.put(NetFileContext.SRAP_NF_COMPRESSIONTYPE,
342:                            nfAttrs.getString(
343:                                    NetFileContext.SRAP_NF_COMPRESSIONTYPE,
344:                                    "zip"));
345:
346:                    htSessionData.put(NetFileContext.SRAP_NF_COMPRESSIONLEVEL,
347:                            nfAttrs.getString(
348:                                    NetFileContext.SRAP_NF_COMPRESSIONLEVEL,
349:                                    "6"));
350:
351:                    htSessionData.put(NetFileContext.SRAP_NF_WINACCESS, nfAttrs
352:                            .getBoolean(NetFileContext.SRAP_NF_WINACCESS, true)
353:                            .toString());
354:
355:                    htSessionData.put(NetFileContext.SRAP_NF_NFSACCESS, nfAttrs
356:                            .getBoolean(NetFileContext.SRAP_NF_NFSACCESS, true)
357:                            .toString());
358:
359:                    htSessionData.put(NetFileContext.SRAP_NF_FTPACCESS, nfAttrs
360:                            .getBoolean(NetFileContext.SRAP_NF_FTPACCESS, true)
361:                            .toString());
362:
363:                    htSessionData.put(NetFileContext.SRAP_NF_NETWAREACCESS,
364:                            nfAttrs.getBoolean(
365:                                    NetFileContext.SRAP_NF_NETWAREACCESS, true)
366:                                    .toString());
367:
368:                    htSessionData.put(NetFileContext.SRAP_NF_ALLOWDELETE,
369:                            nfAttrs.getBoolean(
370:                                    NetFileContext.SRAP_NF_ALLOWDELETE, true));
371:
372:                    htSessionData.put(NetFileContext.SRAP_NF_ALLOWRENAME,
373:                            nfAttrs.getBoolean(
374:                                    NetFileContext.SRAP_NF_ALLOWRENAME, true));
375:
376:                    htSessionData
377:                            .put(NetFileContext.SRAP_NF_ALLOWMAIL, nfAttrs
378:                                    .getBoolean(
379:                                            NetFileContext.SRAP_NF_ALLOWMAIL,
380:                                            true));
381:
382:                    htSessionData.put(NetFileContext.SRAP_NF_ALLOWSEARCH,
383:                            nfAttrs.getBoolean(
384:                                    NetFileContext.SRAP_NF_ALLOWSEARCH, true));
385:
386:                    htSessionData
387:                            .put(
388:                                    NetFileContext.SRAP_NF_ALLOWCOMPRESS,
389:                                    nfAttrs
390:                                            .getBoolean(
391:                                                    NetFileContext.SRAP_NF_ALLOWCOMPRESS,
392:                                                    true));
393:
394:                    htSessionData.put(NetFileContext.SRAP_NF_ALLOWUPLOAD,
395:                            nfAttrs.getBoolean(
396:                                    NetFileContext.SRAP_NF_ALLOWUPLOAD, true));
397:
398:                    htSessionData
399:                            .put(
400:                                    NetFileContext.SRAP_NF_ALLOWDOWNLOAD,
401:                                    nfAttrs
402:                                            .getBoolean(
403:                                                    NetFileContext.SRAP_NF_ALLOWDOWNLOAD,
404:                                                    true));
405:
406:                    htSessionData.put(NetFileContext.SRAP_NF_CHANGEUID, nfAttrs
407:                            .getBoolean(NetFileContext.SRAP_NF_CHANGEUID, true)
408:                            .toString());
409:
410:                    htSessionData.put(NetFileContext.SRAP_NF_CHANGEDOMAIN,
411:                            nfAttrs.getBoolean(
412:                                    NetFileContext.SRAP_NF_CHANGEDOMAIN, true)
413:                                    .toString());
414:
415:                    htSessionData.put(NetFileContext.SRAP_NF_UPLOADLIMIT,
416:                            nfAttrs.getInt(NetFileContext.SRAP_NF_UPLOADLIMIT,
417:                                    5));
418:
419:                    String szBaseTempDir = nfAttrs.getString(
420:                            NetFileContext.SRAP_NF_TEMPDIR, "/tmp");
421:                    htSessionData
422:                            .put(nfContext.SRAP_NF_TEMPDIR,
423:                                    getTemporaryDirectory(this .ssoToken,
424:                                            szBaseTempDir));
425:
426:                    htSessionData.put(NetFileContext.SRAP_NF_OSCHARSET, nfAttrs
427:                            .getString(NetFileContext.SRAP_NF_OSCHARSET,
428:                                    "Unicode(UTF-8)"));
429:
430:                    htSessionData.put(NetFileContext.SRAP_NF_WINNAMESERVER,
431:                            nfAttrs.getString(
432:                                    NetFileContext.SRAP_NF_WINNAMESERVER, ""));
433:
434:                    htSessionData.put(NetFileContext.SRAP_NF_MIMELOCATION,
435:                            nfAttrs.getString(
436:                                    NetFileContext.SRAP_NF_MIMELOCATION, ""));
437:
438:                    nfAttrs.setUserAttributesMap(prefs[1]);
439:
440:                    htSessionData.put(NetFileContext.SRAP_NF_APPNAME, nfAttrs
441:                            .getString(NetFileContext.SRAP_NF_APPNAME, nfRes
442:                                    .getString("appName")));
443:                    htSessionData.put(NetFileContext.SRAP_NF_APPVERSION,
444:                            nfAttrs.getString(
445:                                    NetFileContext.SRAP_NF_APPVERSION, nfRes
446:                                            .getString("appRelease")));
447:                    htSessionData.put(NetFileContext.SRAP_NF_APPRELEASE,
448:                            nfAttrs.getString(
449:                                    NetFileContext.SRAP_NF_APPRELEASE, nfRes
450:                                            .getString("appDate")));
451:                    htSessionData.put(NetFileContext.SRAP_NF_COMPNAME, nfAttrs
452:                            .getString(NetFileContext.SRAP_NF_COMPNAME, nfRes
453:                                    .getString("vendorName")));
454:
455:                    htSessionData
456:                            .put("htmlCharset", nfContext.getHTMLCharset());
457:
458:                    //logSessionStartTime(this.logMgr);
459:                    return htSessionData;
460:                } catch (Exception e) {
461:                    //            logger.log(Level.SEVERE, "Exception getting attributes data",e);
462:                    logger.log(Level.SEVERE, "PSSRNF_CSPNSJ2116");
463:                }
464:                return null;
465:            }
466:
467:            private void createNetFileAttributeExtractor(Map m) {
468:                nfAttrs = new NetFileAttributeExtractor(m);
469:            }
470:
471:            private List getUserAddedHosts() {
472:                return nfAttrs.getStringList(NetFileContext.SRAP_NF_USERHOST);
473:            }
474:
475:            private List getDeniedHosts() {
476:                return nfAttrs.getStringList(NetFileContext.SRAP_NF_DENYHOST);
477:            }
478:
479:            private List getCommonHosts() {
480:                ArrayList decryptedNetFileHosts = null;
481:                List encryptedHosts = nfAttrs
482:                        .getStringList(NetFileContext.SRAP_NF_COMHOST);
483:                if (encryptedHosts != null) {
484:                    if (!encryptedHosts.isEmpty()) {
485:                        decryptedNetFileHosts = new ArrayList();
486:                        Iterator hosts = encryptedHosts.iterator();
487:                        String tmpHostStr = null;
488:                        while (hosts.hasNext()) {
489:                            tmpHostStr = (String) hosts.next();
490:                            if (tmpHostStr.length() > 0) {
491:                                decryptedNetFileHosts
492:                                        .add(getDecryptedHostInfo(tmpHostStr));
493:                            }
494:                        }
495:                    }
496:                }
497:                return decryptedNetFileHosts;
498:            }
499:
500:            private String getDecryptedHostInfo(String szEncryptedHostInfo) {
501:                return (String) AccessController
502:                        .doPrivileged(new DecryptAction(szEncryptedHostInfo));
503:            }
504:
505:            private List getAllowedHosts() {
506:                return nfAttrs
507:                        .getStringList(NetFileContext.SRAP_NF_ALLOWEDHOST);
508:            }
509:
510:            String getTemporaryDirectory(SSOToken ssoToken, String szBaseTempDir)
511:                    throws NetFileException {
512:
513:                if ((szBaseTempDir == null)
514:                        || (szBaseTempDir.trim().length() == 0))
515:                    throw new NetFileException(NetFileException.NF_FATAL_ERROR,
516:                            "Could not create temporary directory");
517:
518:                String szTheTempDir = null;
519:                try {
520:                    szTheTempDir = createTemporaryDirectoryName(ssoToken,
521:                            szBaseTempDir);
522:                    if (!createTemporaryDirectory(szTheTempDir))
523:                        throw new NetFileException(
524:                                NetFileException.NF_FATAL_ERROR,
525:                                "Could not create temporary directory");
526:
527:                    NetFileServlet.putTempDirCache(ssoToken.getTokenID()
528:                            .toString(), szTheTempDir);
529:
530:                    //            logger.info("Temporary directory created is "+szTheTempDir);
531:                    Object[] params13 = { szTheTempDir };
532:                    logger.log(Level.INFO, "PSSRNF_CSPNSJ2117", params13);
533:
534:                    ssoToken.addSSOTokenListener(NetFileServlet
535:                            .getNetFileSessionCleaner());
536:
537:                } catch (Exception e) {
538:                    //            logger.log(Level.SEVERE, "Exception in creating temporary directory ", e);
539:                    logger.log(Level.SEVERE, "PSSRNF_CSPNSJ2118");
540:                    throw new NetFileException(NetFileException.NF_FATAL_ERROR,
541:                            "Could not create temporary directory");
542:                }
543:
544:                return szTheTempDir;
545:            }
546:
547:            String createTemporaryDirectoryName(SSOToken ssoToken,
548:                    String szBaseTempDir) {
549:
550:                String szSSOToken = ssoToken.getTokenID().toString();
551:                int index = szSSOToken.indexOf('@');
552:                int length = szSSOToken.length();
553:
554:                for (int i = 0; i < length; i++) {
555:                    if (!Character.isJavaIdentifierPart(szSSOToken.charAt(i))) {
556:                        if (i > 1) {
557:                            index = i;
558:                        }
559:                        break;
560:                    }
561:                }
562:                return szBaseTempDir + "/nfj2" + szSSOToken.substring(0, index);
563:            }
564:
565:            boolean createTemporaryDirectory(String szTempDirName) {
566:                File tempDir = new File(szTempDirName);
567:                if (!tempDir.exists()) {
568:                    tempDir.mkdirs();
569:                    if (!tempDir.exists()) {
570:                        return false;
571:                    }
572:                }
573:                if (!tempDir.canRead()) {
574:                    return false;
575:                }
576:                if (!tempDir.canWrite()) {
577:                    return false;
578:                }
579:                return true;
580:            }
581:
582:            public void setPathInfo(String[] pathinfo) {
583:                this.pathInfo = pathinfo;
584:            }
585:
586:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.