Source Code Cross Referenced for ConsumerAttributeHandler.java in  » Portal » Open-Portal » com » sun » portal » wsrp » consumer » admin » mbeans » 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.wsrp.consumer.admin.mbeans 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * $Id: ConsumerAttributeHandler.java,v 1.17 2006/05/25 07:19:31 rt130506 Exp $
003:         * Copyright 2005 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.wsrp.consumer.admin.mbeans;
014:
015:        import java.util.ArrayList;
016:        import java.util.Collections;
017:        import java.util.HashMap;
018:        import java.util.Iterator;
019:        import java.util.List;
020:        import java.util.Map;
021:        import java.util.Set;
022:        import java.util.StringTokenizer;
023:        import java.util.logging.Level;
024:        import java.util.logging.Logger;
025:        import java.util.Date;
026:
027:        import com.iplanet.am.util.Locale;
028:        import com.iplanet.sso.SSOException;
029:        import com.sun.portal.admin.common.AttrOptionConstants;
030:        import com.sun.portal.admin.common.PSMBeanException;
031:        import com.sun.portal.admin.common.PSConfigConstants;
032:        import com.sun.portal.wsrp.consumer.common.WSRPConsumerBootstrap;
033:        import com.sun.portal.admin.server.AdminServerUtil;
034:        import com.sun.portal.fabric.common.GenericDSAMEAttributeHandler;
035:        import com.sun.portal.log.common.PortalLogger;
036:        import com.sun.portal.wsrp.common.stubs.ItemDescription;
037:        import com.sun.portal.wsrp.common.stubs.LocalizedString;
038:        import com.sun.portal.wsrp.common.stubs.ModelDescription;
039:        import com.sun.portal.wsrp.common.stubs.Property;
040:        import com.sun.portal.wsrp.common.stubs.PropertyDescription;
041:        import com.sun.portal.wsrp.common.stubs.RegistrationContext;
042:        import com.sun.portal.wsrp.common.stubs.RegistrationData;
043:        import com.sun.portal.wsrp.common.stubs.ServiceDescription;
044:        import com.sun.portal.wsrp.common.IdentityPropagationConstants;
045:        import com.sun.portal.wsrp.consumer.common.WSRPConsumerException;
046:        import com.sun.portal.wsrp.consumer.producermanager.ProducerEntity;
047:        import com.sun.portal.wsrp.consumer.producermanager.ProducerEntityManager;
048:        import com.sun.portal.wsrp.consumer.producermanager.ProducerEntityManagerFactory;
049:        import com.sun.portal.wsrp.consumer.producermanager.ProducerEntityStatus;
050:        import com.sun.portal.wsrp.consumer.producermanager.impl.ISConsumerMultiPortalConstants;
051:
052:        public class ConsumerAttributeHandler extends
053:                GenericDSAMEAttributeHandler {
054:            public static final String LANG = Locale.getDefaultLocale()
055:                    .toString().replace('_', '-');
056:
057:            private static ProducerEntityManagerFactory pemFactory = ProducerEntityManagerFactory
058:                    .getInstance();
059:            private String wsrpConsumerConfigFileName = PSConfigConstants.PS_WSRP_CONSUMER_CONFIG_FILE;
060:
061:            private static Logger logger = PortalLogger
062:                    .getLogger(ConsumerAttributeHandler.class);
063:
064:            private ISConsumerMultiPortalConstants iscmpc = null;
065:            private Map userFriendlyMap = new HashMap();
066:            private Map systemFriendlyMap = new HashMap();
067:
068:            public void init(String component, String domainId, String portalId)
069:                    throws PSMBeanException {
070:
071:                if (portalId == null) {
072:                    logger.severe("PSWS_CSPWCAB0029");
073:                    throw new PSMBeanException("Missing portal Id.");
074:                }
075:
076:                super .init(component, domainId, portalId);
077:                WSRPConsumerBootstrap.cliInitialized(
078:                        wsrpConsumerConfigFileName, portalId);
079:                iscmpc = ISConsumerMultiPortalConstants.getInstance(portalId);
080:                buildMaps();
081:            }
082:
083:            private void buildMaps() {
084:                userFriendlyMap
085:                        .put(
086:                                IdentityPropagationConstants.SSOTOKEN_IDENTITY_PROPAGATION,
087:                                IdentityPropagationConstants.SSOTOKEN_IDENTITY_PROPAGATION_UF_NAME);
088:                userFriendlyMap
089:                        .put(
090:                                IdentityPropagationConstants.NO_IDENTITY_PROPAGATION,
091:                                IdentityPropagationConstants.NO_IDENTITY_PROPAGATION_UF_NAME);
092:                userFriendlyMap
093:                        .put(
094:                                IdentityPropagationConstants.OASIS_WSS_USERNAME_ONLY_PROPAGATION,
095:                                IdentityPropagationConstants.OASIS_WSS_USERNAME_ONLY_PROPAGATION_UF_NAME);
096:                userFriendlyMap
097:                        .put(
098:                                IdentityPropagationConstants.OASIS_WSS_USERNAME_PASSWORD_PLAINTEXT_PROPAGATION,
099:                                IdentityPropagationConstants.OASIS_WSS_USERNAME_PASSWORD_PLAINTEXT_PROPAGATION_UF_NAME);
100:                userFriendlyMap
101:                        .put(
102:                                IdentityPropagationConstants.OASIS_WSS_USERNAME_PASSWORD_DIGEST_PROPAGATION,
103:                                IdentityPropagationConstants.OASIS_WSS_USERNAME_PASSWORD_DIGEST_PROPAGATION_UF_NAME);
104:
105:                systemFriendlyMap
106:                        .put(
107:                                IdentityPropagationConstants.SSOTOKEN_IDENTITY_PROPAGATION_UF_NAME,
108:                                IdentityPropagationConstants.SSOTOKEN_IDENTITY_PROPAGATION);
109:                systemFriendlyMap
110:                        .put(
111:                                IdentityPropagationConstants.NO_IDENTITY_PROPAGATION_UF_NAME,
112:                                IdentityPropagationConstants.NO_IDENTITY_PROPAGATION);
113:                systemFriendlyMap
114:                        .put(
115:                                IdentityPropagationConstants.OASIS_WSS_USERNAME_ONLY_PROPAGATION_UF_NAME,
116:                                IdentityPropagationConstants.OASIS_WSS_USERNAME_ONLY_PROPAGATION);
117:                systemFriendlyMap
118:                        .put(
119:                                IdentityPropagationConstants.OASIS_WSS_USERNAME_PASSWORD_PLAINTEXT_PROPAGATION_UF_NAME,
120:                                IdentityPropagationConstants.OASIS_WSS_USERNAME_PASSWORD_PLAINTEXT_PROPAGATION);
121:                systemFriendlyMap
122:                        .put(
123:                                IdentityPropagationConstants.OASIS_WSS_USERNAME_PASSWORD_DIGEST_PROPAGATION_UF_NAME,
124:                                IdentityPropagationConstants.OASIS_WSS_USERNAME_PASSWORD_DIGEST_PROPAGATION);
125:
126:            }
127:
128:            public String getAttributeName(String userFriendlyName) {
129:                // TODO: shouldn't hardcode the "sunPortalWSRPConsumer" string here
130:                return "sunPortalWSRPConsumer" + userFriendlyName;
131:            }
132:
133:            public String getComponentName(String userFriendlyName) {
134:                return iscmpc.MP_SERVICE_WSRP_CONSUMER;
135:            }
136:
137:            public List getAttribute(Map optionsMap) throws PSMBeanException {
138:                String name = (String) optionsMap
139:                        .get(AttrOptionConstants.OPT_ATTR_NAME);
140:
141:                optionsMap.put(AttrOptionConstants.OPT_ATTR_NAMES, Collections
142:                        .singleton(name));
143:
144:                List result = (List) getAttributes(optionsMap).get(name);
145:                if (name.equals(ConsumerAttributes.IDENTITY_PROPAGATION_TYPE)) {
146:                    result = Collections
147:                            .singletonList(getUserFriendlyName((String) result
148:                                    .get(0)));
149:                }
150:                return result;
151:            }
152:
153:            private String getUserFriendlyName(String sf_name) {
154:                return userFriendlyMap.containsKey(sf_name) ? (String) userFriendlyMap
155:                        .get(sf_name)
156:                        : sf_name;
157:            }
158:
159:            private String getSystemFriendlyName(String uf_name) {
160:                return systemFriendlyMap.containsKey(uf_name) ? (String) systemFriendlyMap
161:                        .get(uf_name)
162:                        : uf_name;
163:            }
164:
165:            public Map getAttributes(Map optionsMap) throws PSMBeanException {
166:                // TODO: shouldn't hardcode the "producer" string here
167:                String producerID = (String) optionsMap.get("producer");
168:
169:                if (producerID == null) {
170:                    return getConsumerAttributes(optionsMap);
171:                } else {
172:                    return getPEAttributes(optionsMap, producerID);
173:                }
174:            }
175:
176:            public void setAttribute(List values, Map optionsMap)
177:                    throws PSMBeanException {
178:
179:                String name = (String) optionsMap
180:                        .get(AttrOptionConstants.OPT_ATTR_NAME);
181:
182:                //Convert user frindly IDENTITY_PROPAGATION_TYPE to System expected TYPE
183:                if (name.equals(ConsumerAttributes.IDENTITY_PROPAGATION_TYPE)) {
184:                    values = Collections
185:                            .singletonList(getSystemFriendlyName((String) values
186:                                    .get(0)));
187:                }
188:                setAttributes(Collections.singletonMap(name, values),
189:                        optionsMap);
190:            }
191:
192:            public void setAttributes(Map nameValues, Map optionsMap)
193:                    throws PSMBeanException {
194:
195:                // TODO: shouldn't hardcode the "producer" string here
196:                String producerID = (String) optionsMap.get("producer");
197:
198:                if (producerID == null) {
199:                    setConsumerAttributes(nameValues, optionsMap);
200:                } else {
201:                    setPEAttributes(nameValues, optionsMap, producerID);
202:                }
203:            }
204:
205:            public Map listAttributes(Map optionsMap) throws PSMBeanException {
206:                // TODO: shouldn't hardcode the "configuredproducer" string here
207:                String cp = (String) optionsMap.get("configuredproducer");
208:
209:                if (Boolean.valueOf(cp).booleanValue()) {
210:                    return ConsumerAttributes.PE_MAP;
211:                } else {
212:                    return ConsumerAttributes.CONSUMER_MAP;
213:                }
214:            }
215:
216:            private Map getConsumerAttributes(Map optionsMap)
217:                    throws PSMBeanException {
218:                Set names = (Set) optionsMap
219:                        .get(AttrOptionConstants.OPT_ATTR_NAMES);
220:                Map result = new HashMap(names.size());
221:
222:                for (Iterator i = names.iterator(); i.hasNext();) {
223:                    String name = (String) i.next();
224:                    optionsMap.put(AttrOptionConstants.OPT_ATTR_NAME, name);
225:
226:                    if (name.equals(ConsumerAttributes.IS_DISABLED)) {
227:                        optionsMap.put(AttrOptionConstants.OPT_GLOBAL,
228:                                Boolean.TRUE.toString());
229:                    } else if (name
230:                            .equals(ConsumerAttributes.USER_PROFILE_MAPPING)) {
231:                        optionsMap.put(AttrOptionConstants.OPT_GLOBAL,
232:                                Boolean.TRUE.toString());
233:                    } else if (name.equals(ConsumerAttributes.NAME)) {
234:                        optionsMap.put(AttrOptionConstants.OPT_ORG,
235:                                Boolean.TRUE.toString());
236:                    } else {
237:                        logger.log(Level.WARNING, "PSWS_CSPWCAB0016", name);
238:                        throw new PSMBeanException(
239:                                "No such consumer attribute: " + name);
240:                    }
241:
242:                    result.put(name, super .getAttribute(optionsMap));
243:                }
244:
245:                return result;
246:            }
247:
248:            private Map getPEAttributes(Map optionsMap, String producerID)
249:                    throws PSMBeanException {
250:
251:                Set names = (Set) optionsMap
252:                        .get(AttrOptionConstants.OPT_ATTR_NAMES);
253:                Map result = new HashMap(names.size());
254:                String orgDN = (String) optionsMap
255:                        .get(AttrOptionConstants.OPT_DN);
256:
257:                if (orgDN == null) {
258:                    logger.severe("PSWS_CSPWCAB0017");
259:                    throw new PSMBeanException("Missing organization DN.");
260:                }
261:
262:                ProducerEntityManager pem = getPEM(orgDN);
263:                ProducerEntity pe = null;
264:
265:                try {
266:                    pe = pem.getProducerEntity(producerID);
267:                } catch (WSRPConsumerException e) {
268:                    logger.log(Level.SEVERE, "PSWS_CSPWCAB0018", e);
269:                    throw new PSMBeanException("getPE error", e.getMessage());
270:                }
271:
272:                for (Iterator i = names.iterator(); i.hasNext();) {
273:                    String name = (String) i.next();
274:
275:                    if (name.equals(ConsumerAttributes.NAME)) {
276:                        result.put(name, Collections
277:                                .singletonList(pe.getName()));
278:                    } else if (name.equals(ConsumerAttributes.ENABLED)) {
279:                        ProducerEntityStatus status = pe.getStatus();
280:                        boolean enabled = status
281:                                .equals(ProducerEntityStatus.OK);
282:                        result.put(name, Collections.singletonList(Boolean
283:                                .toString(enabled)));
284:                    } else if (name.equals(ConsumerAttributes.WSDL_URL)) {
285:                        result.put(name, Collections.singletonList(pe.getURL()
286:                                .toString()));
287:                    } else if (name
288:                            .equals(ConsumerAttributes.SERVICE_DESC_LAST_MOD)) {
289:                        long time = pe.getServiceDescriptionLastModified();
290:                        result.put(name, Collections.singletonList((new Date(
291:                                time)).toString()));
292:                    } else if (name
293:                            .equals(ConsumerAttributes.IDENTITY_PROPAGATION_TYPE)) {
294:                        result.put(name, Collections.singletonList(pe
295:                                .getIdentityPropagationType()));
296:                    } else if (name.equals(ConsumerAttributes.ALL_ROLES)) {
297:                        try {
298:                            Map allRoles = AMHelper.getAllRoles(orgDN);
299:                            Set entrySet = allRoles.entrySet();
300:                            List roles = new ArrayList(entrySet.size());
301:
302:                            for (Iterator j = entrySet.iterator(); j.hasNext();) {
303:                                StringBuffer sb = new StringBuffer();
304:                                Map.Entry entry = (Map.Entry) j.next();
305:                                sb.append(entry.getKey());
306:                                sb.append(":");
307:                                sb.append(entry.getValue());
308:                                roles.add(sb.toString());
309:                            }
310:
311:                            result.put(name, roles);
312:                        } catch (Exception e) {
313:                            logger.log(Level.SEVERE, "PSWS_CSPWCAB0019", e);
314:                            throw new PSMBeanException("wsrp.consumer", e
315:                                    .getMessage());
316:                        }
317:                    } else if (name
318:                            .equals(ConsumerAttributes.USER_CATEGORY_DESCRIPTIONS)) {
319:                        List userCategoryDescriptions = new ArrayList();
320:                        ServiceDescription sd = pe.getServiceDescription();
321:                        ItemDescription[] ucds = sd
322:                                .getUserCategoryDescriptions();
323:
324:                        if (ucds != null) {
325:                            for (int j = 0; j < ucds.length; j++) {
326:                                StringBuffer sb = new StringBuffer();
327:                                sb.append(ucds[j].getItemName());
328:                                sb.append("=");
329:                                LocalizedString description = ucds[j]
330:                                        .getDescription();
331:
332:                                if (description != null) {
333:                                    sb.append(description.getValue());
334:                                }
335:
336:                                userCategoryDescriptions.add(sb.toString());
337:                            }
338:                        }
339:
340:                        result.put(name, userCategoryDescriptions);
341:                    } else if (name
342:                            .equals(ConsumerAttributes.USER_CATEGORY_MAPPING)) {
343:                        List ucm = Collections.EMPTY_LIST;
344:                        Map userCategoryMapping = pe.getUserCategoryMapping();
345:
346:                        if (userCategoryMapping != null) {
347:                            Set entrySet = userCategoryMapping.entrySet();
348:                            ucm = new ArrayList(entrySet.size());
349:
350:                            for (Iterator j = entrySet.iterator(); j.hasNext();) {
351:                                StringBuffer sb = new StringBuffer();
352:                                Map.Entry entry = (Map.Entry) j.next();
353:                                sb.append(entry.getKey());
354:                                sb.append("=");
355:                                List values = (List) entry.getValue();
356:
357:                                if ((values != null) && values.size() > 0) {
358:                                    sb.append(values.get(0));
359:
360:                                    for (int k = 1; k < values.size(); k++) {
361:                                        sb.append("|");
362:                                        sb.append(values.get(k));
363:                                    }
364:                                }
365:
366:                                ucm.add(sb.toString());
367:                            }
368:                        }
369:
370:                        result.put(name, ucm);
371:                    } else if (name
372:                            .equals(ConsumerAttributes.REGISTRATION_REQUIRED)) {
373:                        boolean required = pe.getServiceDescription()
374:                                .isRequiresRegistration();
375:                        result.put(name, Collections.singletonList(Boolean
376:                                .toString(required)));
377:                    } else if (name
378:                            .equals(ConsumerAttributes.REGISTRATION_HANDLE)) {
379:                        String handle = null;
380:                        RegistrationContext rc = pe.getRegistrationContext();
381:
382:                        if (rc != null) {
383:                            handle = rc.getRegistrationHandle();
384:                        }
385:
386:                        result.put(name, Collections
387:                                .singletonList((handle == null) ? "" : handle));
388:                    } else if (name
389:                            .equals(ConsumerAttributes.REGISTRATION_PROPERTY_DESCRIPTION)) {
390:                        List rpds = new ArrayList();
391:                        ServiceDescription sd = pe.getServiceDescription();
392:                        ModelDescription md = sd
393:                                .getRegistrationPropertyDescription();
394:
395:                        if (md != null) {
396:                            PropertyDescription[] pds = md
397:                                    .getPropertyDescriptions();
398:
399:                            if (pds != null) {
400:                                for (int j = 0; j < pds.length; j++) {
401:                                    StringBuffer sb = new StringBuffer();
402:                                    sb.append(pds[j].getName());
403:                                    sb.append("=");
404:                                    LocalizedString hint = pds[j].getHint();
405:
406:                                    if (hint != null) {
407:                                        sb.append(hint.getValue());
408:                                    }
409:
410:                                    rpds.add(sb.toString());
411:                                }
412:                            }
413:                        }
414:
415:                        result.put(name, rpds);
416:                    } else if (name
417:                            .equals(ConsumerAttributes.REGISTRATION_PROPERTIES)) {
418:                        List registrationProperties = Collections.EMPTY_LIST;
419:                        RegistrationData regData = pe.getRegistrationData();
420:
421:                        if (regData != null) {
422:                            Property[] rps = regData
423:                                    .getRegistrationProperties();
424:
425:                            if (rps != null) {
426:                                registrationProperties = new ArrayList(
427:                                        rps.length);
428:
429:                                for (int j = 0; j < rps.length; j++) {
430:                                    StringBuffer sb = new StringBuffer();
431:                                    sb.append(rps[j].getName());
432:                                    sb.append("=");
433:                                    sb.append(rps[j].getStringValue());
434:                                    registrationProperties.add(sb.toString());
435:                                }
436:                            }
437:                        }
438:
439:                        result.put(name, registrationProperties);
440:                    } else {
441:                        logger.log(Level.SEVERE, "PSWS_CSPWCAB0020", name);
442:                        throw new PSMBeanException(
443:                                "No such configured producer attribute: "
444:                                        + name);
445:                    }
446:                }
447:
448:                return result;
449:            }
450:
451:            private void setConsumerAttributes(Map nameValues, Map optionsMap)
452:                    throws PSMBeanException {
453:
454:                for (Iterator i = nameValues.entrySet().iterator(); i.hasNext();) {
455:                    Map.Entry attribute = (Map.Entry) i.next();
456:                    String name = (String) attribute.getKey();
457:                    List values = (List) attribute.getValue();
458:                    optionsMap.put(AttrOptionConstants.OPT_ATTR_NAME, name);
459:
460:                    if (name.equals(ConsumerAttributes.IS_DISABLED)) {
461:                        optionsMap.put(AttrOptionConstants.OPT_GLOBAL,
462:                                Boolean.TRUE.toString());
463:                    } else if (name
464:                            .equals(ConsumerAttributes.USER_PROFILE_MAPPING)) {
465:                        optionsMap.put(AttrOptionConstants.OPT_GLOBAL,
466:                                Boolean.TRUE.toString());
467:                    } else if (name.equals(ConsumerAttributes.NAME)) {
468:                        optionsMap.put(AttrOptionConstants.OPT_ORG,
469:                                Boolean.TRUE.toString());
470:                    } else {
471:                        logger.log(Level.SEVERE, "PSWS_CSPWCAB0021", name);
472:                        throw new PSMBeanException(
473:                                "No such consumer attribute: " + name);
474:                    }
475:
476:                    super .setAttribute(values, optionsMap);
477:                }
478:            }
479:
480:            private void setPEAttributes(Map nameValues, Map optionsMap,
481:                    String producerID) throws PSMBeanException {
482:
483:                boolean add = optionsMap
484:                        .containsKey(AttrOptionConstants.OPT_ADD);
485:                boolean remove = optionsMap
486:                        .containsKey(AttrOptionConstants.OPT_REMOVE);
487:                boolean set = !add && !remove;
488:
489:                String orgDN = (String) optionsMap
490:                        .get(AttrOptionConstants.OPT_DN);
491:
492:                if (orgDN == null) {
493:                    throw new PSMBeanException("Missing organization DN.");
494:                }
495:
496:                ProducerEntityManager pem = getPEM(orgDN);
497:
498:                try {
499:                    for (Iterator i = nameValues.entrySet().iterator(); i
500:                            .hasNext();) {
501:                        Map.Entry attribute = (Map.Entry) i.next();
502:                        String name = (String) attribute.getKey();
503:                        List values = (List) attribute.getValue();
504:
505:                        if (name.equals(ConsumerAttributes.NAME)) {
506:                            checkSingleton(name, values, set);
507:                            pem.setName(producerID, (String) values.get(0));
508:                        } else if (name
509:                                .equals(ConsumerAttributes.IDENTITY_PROPAGATION_TYPE)) {
510:                            //TODO: Map between userfriendly name and system name
511:                            checkSingleton(name, values, set);
512:                            String value = (String) values.get(0);
513:                            pem.setIdentityPropagationType(producerID, value);
514:                            modifyWSSOConfiguration(pem, value, producerID,
515:                                    orgDN);
516:                        } else if (name.equals(ConsumerAttributes.ENABLED)) {
517:                            boolean enabled = Boolean.valueOf(
518:                                    (String) values.get(0)).booleanValue();
519:
520:                            ProducerEntityStatus status = enabled ? ProducerEntityStatus.OK
521:                                    : ProducerEntityStatus.DISABLED;
522:
523:                            pem.setStatus(producerID, status);
524:                        } else if (name.equals(ConsumerAttributes.WSDL_URL)) {
525:                            throw new PSMBeanException(
526:                                    ConsumerAttributes.WSDL_URL
527:                                            + " is a read-only attribute.");
528:                        } else if (name
529:                                .equals(ConsumerAttributes.SERVICE_DESC_LAST_MOD)) {
530:                            throw new PSMBeanException(
531:                                    ConsumerAttributes.SERVICE_DESC_LAST_MOD
532:                                            + " is a read-only attribute.");
533:                        } else if (name.equals(ConsumerAttributes.ALL_ROLES)) {
534:                            throw new PSMBeanException(
535:                                    ConsumerAttributes.ALL_ROLES
536:                                            + " is a read-only attribute.");
537:                        } else if (name
538:                                .equals(ConsumerAttributes.USER_CATEGORY_DESCRIPTIONS)) {
539:                            throw new PSMBeanException(
540:                                    ConsumerAttributes.USER_CATEGORY_DESCRIPTIONS
541:                                            + " is a read-only attribute.");
542:                        } else if (name
543:                                .equals(ConsumerAttributes.USER_CATEGORY_MAPPING)) {
544:                            Map userCategoryMap = null;
545:                            ProducerEntity pe = pem
546:                                    .getProducerEntity(producerID);
547:                            ServiceDescription sd = pe.getServiceDescription();
548:                            ItemDescription[] ucds = sd
549:                                    .getUserCategoryDescriptions();
550:
551:                            if ((ucds != null) && (ucds.length > 0)) {
552:                                userCategoryMap = new HashMap();
553:
554:                                for (int j = 0; j < ucds.length; j++) {
555:                                    String uc = ucds[j].getItemName();
556:
557:                                    for (int k = 0; k < values.size(); k++) {
558:                                        String ucm = (String) values.get(k);
559:
560:                                        if (ucm.startsWith(uc)) {
561:                                            int index = ucm.indexOf("^");
562:                                            String roles = ucm
563:                                                    .substring(index + 1);
564:                                            StringTokenizer st = new StringTokenizer(
565:                                                    roles, "|");
566:                                            userCategoryMap.put(uc, Collections
567:                                                    .list(st));
568:                                            break;
569:                                        }
570:                                    }
571:                                }
572:                            }
573:
574:                            pem.setUserCategoryMapping(producerID,
575:                                    userCategoryMap);
576:                        } else if (name
577:                                .equals(ConsumerAttributes.REGISTRATION_REQUIRED)) {
578:                            throw new PSMBeanException(
579:                                    ConsumerAttributes.REGISTRATION_REQUIRED
580:                                            + " is a read-only attribute.");
581:                        } else if (name
582:                                .equals(ConsumerAttributes.REGISTRATION_HANDLE)) {
583:                            throw new PSMBeanException(
584:                                    ConsumerAttributes.REGISTRATION_HANDLE
585:                                            + " is a read-only attribute.");
586:                        } else if (name
587:                                .equals(ConsumerAttributes.REGISTRATION_PROPERTY_DESCRIPTION)) {
588:                            throw new PSMBeanException(
589:                                    ConsumerAttributes.REGISTRATION_PROPERTY_DESCRIPTION
590:                                            + " is a read-only attribute.");
591:                        } else if (name
592:                                .equals(ConsumerAttributes.REGISTRATION_PROPERTIES)) {
593:                            setRegProp(values, optionsMap, set, pem, producerID);
594:                        } else {
595:                            logger.log(Level.SEVERE, "PSWS_CSPWCAB0022", name);
596:                            throw new PSMBeanException(
597:                                    "No such configured producer attribute: "
598:                                            + name);
599:                        }
600:                    }
601:                } catch (WSRPConsumerException e) {
602:                    logger.log(Level.SEVERE, "PSWS_CSPWCAB0023", e);
603:                    throw new PSMBeanException("PE error", e.getMessage());
604:                }
605:            }
606:
607:            private ProducerEntityManager getPEM(String orgDN)
608:                    throws PSMBeanException {
609:                try {
610:                    return pemFactory.getProducerEntityManager(AdminServerUtil
611:                            .getSSOToken(), portalId, orgDN);
612:                } catch (WSRPConsumerException e) {
613:                    logger.log(Level.SEVERE, "PSWS_CSPWCAB0024", e);
614:                    throw new PSMBeanException("Can't get PEM.", e.getMessage());
615:                }
616:            }
617:
618:            private void checkSingleton(String attributeName, List values,
619:                    boolean set) throws PSMBeanException {
620:
621:                if (!set) {
622:                    logger.log(Level.SEVERE, "PSWS_CSPWCAB0025", attributeName);
623:                    throw new PSMBeanException(attributeName
624:                            + " does not allow add or remove.");
625:                }
626:
627:                if (values.size() != 1) {
628:                    logger.log(Level.SEVERE, "PSWS_CSPWCAB0026", attributeName);
629:                    throw new PSMBeanException(attributeName
630:                            + " requires one and only one value specified.");
631:                }
632:            }
633:
634:            private void setRegProp(List values, Map optionsMap, boolean set,
635:                    ProducerEntityManager pem, String producerID)
636:                    throws WSRPConsumerException {
637:
638:                ProducerEntity pe = pem.getProducerEntity(producerID);
639:                RegistrationData regData = pe.getRegistrationData();
640:
641:                if (regData == null) {
642:                    regData = pem.getDefaultRegistrationData();
643:                }
644:
645:                Property[] oldValues = regData.getRegistrationProperties();
646:                Property[] newValues = null;
647:
648:                ServiceDescription sd = pe.getServiceDescription();
649:                ModelDescription md = sd.getRegistrationPropertyDescription();
650:
651:                if (md != null) {
652:                    PropertyDescription[] pds = md.getPropertyDescriptions();
653:
654:                    if (pds != null) {
655:                        newValues = new Property[pds.length];
656:
657:                        for (int i = 0; i < pds.length; i++) {
658:                            String name = pds[i].getName();
659:                            String value = null;
660:
661:                            if (oldValues != null) {
662:                                for (int j = 0; j < oldValues.length; j++) {
663:                                    if (oldValues[j].getName().equals(name)) {
664:                                        value = oldValues[j].getStringValue();
665:                                        break;
666:                                    }
667:                                }
668:                            }
669:
670:                            if (set) {
671:                                value = getLastValueForName(name, values);
672:                            } else {
673:                                List addValues = (List) optionsMap
674:                                        .get(AttrOptionConstants.OPT_ADD);
675:
676:                                if (addValues != null) {
677:                                    String v = getLastValueForName(name,
678:                                            addValues);
679:
680:                                    if (v != null) {
681:                                        value = v;
682:                                    }
683:                                }
684:
685:                                List removeValues = (List) optionsMap
686:                                        .get(AttrOptionConstants.OPT_REMOVE);
687:
688:                                if (removeValues != null) {
689:                                    String v = getLastValueForName(name,
690:                                            removeValues);
691:
692:                                    if (v != null) {
693:                                        value = null;
694:                                    }
695:                                }
696:                            }
697:
698:                            newValues[i] = new Property(name, LANG, value, null);
699:                        }
700:                    }
701:                }
702:
703:                regData.setRegistrationProperties(newValues);
704:                pem.modifyRegistration(producerID, regData);
705:            }
706:
707:            private String getLastValueForName(String name, List properties) {
708:                String result = null;
709:
710:                for (int i = 0; i < properties.size(); i++) {
711:                    String n = null;
712:                    String v = null;
713:                    String property = (String) properties.get(i);
714:                    int index = property.indexOf("=");
715:
716:                    if (index >= 0) {
717:                        n = property.substring(0, index).trim();
718:                        v = property.substring(index + 1).trim();
719:                    } else {
720:                        n = property.trim();
721:                        v = "";
722:                    }
723:
724:                    if (n.equals(name)) {
725:                        result = v;
726:                    }
727:                }
728:
729:                return result;
730:            }
731:
732:            private void modifyWSSOConfiguration(ProducerEntityManager pem,
733:                    String newIdType, String producerId, String orgDN)
734:                    throws WSRPConsumerException {
735:                WSSSOHelper.modifyWSSOConfiguration(newIdType, orgDN, pem,
736:                        producerId, domainId, portalId);
737:            }
738:        }
ww_w_.j__a__v___a2__s.c_o__m | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.