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


001:        /**
002:         * $Id: DSAMEAttributeOperations.java,v 1.14 2006/02/08 11:42:31 fo160993 Exp $
003:         * Copyright 2004 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.fabric.common;
014:
015:        import java.util.Set;
016:        import java.util.HashSet;
017:        import java.util.Map;
018:        import java.util.HashMap;
019:        import java.util.List;
020:        import java.util.ArrayList;
021:        import java.util.Map;
022:        import java.util.Collections;
023:        import java.util.Iterator;
024:
025:        import java.util.logging.Level;
026:        import java.util.logging.Logger;
027:        import com.sun.portal.log.common.PortalLogger;
028:
029:        import com.sun.portal.admin.server.AdminServerUtil;
030:
031:        import com.iplanet.sso.SSOToken;
032:        import com.iplanet.sso.SSOException;
033:        import com.iplanet.am.sdk.AMStoreConnection;
034:        import com.iplanet.am.sdk.AMObject;
035:        import com.iplanet.am.sdk.AMOrganization;
036:        import com.iplanet.am.sdk.AMUser;
037:        import com.iplanet.am.sdk.AMRole;
038:        import com.iplanet.am.sdk.AMFilteredRole;
039:        import com.iplanet.am.sdk.AMTemplate;
040:        import com.iplanet.am.sdk.AMException;
041:        import com.sun.identity.sm.ServiceSchemaManager;
042:        import com.sun.identity.sm.SMSException;
043:        import com.sun.identity.sm.ServiceSchema;
044:        import com.sun.identity.sm.AttributeSchema;
045:
046:        public class DSAMEAttributeOperations implements  AttributeOperations {
047:
048:            public static final String COS_PRIORITY_STRING = "priority";
049:
050:            //keys for extrainfo
051:            public static final String SCHEMA_TYPE = "type";
052:            public static final String DN = "dn";
053:            public static final String INHERIT = "inherit";
054:            public static final String ADD = "add";
055:            public static final String REMOVE = "remove";
056:
057:            //values for SCHEMA_TYPE key in extraInfo
058:            public static final int UNKNOWN = -1;
059:            public static final int GLOBAL = 0;
060:            public static final int ORG = 1;
061:
062:            protected SSOToken token = null;
063:            protected AMStoreConnection amsc = null;
064:
065:            private static Logger logger = PortalLogger
066:                    .getLogger(DSAMEAttributeOperations.class);
067:
068:            public DSAMEAttributeOperations(SSOToken token) throws Exception {
069:                this .token = token;
070:                try {
071:                    amsc = new AMStoreConnection(token);
072:                } catch (SSOException ssoe) {
073:                    logger.log(Level.SEVERE, "PSFB_CSPFCM0001", ssoe);
074:                    throw new Exception(ssoe.getMessage(), ssoe);
075:                }
076:            }
077:
078:            public List getAttribute(String serviceName, String attrName,
079:                    Map extraInfo) throws Exception {
080:                if (serviceName == null || serviceName.length() == 0
081:                        || attrName == null || attrName.length() == 0
082:                        || extraInfo == null) {
083:                    logger.log(Level.SEVERE, "PSFB_CSPFCM0002");
084:                    throw new Exception(
085:                            "Arguments passed are either null or empty");
086:                }
087:
088:                Set values = null;
089:
090:                int type = UNKNOWN;
091:                Integer t = (Integer) extraInfo.get(SCHEMA_TYPE);
092:                if (t != null) {
093:                    type = t.intValue();
094:                }
095:                String dn = (String) extraInfo.get(DN);
096:                try {
097:                    switch (type) {
098:                    case GLOBAL:
099:                        values = getGlobalAttribute(serviceName, attrName);
100:                        break;
101:                    case ORG:
102:                        if (dn == null) {
103:                            values = getDefaultOrgAttribute(serviceName,
104:                                    attrName);
105:                        } else {
106:                            values = getOrgAttribute(serviceName, attrName, dn);
107:                        }
108:                        break;
109:                    default:
110:                        if (dn == null) {
111:                            values = getDefaultDynamicAttribute(serviceName,
112:                                    attrName);
113:                        } else {
114:                            int objType = amsc.getAMObjectType(dn);
115:                            if (objType == AMObject.USER) {
116:                                values = getUserAttribute(attrName, dn);
117:                            } else {
118:                                values = getDynamicAttribute(serviceName,
119:                                        attrName, dn, objType);
120:                            }
121:                        }
122:                        break;
123:                    }
124:                } catch (AMException ame) {
125:                    logger.log(Level.INFO, "PSFB_CSPFCM0003", ame);
126:                    throw new Exception(ame.getMessage(), ame);
127:                } catch (SSOException ssoe) {
128:                    logger.log(Level.SEVERE, "PSFB_CSPFCM0003", ssoe);
129:                    throw new Exception(ssoe.getMessage(), ssoe);
130:                } catch (SMSException smse) {
131:                    logger.log(Level.SEVERE, "PSFB_CSPFCM0003", smse);
132:                    throw new Exception(smse.getMessage(), smse);
133:                }
134:
135:                logger.log(Level.FINEST, "PSFB_CSPFCM0004", new Object[] {
136:                        attrName, values });
137:                return values == null ? Collections.EMPTY_LIST : new ArrayList(
138:                        values);
139:            }
140:
141:            public Map getAttributes(String serviceName, Set names,
142:                    Map extraInfo) throws Exception {
143:                if (serviceName == null || serviceName.length() == 0
144:                        || names == null || names.size() == 0
145:                        || extraInfo == null) {
146:                    logger.log(Level.SEVERE, "PSFB_CSPFCM0005");
147:                    throw new Exception(
148:                            "Arguments passed are either null or empty");
149:                }
150:
151:                Map nameValues = null;
152:
153:                int type = UNKNOWN;
154:                Integer t = (Integer) extraInfo.get(SCHEMA_TYPE);
155:                if (t != null) {
156:                    type = t.intValue();
157:                }
158:                String dn = (String) extraInfo.get(DN);
159:                try {
160:                    switch (type) {
161:                    case GLOBAL:
162:                        nameValues = getGlobalAttributes(serviceName, names);
163:                        break;
164:                    case ORG:
165:                        if (dn == null) {
166:                            nameValues = getDefaultOrgAttributes(serviceName,
167:                                    names);
168:                        } else {
169:                            nameValues = getOrgAttributes(serviceName, names,
170:                                    dn);
171:                        }
172:                        break;
173:                    default:
174:                        if (dn == null) {
175:                            nameValues = getDefaultDynamicAttributes(
176:                                    serviceName, names);
177:                        } else {
178:                            int objType = amsc.getAMObjectType(dn);
179:                            if (objType == AMObject.USER) {
180:                                nameValues = getUserAttributes(names, dn);
181:                            } else {
182:                                nameValues = getDynamicAttributes(serviceName,
183:                                        names, dn, objType);
184:                            }
185:                        }
186:                        break;
187:                    }
188:                } catch (AMException ame) {
189:                    logger.log(Level.INFO, "PSFB_CSPFCM0006", ame);
190:                    throw new Exception(ame.getMessage(), ame);
191:                } catch (SSOException ssoe) {
192:                    logger.log(Level.SEVERE, "PSFB_CSPFCM0006", ssoe);
193:                    throw new Exception(ssoe.getMessage(), ssoe);
194:                } catch (SMSException smse) {
195:                    logger.log(Level.SEVERE, "PSFB_CSPFCM0006", smse);
196:                    throw new Exception(smse.getMessage(), smse);
197:                }
198:
199:                //return map contains name-value pairs, where value is a List object
200:                Map returnMap = new HashMap(names.size());
201:
202:                //convert return value from Set to List
203:                Iterator iter = names.iterator();
204:                while (iter.hasNext()) {
205:                    String name = (String) iter.next();
206:                    Set values = (Set) nameValues.get(name);
207:                    if (values != null) {
208:                        List listValue = new ArrayList(values);
209:                        returnMap.put(name, listValue);
210:                    } else {
211:                        logger.log(Level.FINEST, "PSFB_CSPFCM0007", name);
212:                    }
213:                }
214:
215:                logger.log(Level.FINEST, "PSFB_CSPFCM0008", returnMap);
216:                return returnMap;
217:            }
218:
219:            public void setAttribute(String serviceName, String attrName,
220:                    List valuesList, Map extraInfo) throws Exception {
221:                if (serviceName == null || serviceName.length() == 0
222:                        || attrName == null || attrName.length() == 0
223:                        || valuesList == null || extraInfo == null) {
224:                    logger.log(Level.SEVERE, "PSFB_CSPFCM0009");
225:                    throw new Exception(
226:                            "Arguments passed are either null or empty");
227:                }
228:
229:                Set values = new HashSet(valuesList);
230:
231:                int type = UNKNOWN;
232:                Integer t = (Integer) extraInfo.get(SCHEMA_TYPE);
233:                if (t != null) {
234:                    type = t.intValue();
235:                }
236:                String dn = (String) extraInfo.get(DN);
237:                Set addValues = (Set) extraInfo.get(ADD);
238:                Set removeValues = (Set) extraInfo.get(REMOVE);
239:                boolean inherit = ((Boolean) extraInfo.get(INHERIT))
240:                        .booleanValue();
241:                try {
242:                    switch (type) {
243:                    case GLOBAL:
244:                        if (addValues != null && removeValues != null) {
245:                            addGlobalAttributeValue(serviceName, attrName,
246:                                    addValues);
247:                            removeGlobalAttributeValue(serviceName, attrName,
248:                                    removeValues);
249:                        } else if (removeValues != null) {
250:                            removeGlobalAttributeValue(serviceName, attrName,
251:                                    removeValues);
252:                        } else if (addValues != null) {
253:                            addGlobalAttributeValue(serviceName, attrName,
254:                                    addValues);
255:                        } else {
256:                            setGlobalAttribute(serviceName, attrName, values);
257:                        }
258:                        break;
259:                    case ORG:
260:                        if (dn == null) {
261:                            if (addValues != null && removeValues != null) {
262:                                addDefaultOrgAttributeValue(serviceName,
263:                                        attrName, addValues);
264:                                removeDefaultOrgAttributeValue(serviceName,
265:                                        attrName, removeValues);
266:                            } else if (removeValues != null) {
267:                                removeDefaultOrgAttributeValue(serviceName,
268:                                        attrName, removeValues);
269:                            } else if (addValues != null) {
270:                                addDefaultOrgAttributeValue(serviceName,
271:                                        attrName, addValues);
272:                            } else {
273:                                setDefaultOrgAttribute(serviceName, attrName,
274:                                        values);
275:                            }
276:                        } else {
277:                            if (addValues != null && removeValues != null) {
278:                                addOrgAttributeValue(serviceName, attrName,
279:                                        addValues, dn);
280:                                removeOrgAttributeValue(serviceName, attrName,
281:                                        removeValues, dn);
282:                            } else if (removeValues != null) {
283:                                removeOrgAttributeValue(serviceName, attrName,
284:                                        removeValues, dn);
285:                            } else if (addValues != null) {
286:                                addOrgAttributeValue(serviceName, attrName,
287:                                        addValues, dn);
288:                            } else if (inherit) {
289:                                throw new Exception("Unsupported operation: "
290:                                        + "supported only on user dn");
291:                            } else {
292:                                setOrgAttribute(serviceName, attrName, values,
293:                                        dn);
294:                            }
295:                        }
296:                        break;
297:                    default:
298:                        if (dn == null) {
299:                            if (addValues != null && removeValues != null) {
300:                                addDefaultDynamicAttributeValue(serviceName,
301:                                        attrName, addValues);
302:                                removeDefaultDynamicAttributeValue(serviceName,
303:                                        attrName, removeValues);
304:                            } else if (removeValues != null) {
305:                                removeDefaultDynamicAttributeValue(serviceName,
306:                                        attrName, removeValues);
307:                            } else if (addValues != null) {
308:                                addDefaultDynamicAttributeValue(serviceName,
309:                                        attrName, addValues);
310:                            } else {
311:                                setDefaultDynamicAttribute(serviceName,
312:                                        attrName, values);
313:                            }
314:                        } else {
315:                            int objType = amsc.getAMObjectType(dn);
316:                            if (objType == AMObject.USER) {
317:                                if (addValues != null && removeValues != null) {
318:                                    addUserAttributeValue(attrName, addValues,
319:                                            dn);
320:                                    removeUserAttributeValue(attrName,
321:                                            removeValues, dn);
322:                                } else if (removeValues != null) {
323:                                    removeUserAttributeValue(attrName,
324:                                            removeValues, dn);
325:                                } else if (addValues != null) {
326:                                    addUserAttributeValue(attrName, addValues,
327:                                            dn);
328:                                } else if (inherit) {
329:                                    inherit(attrName, dn);
330:                                } else {
331:                                    setUserAttribute(attrName, values, dn);
332:                                }
333:                            } else {
334:                                if (addValues != null && removeValues != null) {
335:                                    addDynamicAttributeValue(serviceName,
336:                                            attrName, addValues, dn, objType);
337:                                    removeDynamicAttributeValue(serviceName,
338:                                            attrName, removeValues, dn, objType);
339:                                } else if (removeValues != null) {
340:                                    removeDynamicAttributeValue(serviceName,
341:                                            attrName, removeValues, dn, objType);
342:                                } else if (addValues != null) {
343:                                    addDynamicAttributeValue(serviceName,
344:                                            attrName, addValues, dn, objType);
345:                                } else if (inherit) {
346:                                    throw new Exception(
347:                                            "Unsupported operation: "
348:                                                    + "supported only on user dn");
349:                                } else {
350:                                    setDynamicAttribute(serviceName, attrName,
351:                                            values, dn, objType);
352:                                }
353:                            }
354:                        }
355:                        break;
356:                    }
357:                } catch (AMException ame) {
358:                    logger.log(Level.SEVERE, "PSFB_CSPFCM0010", ame);
359:                    throw new Exception(ame.getMessage(), ame);
360:                } catch (SSOException ssoe) {
361:                    logger.log(Level.SEVERE, "PSFB_CSPFCM0010", ssoe);
362:                    throw new Exception(ssoe.getMessage(), ssoe);
363:                } catch (SMSException smse) {
364:                    logger.log(Level.SEVERE, "PSFB_CSPFCM0010", smse);
365:                    throw new Exception(smse.getMessage(), smse);
366:                }
367:            }
368:
369:            public void setAttributes(String serviceName, Map values,
370:                    Map extraInfo) throws Exception {
371:                if (serviceName == null || serviceName.length() == 0
372:                        || values == null || values.size() == 0
373:                        || extraInfo == null) {
374:                    logger.log(Level.SEVERE, "PSFB_CSPFCM0009");
375:                    throw new Exception(
376:                            "Arguments passed are either null or empty");
377:                }
378:
379:                //values is a name-value map with value as a List object
380:                //dsame needs value to be a Set object
381:                //so first convert it to name-Set pairs
382:                Map nameValues = new HashMap(values.size());
383:                Iterator iter = values.keySet().iterator();
384:                while (iter.hasNext()) {
385:                    String name = (String) iter.next();
386:                    nameValues.put(name, new HashSet((List) values.get(name)));
387:                }
388:
389:                int type = UNKNOWN;
390:                Integer t = (Integer) extraInfo.get(SCHEMA_TYPE);
391:                if (t != null) {
392:                    type = t.intValue();
393:                }
394:                String dn = (String) extraInfo.get(DN);
395:                try {
396:                    switch (type) {
397:                    case GLOBAL:
398:                        setGlobalAttributes(serviceName, nameValues);
399:                        break;
400:                    case ORG:
401:                        if (dn == null) {
402:                            setDefaultOrgAttributes(serviceName, nameValues);
403:                        } else {
404:                            setOrgAttributes(serviceName, nameValues, dn);
405:                        }
406:                        break;
407:                    default:
408:                        if (dn == null) {
409:                            setDefaultDynamicAttributes(serviceName, nameValues);
410:                        } else {
411:                            int objType = amsc.getAMObjectType(dn);
412:                            if (objType == AMObject.USER) {
413:                                setUserAttributes(nameValues, dn);
414:                            } else {
415:                                setDynamicAttributes(serviceName, nameValues,
416:                                        dn, objType);
417:                            }
418:                        }
419:                        break;
420:                    }
421:                } catch (AMException ame) {
422:                    logger.log(Level.SEVERE, "PSFB_CSPFCM0011", ame);
423:                    throw new Exception(ame.getMessage(), ame);
424:                } catch (SSOException ssoe) {
425:                    logger.log(Level.SEVERE, "PSFB_CSPFCM0011", ssoe);
426:                    throw new Exception(ssoe.getMessage(), ssoe);
427:                } catch (SMSException smse) {
428:                    logger.log(Level.SEVERE, "PSFB_CSPFCM0011", smse);
429:                    throw new Exception(smse.getMessage(), smse);
430:                }
431:            }
432:
433:            public Map listAttributes(String serviceName, Map extraInfo) {
434:                logger.log(Level.INFO, "PSFB_CSPFCM0012");
435:                return Collections.EMPTY_MAP;
436:            }
437:
438:            ////////////////////////////////////////
439:            // Getters
440:            ////////////////////////////////////////
441:            protected Set getGlobalAttribute(String serviceName,
442:                    String attributeName) throws SSOException, SMSException {
443:                Set values = null;
444:                ServiceSchemaManager svcMgr = new ServiceSchemaManager(
445:                        serviceName, token);
446:                ServiceSchema svcSchema = svcMgr.getGlobalSchema();
447:                Map attrs = svcSchema.getAttributeDefaults();
448:                values = (Set) attrs.get(attributeName);
449:
450:                return values == null ? Collections.EMPTY_SET : values;
451:            }
452:
453:            protected Map getGlobalAttributes(String serviceName, Set names)
454:                    throws SSOException, SMSException {
455:                ServiceSchemaManager svcMgr = new ServiceSchemaManager(
456:                        serviceName, token);
457:                ServiceSchema svcSchema = svcMgr.getGlobalSchema();
458:                Map attrs = svcSchema.getAttributeDefaults();
459:                //remove the unwanted attrs
460:                if (attrs != null && !attrs.isEmpty()) {
461:                    Set keys = attrs.keySet();
462:                    Iterator iter = keys.iterator();
463:                    while (iter.hasNext()) {
464:                        Object obj = iter.next();
465:                        if (!names.contains(obj)) {
466:                            iter.remove();
467:                        }
468:                    }
469:                }
470:                return attrs == null ? Collections.EMPTY_MAP : attrs;
471:            }
472:
473:            protected Set getDefaultOrgAttribute(String serviceName,
474:                    String attributeName) throws SSOException, SMSException {
475:                Set values = null;
476:                ServiceSchemaManager svcMgr = new ServiceSchemaManager(
477:                        serviceName, token);
478:                ServiceSchema svcSchema = svcMgr.getOrganizationSchema();
479:                Map attrs = svcSchema.getAttributeDefaults();
480:                values = (Set) attrs.get(attributeName);
481:
482:                return values == null ? Collections.EMPTY_SET : values;
483:            }
484:
485:            protected Map getDefaultOrgAttributes(String serviceName, Set names)
486:                    throws SSOException, SMSException {
487:                ServiceSchemaManager svcMgr = new ServiceSchemaManager(
488:                        serviceName, token);
489:                ServiceSchema svcSchema = svcMgr.getOrganizationSchema();
490:                Map attrs = svcSchema.getAttributeDefaults();
491:                //remove the unwanted attrs
492:                if (attrs != null && !attrs.isEmpty()) {
493:                    Set keys = attrs.keySet();
494:                    Iterator iter = keys.iterator();
495:                    while (iter.hasNext()) {
496:                        Object obj = iter.next();
497:                        if (!names.contains(obj)) {
498:                            iter.remove();
499:                        }
500:                    }
501:                }
502:                return attrs == null ? Collections.EMPTY_MAP : attrs;
503:            }
504:
505:            protected Set getOrgAttribute(String serviceName,
506:                    String attributeName, String orgDN) throws AMException,
507:                    SSOException {
508:                Set values = null;
509:                AMOrganization org = amsc.getOrganization(orgDN);
510:                AMTemplate template = org.getTemplate(serviceName,
511:                        AMTemplate.ORGANIZATION_TEMPLATE);
512:                values = template.getAttribute(attributeName);
513:
514:                return values == null ? Collections.EMPTY_SET : values;
515:            }
516:
517:            protected Map getOrgAttributes(String serviceName, Set names,
518:                    String orgDN) throws AMException, SSOException {
519:                AMOrganization org = amsc.getOrganization(orgDN);
520:                AMTemplate template = org.getTemplate(serviceName,
521:                        AMTemplate.ORGANIZATION_TEMPLATE);
522:                Map nameValues = template.getAttributes(names);
523:
524:                return nameValues == null ? Collections.EMPTY_MAP : nameValues;
525:            }
526:
527:            protected Set getDefaultDynamicAttribute(String serviceName,
528:                    String attributeName) throws SSOException, SMSException {
529:                Set values = null;
530:                ServiceSchemaManager svcMgr = new ServiceSchemaManager(
531:                        serviceName, token);
532:                ServiceSchema svcSchema = svcMgr.getDynamicSchema();
533:                Map attrs = svcSchema.getAttributeDefaults();
534:                values = (Set) attrs.get(attributeName);
535:
536:                return values == null ? Collections.EMPTY_SET : values;
537:            }
538:
539:            protected Map getDefaultDynamicAttributes(String serviceName,
540:                    Set names) throws SSOException, SMSException {
541:                ServiceSchemaManager svcMgr = new ServiceSchemaManager(
542:                        serviceName, token);
543:                ServiceSchema svcSchema = svcMgr.getDynamicSchema();
544:                Map attrs = svcSchema.getAttributeDefaults();
545:                //remove the unwanted attrs
546:                if (attrs != null && !attrs.isEmpty()) {
547:                    Set keys = attrs.keySet();
548:                    Iterator iter = keys.iterator();
549:                    while (iter.hasNext()) {
550:                        Object obj = iter.next();
551:                        if (!names.contains(obj)) {
552:                            iter.remove();
553:                        }
554:                    }
555:                }
556:                return attrs == null ? Collections.EMPTY_MAP : attrs;
557:            }
558:
559:            protected Set getDynamicAttribute(String serviceName,
560:                    String attributeName, String templateDN, int objType)
561:                    throws AMException, SSOException, Exception {
562:                Set values = null;
563:                AMTemplate template = getTemplate(serviceName, templateDN,
564:                        objType);
565:                if (template != null && template.isExists()) {
566:                    if (COS_PRIORITY_STRING.equals(attributeName)) {
567:                        values = new HashSet();
568:                        values.add(new Integer(template.getPriority()));
569:                    } else {
570:                        values = template.getAttribute(attributeName);
571:                    }
572:                }
573:
574:                return values == null ? Collections.EMPTY_SET : values;
575:            }
576:
577:            protected Map getDynamicAttributes(String serviceName, Set names,
578:                    String templateDN, int objType) throws AMException,
579:                    SSOException, Exception {
580:                Map nameValues = null;
581:                AMTemplate template = getTemplate(serviceName, templateDN,
582:                        objType);
583:                if (template != null && template.isExists()) {
584:                    boolean getPriority = false;
585:                    if (names.contains(COS_PRIORITY_STRING)) {
586:                        getPriority = true;
587:                        names.remove(COS_PRIORITY_STRING);
588:                    }
589:                    nameValues = template.getAttributes(names);
590:                    if (getPriority) {
591:                        if (nameValues.isEmpty()) {
592:                            //we do not know if amsdk returns an EMPTY_MAP
593:                            //which will be immutable. So create new
594:                            nameValues = new HashMap(1);
595:                        }
596:                        Set values = new HashSet();
597:                        values.add(new Integer(template.getPriority()));
598:                        nameValues.put(COS_PRIORITY_STRING, values);
599:                        names.add(COS_PRIORITY_STRING);
600:                    }
601:                }
602:
603:                return nameValues == null ? Collections.EMPTY_MAP : nameValues;
604:            }
605:
606:            protected Set getUserAttribute(String attributeName, String userDN)
607:                    throws AMException, SSOException {
608:                Set values = null;
609:                AMUser user = amsc.getUser(userDN);
610:                values = user.getAttribute(attributeName);
611:
612:                return values == null ? Collections.EMPTY_SET : values;
613:            }
614:
615:            protected Map getUserAttributes(Set names, String userDN)
616:                    throws AMException, SSOException {
617:                Map nameValues = null;
618:                AMUser user = amsc.getUser(userDN);
619:                nameValues = user.getAttributes(names);
620:
621:                return nameValues == null ? Collections.EMPTY_MAP : nameValues;
622:            }
623:
624:            ////////////////////////////////////////
625:            // Setters
626:            ///////////////////////////////////////
627:            protected void setGlobalAttribute(String serviceName,
628:                    String attributeName, Set values) throws SSOException,
629:                    SMSException {
630:                ServiceSchemaManager svcMgr = new ServiceSchemaManager(
631:                        serviceName, token);
632:                ServiceSchema svcSchema = svcMgr.getGlobalSchema();
633:                AttributeSchema attrSchema = svcSchema
634:                        .getAttributeSchema(attributeName);
635:                attrSchema.setDefaultValues(values);
636:            }
637:
638:            protected void setGlobalAttributes(String serviceName,
639:                    Map nameValues) throws SSOException, SMSException {
640:                ServiceSchemaManager svcMgr = new ServiceSchemaManager(
641:                        serviceName, token);
642:                ServiceSchema svcSchema = svcMgr.getGlobalSchema();
643:                svcSchema.setAttributeDefaults(nameValues);
644:            }
645:
646:            protected void addGlobalAttributeValue(String serviceName,
647:                    String attributeName, Set values) throws SSOException,
648:                    SMSException {
649:                ServiceSchemaManager svcMgr = new ServiceSchemaManager(
650:                        serviceName, token);
651:                ServiceSchema svcSchema = svcMgr.getGlobalSchema();
652:                AttributeSchema attrSchema = svcSchema
653:                        .getAttributeSchema(attributeName);
654:                Iterator iter = values.iterator();
655:                while (iter.hasNext()) {
656:                    attrSchema.addDefaultValue((String) iter.next());
657:                }
658:            }
659:
660:            protected void removeGlobalAttributeValue(String serviceName,
661:                    String attributeName, Set values) throws SSOException,
662:                    SMSException {
663:                ServiceSchemaManager svcMgr = new ServiceSchemaManager(
664:                        serviceName, token);
665:                ServiceSchema svcSchema = svcMgr.getGlobalSchema();
666:                AttributeSchema attrSchema = svcSchema
667:                        .getAttributeSchema(attributeName);
668:                Iterator iter = values.iterator();
669:                while (iter.hasNext()) {
670:                    attrSchema.removeDefaultValue((String) iter.next());
671:                }
672:            }
673:
674:            protected void setDefaultOrgAttribute(String serviceName,
675:                    String attributeName, Set values) throws SSOException,
676:                    SMSException {
677:                ServiceSchemaManager svcMgr = new ServiceSchemaManager(
678:                        serviceName, token);
679:                ServiceSchema svcSchema = svcMgr.getOrganizationSchema();
680:                AttributeSchema attrSchema = svcSchema
681:                        .getAttributeSchema(attributeName);
682:                attrSchema.setDefaultValues(values);
683:            }
684:
685:            protected void setDefaultOrgAttributes(String serviceName,
686:                    Map nameValues) throws SSOException, SMSException {
687:                ServiceSchemaManager svcMgr = new ServiceSchemaManager(
688:                        serviceName, token);
689:                ServiceSchema svcSchema = svcMgr.getOrganizationSchema();
690:                svcSchema.setAttributeDefaults(nameValues);
691:            }
692:
693:            protected void addDefaultOrgAttributeValue(String serviceName,
694:                    String attributeName, Set values) throws SSOException,
695:                    SMSException {
696:                ServiceSchemaManager svcMgr = new ServiceSchemaManager(
697:                        serviceName, token);
698:                ServiceSchema svcSchema = svcMgr.getOrganizationSchema();
699:                AttributeSchema attrSchema = svcSchema
700:                        .getAttributeSchema(attributeName);
701:                Iterator iter = values.iterator();
702:                while (iter.hasNext()) {
703:                    attrSchema.addDefaultValue((String) iter.next());
704:                }
705:            }
706:
707:            protected void removeDefaultOrgAttributeValue(String serviceName,
708:                    String attributeName, Set values) throws SSOException,
709:                    SMSException {
710:                ServiceSchemaManager svcMgr = new ServiceSchemaManager(
711:                        serviceName, token);
712:                ServiceSchema svcSchema = svcMgr.getOrganizationSchema();
713:                AttributeSchema attrSchema = svcSchema
714:                        .getAttributeSchema(attributeName);
715:                Iterator iter = values.iterator();
716:                while (iter.hasNext()) {
717:                    attrSchema.removeDefaultValue((String) iter.next());
718:                }
719:            }
720:
721:            protected void setOrgAttribute(String serviceName,
722:                    String attributeName, Set values, String orgDN)
723:                    throws SSOException, AMException {
724:                AMOrganization org = amsc.getOrganization(orgDN);
725:                AMTemplate template = org.getTemplate(serviceName,
726:                        AMTemplate.ORGANIZATION_TEMPLATE);
727:                Map map = new HashMap();
728:                map.put(attributeName, values);
729:                template.setAttributes(map);
730:                template.store();
731:            }
732:
733:            protected void setOrgAttributes(String serviceName, Map nameValues,
734:                    String orgDN) throws SSOException, AMException {
735:                AMOrganization org = amsc.getOrganization(orgDN);
736:                AMTemplate template = org.getTemplate(serviceName,
737:                        AMTemplate.ORGANIZATION_TEMPLATE);
738:                template.setAttributes(nameValues);
739:                template.store();
740:            }
741:
742:            protected void addOrgAttributeValue(String serviceName,
743:                    String attributeName, Set values, String orgDN)
744:                    throws SSOException, AMException {
745:                Set oldValues = getOrgAttribute(serviceName, attributeName,
746:                        orgDN);
747:                values.addAll(oldValues);
748:                setOrgAttribute(serviceName, attributeName, values, orgDN);
749:            }
750:
751:            protected void removeOrgAttributeValue(String serviceName,
752:                    String attributeName, Set values, String orgDN)
753:                    throws SSOException, AMException {
754:                Set oldValues = getOrgAttribute(serviceName, attributeName,
755:                        orgDN);
756:                oldValues.removeAll(values);
757:                setOrgAttribute(serviceName, attributeName, oldValues, orgDN);
758:            }
759:
760:            protected void setDefaultDynamicAttribute(String serviceName,
761:                    String attributeName, Set values) throws SMSException,
762:                    SSOException {
763:                ServiceSchemaManager svcMgr = new ServiceSchemaManager(
764:                        serviceName, token);
765:                ServiceSchema svcSchema = svcMgr.getDynamicSchema();
766:                AttributeSchema attrSchema = svcSchema
767:                        .getAttributeSchema(attributeName);
768:                attrSchema.setDefaultValues(values);
769:            }
770:
771:            protected void setDefaultDynamicAttributes(String serviceName,
772:                    Map nameValues) throws SMSException, SSOException {
773:                ServiceSchemaManager svcMgr = new ServiceSchemaManager(
774:                        serviceName, token);
775:                ServiceSchema svcSchema = svcMgr.getDynamicSchema();
776:                svcSchema.setAttributeDefaults(nameValues);
777:            }
778:
779:            protected void addDefaultDynamicAttributeValue(String serviceName,
780:                    String attributeName, Set values) throws SMSException,
781:                    SSOException {
782:                ServiceSchemaManager svcMgr = new ServiceSchemaManager(
783:                        serviceName, token);
784:                ServiceSchema svcSchema = svcMgr.getDynamicSchema();
785:                AttributeSchema attrSchema = svcSchema
786:                        .getAttributeSchema(attributeName);
787:                Iterator iter = values.iterator();
788:                while (iter.hasNext()) {
789:                    attrSchema.addDefaultValue((String) iter.next());
790:                }
791:            }
792:
793:            protected void removeDefaultDynamicAttributeValue(
794:                    String serviceName, String attributeName, Set values)
795:                    throws SMSException, SSOException {
796:                ServiceSchemaManager svcMgr = new ServiceSchemaManager(
797:                        serviceName, token);
798:                ServiceSchema svcSchema = svcMgr.getDynamicSchema();
799:                AttributeSchema attrSchema = svcSchema
800:                        .getAttributeSchema(attributeName);
801:                Iterator iter = values.iterator();
802:                while (iter.hasNext()) {
803:                    attrSchema.removeDefaultValue((String) iter.next());
804:                }
805:            }
806:
807:            protected void setDynamicAttribute(String serviceName,
808:                    String attributeName, Set values, String templateDN,
809:                    int objType) throws SSOException, AMException, Exception {
810:                Map map = new HashMap();
811:                boolean setPriority = false;
812:                if (COS_PRIORITY_STRING.equals(attributeName)) {
813:                    setPriority = true;
814:                } else {
815:                    map.put(attributeName, values);
816:                }
817:                AMTemplate template = getTemplate(serviceName, templateDN,
818:                        objType);
819:                if (template != null && template.isExists()) {
820:                    if (setPriority && !values.isEmpty()) {
821:                        String pStr = (String) values.iterator().next();
822:                        int pri = AMTemplate.UNDEFINED_PRIORITY;
823:                        try {
824:                            pri = Integer.parseInt(pStr);
825:                        } catch (NumberFormatException nfe) {
826:                            throw new Exception(nfe);
827:                        }
828:                        if (pri >= 0 && pri <= 6) {
829:                            template.setPriority(pri);
830:                        } else {
831:                            logger.log(Level.SEVERE, "PSFB_CSPFCM0013");
832:                            throw new Exception(
833:                                    "Incorrect priority value. Not between 0 and 6.");
834:                        }
835:                    } else {
836:                        template.setAttributes(map);
837:                    }
838:                    template.store();
839:                }
840:            }
841:
842:            private AMTemplate getTemplate(String serviceName,
843:                    String templateDN, int objType) throws Exception {
844:                AMTemplate template = null;
845:                switch (objType) {
846:                case AMObject.ORGANIZATION:
847:                    AMOrganization org = amsc.getOrganization(templateDN);
848:                    template = org.getTemplate(serviceName,
849:                            AMTemplate.DYNAMIC_TEMPLATE);
850:                    if (!template.isExists()) {
851:                        org.createTemplate(AMTemplate.DYNAMIC_TEMPLATE,
852:                                serviceName, null);
853:                    }
854:                    break;
855:                case AMObject.ROLE:
856:                    AMRole amrole = amsc.getRole(templateDN);
857:                    template = amrole.getTemplate(serviceName,
858:                            AMTemplate.DYNAMIC_TEMPLATE);
859:                    if (!template.isExists()) {
860:                        amrole.createTemplate(AMTemplate.DYNAMIC_TEMPLATE,
861:                                serviceName, null);
862:                    }
863:                    break;
864:                case AMObject.FILTERED_ROLE:
865:                    AMFilteredRole amFRole = amsc.getFilteredRole(templateDN);
866:                    template = amFRole.getTemplate(serviceName,
867:                            AMTemplate.DYNAMIC_TEMPLATE);
868:                    if (!template.isExists()) {
869:                        amFRole.createTemplate(AMTemplate.DYNAMIC_TEMPLATE,
870:                                serviceName, null);
871:                    }
872:                    break;
873:                default:
874:                    logger.log(Level.SEVERE, "PSFB_CSPFCM0014");
875:                    throw new Exception("Unknown node.");
876:                }
877:                return template;
878:            }
879:
880:            protected void setDynamicAttributes(String serviceName,
881:                    Map nameValues, String templateDN, int objType)
882:                    throws SSOException, AMException, Exception {
883:                boolean setPriority = false;
884:                Set values = Collections.EMPTY_SET;
885:                if (nameValues.containsKey(COS_PRIORITY_STRING)) {
886:                    setPriority = true;
887:                    values = (Set) nameValues.remove(COS_PRIORITY_STRING);
888:                }
889:                AMTemplate template = getTemplate(serviceName, templateDN,
890:                        objType);
891:                if (template != null && template.isExists()) {
892:                    if (setPriority && !values.isEmpty()) {
893:                        String pStr = (String) values.iterator().next();
894:                        int pri = AMTemplate.UNDEFINED_PRIORITY;
895:                        try {
896:                            pri = Integer.parseInt(pStr);
897:                        } catch (NumberFormatException nfe) {
898:                            throw new Exception(nfe);
899:                        }
900:                        if (pri >= 0 && pri <= 6) {
901:                            template.setPriority(pri);
902:                        } else {
903:                            logger.log(Level.FINE, "PSFB_CSPFCM0015");
904:                        }
905:                    }
906:                    if (!nameValues.isEmpty()) {
907:                        template.setAttributes(nameValues);
908:                    }
909:                    template.store();
910:                }
911:            }
912:
913:            protected void addDynamicAttributeValue(String serviceName,
914:                    String attributeName, Set values, String templateDN,
915:                    int objType) throws SSOException, AMException, Exception {
916:                Set oldValues = getDynamicAttribute(serviceName, attributeName,
917:                        templateDN, objType);
918:                values.addAll(oldValues);
919:                setDynamicAttribute(serviceName, attributeName, values,
920:                        templateDN, objType);
921:            }
922:
923:            protected void removeDynamicAttributeValue(String serviceName,
924:                    String attributeName, Set values, String templateDN,
925:                    int objType) throws SSOException, AMException, Exception {
926:                Set oldValues = getDynamicAttribute(serviceName, attributeName,
927:                        templateDN, objType);
928:                oldValues.removeAll(values);
929:                setDynamicAttribute(serviceName, attributeName, oldValues,
930:                        templateDN, objType);
931:            }
932:
933:            protected void setUserAttribute(String attributeName, Set values,
934:                    String userDN) throws AMException, SSOException {
935:                AMUser user = amsc.getUser(userDN);
936:                Map map = new HashMap();
937:                map.put(attributeName, values);
938:                user.setAttributes(map);
939:                user.store();
940:            }
941:
942:            protected void setUserAttributes(Map nameValues, String userDN)
943:                    throws AMException, SSOException {
944:                AMUser user = amsc.getUser(userDN);
945:                user.setAttributes(nameValues);
946:                user.store();
947:            }
948:
949:            protected void addUserAttributeValue(String attributeName,
950:                    Set values, String userDN) throws AMException, SSOException {
951:                Set oldValues = getUserAttribute(attributeName, userDN);
952:                values.addAll(oldValues);
953:                setUserAttribute(attributeName, values, userDN);
954:            }
955:
956:            protected void removeUserAttributeValue(String attributeName,
957:                    Set values, String userDN) throws AMException, SSOException {
958:                Set oldValues = getUserAttribute(attributeName, userDN);
959:                oldValues.removeAll(values);
960:                setUserAttribute(attributeName, oldValues, userDN);
961:            }
962:
963:            // Inheritors
964:            protected void inherit(String attributeName, String userDN)
965:                    throws AMException, SSOException {
966:                AMUser user = amsc.getUser(userDN);
967:                Set set = new HashSet();
968:                set.add(attributeName);
969:                user.removeAttributes(set);
970:                user.store();
971:            }
972:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.