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


001:        /*
002:         * Copyright © 2006 Sun Microsystems, Inc. All rights reserved. 
003:         *
004:         * Sun Microsystems, Inc. has intellectual property rights relating to
005:         * technology embodied in the product that is described in this document. 
006:         * In particular, and without limitation, these intellectual property 
007:         * rights may include one or more of the U.S. patents listed at 
008:         * http://www.sun.com/patents and one or more additional patents or
009:         * pending patent applications in the U.S. and in other countries.
010:         * 
011:         * U.S. Government Rights - Commercial software. Government users are subject
012:         * to the Sun Microsystems, Inc. standard license agreement and applicable 
013:         * provisions of the FAR and its supplements. Use is subject to license terms. 
014:         * This distribution may include materials developed by third parties.
015:         * Sun, Sun Microsystems, the Sun logo and Java are trademarks or registered 
016:         * trademarks of Sun Microsystems, Inc. in the U.S. and other countries. 
017:         */
018:
019:        package com.sun.portal.community.impl;
020:
021:        import java.io.FileNotFoundException;
022:        import java.io.IOException;
023:        import java.net.MalformedURLException;
024:        import java.net.URL;
025:        import java.util.ArrayList;
026:        import java.util.HashMap;
027:        import java.util.HashSet;
028:        import java.util.Iterator;
029:        import java.util.List;
030:        import java.util.Locale;
031:        import java.util.Map;
032:        import java.util.Properties;
033:        import java.util.regex.Pattern;
034:        import java.util.Set;
035:
036:        import javax.servlet.http.HttpServletRequest;
037:        import javax.servlet.http.HttpServletResponse;
038:
039:        import com.iplanet.sso.SSOTokenManager;
040:        import com.iplanet.sso.SSOToken;
041:        import com.iplanet.sso.SSOException;
042:
043:        import netscape.ldap.LDAPDN;
044:
045:        import com.sun.portal.util.ResourceLoader;
046:
047:        import com.sun.portal.community.Community;
048:        import com.sun.portal.community.CommunityException;
049:        import com.sun.portal.community.CommunityFactory;
050:        import com.sun.portal.community.CommunityId;
051:        import com.sun.portal.community.CommunityManager;
052:        import com.sun.portal.community.CommunityServiceException;
053:        import com.sun.portal.community.CommunityUser;
054:        import com.sun.portal.community.DPName;
055:        import com.sun.portal.community.RoleId;
056:        import com.sun.portal.community.template.TemplateDescriptor;
057:        import com.sun.portal.community.template.TemplateException;
058:        import com.sun.portal.community.template.TemplateManager;
059:        import com.sun.portal.community.template.TemplateManagerFactory;
060:
061:        import com.sun.portal.community.CommunityManagerWSInterface;
062:        import com.sun.portal.community.filter.CommunityManagerWSThreadLocalizer;
063:
064:        public class CommunityManagerWSImpl implements 
065:                CommunityManagerWSInterface {
066:
067:            private static String communityType = "";
068:            private static Pattern allPattern = null;
069:
070:            public CommunityManagerWSImpl() {
071:                ResourceLoader rl = ResourceLoader.getInstance(System
072:                        .getProperties());
073:                try {
074:                    Properties p = rl
075:                            .getProperties("communitymgmnt.properties");
076:                    communityType = p.getProperty("ps-community-types");
077:                } catch (FileNotFoundException fnfe) {
078:                    throw new RuntimeException("CommunityManagerWSImpl: ", fnfe);
079:                } catch (IOException ioe) {
080:                    throw new RuntimeException("CommunityManagerWSImpl: ", ioe);
081:                }
082:            }
083:
084:            public boolean validate() {
085:                return true;
086:            }
087:
088:            public String getSearchServerURL(String ssoTokenID)
089:                    throws SSOException, CommunityException {
090:                SSOToken ssoToken = getAmadminSSOToken(ssoTokenID);
091:                CommunityManager cm = getCommunityManager(ssoToken);
092:                return cm.getSearchUrl();
093:            }
094:
095:            public String getSearchServerID(String ssoTokenID)
096:                    throws SSOException, CommunityException {
097:                SSOToken ssoToken = getAmadminSSOToken(ssoTokenID);
098:                CommunityManager cm = getCommunityManager(ssoToken);
099:
100:                try {
101:                    URL url = new URL(cm.getSearchUrl());
102:                    String path = url.getPath();
103:                    if (path.startsWith("/")) {
104:                        path = path.substring(1);
105:                    }
106:                    String[] strings = path.split("/");
107:                    int length = strings.length;
108:                    if (length >= 2) {
109:                        return strings[length - 2];
110:                    } else {
111:                        throw new CommunityException(
112:                                "Invalid search server URL " + url.toString());
113:                    }
114:                } catch (MalformedURLException murle) {
115:                    throw new CommunityException(murle);
116:                }
117:            }
118:
119:            public String getCommunityDatabase(String ssoTokenID)
120:                    throws SSOException, CommunityException {
121:                SSOToken ssoToken = getAmadminSSOToken(ssoTokenID);
122:                CommunityManager cm = getCommunityManager(ssoToken);
123:                return cm.getSearchDb();
124:            }
125:
126:            public List getAvailableTemplates(String ssoTokenID, String locale)
127:                    throws SSOException, CommunityException {
128:                // public List getAvailableTemplates(String ssoTokenID, String locale) throws SSOException, TemplateException {
129:                SSOToken ssoToken = getAmadminSSOToken(ssoTokenID);
130:
131:                List result = new ArrayList();
132:
133:                try {
134:                    TemplateManager tm = TemplateManagerFactory.getInstance()
135:                            .getTemplateManager();
136:                    Set s = tm.getAllTemplateIds();
137:                    Iterator i = s.iterator();
138:                    while (i.hasNext()) {
139:                        TemplateDescriptor td = tm.getTemplateDescriptor(
140:                                (String) i.next(), new Locale(locale));
141:                        Properties p = new Properties();
142:                        p.setProperty("id", td.getId());
143:                        p.setProperty("name", td.getName());
144:                        p.setProperty("description", td.getDescription());
145:                        result.add(p);
146:                    }
147:                } catch (TemplateException te) {
148:                    throw new CommunityException(te);
149:                }
150:
151:                return result;
152:            }
153:
154:            public List getAvailableDPs(String ssoTokenID) throws SSOException {
155:                SSOToken ssoToken = getAmadminSSOToken(ssoTokenID);
156:
157:                List result = new ArrayList();
158:
159:                Set s = DPName.ALL_DP_NAMES;
160:                Iterator i = s.iterator();
161:                while (i.hasNext()) {
162:                    DPName dpName = (DPName) i.next();
163:                    result.add(dpName.getName());
164:                }
165:
166:                return result;
167:            }
168:
169:            public List search(String ssoTokenID, String query)
170:                    throws SSOException, CommunityException {
171:                SSOToken ssoToken = getAmadminSSOToken(ssoTokenID);
172:
173:                List result = new ArrayList();
174:
175:                HashSet hs = new HashSet();
176:                hs.add(RoleId.PENDING_ROLE);
177:
178:                CommunityManager cm = getCommunityManager(ssoToken);
179:                Set s = cm.match(Pattern.compile(query), false);
180:                Iterator i = s.iterator();
181:                while (i.hasNext()) {
182:                    CommunityId cId = (CommunityId) i.next();
183:                    Community c = getCommunity(ssoToken, cId);
184:                    if (c != null) {
185:                        Properties p = new Properties();
186:                        p.setProperty("id", cId.toString());
187:                        p.setProperty("name", cId.getName());
188:                        p.setProperty("description", c.getDescription());
189:                        p.setProperty("category", c.getCategory());
190:                        p.setProperty("unlisted", (c.isListed()) ? "false"
191:                                : "true");
192:                        p.setProperty("membershiprestricted", (c
193:                                .isMembershipRestricted()) ? "true" : "false");
194:                        p.setProperty("secured", (c.isSecure()) ? "true"
195:                                : "false");
196:                        p.setProperty("disabled", (c.isDisabled()) ? "true"
197:                                : "false");
198:                        p.setProperty("deleted", (c.isDeleted()) ? "true"
199:                                : "false");
200:                        p.setProperty("users", Integer.toString(c.getUsers()
201:                                .size()));
202:                        p.setProperty("pendingusers", Integer.toString(c
203:                                .getUsers(hs).size()));
204:                        result.add(p);
205:                    }
206:                }
207:
208:                return result;
209:            }
210:
211:            public List getSecuredCommunityMembership(String ssoTokenID,
212:                    String user) throws NullPointerException, SSOException,
213:                    CommunityException {
214:                SSOToken ssoToken = getAmadminSSOToken(ssoTokenID);
215:                HttpServletRequest request = CommunityManagerWSThreadLocalizer
216:                        .getRequest();
217:                if (request == null) {
218:                    throw new NullPointerException(
219:                            "CommunityManagerWSImpl:getSecuredCommunityMembership request was null from thread local");
220:                }
221:                CommunityUser cu = CommunityFactory.getInstance()
222:                        .getCommunityUser(request, user);
223:                Map m = cu.getMembership(false);
224:                List l = new ArrayList();
225:                Iterator i = m.keySet().iterator();
226:                while (i.hasNext()) {
227:                    CommunityId cId = (CommunityId) i.next();
228:                    Set roleIds = (Set) m.get(cId);
229:                    Community c = getCommunity(ssoToken, cId);
230:                    if (c.isSecure() && roleIds != null
231:                            && roleIds.contains(RoleId.MEMBER_ROLE)) {
232:                        l.add(cId.toString());
233:                    }
234:                }
235:                return l;
236:            }
237:
238:            public Properties getCommunityProperties(String ssoTokenID,
239:                    String name) throws SSOException, CommunityException {
240:                SSOToken ssoToken = getAmadminSSOToken(ssoTokenID);
241:                CommunityManager cm = getCommunityManager(ssoToken);
242:                Community c = getCommunity(ssoToken, name);
243:
244:                Properties result = new Properties();
245:
246:                result.setProperty("id", c.getCommunityId().toString());
247:                result.setProperty("name", name);
248:                result.setProperty("description", c.getDescription());
249:                result.setProperty("category", c.getCategory());
250:                result.setProperty("unlisted", (c.isListed()) ? "false"
251:                        : "true");
252:                result.setProperty("membershiprestricted", (c
253:                        .isMembershipRestricted()) ? "true" : "false");
254:                result
255:                        .setProperty("secured", (c.isSecure()) ? "true"
256:                                : "false");
257:                result.setProperty("disabled", (c.isDisabled()) ? "true"
258:                        : "false");
259:                result.setProperty("deleted", (c.isDeleted()) ? "true"
260:                        : "false");
261:                result.setProperty("users", Integer.toString(c.getUsers()
262:                        .size()));
263:
264:                HashSet hs = new HashSet();
265:                hs.add(RoleId.PENDING_ROLE);
266:                result.setProperty("pendingusers", Integer.toString(c.getUsers(
267:                        hs).size()));
268:
269:                return result;
270:            }
271:
272:            public byte[] getCommunityDP(String ssoTokenID, String name,
273:                    String dp) throws SSOException, CommunityException {
274:                SSOToken ssoToken = getAmadminSSOToken(ssoTokenID);
275:                Community c = getCommunity(ssoToken, name);
276:                return c.getDP(DPName.valueOf(dp));
277:            }
278:
279:            public void setCommunityProperties(String ssoTokenID, String name,
280:                    Properties p) throws SSOException, CommunityException {
281:                SSOToken ssoToken = getAmadminSSOToken(ssoTokenID);
282:                CommunityManager cm = getCommunityManager(ssoToken);
283:                Community c = getCommunity(ssoToken, name);
284:                c.setDescription(p.getProperty("description"));
285:                c.setCategory(p.getProperty("category"));
286:                c.setListed((p.getProperty("unlisted").equals("true")) ? false
287:                        : true);
288:                c
289:                        .setMembershipRestricted((p
290:                                .getProperty("membershiprestricted")
291:                                .equals("true")) ? true : false);
292:                c.setSecure((p.getProperty("secured").equals("true")) ? true
293:                        : false);
294:            }
295:
296:            public void createCommunity(String ssoTokenID, String name,
297:                    String description, String owner, String category,
298:                    String template, String unlisted,
299:                    String membershipRestricted, String secured)
300:                    throws SSOException, CommunityException,
301:                    CommunityServiceException {
302:                SSOToken ssoToken = getAmadminSSOToken(ssoTokenID);
303:                CommunityManager cm = getCommunityManager(ssoToken);
304:                cm.createCommunity(new CommunityId(communityType, name), owner,
305:                        template, category, description, (membershipRestricted
306:                                .equals("true")) ? true : false, (secured
307:                                .equals("true")) ? true : false, (unlisted
308:                                .equals("true")) ? false : true);
309:            }
310:
311:            public void enableCommunity(String ssoTokenID, String name)
312:                    throws SSOException, CommunityException,
313:                    CommunityServiceException {
314:                SSOToken ssoToken = getAmadminSSOToken(ssoTokenID);
315:                Community c = getCommunity(ssoToken, name);
316:                c.setDisabled(false);
317:            }
318:
319:            public void disableCommunity(String ssoTokenID, String name)
320:                    throws SSOException, CommunityException,
321:                    CommunityServiceException {
322:                SSOToken ssoToken = getAmadminSSOToken(ssoTokenID);
323:                Community c = getCommunity(ssoToken, name);
324:                c.setDisabled(true);
325:            }
326:
327:            public void deleteCommunity(String ssoTokenID, String name)
328:                    throws SSOException, CommunityException,
329:                    CommunityServiceException {
330:                SSOToken ssoToken = getAmadminSSOToken(ssoTokenID);
331:                Community c = getCommunity(ssoToken, name);
332:                c.setDeleted(true);
333:            }
334:
335:            public void undeleteCommunity(String ssoTokenID, String name)
336:                    throws SSOException, CommunityException,
337:                    CommunityServiceException {
338:                SSOToken ssoToken = getAmadminSSOToken(ssoTokenID);
339:                Community c = getCommunity(ssoToken, name);
340:                c.setDeleted(false);
341:            }
342:
343:            public void destroyCommunity(String ssoTokenID, String name)
344:                    throws SSOException, CommunityException,
345:                    CommunityServiceException {
346:                SSOToken ssoToken = getAmadminSSOToken(ssoTokenID);
347:                CommunityManager cm = getCommunityManager(ssoToken);
348:                cm.destroyCommunity(new CommunityId(communityType, name));
349:            }
350:
351:            public boolean isCommunitySecure(String ssoTokenID, String name)
352:                    throws SSOException, CommunityException {
353:                SSOToken ssoToken = getAmadminSSOToken(ssoTokenID);
354:                CommunityManager cm = getCommunityManager(ssoToken);
355:                Community c = getCommunity(ssoToken, name);
356:                return c.isSecure();
357:            }
358:
359:            public void addUser(String ssoTokenID, String name, String user)
360:                    throws SSOException, CommunityException,
361:                    CommunityServiceException {
362:                SSOToken ssoToken = getAmadminSSOToken(ssoTokenID);
363:                Community c = getCommunity(ssoToken, name);
364:                c.addMember(user);
365:            }
366:
367:            public void removeUser(String ssoTokenID, String name, String user)
368:                    throws SSOException, CommunityException,
369:                    CommunityServiceException {
370:                SSOToken ssoToken = getAmadminSSOToken(ssoTokenID);
371:                Community c = getCommunity(ssoToken, name);
372:
373:                Set s = RoleId.ALL_ROLES;
374:                Iterator i = s.iterator();
375:                while (i.hasNext()) {
376:                    c.removeUser(user, (RoleId) i.next());
377:                }
378:            }
379:
380:            public void approveUser(String ssoTokenID, String name, String user)
381:                    throws SSOException, CommunityException,
382:                    CommunityServiceException {
383:                SSOToken ssoToken = getAmadminSSOToken(ssoTokenID);
384:                Community c = getCommunity(ssoToken, name);
385:                c.approveMembershipRequest(user);
386:            }
387:
388:            public void denyUser(String ssoTokenID, String name, String user)
389:                    throws SSOException, CommunityException,
390:                    CommunityServiceException {
391:                SSOToken ssoToken = getAmadminSSOToken(ssoTokenID);
392:                Community c = getCommunity(ssoToken, name);
393:                c.rejectMembershipRequest(user);
394:            }
395:
396:            public void banUser(String ssoTokenID, String name, String user)
397:                    throws SSOException, CommunityException,
398:                    CommunityServiceException {
399:                SSOToken ssoToken = getAmadminSSOToken(ssoTokenID);
400:                Community c = getCommunity(ssoToken, name);
401:                c.banUser(user);
402:            }
403:
404:            public void unbanUser(String ssoTokenID, String name, String user)
405:                    throws SSOException, CommunityException,
406:                    CommunityServiceException {
407:                SSOToken ssoToken = getAmadminSSOToken(ssoTokenID);
408:                Community c = getCommunity(ssoToken, name);
409:                c.unbanUser(user);
410:            }
411:
412:            public void addOwner(String ssoTokenID, String name, String user)
413:                    throws SSOException, CommunityException,
414:                    CommunityServiceException {
415:                SSOToken ssoToken = getAmadminSSOToken(ssoTokenID);
416:                Community c = getCommunity(ssoToken, name);
417:                c.addOwner(user);
418:            }
419:
420:            public void removeOwner(String ssoTokenID, String name, String user)
421:                    throws SSOException, CommunityException,
422:                    CommunityServiceException {
423:                SSOToken ssoToken = getAmadminSSOToken(ssoTokenID);
424:                Community c = getCommunity(ssoToken, name);
425:                c.removeUser(user, RoleId.OWNER_ROLE);
426:            }
427:
428:            public List getUsers(String ssoTokenID, String name)
429:                    throws SSOException, CommunityException {
430:                SSOToken ssoToken = getAmadminSSOToken(ssoTokenID);
431:
432:                CommunityId cId = new CommunityId(communityType, name);
433:
434:                HttpServletRequest request = CommunityManagerWSThreadLocalizer
435:                        .getRequest();
436:                if (request == null) {
437:                    throw new NullPointerException(
438:                            "CommunityManagerWSImpl:getUserRoles request was null from thread local");
439:                }
440:
441:                List result = new ArrayList();
442:
443:                Community c = getCommunity(ssoToken, name);
444:                Set roleIds = RoleId.ALL_ROLES;
445:                roleIds.remove(RoleId.VISITOR_ROLE);
446:                roleIds.remove(RoleId.PENDING_ROLE);
447:                Set users = c.getUsers(roleIds);
448:                Iterator i1 = users.iterator();
449:                while (i1.hasNext()) {
450:                    Properties p = new Properties();
451:
452:                    String user = (String) i1.next();
453:                    p.setProperty("dn", user);
454:
455:                    String roles = "";
456:                    CommunityUser cu = CommunityFactory.getInstance()
457:                            .getCommunityUser(request, user);
458:                    Map m = cu.getMembership(false);
459:                    Set memberships = (Set) m.get(cId);
460:                    Iterator i2 = memberships.iterator();
461:                    while (i2.hasNext()) {
462:                        RoleId rId = (RoleId) i2.next();
463:                        roles = roles + rId.toString() + " ";
464:                    }
465:                    p.setProperty("roles", roles);
466:
467:                    result.add(p);
468:                }
469:
470:                return result;
471:            }
472:
473:            public List getPendingUsers(String ssoTokenID, String name)
474:                    throws SSOException, CommunityException {
475:                SSOToken ssoToken = getAmadminSSOToken(ssoTokenID);
476:
477:                List result = new ArrayList();
478:
479:                Community c = getCommunity(ssoToken, name);
480:                RoleId rId = RoleId.PENDING_ROLE;
481:                HashSet hs = new HashSet();
482:                hs.add(rId);
483:                Set s = c.getUsers(hs);
484:                Iterator i = s.iterator();
485:                while (i.hasNext()) {
486:                    String user = (String) i.next();
487:                    Properties p = new Properties();
488:                    p.setProperty("dn", user);
489:                    p.setProperty("roles", rId.toString());
490:                    result.add(p);
491:                }
492:
493:                return result;
494:            }
495:
496:            public List getUserRoles(String ssoTokenID, String name, String user)
497:                    throws NullPointerException, SSOException,
498:                    CommunityException {
499:                SSOToken ssoToken = getAmadminSSOToken(ssoTokenID);
500:
501:                CommunityId cId = new CommunityId(communityType, name);
502:
503:                HttpServletRequest request = CommunityManagerWSThreadLocalizer
504:                        .getRequest();
505:                if (request == null) {
506:                    throw new NullPointerException(
507:                            "CommunityManagerWSImpl:getUserRoles request was null from thread local");
508:                }
509:                CommunityUser cu = CommunityFactory.getInstance()
510:                        .getCommunityUser(request, user);
511:
512:                List result = new ArrayList();
513:
514:                Map m = cu.getMembership(false);
515:                Set s = (Set) m.get(cId);
516:                if (s != null) {
517:                    Iterator i = s.iterator();
518:                    while (i.hasNext()) {
519:                        RoleId rId = (RoleId) i.next();
520:                        result.add(rId.toString());
521:                    }
522:                }
523:
524:                return result;
525:            }
526:
527:            public boolean hasUser(String ssoTokenID, String name, String user)
528:                    throws SSOException, CommunityException {
529:                SSOToken ssoToken = getAmadminSSOToken(ssoTokenID);
530:                user = LDAPDN.normalize(user.toLowerCase());
531:                Community c = getCommunity(ssoToken, name);
532:                Set s = c.getUsers();
533:                Iterator i = s.iterator();
534:                while (i.hasNext()) {
535:                    String testUser = (String) i.next();
536:                    testUser = LDAPDN.normalize(testUser.toLowerCase());
537:                    if (testUser.equals(user)) {
538:                        return true;
539:                    }
540:                }
541:                return false;
542:            }
543:
544:            public boolean isOwner(String ssoTokenID, String name, String user)
545:                    throws SSOException, CommunityException {
546:                SSOToken ssoToken = getAmadminSSOToken(ssoTokenID);
547:
548:                user = LDAPDN.normalize(user.toLowerCase());
549:
550:                HashSet hs = new HashSet();
551:                hs.add(RoleId.OWNER_ROLE);
552:
553:                Community c = getCommunity(ssoToken, name);
554:                Set s = c.getUsers(hs);
555:                Iterator i = s.iterator();
556:                while (i.hasNext()) {
557:                    String testUser = (String) i.next();
558:                    testUser = LDAPDN.normalize(testUser.toLowerCase());
559:                    if (testUser.equals(user)) {
560:                        return true;
561:                    }
562:                }
563:                return false;
564:            }
565:
566:            public boolean isUserBanned(String ssoTokenID, String name,
567:                    String user) throws SSOException, CommunityException {
568:                SSOToken ssoToken = getAmadminSSOToken(ssoTokenID);
569:
570:                user = LDAPDN.normalize(user.toLowerCase());
571:
572:                HashSet hs = new HashSet();
573:                hs.add(RoleId.BANNED_ROLE);
574:
575:                Community c = getCommunity(ssoToken, name);
576:                Set s = c.getUsers(hs);
577:                Iterator i = s.iterator();
578:                while (i.hasNext()) {
579:                    String testUser = (String) i.next();
580:                    testUser = LDAPDN.normalize(testUser.toLowerCase());
581:                    if (testUser.equals(user)) {
582:                        return true;
583:                    }
584:                }
585:                return false;
586:            }
587:
588:            public boolean isUserPending(String ssoTokenID, String name,
589:                    String user) throws SSOException, CommunityException {
590:                SSOToken ssoToken = getAmadminSSOToken(ssoTokenID);
591:
592:                user = LDAPDN.normalize(user.toLowerCase());
593:
594:                HashSet hs = new HashSet();
595:                hs.add(RoleId.PENDING_ROLE);
596:
597:                Community c = getCommunity(ssoToken, name);
598:                Set s = c.getUsers(hs);
599:                Iterator i = s.iterator();
600:                while (i.hasNext()) {
601:                    String testUser = (String) i.next();
602:                    testUser = LDAPDN.normalize(testUser.toLowerCase());
603:                    if (testUser.equals(user)) {
604:                        return true;
605:                    }
606:                }
607:                return false;
608:            }
609:
610:            /*
611:             ** For testing!
612:             */
613:            public void requestMembership(String ssoTokenID, String name,
614:                    String user) throws SSOException, CommunityException,
615:                    CommunityServiceException {
616:                SSOToken ssoToken = getAmadminSSOToken(ssoTokenID);
617:                Community c = getCommunity(ssoToken, name);
618:                c.requestMembership(user);
619:            }
620:
621:            private SSOToken getAmadminSSOToken(String ssoTokenID)
622:                    throws SSOException {
623:                SSOToken ssoToken = SSOTokenManager.getInstance()
624:                        .createSSOToken(ssoTokenID);
625:                SSOTokenManager.getInstance().validateToken(ssoToken);
626:                return ssoToken;
627:            }
628:
629:            private CommunityManager getCommunityManager(SSOToken ssoToken)
630:                    throws NullPointerException, CommunityException {
631:                HttpServletRequest request = CommunityManagerWSThreadLocalizer
632:                        .getRequest();
633:                if (request == null) {
634:                    throw new NullPointerException(
635:                            "CommunityManagerWSImpl:getCommunityManager request was null from thread local");
636:                }
637:
638:                HttpServletResponse response = CommunityManagerWSThreadLocalizer
639:                        .getResponse();
640:                if (response == null) {
641:                    throw new NullPointerException(
642:                            "CommunityManagerWSImpl:getCommunityManager response was null from thread local");
643:                }
644:
645:                return CommunityFactory.getInstance().getCommunityManager(
646:                        request, response, ssoToken);
647:            }
648:
649:            private Community getCommunity(SSOToken ssoToken, CommunityId cId)
650:                    throws NullPointerException, CommunityException {
651:                HttpServletRequest request = CommunityManagerWSThreadLocalizer
652:                        .getRequest();
653:                if (request == null) {
654:                    throw new NullPointerException(
655:                            "CommunityManagerWSImpl:getCommunity request was null from thread local");
656:                }
657:
658:                HttpServletResponse response = CommunityManagerWSThreadLocalizer
659:                        .getResponse();
660:                if (response == null) {
661:                    throw new NullPointerException(
662:                            "CommunityManagerWSImpl:getCommunity response was null from thread local");
663:                }
664:
665:                return CommunityFactory.getInstance().getCommunity(request,
666:                        response, ssoToken, cId);
667:            }
668:
669:            private Community getCommunity(SSOToken ssoToken, String name)
670:                    throws CommunityException {
671:                return getCommunity(ssoToken, new CommunityId(communityType,
672:                        name));
673:            }
674:
675:            private HashSet toCommunityIds(Set names) {
676:                HashSet hs = new HashSet();
677:                Iterator i = names.iterator();
678:                while (i.hasNext()) {
679:                    CommunityId cId = new CommunityId(communityType, (String) i
680:                            .next());
681:                    hs.add(cId);
682:                }
683:                return hs;
684:            }
685:
686:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.