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


001:        /**
002:         * $Id: DSAMEConnection.java,v 1.13 2005/10/13 16:35:49 dpolla Exp $
003:         * Copyright 2002 Sun Microsystems, Inc. Allrights reserved. Use of
004:         * this product is subjectto license terms. Federal Acquisitions:
005:         * Commercial Software -- Government Users Subject to Standard License
006:         * Terms and Conditions.
007:         *
008:         * Sun, Sun Microsystems, the Sun logo, and Sun ONE are trademarks or
009:         * registered trademarks of Sun Microsystems,Inc. in the United States
010:         * and other countries.
011:         */package com.sun.ssoadapter.config;
012:
013:        import java.util.Iterator;
014:        import java.util.Set;
015:        import java.util.HashSet;
016:        import java.util.Map;
017:        import java.util.HashMap;
018:        import java.util.Enumeration;
019:        import java.util.logging.Level;
020:        import java.util.logging.Logger;
021:        import java.util.Collections;
022:
023:        import java.io.IOException;
024:
025:        import com.iplanet.sso.SSOTokenManager;
026:        import com.iplanet.sso.SSOToken;
027:        import com.iplanet.sso.SSOException;
028:
029:        import com.iplanet.am.sdk.AMStoreConnection;
030:        import com.iplanet.am.sdk.AMObject;
031:        import com.iplanet.am.sdk.AMUser;
032:        import com.iplanet.am.sdk.AMOrganization;
033:        import com.iplanet.am.sdk.AMTemplate;
034:        import com.iplanet.am.sdk.AMException;
035:        import com.iplanet.am.sdk.AMRole;
036:        import com.iplanet.am.sdk.AMFilteredRole;
037:
038:        import com.iplanet.am.util.SystemProperties;
039:        import com.iplanet.am.util.AdminUtils;
040:
041:        import java.security.AccessController;
042:        import java.security.Principal;
043:
044:        import com.sun.identity.security.AdminTokenAction;
045:        import com.sun.identity.sm.SchemaType;
046:        import com.sun.identity.sm.ServiceSchema;
047:        import com.sun.identity.sm.ServiceManager;
048:        import com.sun.identity.sm.ServiceSchemaManager;
049:
050:        import com.sun.identity.sm.SMSException;
051:        import com.sun.ssoadapter.SSOAdapterLogger;
052:        import com.sun.ssoadapter.SSOAdapterSession;
053:
054:        public class DSAMEConnection implements  DSAMEConstants {
055:            //public static Debug debug = Debug.getInstance(DEBUG_FILENAME);
056:            private static String this Class = null;
057:
058:            protected AMUser user = null;
059:            protected AMStoreConnection connection = null;
060:
061:            protected SSOToken userToken = null;
062:
063:            // lazy instantiation: use getXXX() to access
064:            private static SSOToken adminToken = null;
065:            private static SSOTokenManager _tokenMgr = null;
066:
067:            private static AMStoreConnection adminConnection = null;
068:
069:            //
070:            // keep it static to prevent a clutter of manager objects & use
071:            // admin token to get the ServiceManager.
072:            //
073:            private static ServiceManager sManager = null;
074:
075:            private static Logger logger = SSOAdapterLogger
076:                    .getLogger("com.sun.portal.ssoadapter.config");
077:
078:            //
079:            // After declaring adminToken, adminConnection, sManager & _tokenMgr call
080:            // getAdminConnection()
081:            //
082:            static {
083:                getAdminConnection(); // initializes the adminConnection
084:            }
085:
086:            /*
087:             * Empty constructor declared private.
088:             * This is done for logging purposes
089:             */
090:            private DSAMEConnection() {
091:            }
092:
093:            /*
094:             * DSAMEConnection called from PSContextFactory
095:             * 
096:             * @param session  user SSOAdapterSession
097:             * @throws java.lang.IllegalStateException 
098:             */
099:            public DSAMEConnection(SSOAdapterSession session)
100:                    throws IllegalStateException {
101:                this (session.getSSOToken());
102:            }
103:
104:            /*
105:             * DSAMEConnection established per user SSOToken
106:             * 
107:             * @param token  user SSOToken
108:             * @throws java.lang.IllegalStateException 
109:             */
110:            public DSAMEConnection(SSOToken token) throws IllegalStateException {
111:
112:                if (this Class == null)
113:                    this Class = getClass().getName(); // for debug
114:
115:                userToken = token; // reqd to get Schema info
116:
117:                try {
118:                    connection = new AMStoreConnection(token);
119:                } catch (SSOException se) {
120:                    throw new IllegalStateException(this Class
121:                            + "(): Invalid Token: " + se);
122:                }
123:
124:                init(token);
125:            }
126:
127:            /*
128:             * DSAMEConnection established per admin SSOToken and userDN. 
129:             * This method is similar to proxy admin authentication and used
130:             * in an authentication-less context.
131:             * 
132:             * @param token   admin SSOToken
133:             * @param userDN  user dn
134:             * @throws java.lang.IllegalStateException 
135:             */
136:            public DSAMEConnection(SSOToken token, String userDN)
137:                    throws IllegalStateException {
138:
139:                this (token);
140:                try {
141:                    user = connection.getUser(userDN);
142:                    if (logger.isLoggable(Level.FINEST)) {
143:                        logger.log(Level.FINEST, "PSSA_CSSC0060", userDN);
144:                    }
145:                } catch (SSOException se) {
146:                    throw new IllegalStateException(this Class
147:                            + ".DSAMEConnection()" + se);
148:                }
149:            }
150:
151:            /**
152:             * 
153:             * @param token 
154:             * @throws java.lang.IllegalStateException 
155:             */
156:            protected void init(SSOToken token) throws IllegalStateException {
157:                try {
158:                    String uid = token.getPrincipal().getName();
159:                    user = connection.getUser(uid);
160:
161:                    if (logger.isLoggable(Level.FINEST)) {
162:                        logger.log(Level.FINEST, "PSSA_CSSC0060", uid);
163:                    }
164:                } catch (SSOException se) {
165:                    throw new IllegalStateException(this Class + ".init()" + se);
166:                }
167:
168:            }
169:
170:            /**
171:             * 
172:             * @param token 
173:             * @return 
174:             */
175:            private static boolean isTokenValid(SSOToken token) {
176:                boolean valid = false;
177:
178:                try {
179:                    if (token != null) {
180:                        token.getPrincipal();
181:                        valid = true; // we didn't get any Exceptions
182:                    }
183:                } catch (SSOException ssoe) {
184:                    valid = false;
185:                }
186:
187:                return valid;
188:            }
189:
190:            /**
191:             * To get around DSAME bug #4619045
192:             * Lazy instantiation.
193:             */
194:            private static AMStoreConnection getAdminConnection() {
195:                if ((adminConnection == null) || (!isTokenValid(adminToken))) {
196:
197:                    try {
198:                        SSOTokenManager ssom = DSAMEConnection
199:                                .getSSOTokenManager();
200:                        adminToken = (SSOToken) AccessController
201:                                .doPrivileged(AdminTokenAction.getInstance());
202:                        adminConnection = new AMStoreConnection(adminToken);
203:                        sManager = new ServiceManager(adminToken); // to get schema ..
204:                    } catch (Exception e) {
205:                        logger.log(Level.SEVERE, "PSSA_CSSC0062", e);
206:                        throw new RuntimeException(this Class
207:                                + ".getAdminConnection(): " + e);
208:                    }
209:
210:                    if (logger.isLoggable(Level.FINEST)) {
211:                        logger.log(Level.FINEST, "PSSA_CSSC0061");
212:                    }
213:
214:                }
215:                return adminConnection;
216:            }
217:
218:            /**
219:             * 
220:             * @param srvcName 
221:             * @throws com.sun.identity.sm.SMSException 
222:             * @throws java.lang.IllegalStateException 
223:             * @return 
224:             */
225:            private ServiceSchemaManager getServiceSchemaManager(String srvcName)
226:                    throws SMSException, IllegalStateException {
227:                ServiceSchemaManager ssMngr = null;
228:
229:                try {
230:                    ssMngr = sManager.getSchemaManager(srvcName, VERSION);
231:                } catch (SSOException se) {
232:                    throw new IllegalStateException(this Class
233:                            + ".getServiceSchemaManager()" + se); // normally wont happen, since we are using adminToken
234:                }
235:
236:                if (logger.isLoggable(Level.FINEST)) {
237:                    logger.log(Level.FINEST, "PSSA_CSSC0063", srvcName);
238:                }
239:
240:                return ssMngr;
241:            }
242:
243:            /**
244:             * Gets USER/DYNAMIC attribute.
245:             * @return The attribute value in String format.  If property is
246:             * not not found, return null.  If DSAME returns multi-value,
247:             * warning is issued and only the first value is returned.
248:             * @param attributeName Name of the attribute to retrieve
249:             * @throws java.lang.IllegalStateException 
250:             * @throws java.io.IOException 
251:             */
252:            public String getStringAttribute(String attributeName)
253:                    throws IllegalStateException, IOException {
254:
255:                String val = null;
256:                Set vals = getAttribute(attributeName);
257:
258:                if (vals != null && vals.size() > 0) {
259:                    Iterator iter = vals.iterator();
260:                    val = (String) iter.next();
261:                }
262:
263:                return val;
264:            }
265:
266:            /**
267:             * Gets multi-valued USER/DYNAMIC attribute.
268:             * @return Set of String values.  If property is
269:             * not not found, return null.
270:             * @param attributeName Name of the attribute to retrieve
271:             * @throws java.lang.IllegalStateException 
272:             * @throws java.io.IOException 
273:             */
274:            public Set getAttribute(String attributeName)
275:                    throws IllegalStateException, IOException {
276:                Set vals = null;
277:
278:                if (logger.isLoggable(Level.FINEST)) {
279:                    logger.log(Level.FINEST, "PSSA_CSSC0064", attributeName);
280:                }
281:                try {
282:                    vals = user.getAttribute(attributeName);
283:                } catch (SSOException se) {
284:                    throw new IllegalStateException(this Class
285:                            + ".getAttributeMultiVal()" + se);
286:                } catch (AMException ae) {
287:                    throw new IOException(this Class + ".getAttributeMultiVal()"
288:                            + ae);
289:                }
290:
291:                return vals;
292:            }
293:
294:            /**
295:             * Sets USER/DYNAMIC attribute.
296:             * @param attributeName Name of the attribute to retrieve
297:             * @param val Value of the attribute
298:             * @throws java.lang.IllegalStateException 
299:             * @throws java.io.IOException 
300:             */
301:            public void setStringAttribute(String attributeName, String val)
302:                    throws IllegalStateException, IOException {
303:                if (logger.isLoggable(Level.FINEST)) {
304:                    String[] param = { attributeName, val };
305:                    logger.log(Level.FINEST, "PSSA_CSSC0065", param);
306:                }
307:
308:                try {
309:                    user.setStringAttribute(attributeName, val);
310:                    user.store();
311:                } catch (SSOException se) {
312:                    throw new IllegalStateException(this Class
313:                            + ".setAttribute(): " + "attributeName="
314:                            + attributeName);
315:                } catch (AMException ae) {
316:                    throw new IOException(this Class
317:                            + ".setAttribute(): Attr = " + attributeName
318:                            + " value = " + val + " Exception = " + ae);
319:                }
320:            }
321:
322:            /**
323:             * 
324:             * @param attributeName 
325:             * @param vals 
326:             * @throws java.lang.IllegalStateException 
327:             * @throws java.io.IOException 
328:             */
329:            public void setAttribute(String attributeName, Set vals)
330:                    throws IllegalStateException, IOException {
331:                Map map = new HashMap();
332:                map.put(attributeName, vals);
333:
334:                if (logger.isLoggable(Level.FINEST)) {
335:                    Iterator iter = vals.iterator();
336:                    String[] param = new String[2];
337:                    while (iter.hasNext()) {
338:                        param[0] = attributeName;
339:                        param[1] = (String) iter.next();
340:                        logger.log(Level.FINEST, "PSSA_CSSC0065", param);
341:                    }
342:                }
343:
344:                try {
345:                    user.setAttributes(map);
346:                    user.store();
347:                } catch (SSOException se) {
348:                    throw new IllegalStateException(this Class
349:                            + ".setAttribute(): " + "Attr = " + attributeName);
350:                } catch (AMException ae) {
351:                    throw new IOException(this Class
352:                            + ".setAttribute(): Attr = " + attributeName
353:                            + " :: value= " + vals + " Exception = " + ae);
354:                }
355:            }
356:
357:            /**
358:             * Gets ORGANIZATION attribute.  Internally this translates
359:             * to a template attribute set at the org. level that the current
360:             * user belongs to.
361:             * @param serviceName Name of the service
362:             * @param attributeName Name of the attribute to retrieve
363:             * @return The attribute value in String format.  If property is
364:             * not not found, return null.  If DSAME returns multi-value,
365:             * warning is issued and only the first value is returned.
366:             */
367:            public String getOrganizationStringAttribute(String serviceName,
368:                    String attributeName) throws IllegalStateException,
369:                    IOException {
370:                if (logger.isLoggable(Level.FINEST)) {
371:                    String[] param = { serviceName, attributeName, };
372:                    logger.log(Level.FINEST, "PSSA_CSSC0066", param);
373:                }
374:
375:                String val = null;
376:                Set vals = getOrganizationAttribute(serviceName, attributeName);
377:
378:                if (vals != null && vals.size() > 0) {
379:                    Iterator iter = vals.iterator();
380:                    val = (String) iter.next();
381:                }
382:
383:                return val;
384:            }
385:
386:            /**
387:             * 
388:             * @param serviceName 
389:             * @param attributeName 
390:             * @throws java.lang.IllegalStateException 
391:             * @throws java.io.IOException 
392:             * @return 
393:             */
394:            public Set getOrganizationAttribute(String serviceName,
395:                    String attributeName) throws IllegalStateException,
396:                    IOException {
397:                Set vals = null;
398:
399:                if (logger.isLoggable(Level.FINEST)) {
400:                    String[] param = { serviceName, attributeName, };
401:                    logger.log(Level.FINEST, "PSSA_CSSC0066", param);
402:                }
403:
404:                try {
405:                    String orgDN = null;
406:
407:                    orgDN = user.getOrganizationDN();
408:                    AMOrganization org = getAdminConnection().getOrganization(
409:                            orgDN);
410:                    if (org == null) {
411:                        return null;
412:                    }
413:
414:                    AMTemplate temp = org.getTemplate(serviceName,
415:                            AMTemplate.ORGANIZATION_TEMPLATE);
416:                    boolean tempExists = (temp != null) && temp.isExists();
417:                    if (!tempExists) {
418:                        return null;
419:                    }
420:
421:                    vals = temp.getAttribute(attributeName);
422:
423:                } catch (SSOException se) {
424:                    throw new IllegalStateException(this Class
425:                            + ".getOrganizationAttribute(): " + "serviceName="
426:                            + serviceName + se);
427:                } catch (AMException ae) {
428:                    throw new IOException(this Class
429:                            + ".getOrganizationAttribute(): " + "serviceName="
430:                            + serviceName + "+ attributeName=" + attributeName
431:                            + ae);
432:                }
433:
434:                return vals;
435:            }
436:
437:            /**
438:             * 
439:             * @param serviceName 
440:             * @param attributeName 
441:             * @throws java.io.IOException 
442:             * @return 
443:             */
444:            public String getGlobalStringAttribute(String serviceName,
445:                    String attributeName) throws IOException {
446:                if (logger.isLoggable(Level.FINEST)) {
447:                    String[] param = { serviceName, attributeName };
448:                    logger.log(Level.FINEST, "PSSA_CSSC0067", param);
449:                }
450:
451:                String val = null;
452:                Set vals = getGlobalAttribute(serviceName, attributeName);
453:
454:                if (vals != null && vals.size() > 0) {
455:                    Iterator iter = vals.iterator();
456:                    val = (String) iter.next();
457:                }
458:
459:                return val;
460:            }
461:
462:            /**
463:             * 
464:             * @param serviceName 
465:             * @param attributeName 
466:             * @throws java.io.IOException 
467:             * @return 
468:             */
469:            public Set getGlobalAttribute(String serviceName,
470:                    String attributeName) throws IOException {
471:                Set vals = null;
472:
473:                if (logger.isLoggable(Level.FINEST)) {
474:                    String[] param = { serviceName, attributeName };
475:                    logger.log(Level.FINEST, "PSSA_CSSC0067", param);
476:                }
477:
478:                try {
479:                    ServiceSchemaManager ssMngr = getServiceSchemaManager(serviceName);
480:                    ServiceSchema schema = ssMngr.getGlobalSchema();
481:
482:                    Map attrs = schema.getAttributeDefaults();
483:                    vals = (Set) attrs.get(attributeName);
484:                } catch (SMSException sme) {
485:                    throw new IOException(this Class
486:                            + ".getGlobalAttributes(): " + serviceName + ": "
487:                            + sme);
488:                }
489:
490:                return vals;
491:            }
492:
493:            /**
494:             * 
495:             * @param serviceName 
496:             * @param attributeName 
497:             * @param vals 
498:             * @throws java.io.IOException 
499:             */
500:            public void setGlobalAttribute(String serviceName,
501:                    String attributeName, Set vals) throws IOException {
502:                if (logger.isLoggable(Level.FINEST)) {
503:                    Iterator iter = vals.iterator();
504:                    String[] param = new String[3];
505:                    while (iter.hasNext()) {
506:                        param[0] = serviceName;
507:                        param[1] = attributeName;
508:                        param[2] = (String) iter.next();
509:                        logger.log(Level.FINEST, "PSSA_CSSC0068", param);
510:                    }
511:                }
512:
513:                try {
514:                    ServiceSchemaManager ssMngr = new ServiceSchemaManager(
515:                            userToken, serviceName, VERSION);
516:
517:                    ServiceSchema schema = ssMngr.getGlobalSchema();
518:                    schema.setAttributeDefaults(attributeName, vals);
519:                } catch (SMSException smse) {
520:                    throw new IOException(this Class + ".setGlobalAttribute(): "
521:                            + serviceName + "." + attributeName + " = " + vals
522:                            + smse);
523:                } catch (SSOException se) {
524:                    throw new IllegalStateException(this Class
525:                            + ".setGlobalAttribute()" + se);
526:                }
527:
528:            }
529:
530:            /**
531:             * 
532:             * @param serviceName 
533:             * @param attributeName 
534:             * @param vals 
535:             * @throws java.lang.IllegalStateException 
536:             * @throws java.io.IOException 
537:             */
538:            public void setOrganizationAttribute(String serviceName,
539:                    String attributeName, Set vals)
540:                    throws IllegalStateException, IOException {
541:                boolean noPerms = false;
542:                String msg = null;
543:
544:                Map map = new HashMap();
545:                map.put(attributeName, vals);
546:
547:                if (logger.isLoggable(Level.FINEST)) {
548:                    Iterator iter = vals.iterator();
549:                    String[] param = new String[3];
550:                    while (iter.hasNext()) {
551:                        param[0] = serviceName;
552:                        param[1] = attributeName;
553:                        param[2] = (String) iter.next();
554:                        logger.log(Level.FINEST, "PSSA_CSSC0069", param);
555:                    }
556:                }
557:
558:                try {
559:                    String orgDN = null;
560:
561:                    orgDN = user.getOrganizationDN();
562:
563:                    //
564:                    // Use the connection and not adminConnection
565:                    //
566:                    AMOrganization org = connection.getOrganization(orgDN);
567:
568:                    if (org == null) {
569:                        noPerms = true;
570:                        msg = "Insufficient Permission";
571:                    } else {
572:                        AMTemplate temp = org.getTemplate(serviceName,
573:                                AMTemplate.ORGANIZATION_TEMPLATE);
574:
575:                        boolean tempExists = (temp != null) && temp.isExists();
576:
577:                        if (!tempExists) {
578:                            noPerms = true;
579:                            msg = "Insufficient Permission";
580:                        } else {
581:                            temp.setAttributes(map);
582:                        }
583:                    }
584:
585:                } catch (SSOException se) {
586:                    throw new IllegalStateException(this Class
587:                            + ".getOrganizationAttribute(): " + "serviceName="
588:                            + serviceName + se);
589:                } catch (AMException ae) {
590:                    noPerms = true;
591:                    msg = ae.toString();
592:                }
593:
594:                if (noPerms) {
595:                    throw new IOException(this Class
596:                            + ".getOrganizationAttribute():: " + msg);
597:                }
598:            }
599:
600:            /**
601:             * 
602:             * @throws com.iplanet.sso.SSOException 
603:             * @return 
604:             */
605:            public static SSOTokenManager getSSOTokenManager()
606:                    throws SSOException {
607:                if (_tokenMgr == null) {
608:                    _tokenMgr = SSOTokenManager.getInstance();
609:                }
610:
611:                return _tokenMgr;
612:            }
613:
614:            /**
615:             * 
616:             * @param serviceName 
617:             * @throws com.sun.identity.sm.SMSException 
618:             * @return 
619:             */
620:            public Set getSchemaTypes(String serviceName) throws SMSException {
621:                ServiceSchemaManager ssMngr = getServiceSchemaManager(serviceName);
622:                return ssMngr.getSchemaTypes();
623:            }
624:
625:            /**
626:             * 
627:             * @param serviceName 
628:             * @param scope 
629:             * @throws com.sun.identity.sm.SMSException 
630:             * @return 
631:             */
632:            public ServiceSchema getSchema(String serviceName, SchemaType scope)
633:                    throws SMSException {
634:                ServiceSchemaManager ssMngr = getServiceSchemaManager(serviceName);
635:
636:                return ssMngr.getSchema(scope);
637:            }
638:
639:            /**
640:             * 
641:             * @param attrs 
642:             * @throws java.lang.IllegalStateException 
643:             * @throws java.io.IOException 
644:             */
645:            public void removeAttribute(Set attrs)
646:                    throws IllegalStateException, IOException {
647:                if (logger.isLoggable(Level.FINEST)) {
648:                    Iterator iter = attrs.iterator();
649:                    String[] param = new String[1];
650:                    while (iter.hasNext()) {
651:                        param[0] = (String) iter.next();
652:                        logger.log(Level.FINEST, "PSSA_CSSC0070", param);
653:                    }
654:                }
655:
656:                try {
657:                    user.removeAttributes(attrs);
658:                } catch (SSOException se) {
659:                    throw new IllegalStateException(this Class
660:                            + ".removeAttribute()" + se);
661:                } catch (AMException ae) {
662:                    throw new IOException(this Class + ".removeAttribute()" + ae);
663:                }
664:            }
665:
666:            /**
667:             * 
668:             * @param serviceName 
669:             * @param attrs 
670:             * @throws java.lang.IllegalStateException 
671:             * @throws java.io.IOException 
672:             */
673:            public void removeOrganizationAttribute(String serviceName,
674:                    Set attrs) throws IllegalStateException, IOException {
675:                boolean noPerms = false;
676:                String msg = null;
677:
678:                if (logger.isLoggable(Level.FINEST)) {
679:                    Iterator iter = attrs.iterator();
680:                    String[] param = new String[1];
681:                    while (iter.hasNext()) {
682:                        param[0] = serviceName;
683:                        param[1] = (String) iter.next();
684:                        logger.log(Level.FINEST, "PSSA_CSSC0071", param);
685:                    }
686:                }
687:
688:                try {
689:                    String orgDN = null;
690:
691:                    orgDN = user.getOrganizationDN();
692:
693:                    //
694:                    // Use the connection and not adminConnection
695:                    //
696:                    AMOrganization org = connection.getOrganization(orgDN);
697:
698:                    if (org == null) {
699:                        noPerms = true;
700:                        msg = "Insufficient Permission";
701:                    } else {
702:                        AMTemplate temp = org.getTemplate(serviceName,
703:                                AMTemplate.ORGANIZATION_TEMPLATE);
704:
705:                        boolean tempExists = (temp != null) && temp.isExists();
706:
707:                        if (!tempExists) {
708:                            noPerms = true;
709:                            msg = "Insufficient Permission";
710:                        } else {
711:                            temp.removeAttributes(attrs);
712:                        }
713:                    }
714:
715:                } catch (SSOException se) {
716:                    throw new IllegalStateException(this Class
717:                            + ".removeOrganizationAttribute(): "
718:                            + "serviceName=" + serviceName + se);
719:                } catch (AMException ae) {
720:                    noPerms = true;
721:                    msg = ae.toString();
722:                }
723:
724:                if (noPerms) {
725:                    throw new IOException(this Class
726:                            + ".removeOrganizationAttribute():: " + msg);
727:                }
728:            }
729:
730:            private Map getConfigsFromSet(Set values) {
731:                Map result = new HashMap();
732:                if (values == null)
733:                    return result;
734:                Iterator iter = values.iterator();
735:                while (iter.hasNext()) {
736:                    String configSt = (String) iter.next();
737:                    Configuration aConfig = new Configuration(configSt);
738:                    if (aConfig.getConfigurationName() != null) {
739:                        result.put(aConfig.getConfigurationName(), configSt);
740:                    }
741:                }
742:                return result;
743:            }
744:
745:            Set getMergedDynamicConfigurations(String serviceName,
746:                    String attributeName) throws IllegalStateException,
747:                    IOException {
748:                try {
749:                    Map result = new HashMap();
750:                    String orgDN = user.getOrganizationDN();
751:                    result.putAll(getMergedDynamicConfigurations(serviceName,
752:                            attributeName, orgDN));
753:                    result
754:                            .putAll(getConfigsFromSet(getAttribute(attributeName)));
755:                    return new HashSet(result.values());
756:                } catch (SSOException se) {
757:                    throw new IllegalStateException(this Class
758:                            + ".getDynamicAttribute(): " + "serviceName="
759:                            + serviceName + se);
760:                } catch (AMException ae) {
761:                    throw new IOException(this Class
762:                            + ".getDynamicAttribute(): " + "serviceName="
763:                            + serviceName + "+ attributeName=" + attributeName
764:                            + ae);
765:                }
766:
767:            }
768:
769:            private Map getMergedDynamicConfigurations(String serviceName,
770:                    String attributeName, String orgDN)
771:                    throws IllegalStateException, IOException {
772:                try {
773:                    Map result = new HashMap();
774:                    AMOrganization org = getAdminConnection().getOrganization(
775:                            orgDN);
776:                    String parentDN = org.getParentDN();
777:                    if (parentDN != null) {
778:                        result.putAll(getMergedDynamicConfigurations(
779:                                serviceName, attributeName, parentDN));
780:                    } else {
781:                        result
782:                                .putAll(getConfigsFromSet(getDefaultDynamicAttribute(
783:                                        serviceName, attributeName)));
784:                    }
785:                    result.putAll(getConfigsFromSet(getDynamicAttribute(
786:                            serviceName, attributeName, orgDN,
787:                            AMObject.ORGANIZATION)));
788:                    return result;
789:                } catch (SSOException se) {
790:                    throw new IllegalStateException(this Class
791:                            + ".getDynamicAttribute(): " + "serviceName="
792:                            + serviceName + se);
793:                } catch (Exception ae) {
794:                    throw new IOException(this Class
795:                            + ".getDynamicAttribute(): " + "serviceName="
796:                            + serviceName + "+ attributeName=" + attributeName
797:                            + ae);
798:                }
799:            }
800:
801:            private Set getDynamicAttribute(String serviceName,
802:                    String attributeName, String templateDN, int objType)
803:                    throws AMException, SSOException, Exception {
804:                Set values = null;
805:                AMTemplate template = getDynamicTemplate(serviceName,
806:                        templateDN, objType);
807:                if (template != null && template.isExists()) {
808:                    values = template.getAttribute(attributeName);
809:                }
810:                return values == null ? Collections.EMPTY_SET : values;
811:            }
812:
813:            private Set getDefaultDynamicAttribute(String serviceName,
814:                    String attributeName) throws SSOException, SMSException {
815:                Set values = null;
816:                ServiceSchemaManager svcMgr = getServiceSchemaManager(serviceName);
817:                ServiceSchema svcSchema = svcMgr.getDynamicSchema();
818:                Map attrs = svcSchema.getAttributeDefaults();
819:                values = (Set) attrs.get(attributeName);
820:
821:                return values == null ? Collections.EMPTY_SET : values;
822:            }
823:
824:            private AMTemplate getDynamicTemplate(String serviceName,
825:                    String templateDN, int objType) throws Exception {
826:                AMTemplate template = null;
827:                switch (objType) {
828:                case AMObject.ORGANIZATION:
829:                    AMOrganization org = getAdminConnection().getOrganization(
830:                            templateDN);
831:                    template = org.getTemplate(serviceName,
832:                            AMTemplate.DYNAMIC_TEMPLATE);
833:                    break;
834:                case AMObject.ROLE:
835:                    AMRole amrole = getAdminConnection().getRole(templateDN);
836:                    template = amrole.getTemplate(serviceName,
837:                            AMTemplate.DYNAMIC_TEMPLATE);
838:                    break;
839:                case AMObject.FILTERED_ROLE:
840:                    AMFilteredRole amFRole = getAdminConnection()
841:                            .getFilteredRole(templateDN);
842:                    template = amFRole.getTemplate(serviceName,
843:                            AMTemplate.DYNAMIC_TEMPLATE);
844:                    break;
845:                default:
846:                    logger.log(Level.SEVERE,
847:                            "Unable to determine type of AMObject");
848:                    throw new Exception("Unknown type: can not get template");
849:                }
850:                return template;
851:            }
852:
853:            private static class MyPrincipal implements  Principal {
854:                protected String name;
855:
856:                /**
857:                 * 
858:                 * @param name 
859:                 */
860:                public MyPrincipal(String name) {
861:                    this .name = new String(name);
862:                }
863:
864:                /**
865:                 * 
866:                 * @return 
867:                 */
868:                public String getName() {
869:                    return name;
870:                }
871:            }
872:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.