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


0001:        /*
0002:         * Copyright 2001 Sun Microsystems, Inc.  All rights reserved. 
0003:         * PROPRIETARY/CONFIDENTIAL.  Use of this product is subject to license terms. 
0004:         */
0005:
0006:        package com.sun.portal.desktop.context;
0007:
0008:        import java.util.Iterator;
0009:        import java.util.Set;
0010:        import java.util.HashSet;
0011:        import java.util.Map;
0012:        import java.util.HashMap;
0013:        import javax.servlet.http.HttpServletRequest;
0014:
0015:        import com.iplanet.sso.SSOTokenManager;
0016:        import com.iplanet.sso.SSOToken;
0017:        import com.iplanet.sso.SSOException;
0018:
0019:        import com.iplanet.am.sdk.AMStoreConnection;
0020:        import com.iplanet.am.sdk.AMObject;
0021:        import com.iplanet.am.sdk.AMUser;
0022:        import com.iplanet.am.sdk.AMOrganization;
0023:        import com.iplanet.am.sdk.AMOrganizationalUnit;
0024:        import com.iplanet.am.sdk.AMRole;
0025:        import com.iplanet.am.sdk.AMFilteredRole;
0026:        import com.iplanet.am.sdk.AMTemplate;
0027:        import com.iplanet.am.sdk.AMException;
0028:        import com.iplanet.am.util.SystemProperties;
0029:
0030:        import com.sun.identity.sm.ServiceManager;
0031:        import com.sun.identity.sm.ServiceSchema;
0032:        import com.sun.identity.sm.ServiceSchemaManager;
0033:        import com.sun.identity.sm.SMSException;
0034:        import com.sun.portal.desktop.ROC;
0035:        import com.sun.portal.util.SSOUtil;
0036:
0037:        import java.util.Set;
0038:
0039:        public class DSAMEConnection implements  DSAMEConstants {
0040:            public static final String ROC_NODE_NAMES = "nodeNames";
0041:            public static final String ROC_ROLES = "roles";
0042:            //
0043:            // a fake global DN.
0044:            // convenient way to *internally* represent global level attribute.
0045:            // 
0046:            // NOTE: DO NOT expose this DN to the user
0047:            //
0048:            protected static final String GLOBAL_KEY = "_!global!_";
0049:
0050:            protected AMUser user = null;
0051:            protected AMStoreConnection connection = null;
0052:            protected ServiceManager serviceManager = null;
0053:
0054:            // lazy instantiation: use getXXX() to access
0055:            private static SSOTokenManager _tokenMgr = null;
0056:            private static AMStoreConnection adminConnection = null;
0057:
0058:            /* Initialized by init method, to be used for policy evaluation later */
0059:            private SSOToken ssoToken = null;
0060:
0061:            private static DesktopAppContext dac = null;
0062:
0063:            private DSAMEMultiPortalConstants dmpc = null;
0064:
0065:            /**
0066:             * DSAMEConnection called from provider and servlet
0067:             */
0068:            public DSAMEConnection(HttpServletRequest req) {
0069:                this (getSSOToken(req));
0070:                dmpc = DSAMEMultiPortalConstants.getInstance();
0071:            }
0072:
0073:            /**
0074:             * DSAMEConnection with no logging support
0075:             * (i.e. Used by application context)
0076:             */
0077:            public DSAMEConnection(SSOToken token) {
0078:                try {
0079:                    connection = new AMStoreConnection(token);
0080:                } catch (SSOException se) {
0081:                    throw new ContextError(se, ContextError.SESSION_TYPE);
0082:                }
0083:                init(token);
0084:                dmpc = DSAMEMultiPortalConstants.getInstance();
0085:            }
0086:
0087:            /**
0088:             * Called by CLIs and mbeans only, who have the portalId
0089:             * All other constructors are used from the webapp for which the portalId
0090:             * is set as System property in the JVM of webcontainer's instance
0091:             */
0092:            public DSAMEConnection(SSOToken token, String portalId) {
0093:                try {
0094:                    connection = new AMStoreConnection(token);
0095:                } catch (SSOException se) {
0096:                    throw new ContextError(se, ContextError.SESSION_TYPE);
0097:                }
0098:                init(token);
0099:                dmpc = DSAMEMultiPortalConstants.getInstance(portalId);
0100:            }
0101:
0102:            public DSAMEConnection(final String uid, String pw) {
0103:                SSOToken token = null;
0104:
0105:                try {
0106:                    //FOLLOWING IS COMMENTED TO FIX CR 6273650
0107:                    /*
0108:                    SSOTokenManager ssom = DSAMEConnection.getSSOTokenManager();
0109:                    token = ssom.createSSOToken(
0110:                    			new java.security.Principal() {
0111:                    			    public String getName() { return uid; }
0112:                    			}, pw);
0113:                     */
0114:                    token = SSOUtil.createSSOToken(uid, pw);
0115:                    connection = new AMStoreConnection(token);
0116:                } catch (SSOException se) {
0117:                    throw new ContextError(se, ContextError.SESSION_TYPE);
0118:                }
0119:
0120:                init(token);
0121:                dmpc = DSAMEMultiPortalConstants.getInstance();
0122:            }
0123:
0124:            protected void init(SSOToken token) {
0125:                //store the sso token for policy evaluation done later
0126:                ssoToken = token;
0127:                try {
0128:                    String uid = token.getPrincipal().getName();
0129:                    user = connection.getUser(uid);
0130:                    serviceManager = new ServiceManager(ssoToken);
0131:                } catch (SSOException se) {
0132:                    throw new ContextError(se, ContextError.SESSION_TYPE);
0133:                } catch (SMSException smse) {
0134:                    throw new ContextError(smse);
0135:                }
0136:            }
0137:
0138:            /**
0139:             *  returns all roles - static as well as filtered
0140:             * @return
0141:             */
0142:            public Set getRoleDNsFromROC() {
0143:                Set names = null;
0144:
0145:                if (ROC.containsObject(ROC_ROLES)) {
0146:                    names = (Set) ROC.getObject(ROC_ROLES);
0147:                } else {
0148:                    names = getRoleDNs();
0149:                    ROC.setObject(ROC_ROLES, names);
0150:                }
0151:
0152:                return names;
0153:            }
0154:
0155:            public Set getNodeNamesFromROC() {
0156:                Set names = null;
0157:
0158:                if (ROC.containsObject(ROC_NODE_NAMES)) {
0159:                    names = (Set) ROC.getObject(ROC_NODE_NAMES);
0160:                } else {
0161:                    names = getNodeNames();
0162:                    ROC.setObject(ROC_NODE_NAMES, names);
0163:                }
0164:
0165:                return names;
0166:            }
0167:
0168:            //
0169:            // caution: this is an expensive call.  (creating AMUser object, etc.) 
0170:            // should only be used by the dpadmin or such tool where performance
0171:            // impact is not an issue.
0172:            //
0173:            public Set getNodeNames(String dn) {
0174:                Set names = new HashSet();
0175:
0176:                try {
0177:                    int objType = getAdminConnection().getAMObjectType(dn);
0178:
0179:                    switch (objType) {
0180:                    case AMObject.USER:
0181:                        AMUser user = getAdminConnection().getUser(dn);
0182:                        names.addAll(getUserNodeNames(user));
0183:                        break;
0184:
0185:                    case AMObject.ORGANIZATION:
0186:                        AMOrganization org = getAdminConnection()
0187:                                .getOrganization(dn);
0188:
0189:                        if (org == null) {
0190:                            throw new ContextError(
0191:                                    "organization not found for dn: " + dn);
0192:                        }
0193:
0194:                        names.add(GLOBAL_KEY);
0195:
0196:                        String rootDN = getRootDN();
0197:
0198:                        //
0199:                        // workaround for IS bug #4836807
0200:                        // 
0201:                        if (org.getDN().equals(rootDN)) {
0202:                            break;
0203:                        }
0204:                        names.add(rootDN);
0205:
0206:                        String orgDN = org.getParentDN();
0207:
0208:                        if (orgDN != null && orgDN.length() > 0) {
0209:                            while (!orgDN.equals(rootDN)) {
0210:                                org = getAdminConnection().getOrganization(
0211:                                        orgDN);
0212:                                names.add(orgDN);
0213:                                orgDN = org.getParentDN();
0214:                            }
0215:                        }
0216:                        break;
0217:
0218:                    case AMObject.ROLE:
0219:                        AMRole role = getAdminConnection().getRole(dn);
0220:                        if (role == null) {
0221:                            throw new ContextError(
0222:                                    "DSAMEConnection.getNodeNames(): "
0223:                                            + "Role not found.  dn=" + dn);
0224:                        }
0225:
0226:                        orgDN = role.getParentDN();
0227:                        rootDN = getRootDN();
0228:
0229:                        names.add(GLOBAL_KEY);
0230:                        names.add(rootDN);
0231:
0232:                        if (orgDN != null && orgDN.length() > 0) {
0233:                            while (!orgDN.equals(rootDN)) {
0234:                                org = getAdminConnection().getOrganization(
0235:                                        orgDN);
0236:                                names.add(orgDN);
0237:                                orgDN = org.getParentDN();
0238:                            }
0239:                        }
0240:                        break;
0241:
0242:                    case AMObject.FILTERED_ROLE:
0243:                        AMFilteredRole frole = getAdminConnection()
0244:                                .getFilteredRole(dn);
0245:                        if (frole == null) {
0246:                            throw new ContextError(
0247:                                    "filtered role not found for dn: " + dn);
0248:                        }
0249:
0250:                        orgDN = frole.getParentDN();
0251:                        rootDN = getRootDN();
0252:
0253:                        names.add(GLOBAL_KEY);
0254:                        names.add(rootDN);
0255:
0256:                        if (orgDN != null && orgDN.length() > 0) {
0257:                            while (!orgDN.equals(rootDN)) {
0258:                                org = getAdminConnection().getOrganization(
0259:                                        orgDN);
0260:                                names.add(orgDN);
0261:                                orgDN = org.getParentDN();
0262:                            }
0263:                        }
0264:                        break;
0265:
0266:                    default:
0267:                        throw new ContextError(
0268:                                "unsupported AMObject found for dn: " + dn);
0269:                    }
0270:                } catch (AMException dpe) {
0271:                    throw new ContextError("dn: " + dn, dpe);
0272:                } catch (SSOException sso) {
0273:                    throw new ContextError(sso, ContextError.SESSION_TYPE);
0274:                }
0275:
0276:                return names;
0277:            }
0278:
0279:            public Set getNodeNames() {
0280:                Set names = getUserNodeNames(user);
0281:                return names;
0282:            }
0283:
0284:            //
0285:            // This method search the ldap tree based on the level that is
0286:            // specified from the level parameter. It only search for sub-org
0287:            // and roles belongs to the based dn.
0288:            //
0289:            // caution: this is an expensive call.  (creating AMUser object, etc.) 
0290:            // should only be used by the dpadmin or such tool where performance
0291:            // impact is not an issue.
0292:            //
0293:            public Set getChildrenNodeNames(String dn, int level) {
0294:                Set names = new HashSet();
0295:
0296:                try {
0297:                    int objType = getAdminConnection().getAMObjectType(dn);
0298:
0299:                    switch (objType) {
0300:                    case AMObject.USER:
0301:                        //don't add any user nodes
0302:                        break;
0303:
0304:                    case AMObject.ORGANIZATION:
0305:                        AMOrganization org = getAdminConnection()
0306:                                .getOrganization(dn);
0307:
0308:                        if (org == null) {
0309:                            throw new ContextError(
0310:                                    "DSAMEConnection.getChildrenNodeNames(): "
0311:                                            + "Organization not found.  dn="
0312:                                            + dn);
0313:                        }
0314:
0315:                        names.add(dn);
0316:                        Set subOrgs = org.getSubOrganizations(level);
0317:                        Set roles = org.getRoles(level);
0318:
0319:                        for (Iterator i = subOrgs.iterator(); i.hasNext();) {
0320:                            names.add((String) i.next());
0321:                        }
0322:
0323:                        for (Iterator i = roles.iterator(); i.hasNext();) {
0324:                            names.add((String) i.next());
0325:                        }
0326:
0327:                        break;
0328:
0329:                    case AMObject.ROLE:
0330:                        names.add(dn);
0331:                        //the search stops here
0332:                        break;
0333:
0334:                    case AMObject.FILTERED_ROLE:
0335:                        names.add(dn);
0336:                        //the search stops here
0337:                        break;
0338:
0339:                    default:
0340:                        throw new ContextError(
0341:                                "DSAMEConnection.getChildrenNodeNames(): "
0342:                                        + "Unsupported AMObject found.  dn="
0343:                                        + dn);
0344:                    }
0345:                } catch (AMException dpe) {
0346:                    throw new ContextError(
0347:                            "DSAMEConnectoin.getChildrenNodeNames(): " + "dn="
0348:                                    + dn, dpe);
0349:                } catch (SSOException sso) {
0350:                    throw new ContextError("dn: " + dn, sso,
0351:                            ContextError.SESSION_TYPE);
0352:                }
0353:
0354:                return names;
0355:            }
0356:
0357:            /**
0358:             * Get the set of role DNs for the user
0359:             */
0360:            public Set getRoleDNs() {
0361:                Set roleDNs = null;
0362:                Set names = new HashSet();
0363:                try {
0364:                    // get the set of static role DNs for the user
0365:                    roleDNs = user.getRoleDNs();
0366:                    for (Iterator i = roleDNs.iterator(); i.hasNext();) {
0367:                        String roleDN = (String) i.next();
0368:                        if (roleDN != null && roleDN.length() > 0) {
0369:                            names.add(roleDN);
0370:                        }
0371:                    }
0372:                    // get the set of filtered role DNs for the user
0373:
0374:                    Set filteredRoleDNs = user.getFilteredRoleDNs();
0375:                    for (Iterator i = filteredRoleDNs.iterator(); i.hasNext();) {
0376:                        String filteredRoleDN = (String) i.next();
0377:                        if (filteredRoleDN != null
0378:                                && filteredRoleDN.length() > 0) {
0379:                            names.add(filteredRoleDN);
0380:                        }
0381:                    }
0382:
0383:                } catch (AMException ame) {
0384:                    throw new ContextError("DSAMEConnection.getRoleDNs(): ",
0385:                            ame);
0386:                } catch (SSOException ssoe) {
0387:                    throw new ContextError(ssoe, ContextError.SESSION_TYPE);
0388:                }
0389:                return names;
0390:            }
0391:
0392:            public Set getChildrenNodeNames(int level) {
0393:                String rootDN = getRootDN();
0394:
0395:                return getChildrenNodeNames(rootDN, level);
0396:            }
0397:
0398:            private Set getUserNodeNames(AMUser user) {
0399:                Set names = new HashSet();
0400:
0401:                try {
0402:                    //
0403:                    // walk the LDAP node tree to get the organizations /
0404:                    // sub organizations the user belongs to
0405:                    //
0406:
0407:                    String orgDN = user.getOrganizationDN();
0408:                    String rootDN = getRootDN();
0409:
0410:                    names.add(GLOBAL_KEY);
0411:                    names.add(rootDN);
0412:
0413:                    if (orgDN != null && orgDN.length() > 0) {
0414:                        while (!orgDN.equalsIgnoreCase(rootDN)) {
0415:                            AMOrganization org = getAdminConnection()
0416:                                    .getOrganization(orgDN);
0417:                            names.add(orgDN);
0418:                            orgDN = org.getParentDN();
0419:                        }
0420:                    }
0421:                    //if logged is user is same as user passed as argument
0422:                    if (this .user == user) {
0423:                        //
0424:                        // get the set of all role DNs for the user  from ROLES_ROC  set of ROC
0425:                        //
0426:                        Set roleDNs = getRoleDNsFromROC();
0427:                        for (Iterator i = roleDNs.iterator(); i.hasNext();) {
0428:                            String roleDN = (String) i.next();
0429:                            if (roleDN != null && roleDN.length() > 0) {
0430:                                names.add(roleDN);
0431:                            }
0432:                        }
0433:
0434:                    } else { //Since this is a generic method, get the roles from DSAME.
0435:                    //
0436:                        // get the set of role DNs for the user
0437:                        //
0438:
0439:                        Set roleDNs = user.getRoleDNs();
0440:                        for (Iterator i = roleDNs.iterator(); i.hasNext();) {
0441:                            String roleDN = (String) i.next();
0442:                            if (roleDN != null && roleDN.length() > 0) {
0443:                                names.add(roleDN);
0444:                            }
0445:                        }
0446:
0447:                        //
0448:                        // get the set of filtered role DNs for the user
0449:                        //
0450:
0451:                        Set filteredRoleDNs = user.getFilteredRoleDNs();
0452:                        for (Iterator i = filteredRoleDNs.iterator(); i
0453:                                .hasNext();) {
0454:                            String froleDN = (String) i.next();
0455:                            if (froleDN != null && froleDN.length() > 0) {
0456:                                names.add(froleDN);
0457:                            }
0458:                        }
0459:
0460:                    }
0461:
0462:                } catch (AMException ame) {
0463:                    throw new ContextError(
0464:                            "DSAMEConnection.getUserNodeNames(): ", ame);
0465:                } catch (SSOException ssoe) {
0466:                    throw new ContextError(ssoe, ContextError.SESSION_TYPE);
0467:                }
0468:
0469:                return names;
0470:            }
0471:
0472:            /**
0473:             * To get around DSAME bug #4619045 
0474:             * Lazy instantiation.
0475:             */
0476:            private AMStoreConnection getAdminConnection() {
0477:                if (adminConnection == null) {
0478:                    try {
0479:                        adminConnection = new AMStoreConnection(SSOUtil
0480:                                .getAdminSSOToken());
0481:                    } catch (SSOException se) {
0482:                        throw new ContextError(se, ContextError.SESSION_TYPE);
0483:                    }
0484:                }
0485:                return adminConnection;
0486:            }
0487:
0488:            /**
0489:             * Gets a DSAME attribute corresponding to the given DN.
0490:             * It first tries to determine what type of object is represented
0491:             * by the given DN and then retrieve the attribute
0492:             * accordingly.  If DN represents a user entry, then it returns
0493:             * the user's attribute.  If DN represents an organization,
0494:             * it returns the attribute from the template associated
0495:             * with the organization.
0496:             *
0497:             * NOTE: DSAME does not allow attributes to be retrieved from the user
0498:             * level, without attempting to walk up to the role / org levels to find
0499:             * the value. Here, it is assumed that user level attr keys are equals
0500:             * to the attribute key + User.
0501:             * @param dn DN of the attribute to retrieve
0502:             * @return Attribute value.
0503:             */
0504:            public String getAttributeByDN(String dn, String key) {
0505:                if (dn == null) {
0506:                    throw new ContextError(
0507:                            "DSAMEConnection.getAttributeByDN(): "
0508:                                    + "DN passed in was NULL.");
0509:                }
0510:
0511:                String value = null;
0512:                try {
0513:                    if (dn.equals(GLOBAL_KEY)) {
0514:                        value = getGlobalAttribute(dmpc.MP_SUN_DESKTOP_SERVICE,
0515:                                key);
0516:                    } else {
0517:                        int objType = getAdminConnection().getAMObjectType(dn);
0518:                        if (objType == AMObject.USER) {
0519:
0520:                            AMUser u = connection.getUser(dn);
0521:
0522:                            if (u == null) {
0523:                                throw new ContextError(
0524:                                        "DSAMEConnection.getAttributeByDN(): User not found.  "
0525:                                                + "dn=" + dn);
0526:                            }
0527:                            if (key.equals(DSAMEConstants.ATTR_DP_DOCUMENT)) {
0528:                                key = dmpc.MP_ATTR_DP_DOCUMENT_USER;
0529:                            } else if (key
0530:                                    .equals(DSAMEConstants.ATTR_DP_LAST_MODIFIED)) {
0531:                                key = dmpc.MP_ATTR_DP_LAST_MODIFIED_USER;
0532:                            }
0533:                            Set vals = u.getAttribute(key);
0534:
0535:                            if (vals != null && vals.size() > 0) {
0536:                                Iterator iter = vals.iterator();
0537:                                value = (String) iter.next();
0538:                            }
0539:                        } else {
0540:                            value = getTemplateAttribute(dn,
0541:                                    dmpc.MP_SUN_DESKTOP_SERVICE, key);
0542:                        }
0543:                    }
0544:                } catch (AMException dpe) {
0545:                    throw new ContextError(
0546:                            "DSAMEConnection.getAttributeByDN(): " + "dn=" + dn
0547:                                    + ": ", dpe);
0548:                } catch (SSOException sso) {
0549:                    throw new ContextError("dn: " + dn, sso,
0550:                            ContextError.SESSION_TYPE);
0551:                }
0552:
0553:                //
0554:                // a value of null means that the attribute, or the template that
0555:                // the attribute lives in, did not exist. this is okay and clients of
0556:                // this class should expect a null return value
0557:                //
0558:
0559:                return value;
0560:            }
0561:
0562:            private String getTemplateAttribute(String dn, String serviceName,
0563:                    String key) {
0564:                if (dn == null) {
0565:                    throw new ContextError(
0566:                            "DSAMEConnection.getTemplateAttribute(): "
0567:                                    + "DN passed in was NULL.");
0568:                }
0569:
0570:                String value = null;
0571:                AMTemplate temp = getTemplate(dn, serviceName);
0572:                if (temp != null) {
0573:                    try {
0574:                        Set vals = temp.getAttribute(key);
0575:                        if (vals != null && vals.size() > 0) {
0576:                            Iterator iter = vals.iterator();
0577:                            value = (String) iter.next();
0578:                        }
0579:                    } catch (AMException dpe) {
0580:                        throw new ContextError(
0581:                                "DSAMEConnection.getTemplateAttribute():  temp: "
0582:                                        + temp + "dn=" + dn + ", serviceName="
0583:                                        + serviceName + ", attributeName="
0584:                                        + key, dpe);
0585:                    } catch (SSOException sso) {
0586:                        throw new ContextError("dn: " + dn + ", serviceName: "
0587:                                + serviceName + ", attributeName: " + key, sso,
0588:                                ContextError.SESSION_TYPE);
0589:                    }
0590:                }
0591:
0592:                return value;
0593:            }
0594:
0595:            public Set getTemplateAttributeMultiVal(String dn,
0596:                    String serviceName, String attributeName) {
0597:                Set vals = null;
0598:
0599:                try {
0600:                    AMTemplate temp = getTemplate(dn, serviceName);
0601:                    if (temp != null) {
0602:                        vals = temp.getAttribute(attributeName);
0603:                    }
0604:                } catch (AMException dpe) {
0605:                    throw new ContextError(
0606:                            "DSAMEConnection.getTemplateAttributeMultiVal(): "
0607:                                    + "dn=" + dn + ", serviceName="
0608:                                    + serviceName + ", attributeName="
0609:                                    + attributeName, dpe);
0610:
0611:                } catch (SSOException sso) {
0612:                    throw new ContextError(
0613:                            "dn: " + dn + ", serviceName: " + serviceName
0614:                                    + ", attributeName: " + attributeName, sso,
0615:                            ContextError.SESSION_TYPE);
0616:                }
0617:
0618:                return vals;
0619:
0620:            }
0621:
0622:            public void setAttributeByDN(String dn, String key, String val) {
0623:                if (dn == null) {
0624:                    throw new ContextError(
0625:                            "DSAMEConnection.setAttributeByDN(): "
0626:                                    + "DN passed in was NULL.");
0627:                }
0628:
0629:                if (key == null) {
0630:                    throw new ContextError(
0631:                            "DSAMEConnection.setAttributeByDN(): "
0632:                                    + "attrbiute key was NULL.");
0633:                }
0634:
0635:                if (val == null) {
0636:                    throw new ContextError(
0637:                            "DSAMEConnection.setAttributeByDN(): "
0638:                                    + "attrbiute value was NULL.");
0639:                }
0640:
0641:                try {
0642:                    if (dn.equals(GLOBAL_KEY)) {
0643:                        setGlobalAttribute(dmpc.MP_SUN_DESKTOP_SERVICE, key,
0644:                                val);
0645:                    } else {
0646:                        int objType = getAdminConnection().getAMObjectType(dn);
0647:                        if (objType == AMObject.USER) {
0648:
0649:                            AMUser u = connection.getUser(dn);
0650:
0651:                            if (u == null) {
0652:                                throw new ContextError(
0653:                                        "DSAMEConnection.setAttributeByDN(): "
0654:                                                + "User not found: " + dn);
0655:                            }
0656:                            if (key.equals(DSAMEConstants.ATTR_DP_DOCUMENT)) {
0657:                                key = dmpc.MP_ATTR_DP_DOCUMENT_USER;
0658:                            } else if (key
0659:                                    .equals(DSAMEConstants.ATTR_DP_LAST_MODIFIED)) {
0660:                                key = dmpc.MP_ATTR_DP_LAST_MODIFIED_USER;
0661:                            }
0662:                            u.setStringAttribute(key, val);
0663:                            u.store();
0664:                        } else {
0665:                            setTemplateAttribute(dn,
0666:                                    dmpc.MP_SUN_DESKTOP_SERVICE, key, val);
0667:                        }
0668:                    }
0669:                } catch (AMException dpe) {
0670:                    throw new ContextError(
0671:                            "DSAMEConnection.setAttributeByDN(): " + "dn=" + dn
0672:                                    + ", key=" + key, dpe);
0673:                } catch (SSOException sso) {
0674:                    throw new ContextError("dn: " + dn + ", key: " + key, sso,
0675:                            ContextError.SESSION_TYPE);
0676:                }
0677:            }
0678:
0679:            /**
0680:             * Removes Display Profile document corresponding to the given DN.
0681:             * Note that this does not take merging into consideration.
0682:             * It first tries to determine what type of object is represented
0683:             * by the given DN and then removes the Display Profile
0684:             * accordingly.  If DN represents a user entry, then it removes
0685:             * the user's Display profile.  If DN represents an organization,
0686:             * it removes the Display profile from the template associated
0687:             * with the organization. 
0688:             *
0689:             * @param dn DN of the display profile to remove
0690:             */
0691:            public void removeAttributeByDN(String dn, String key) {
0692:                if (dn == null) {
0693:                    throw new ContextError(
0694:                            "DSAMEConnection.removeAttributeByDN(): "
0695:                                    + "DN passed in was NULL.");
0696:                }
0697:
0698:                try {
0699:                    if (dn.equals(GLOBAL_KEY)) {
0700:                        removeGlobalAttribute(dmpc.MP_SUN_DESKTOP_SERVICE, key);
0701:                    } else {
0702:                        int objType = getAdminConnection().getAMObjectType(dn);
0703:                        if (objType == AMObject.USER) {
0704:
0705:                            AMUser u = connection.getUser(dn);
0706:
0707:                            if (u == null) {
0708:                                throw new ContextError(
0709:                                        "DSAMEConnection.removeAttributeByDN(): "
0710:                                                + "User not found.  " + "dn="
0711:                                                + dn);
0712:                            }
0713:                            Set attrs = new HashSet();
0714:                            if (key.equals(DSAMEConstants.ATTR_DP_DOCUMENT)) {
0715:                                key = dmpc.MP_ATTR_DP_DOCUMENT_USER;
0716:                            } else if (key
0717:                                    .equals(DSAMEConstants.ATTR_DP_LAST_MODIFIED)) {
0718:                                key = dmpc.MP_ATTR_DP_LAST_MODIFIED_USER;
0719:                            }
0720:                            attrs.add(key);
0721:                            u.removeAttributes(attrs);
0722:                        } else {
0723:                            removeTemplateAttribute(dn,
0724:                                    dmpc.MP_SUN_DESKTOP_SERVICE, key);
0725:                        }
0726:                    }
0727:                } catch (AMException dpe) {
0728:                    throw new ContextError(
0729:                            "DSAMEConnection.removeAttributeByDN(): " + "dn="
0730:                                    + dn, dpe);
0731:                } catch (SSOException sso) {
0732:                    throw new ContextError("dn: " + dn, sso,
0733:                            ContextError.SESSION_TYPE);
0734:                }
0735:            }
0736:
0737:            public void setAttributesByDN(String dn, String serviceName,
0738:                    String key, Set vals) {
0739:                if (dn == null) {
0740:                    throw new ContextError(
0741:                            "DSAMEConnection.setAttributesByDN(): "
0742:                                    + "DN passed in was NULL.");
0743:                }
0744:
0745:                if (key == null) {
0746:                    throw new ContextError(
0747:                            "DSAMEConnection.setAttributesByDN(): "
0748:                                    + "attrbiute key was NULL.");
0749:                }
0750:
0751:                if (vals == null) {
0752:                    throw new ContextError(
0753:                            "DSAMEConnection.setAttributesByDN(): "
0754:                                    + "attrbiute value was NULL.");
0755:                }
0756:
0757:                try {
0758:                    if (dn.equals(GLOBAL_KEY)) {
0759:                        setGlobalAttributes(serviceName, key, vals);
0760:                    } else {
0761:                        int objType = getAdminConnection().getAMObjectType(dn);
0762:                        if (objType == AMObject.USER) {
0763:
0764:                            AMUser u = connection.getUser(dn);
0765:
0766:                            if (u == null) {
0767:                                throw new ContextError(
0768:                                        "DSAMEConnection.setAttributesByDN(): "
0769:                                                + "User not found: " + dn);
0770:                            }
0771:                            HashMap map = new HashMap();
0772:                            map.put(key + "User", vals);
0773:                            u.setAttributes(map);
0774:                            u.store();
0775:                        } else {
0776:                            setTemplateAttributes(dn, serviceName, key, vals);
0777:                        }
0778:                    }
0779:                } catch (AMException dpe) {
0780:                    throw new ContextError(
0781:                            "DSAMEConnection.setAttributesByDN(): " + "dn="
0782:                                    + dn + ", key=" + key, dpe);
0783:                } catch (SSOException sso) {
0784:                    throw new ContextError("dn: " + dn + ", key: " + key, sso,
0785:                            ContextError.SESSION_TYPE);
0786:                }
0787:            }
0788:
0789:            /**
0790:             * Gets USER/DYNAMIC attribute.
0791:             * @param attributeName Name of the attribute to retrieve
0792:             * @return The attribute value in String format.  If property is
0793:             * not not found, return null.  If DSAME returns multi-value,
0794:             * warning is issued and only the first value is returned.
0795:             */
0796:            public String getAttribute(String attributeName) {
0797:                String val = null;
0798:                Set vals = getAttributeMultiVal(attributeName);
0799:
0800:                if (vals != null && vals.size() > 0) {
0801:                    Iterator iter = vals.iterator();
0802:                    val = (String) iter.next();
0803:                }
0804:
0805:                return val;
0806:            }
0807:
0808:            public byte[] getAttributeByteArray(String attributeName) {
0809:                byte[] val = null;
0810:                byte[][] vals = null;
0811:
0812:                try {
0813:                    vals = user.getAttributeByteArray(attributeName);
0814:                } catch (AMException ame) {
0815:                    throw new ContextError(
0816:                            "DSAMEConnection.getAttributeByteArray()", ame);
0817:                } catch (SSOException ssoe) {
0818:                    throw new ContextError(ssoe, ContextError.SESSION_TYPE);
0819:                }
0820:
0821:                if (vals != null && vals.length > 0) {
0822:                    val = (byte[]) vals[0];
0823:                }
0824:
0825:                return val;
0826:            }
0827:
0828:            /**
0829:             * Gets USER/DYNAMIC attribute in int.
0830:             * @param attributeName Name of the attribute to retrieve
0831:             * @return The attribute value in int.  If property is
0832:             * not not found, return null.  If DSAME returns multi-value,
0833:             * warning is issued and only the first value is returned.
0834:             */
0835:            public int getIntAttribute(String attributeName) {
0836:                String valStr = getAttribute(attributeName);
0837:                int valInt = -1;
0838:                try {
0839:                    valInt = Integer.parseInt(valStr);
0840:                } catch (NumberFormatException nfe) {
0841:                    throw new ContextError(
0842:                            "DSAMEConnection.getIntAttribute(): "
0843:                                    + "Invalid integer value returned.  "
0844:                                    + "attribute=" + attributeName, nfe);
0845:                }
0846:
0847:                return valInt;
0848:            }
0849:
0850:            /**
0851:             * Gets multi-valued USER/DYNAMIC attribute.
0852:             * @param attributeName Name of the attribute to retrieve
0853:             * @return Set of String values.  If property is
0854:             * not not found, return null.  
0855:             */
0856:            public Set getAttributeMultiVal(String attributeName) {
0857:                Set vals = null;
0858:
0859:                try {
0860:                    vals = user.getAttribute(attributeName);
0861:                } catch (Exception e) {
0862:                    throw new ContextError(
0863:                            "DSAMEConnection.getAttributeMultiVal(): "
0864:                                    + "attributeName=" + attributeName, e);
0865:                }
0866:                return vals;
0867:            }
0868:
0869:            /**
0870:             * Sets USER/DYNAMIC attribute.
0871:             * @param attributeName Name of the attribute to retrieve
0872:             * @param val Value of the attribute
0873:             */
0874:            public void setAttribute(String attributeName, String val) {
0875:                try {
0876:                    user.setStringAttribute(attributeName, val);
0877:                    user.store();
0878:                } catch (Exception e) {
0879:                    throw new ContextError("DSAMEConnection.setAttribute(): "
0880:                            + "attributeName=" + attributeName + " value="
0881:                            + val + "  Exception:  ", e);
0882:
0883:                }
0884:            }
0885:
0886:            /**
0887:             * Gets ORGANIZATION attribute.  Internally this translates
0888:             * to a template attribute set at the org. level that the current
0889:             * user belongs to.
0890:             * @param serviceName Name of the service
0891:             * @param attributeName Name of the attribute to retrieve
0892:             * @return The attribute value in String format.  If property is
0893:             * not not found, return null.  If DSAME returns multi-value,
0894:             * warning is issued and only the first value is returned.
0895:             */
0896:
0897:            public String getOrganizationAttribute(String serviceName,
0898:                    String attributeName) {
0899:                String val = null;
0900:                String dn = null;
0901:
0902:                try {
0903:                    dn = user.getOrganizationDN();
0904:                    AMObject amo = null;
0905:                    int type = getAdminConnection().getAMObjectType(dn);
0906:
0907:                    switch (type) {
0908:                    case AMObject.ORGANIZATION:
0909:                        amo = getAdminConnection().getOrganization(dn);
0910:                        break;
0911:
0912:                    case AMObject.ORGANIZATIONAL_UNIT:
0913:                        amo = getAdminConnection().getOrganizationalUnit(dn);
0914:                        break;
0915:
0916:                    default:
0917:                        throw new ContextError(
0918:                                "DSAMEConnection.getOrganizationAttribute(): unknown am object type for dn="
0919:                                        + dn + ", serviceName=" + serviceName);
0920:                    }
0921:
0922:                    if (amo == null) {
0923:                        throw new ContextError(
0924:                                "DSAMEConnection.getOrganizationAttribute(): org / org unit  not found, dn="
0925:                                        + dn + ", serviceName=" + serviceName);
0926:                    }
0927:
0928:                    AMTemplate temp = amo.getTemplate(serviceName,
0929:                            AMTemplate.ORGANIZATION_TEMPLATE);
0930:
0931:                    boolean tempExists = (temp != null) && temp.isExists();
0932:                    if (!tempExists) {
0933:                        throw new ContextError(
0934:                                "DSAMEConnection.getOrganizationAttribute(): "
0935:                                        + "No template found.  " + "dn=" + dn
0936:                                        + ", serviceName=" + serviceName);
0937:                    }
0938:                    Set vals = temp.getAttribute(attributeName);
0939:
0940:                    if (vals != null && vals.size() > 0) {
0941:                        Iterator iter = vals.iterator();
0942:                        val = (String) iter.next();
0943:                    }
0944:
0945:                } catch (Exception e) {
0946:                    throw new ContextError(
0947:                            "DSAMEConnection.getOrganizationAttribute(): "
0948:                                    + "dn=" + dn + "serviceName=" + serviceName
0949:                                    + ", attributeName=" + attributeName, e);
0950:                }
0951:
0952:                return val;
0953:            }
0954:
0955:            public String getGlobalAttribute(String serviceName,
0956:                    String attributeName) {
0957:                Set vals = getGlobalAttributeMultiVal(serviceName,
0958:                        attributeName);
0959:                if (vals == null || vals.size() < 1) {
0960:                    return null;
0961:                }
0962:
0963:                Iterator iter = vals.iterator();
0964:                String val = (String) iter.next();
0965:
0966:                return val;
0967:            }
0968:
0969:            public Set getGlobalAttributeMultiVal(String serviceName,
0970:                    String attributeName) {
0971:                Map attrs = getGlobalAttributes(serviceName);
0972:                Set vals = (Set) attrs.get(attributeName);
0973:                return vals;
0974:            }
0975:
0976:            public Map getGlobalAttributes(String serviceName) {
0977:                Map attrs = null;
0978:
0979:                try {
0980:                    ServiceSchemaManager schemaMgr = serviceManager
0981:                            .getSchemaManager(serviceName, SVC_VERSION);
0982:                    ServiceSchema schema = schemaMgr.getGlobalSchema();
0983:                    attrs = schema.getReadOnlyAttributeDefaults();
0984:                } catch (Exception ex) {
0985:                    throw new ContextError(
0986:                            "DSAMEConnection.getGlobalAttributes(): "
0987:                                    + serviceName, ex);
0988:                }
0989:
0990:                return attrs;
0991:            }
0992:
0993:            public void setGlobalAttribute(String serviceName,
0994:                    String attributeName, String val) {
0995:                try {
0996:                    ServiceSchemaManager schemaMgr = serviceManager
0997:                            .getSchemaManager(serviceName, SVC_VERSION);
0998:                    ServiceSchema schema = schemaMgr.getGlobalSchema();
0999:                    HashSet vals = new HashSet();
1000:
1001:                    vals.add(val);
1002:                    schema.setAttributeDefaults(attributeName, vals);
1003:                } catch (Exception e) {
1004:                    throw new ContextError(
1005:                            "DSAMEConnection.setGlobalAttribute(): "
1006:                                    + serviceName + "." + attributeName + "="
1007:                                    + val, e);
1008:                }
1009:            }
1010:
1011:            public void setGlobalAttributes(String serviceName,
1012:                    String attributeName, Set vals) {
1013:                try {
1014:                    ServiceSchemaManager schemaMgr = serviceManager
1015:                            .getSchemaManager(serviceName, SVC_VERSION);
1016:                    ServiceSchema schema = schemaMgr.getGlobalSchema();
1017:                    schema.setAttributeDefaults(attributeName, vals);
1018:                } catch (Exception e) {
1019:                    throw new ContextError(
1020:                            "DSAMEConnection.setGlobalAttributes(): "
1021:                                    + serviceName + "." + attributeName + "="
1022:                                    + vals, e);
1023:                }
1024:            }
1025:
1026:            public void removeGlobalAttribute(String serviceName,
1027:                    String attributeName) {
1028:                Set attrs = new HashSet();
1029:                attrs.add(attributeName);
1030:
1031:                try {
1032:                    ServiceSchemaManager schemaMgr = serviceManager
1033:                            .getSchemaManager(serviceName, SVC_VERSION);
1034:                    ServiceSchema schema = schemaMgr.getGlobalSchema();
1035:                    schema.removeAttributeDefaults(attrs);
1036:                } catch (Exception e) {
1037:                    throw new ContextError(
1038:                            "DSAMEConnection.removeGlobalAttribute(): "
1039:                                    + serviceName + "." + attributeName, e);
1040:                }
1041:            }
1042:
1043:            public String getPolicyAttribute(String attributeName) {
1044:                Set vals = null;
1045:
1046:                try {
1047:                    vals = user.getAttribute(attributeName);
1048:                } catch (Exception e) {
1049:                    throw new ContextError(
1050:                            "DSAMEConnection.getPolicyAttribute(): "
1051:                                    + attributeName, e);
1052:                }
1053:
1054:                if (vals == null || vals.size() < 1) {
1055:                    return null;
1056:                }
1057:
1058:                Iterator iter = vals.iterator();
1059:                String val = (String) iter.next();
1060:
1061:                return val;
1062:            }
1063:
1064:            private AMTemplate getTemplate(String dn, String serviceName) {
1065:                int objType = -1;
1066:                AMTemplate temp = null;
1067:                try {
1068:                    objType = getAdminConnection().getAMObjectType(dn);
1069:
1070:                    if (objType == AMObject.ORGANIZATION) {
1071:                        AMOrganization org = getAdminConnection()
1072:                                .getOrganization(dn);
1073:                        if (org == null) {
1074:                            throw new ContextError(
1075:                                    "DSAMEConnection.getTemplateAttribute(): "
1076:                                            + "Organization not found.  "
1077:                                            + "dn=" + dn + ", serviceName="
1078:                                            + serviceName);
1079:                        }
1080:                        temp = org.getTemplate(serviceName,
1081:                                AMTemplate.DYNAMIC_TEMPLATE);
1082:
1083:                    } else if (objType == AMObject.ROLE) {
1084:                        AMRole role = getAdminConnection().getRole(dn);
1085:                        if (role == null) {
1086:                            throw new ContextError(
1087:                                    "DSAMEConnection.getTemplateAttribute(): "
1088:                                            + "Role not found.  " + "dn=" + dn
1089:                                            + ", serviceName=" + serviceName);
1090:                        }
1091:                        temp = role.getTemplate(serviceName,
1092:                                AMTemplate.DYNAMIC_TEMPLATE);
1093:                    } else if (objType == AMObject.FILTERED_ROLE) {
1094:                        AMFilteredRole frole = getAdminConnection()
1095:                                .getFilteredRole(dn);
1096:                        if (frole == null) {
1097:                            throw new ContextError(
1098:                                    "DSAMEConnection.getTemplateAttribute(): "
1099:                                            + "filtered role not found.  "
1100:                                            + "dn=" + dn + ", serviceName="
1101:                                            + serviceName);
1102:                        }
1103:                        temp = frole.getTemplate(serviceName,
1104:                                AMTemplate.DYNAMIC_TEMPLATE);
1105:                    } else if (objType == AMObject.ORGANIZATIONAL_UNIT) {
1106:                        AMOrganizationalUnit ou = getAdminConnection()
1107:                                .getOrganizationalUnit(dn);
1108:                        if (ou == null) {
1109:                            throw new ContextError(
1110:                                    "DSAMEConnection.getTemplateAttribute(): "
1111:                                            + "ou not found.  " + "dn=" + dn
1112:                                            + ", serviceName=" + serviceName);
1113:                        }
1114:                        temp = ou.getTemplate(serviceName,
1115:                                AMTemplate.DYNAMIC_TEMPLATE);
1116:                    } else {
1117:                        throw new ContextError(
1118:                                "DSAMEConnection.getTemplateAttribute(): "
1119:                                        + "Unsupported AMObject found.  "
1120:                                        + "dn=" + dn + ", serviceName="
1121:                                        + serviceName + ", objectType="
1122:                                        + objType);
1123:                    }
1124:
1125:                    boolean tempExists = (temp != null) && temp.isExists();
1126:                    if (!tempExists) {
1127:                        return null;
1128:                    }
1129:                } catch (AMException dpe) {
1130:                    throw new ContextError(
1131:                            "DSAMEConnection.getTemplateAttribute(): " + "dn="
1132:                                    + dn + ", serviceName=" + serviceName, dpe);
1133:
1134:                } catch (SSOException sso) {
1135:                    throw new ContextError("dn: " + dn + ", serviceName: "
1136:                            + serviceName, sso, ContextError.SESSION_TYPE);
1137:                }
1138:                return temp;
1139:            }
1140:
1141:            private void setTemplateAttribute(String dn, String serviceName,
1142:                    String attributeName, String val) {
1143:                try {
1144:                    int objType = connection.getAMObjectType(dn);
1145:
1146:                    switch (objType) {
1147:                    case AMObject.ORGANIZATION:
1148:                        AMOrganization org = connection.getOrganization(dn);
1149:                        if (org == null) {
1150:                            throw new ContextError(
1151:                                    "DSAMEConnection.setTemplateAttribute(): "
1152:                                            + "Organization not found.  "
1153:                                            + "dn=" + dn + ", serviceName="
1154:                                            + serviceName);
1155:                        }
1156:
1157:                        AMTemplate temp = org.getTemplate(serviceName,
1158:                                AMTemplate.DYNAMIC_TEMPLATE);
1159:                        boolean tempExists = (temp != null) && temp.isExists();
1160:                        if (!tempExists) {
1161:                            org.createTemplate(AMTemplate.DYNAMIC_TEMPLATE,
1162:                                    serviceName, null);
1163:                        }
1164:                        temp.setStringAttribute(attributeName, val);
1165:                        temp.store();
1166:                        break;
1167:
1168:                    case AMObject.ROLE:
1169:                        AMRole role = connection.getRole(dn);
1170:                        if (role == null) {
1171:                            throw new ContextError(
1172:                                    "DSAMEConnection.setTemplateAttribute(): "
1173:                                            + "Role not found.  " + "dn=" + dn
1174:                                            + ", serviceName=" + serviceName);
1175:                        }
1176:
1177:                        temp = role.getTemplate(serviceName,
1178:                                AMTemplate.DYNAMIC_TEMPLATE);
1179:                        tempExists = (temp != null) && temp.isExists();
1180:                        if (!tempExists) {
1181:                            role.createTemplate(AMTemplate.DYNAMIC_TEMPLATE,
1182:                                    serviceName, null);
1183:                        }
1184:                        temp.setStringAttribute(attributeName, val);
1185:                        temp.store();
1186:                        break;
1187:
1188:                    case AMObject.FILTERED_ROLE:
1189:                        AMFilteredRole frole = connection.getFilteredRole(dn);
1190:                        if (frole == null) {
1191:                            throw new ContextError(
1192:                                    "DSAMEConnection.setTemplateAttribute(): "
1193:                                            + "filtered role not found.  "
1194:                                            + "dn=" + dn + ", serviceName="
1195:                                            + serviceName);
1196:                        }
1197:
1198:                        temp = frole.getTemplate(serviceName,
1199:                                AMTemplate.DYNAMIC_TEMPLATE);
1200:                        tempExists = (temp != null) && temp.isExists();
1201:                        if (!tempExists) {
1202:                            frole.createTemplate(AMTemplate.DYNAMIC_TEMPLATE,
1203:                                    serviceName, null);
1204:                        }
1205:                        temp.setStringAttribute(attributeName, val);
1206:                        temp.store();
1207:                        break;
1208:
1209:                    default:
1210:                        throw new ContextError(
1211:                                "DSAMEConnection.setTemplateAttribute(): "
1212:                                        + "Unsupported AMObject found.  "
1213:                                        + "dn=" + dn + ", serviceName="
1214:                                        + serviceName);
1215:                    }
1216:
1217:                } catch (AMException dpe) {
1218:                    throw new ContextError(
1219:                            "DSAMEConnection.setTemplateAttribute(): "
1220:                                    + ", dn=" + dn + ", serviceName= "
1221:                                    + serviceName + ", " + attributeName + "="
1222:                                    + val, dpe);
1223:
1224:                } catch (SSOException sso) {
1225:                    throw new ContextError("dn: " + dn + ", serviceName: "
1226:                            + serviceName + ", " + attributeName + "=" + val,
1227:                            sso, ContextError.SESSION_TYPE);
1228:                }
1229:            }
1230:
1231:            private void setTemplateAttributes(String dn, String serviceName,
1232:                    String attributeName, Set vals) {
1233:                Map map = new HashMap();
1234:                map.put(attributeName, vals);
1235:
1236:                try {
1237:                    int objType = connection.getAMObjectType(dn);
1238:
1239:                    switch (objType) {
1240:                    case AMObject.ORGANIZATION:
1241:                        AMOrganization org = connection.getOrganization(dn);
1242:                        if (org == null) {
1243:                            throw new ContextError(
1244:                                    "DSAMEConnection.setTemplateAttributes(): "
1245:                                            + "Organization not found.  "
1246:                                            + "dn=" + dn + ", serviceName="
1247:                                            + serviceName);
1248:                        }
1249:
1250:                        AMTemplate temp = org.getTemplate(serviceName,
1251:                                AMTemplate.DYNAMIC_TEMPLATE);
1252:                        boolean tempExists = (temp != null) && temp.isExists();
1253:                        if (!tempExists) {
1254:                            org.createTemplate(AMTemplate.DYNAMIC_TEMPLATE,
1255:                                    serviceName, null);
1256:                        }
1257:                        temp.setAttributes(map);
1258:                        temp.store();
1259:                        break;
1260:
1261:                    case AMObject.ROLE:
1262:                        AMRole role = connection.getRole(dn);
1263:                        if (role == null) {
1264:                            throw new ContextError(
1265:                                    "DSAMEConnection.setTemplateAttributes(): "
1266:                                            + "Role not found.  " + "dn=" + dn
1267:                                            + ", serviceName=" + serviceName);
1268:                        }
1269:
1270:                        temp = role.getTemplate(serviceName,
1271:                                AMTemplate.DYNAMIC_TEMPLATE);
1272:                        tempExists = (temp != null) && temp.isExists();
1273:                        if (!tempExists) {
1274:                            role.createTemplate(AMTemplate.DYNAMIC_TEMPLATE,
1275:                                    serviceName, null);
1276:                        }
1277:                        temp.setAttributes(map);
1278:                        temp.store();
1279:                        break;
1280:
1281:                    case AMObject.FILTERED_ROLE:
1282:                        AMFilteredRole frole = connection.getFilteredRole(dn);
1283:                        if (frole == null) {
1284:                            throw new ContextError(
1285:                                    "DSAMEConnection.setTemplateAttributes(): "
1286:                                            + "filtered role not found.  "
1287:                                            + "dn=" + dn + ", serviceName="
1288:                                            + serviceName);
1289:                        }
1290:
1291:                        temp = frole.getTemplate(serviceName,
1292:                                AMTemplate.DYNAMIC_TEMPLATE);
1293:                        tempExists = (temp != null) && temp.isExists();
1294:                        if (!tempExists) {
1295:                            frole.createTemplate(AMTemplate.DYNAMIC_TEMPLATE,
1296:                                    serviceName, null);
1297:                        }
1298:                        temp.setAttributes(map);
1299:                        temp.store();
1300:                        break;
1301:
1302:                    default:
1303:                        throw new ContextError(
1304:                                "DSAMEConnection.setTemplateAttributes(): "
1305:                                        + "Unsupported AMObject found.  "
1306:                                        + "dn=" + dn + ", serviceName="
1307:                                        + serviceName);
1308:                    }
1309:
1310:                } catch (AMException dpe) {
1311:                    throw new ContextError(
1312:                            "DSAMEConnection.setTemplateAttributes(): "
1313:                                    + ", dn=" + dn + ", serviceName= "
1314:                                    + serviceName + ", " + attributeName + "="
1315:                                    + vals, dpe);
1316:
1317:                } catch (SSOException sso) {
1318:                    throw new ContextError("dn: " + dn + ", serviceName: "
1319:                            + serviceName + ", " + attributeName + "=" + vals,
1320:                            sso, ContextError.SESSION_TYPE);
1321:                }
1322:            }
1323:
1324:            private void removeTemplateAttribute(String dn, String serviceName,
1325:                    String attributeName) {
1326:                try {
1327:                    int objType = connection.getAMObjectType(dn);
1328:
1329:                    Set attrs = new HashSet();
1330:                    attrs.add(attributeName);
1331:
1332:                    switch (objType) {
1333:                    case AMObject.ORGANIZATION:
1334:                        AMOrganization org = connection.getOrganization(dn);
1335:                        if (org == null) {
1336:                            throw new ContextError(
1337:                                    "DSAMEConnection.removeTemplateAttribute(): "
1338:                                            + "Organization not found.  "
1339:                                            + "dn=" + dn + ", serviceName="
1340:                                            + serviceName);
1341:                        }
1342:
1343:                        AMTemplate temp = org.getTemplate(serviceName,
1344:                                AMTemplate.DYNAMIC_TEMPLATE);
1345:                        boolean tempExists = (temp != null) && temp.isExists();
1346:                        if (!tempExists) {
1347:                            org.createTemplate(AMTemplate.DYNAMIC_TEMPLATE,
1348:                                    serviceName, null);
1349:                        }
1350:                        temp.removeAttributes(attrs);
1351:                        temp.store();
1352:                        break;
1353:
1354:                    case AMObject.ROLE:
1355:                        AMRole role = connection.getRole(dn);
1356:                        if (role == null) {
1357:                            throw new ContextError(
1358:                                    "DSAMEConnection.removeTemplateAttribute(): "
1359:                                            + "Role not found.  " + "dn=" + dn
1360:                                            + ", serviceName=" + serviceName);
1361:                        }
1362:
1363:                        temp = role.getTemplate(serviceName,
1364:                                AMTemplate.DYNAMIC_TEMPLATE);
1365:                        tempExists = (temp != null) && temp.isExists();
1366:                        if (!tempExists) {
1367:                            role.createTemplate(AMTemplate.DYNAMIC_TEMPLATE,
1368:                                    serviceName, null);
1369:                        }
1370:                        temp.removeAttributes(attrs);
1371:                        temp.store();
1372:                        break;
1373:
1374:                    case AMObject.FILTERED_ROLE:
1375:                        AMFilteredRole frole = connection.getFilteredRole(dn);
1376:                        if (frole == null) {
1377:                            throw new ContextError(
1378:                                    "DSAMEConnection.removeTemplateAttribute(): "
1379:                                            + "filtered role not found.  "
1380:                                            + "dn=" + dn + ", serviceName="
1381:                                            + serviceName);
1382:                        }
1383:
1384:                        temp = frole.getTemplate(serviceName,
1385:                                AMTemplate.DYNAMIC_TEMPLATE);
1386:                        tempExists = (temp != null) && temp.isExists();
1387:                        if (!tempExists) {
1388:                            frole.createTemplate(AMTemplate.DYNAMIC_TEMPLATE,
1389:                                    serviceName, null);
1390:                        }
1391:                        temp.removeAttributes(attrs);
1392:                        temp.store();
1393:                        break;
1394:
1395:                    default:
1396:                        throw new ContextError(
1397:                                "DSAMEConnection.removeTemplateAttribute(): "
1398:                                        + "Unsupported AMObject found.  "
1399:                                        + "dn=" + dn + ", serviceName="
1400:                                        + serviceName);
1401:                    }
1402:
1403:                } catch (AMException dpe) {
1404:                    throw new ContextError(
1405:                            "DSAMEConnection.removeTemplateAttribute(): "
1406:                                    + ", dn=" + dn + ", serviceName= "
1407:                                    + serviceName + ", " + attributeName, dpe);
1408:
1409:                } catch (SSOException sso) {
1410:                    throw new ContextError("dn: " + dn + ", serviceName: "
1411:                            + serviceName + ", " + attributeName, sso,
1412:                            ContextError.SESSION_TYPE);
1413:                }
1414:            }
1415:
1416:            protected static SSOToken getSSOToken(HttpServletRequest request) {
1417:                SSOToken token = null;
1418:                try {
1419:                    token = getSSOTokenManager().createSSOToken(request);
1420:                } catch (SSOException se) {
1421:                    // This means that SSOToken is invalid
1422:                    throw new ContextError("Failed to get SSOToken", se,
1423:                            ContextError.SESSION_TYPE);
1424:                }
1425:                return token;
1426:            }
1427:
1428:            protected static SSOTokenManager getSSOTokenManager() {
1429:                if (_tokenMgr == null) {
1430:                    try {
1431:                        _tokenMgr = SSOTokenManager.getInstance();
1432:                        if (_tokenMgr == null) {
1433:                            throw new ContextError(
1434:                                    "DSAMEConnection.getSSOTokenMgr(): "
1435:                                            + "Failed to get SSOTokenManager. ");
1436:                        }
1437:                    } catch (SSOException se) {
1438:                        throw new ContextError("failed to get SSOTokenManager",
1439:                                se, ContextError.SESSION_TYPE);
1440:                    }
1441:                }
1442:
1443:                return _tokenMgr;
1444:            }
1445:
1446:            public static String getRootDN() {
1447:                return SystemProperties.get("com.iplanet.am.rootsuffix");
1448:            }
1449:
1450:            public void prefetchAttributes(Set names) {
1451:                try {
1452:                    user.getAttributes(names);
1453:                } catch (AMException dpe) {
1454:                    throw new ContextError(
1455:                            "DAMEConnection.prefetchAttributes(): names="
1456:                                    + names, dpe);
1457:                } catch (SSOException ssoe) {
1458:                    throw new ContextError("names=" + names, ssoe,
1459:                            ContextError.SESSION_TYPE);
1460:                }
1461:            }
1462:
1463:            public String getAttributeFromROC(String key) {
1464:                String v = null;
1465:
1466:                if (ROC.containsObject(key)) {
1467:                    v = (String) ROC.getObject(key);
1468:                } else {
1469:                    v = getAttribute(key);
1470:                    ROC.setObject(key, v);
1471:                }
1472:
1473:                return v;
1474:            }
1475:
1476:            public byte[] getAttributeByteArrayFromROC(String key) {
1477:                byte[] v = null;
1478:
1479:                if (ROC.containsObject(key)) {
1480:                    v = (byte[]) ROC.getObject(key);
1481:                } else {
1482:                    v = getAttributeByteArray(key);
1483:                    ROC.setObject(key, v);
1484:                }
1485:
1486:                return v;
1487:            }
1488:
1489:            public String getOrgAttributeFromROC(String service, String key) {
1490:                String s = null;
1491:                if (ROC.containsObject(key)) {
1492:                    s = (String) ROC.getObject(key);
1493:                } else {
1494:                    s = getOrganizationAttribute(service, key);
1495:                    ROC.setObject(key, s);
1496:                }
1497:
1498:                return s;
1499:            }
1500:
1501:            protected String getGlobalAttributeFromROC(String service,
1502:                    String key) {
1503:                Set vals = getGlobalAttributeMultiValueFromROC(service, key);
1504:                if (vals == null || vals.size() < 1) {
1505:                    return null;
1506:                }
1507:
1508:                Iterator iter = vals.iterator();
1509:                String val = (String) iter.next();
1510:
1511:                return val;
1512:            }
1513:
1514:            protected Set getGlobalAttributeMultiValueFromROC(String service,
1515:                    String key) {
1516:                String rocKey = service + "." + key;
1517:                Map attrs = (Map) ROC.getObject(rocKey);
1518:
1519:                if (attrs == null) {
1520:                    attrs = getGlobalAttributes(service);
1521:                    ROC.setObject(rocKey, attrs);
1522:                }
1523:
1524:                Set vals = (Set) attrs.get(key);
1525:                return vals;
1526:            }
1527:
1528:            public String getAttributeByDNFromROC(String dn, String key) {
1529:                String value = null;
1530:
1531:                if (dn.equals(GLOBAL_KEY)) {
1532:                    value = getGlobalAttributeFromROC(
1533:                            dmpc.MP_SUN_DESKTOP_SERVICE, key);
1534:                } else {
1535:                    int objType;
1536:                    try {
1537:                        objType = getAdminConnection().getAMObjectType(dn);
1538:                    } catch (AMException ame) {
1539:                        throw new ContextError(
1540:                                "DSAMEConnection.getAttrbiuteByDNFromROC()",
1541:                                ame);
1542:                    } catch (SSOException ssoe) {
1543:                        throw new ContextError(ssoe, ContextError.SESSION_TYPE);
1544:                    }
1545:
1546:                    if (objType == AMObject.USER) {
1547:                        if (key.equals(DSAMEConstants.ATTR_DP_DOCUMENT)) {
1548:                            key = dmpc.MP_ATTR_DP_DOCUMENT_USER;
1549:                        } else if (key
1550:                                .equals(DSAMEConstants.ATTR_DP_LAST_MODIFIED)) {
1551:                            key = dmpc.MP_ATTR_DP_LAST_MODIFIED_USER;
1552:                        }
1553:                        value = getAttributeFromROC(key);
1554:                    } else {
1555:                        value = getTemplateAttribute(dn,
1556:                                dmpc.MP_SUN_DESKTOP_SERVICE, key);
1557:                    }
1558:                }
1559:
1560:                return value;
1561:            }
1562:
1563:            public boolean isGlobal(String dn) {
1564:                if (dn.equals(GLOBAL_KEY)) {
1565:                    return true;
1566:                } else {
1567:                    return false;
1568:                }
1569:            }
1570:
1571:            /*
1572:              This method  checks if specified  service is assigned to specified dn
1573:             */
1574:
1575:            public boolean isServiceAssigned(String dn, String serviceName) {
1576:                Set services = null;
1577:                int objType = -1;
1578:                boolean isServiceAssigned = false;
1579:                try {
1580:                    objType = getAdminConnection().getAMObjectType(dn);
1581:
1582:                    if (objType == AMObject.ORGANIZATION) {
1583:                        AMOrganization org = getAdminConnection()
1584:                                .getOrganization(dn);
1585:                        if (org == null) {
1586:                            throw new ContextError(
1587:                                    "DSAMEConnection.isServiceAssigned(): "
1588:                                            + "Organization not found.  "
1589:                                            + "dn=" + dn);
1590:                        }
1591:                        services = org.getRegisteredServiceNames();
1592:                        if (services != null && services.contains(serviceName)) {
1593:                            isServiceAssigned = true;
1594:                        }
1595:
1596:                    } else if (objType == AMObject.ROLE) {
1597:                        AMRole role = getAdminConnection().getRole(dn);
1598:                        if (role == null) {
1599:                            throw new ContextError(
1600:                                    "DSAMEConnection.isServiceAssigned(): "
1601:                                            + "Role not found.  " + "dn=" + dn);
1602:                        }
1603:                        String orgDN = role.getOrganizationDN();
1604:                        isServiceAssigned = isServiceAssigned(orgDN,
1605:                                serviceName);
1606:
1607:                    } else if (objType == AMObject.FILTERED_ROLE) {
1608:                        AMFilteredRole frole = getAdminConnection()
1609:                                .getFilteredRole(dn);
1610:                        if (frole == null) {
1611:                            throw new ContextError(
1612:                                    "DSAMEConnection.isServiceAssigned(): "
1613:                                            + "filtered role not found.  "
1614:                                            + "dn=" + dn);
1615:                        }
1616:                        String orgDN = frole.getOrganizationDN();
1617:                        isServiceAssigned = isServiceAssigned(orgDN,
1618:                                serviceName);
1619:
1620:                    } else if (objType == AMObject.ORGANIZATIONAL_UNIT) {
1621:                        AMOrganizationalUnit ou = getAdminConnection()
1622:                                .getOrganizationalUnit(dn);
1623:                        if (ou == null) {
1624:                            throw new ContextError(
1625:                                    "DSAMEConnection.isServiceAssigned(): "
1626:                                            + "ou not found.  " + "dn=" + dn);
1627:                        }
1628:                        services = ou.getRegisteredServiceNames();
1629:                        if (services != null && services.contains(serviceName)) {
1630:                            isServiceAssigned = true;
1631:                        }
1632:                    } else if (objType == AMObject.USER) {
1633:                        AMUser usr = getAdminConnection().getUser(dn);
1634:                        if (usr == null) {
1635:                            throw new ContextError(
1636:                                    "DSAMEConnection.isServiceAssigned(): "
1637:                                            + "user not found.  " + "dn=" + dn);
1638:                        }
1639:                        services = usr.getAssignedServices();
1640:                        if (services != null && services.contains(serviceName)) {
1641:                            isServiceAssigned = true;
1642:                        }
1643:                    } else {
1644:                        throw new ContextError(
1645:                                "DSAMEConnection.isServiceAssigned(): "
1646:                                        + "Unsupported AMObject found.  "
1647:                                        + "dn=" + dn + ", objectType="
1648:                                        + objType);
1649:                    }
1650:
1651:                } catch (AMException dpe) {
1652:                    throw new ContextError(
1653:                            "DSAMEConnection.isServiceAssigned(): " + "dn="
1654:                                    + dn, dpe);
1655:
1656:                } catch (SSOException sso) {
1657:                    throw new ContextError("dn: " + dn, sso,
1658:                            ContextError.SESSION_TYPE);
1659:                }
1660:                return isServiceAssigned;
1661:            }
1662:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.