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


001:        /**
002:         * $Id: AuthlessUIDBean.java,v 1.8 2006/08/23 02:56:23 rt94277 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.admin.console.desktop;
014:
015:        import java.util.logging.Level;
016:        import java.util.List;
017:        import java.util.ArrayList;
018:        import java.util.Map;
019:        import java.util.HashMap;
020:        import java.util.Set;
021:        import java.util.HashSet;
022:        import java.util.StringTokenizer;
023:        import javax.management.ObjectName;
024:        import javax.management.MBeanException;
025:        import javax.management.ReflectionException;
026:        import javax.management.MalformedObjectNameException;
027:        import com.sun.data.provider.DataProvider;
028:        import com.sun.data.provider.TableDataProvider;
029:        import com.sun.data.provider.impl.ObjectListDataProvider;
030:        import com.sun.data.provider.TableDataListener;
031:        import com.sun.data.provider.FieldKey;
032:        import com.sun.data.provider.RowKey;
033:        import com.sun.web.ui.component.Checkbox;
034:        import com.sun.portal.admin.console.common.PSBaseBean;
035:        import com.sun.portal.admin.common.DesktopConstants;
036:        import com.sun.portal.admin.common.util.AdminUtil;
037:        import com.sun.portal.admin.common.AttrOptionConstants;
038:        import com.sun.portal.admin.common.PSMBeanException;
039:
040:        import javax.faces.context.FacesContext;
041:
042:        /**
043:         * @author rt94277
044:         * This bean handles the Service Attributes page on Desktop tab.
045:         */
046:        public class AuthlessUIDBean extends PSBaseBean implements 
047:                DesktopConstants, TableDataListener {
048:            public static final String RB_NAME = "desktop";
049:            public static final String COMPONENT = "desktop";
050:
051:            private String defaultAuthlessUID = "";
052:            private ObjectListDataProvider authlessUIDs = null;
053:            private ObjectName objName = null;
054:            private Map attrValues = null;
055:            private Set globalAttrNames = null;
056:            private Map optionsMap = new HashMap();
057:            private Map nameValues = new HashMap();
058:            private Map globalNameValues = new HashMap();
059:            private List uidObjectList = new ArrayList();
060:            private String locationDN = null;
061:
062:            private boolean pendingChanges = false;
063:
064:            public boolean alert;
065:            private String alertSummary;
066:            private String alertDetail;
067:            private String alertType;
068:
069:            private String DEFAULT_TEXT_KEY = "authlesstable.dn.defaulttext";
070:
071:            public AuthlessUIDBean() {
072:                locationDN = (String) getCurrentDN();
073:
074:                //global attributes
075:                globalAttrNames = new HashSet();
076:                globalAttrNames.add(DEFAULT_AUTHLESS_UID);
077:                globalAttrNames.add(AUTHORIZED_AUTHLESS_UIDS);
078:
079:                //get MBean Object name
080:                objName = getMBeanObjectName();
081:
082:            }
083:
084:            //get authless uid list and the default authless uid from backend.
085:            public void initAuthlessUIDs() {
086:                //init authlessuid list
087:                Map uidOptionsMap = new HashMap();
088:                uidObjectList = new ArrayList();
089:                uidOptionsMap.put(AttrOptionConstants.OPT_COMPONENT, COMPONENT);
090:                uidOptionsMap.put("operation", "get");
091:                Set authlessAttrs = new HashSet();
092:                authlessAttrs.add(AUTHORIZED_AUTHLESS_UIDS);
093:                authlessAttrs.add(DEFAULT_AUTHLESS_UID);
094:                uidOptionsMap.put(AttrOptionConstants.OPT_ATTR_NAMES,
095:                        authlessAttrs);
096:                // Setting the params and signature
097:                Object[] params = { uidOptionsMap };
098:                String[] signature = { "java.util.Map" };
099:                try {
100:                    Map authlessAttrValues = (Map) getMBeanServerConnection()
101:                            .invoke(objName, "getAttributes", params, signature);
102:                    log(Level.FINEST,
103:                            "return value from MBean for authless attributes="
104:                                    + authlessAttrValues);
105:                    List uids = (List) authlessAttrValues
106:                            .get(AUTHORIZED_AUTHLESS_UIDS);
107:                    List values = (List) authlessAttrValues
108:                            .get(DEFAULT_AUTHLESS_UID);
109:                    if (uids != null && !uids.isEmpty()) {
110:                        if (values != null && !values.isEmpty()) {
111:                            defaultAuthlessUID = (String) values.get(0);
112:                        }
113:                        for (int i = 0; i < uids.size(); i++) {
114:                            String uid = (String) uids.get(i);
115:                            StringTokenizer st = new StringTokenizer(uid, "|");
116:                            int count = st.countTokens();
117:                            String dn = "";
118:                            String password = "";
119:                            boolean defaultUID = false;
120:                            if (count >= 2) {
121:                                dn = st.nextToken();
122:                                defaultUID = false;
123:                                if (dn.equals(defaultAuthlessUID)) {
124:                                    defaultUID = true;
125:                                }
126:                                password = st.nextToken();
127:
128:                            } else {
129:                                dn = st.nextToken();
130:                            }
131:                            uidObjectList.add(new AuthlessUID(dn, password,
132:                                    defaultUID));
133:                        }
134:                        authlessUIDs = new ObjectListDataProvider(uidObjectList);
135:                        authlessUIDs.setUserResizable(true);
136:                        ((TableDataProvider) authlessUIDs)
137:                                .addTableDataListener(this );
138:                    } else {
139:                        Class authlessUIDClass = null;
140:                        try {
141:                            authlessUIDClass = Class
142:                                    .forName("com.sun.portal.admin.console.desktop.AuthlessUID");
143:                        } catch (ClassNotFoundException cnfe) {
144:                            //do nothing
145:                        }
146:                        authlessUIDs = new ObjectListDataProvider(
147:                                authlessUIDClass);
148:                        authlessUIDs.setUserResizable(true);
149:                    }
150:                } catch (MBeanException me) {
151:                    log(Level.SEVERE,
152:                            "Exception in AuthlessUIDBean.initAuthlessUIDs()",
153:                            me);
154:                } catch (ReflectionException re) {
155:                    log(Level.SEVERE,
156:                            "Exception in AuthlessUIDBean.initAuthlessUIDs()",
157:                            re);
158:                } catch (Exception e) {
159:                    log(Level.SEVERE,
160:                            "Exception in AuthlessUIDBean.initAuthlessUIDs()",
161:                            e);
162:                }
163:
164:            }
165:
166:            public DataProvider getAuthlessUIDs() {
167:                if (isDNChanged() || !pendingChanges) {
168:                    initAuthlessUIDs();
169:                }
170:                return authlessUIDs;
171:            }
172:
173:            public void setAuthlessUIDs(DataProvider uids) {
174:                this .authlessUIDs = (ObjectListDataProvider) uids;
175:            }
176:
177:            public String getDefaultAuthlessUID() {
178:                return defaultAuthlessUID;
179:            }
180:
181:            public void setDefaultAuthlessUID(String value) {
182:                this .defaultAuthlessUID = value;
183:            }
184:
185:            public String setDefaultUid() {
186:                RowKey[] rkey = authlessUIDs.getRowKeys(1000, null);
187:                List selectedcbs = Checkbox.getSelected("authlessuidcb");
188:                String defaultUID = null;
189:                boolean defaultSet = false;
190:                AuthlessUID previousDefault = null;
191:                AuthlessUID currentDefault = null;
192:                List l = authlessUIDs.getList();
193:                if (selectedcbs != null && !selectedcbs.isEmpty()) {
194:                    defaultUID = (String) selectedcbs.get(0);
195:                }
196:                for (int index = 0; index < l.size(); index++) {
197:                    AuthlessUID uid = (AuthlessUID) l.get(index);
198:                    if (uid.getDefaultUID()) {
199:                        previousDefault = uid;
200:                    }
201:                    if (uid.getDn() != null
202:                            && uid.getDn().length() != 0
203:                            && !uid.getDn().equals(
204:                                    getLocalizedString(RB_NAME,
205:                                            DEFAULT_TEXT_KEY))) {
206:                        if (defaultUID.equals(uid.getId())) {
207:                            log(Level.FINEST,
208:                                    "AuthlessUID selected for default:"
209:                                            + uid.getDn());
210:                            //set the new default
211:                            currentDefault = uid;
212:                            setDefaultAuthlessUID(uid.getDn());
213:                            uid.setDefaultUID(true);
214:                            defaultSet = true;
215:                        }
216:                    }
217:                    //Make sure the default is set and unset previousdefault
218:                    if (previousDefault != null && currentDefault != null
219:                            && previousDefault != currentDefault && defaultSet) {
220:                        previousDefault.setDefaultUID(false);
221:                        defaultSet = false;
222:                    }
223:                }
224:                authlessUIDs.commitChanges();
225:                pendingChanges = true;
226:                setupAlert(null, "authlesstable.alert.saverequired", null,
227:                        "information");
228:                return "";
229:            }
230:
231:            public String deleteUids() {
232:                ObjectListDataProvider odp = (ObjectListDataProvider) authlessUIDs;
233:                RowKey[] rkey = odp.getRowKeys(odp.getRowCount(), null);
234:                List selectedcbs = Checkbox.getSelected("authlessuidcb");
235:                log(Level.FINEST, "Selected cbs for deletion= " + selectedcbs);
236:                List l = odp.getList();
237:                for (int index = 0; index < l.size(); index++) {
238:                    RowKey rowKey = rkey[index];
239:                    log(Level.FINEST, "rowkey id=" + rowKey.getRowId());
240:                    AuthlessUID uid = (AuthlessUID) l.get(index);
241:                    log(Level.FINEST, "uid from the list=" + uid.getId());
242:                    if (selectedcbs != null && !selectedcbs.isEmpty()
243:                            && selectedcbs.contains(uid.getId())) {
244:                        log(Level.FINEST, "AuthlessUID selected for Deletion:"
245:                                + uid.getDn());
246:                        if (uid.getDefaultUID()) {
247:                            //show alert
248:                            setupAlert(
249:                                    null,
250:                                    "authlesstable.deleteuid.failed.summary",
251:                                    "authlesstable.deleteuid.failed.defaultuid",
252:                                    "error");
253:
254:                        } else {
255:                            //remove uid
256:                            authlessUIDs.removeRow(rowKey);
257:                            pendingChanges = true;
258:                            setupAlert(null,
259:                                    "authlesstable.alert.saverequired", null,
260:                                    "information");
261:
262:                        }
263:                    }
264:
265:                }
266:                authlessUIDs.commitChanges();
267:                return "";
268:            }
269:
270:            public String addUids() {
271:                if (authlessUIDs.canAppendRow()) {
272:                    AuthlessUID uid = new AuthlessUID(getLocalizedString(
273:                            RB_NAME, DEFAULT_TEXT_KEY));
274:                    RowKey rkey = authlessUIDs.appendRow(uid);
275:                }
276:                authlessUIDs.commitChanges();
277:                pendingChanges = true;
278:                setupAlert(null, "authlesstable.alert.saverequired", null,
279:                        "information");
280:                return "";
281:
282:            }
283:
284:            public void saveAttributes() {
285:                if (pendingChanges) {
286:                    optionsMap
287:                            .put(AttrOptionConstants.OPT_COMPONENT, COMPONENT);
288:                    optionsMap.put("operation", "set");
289:                    Object[] params = new Object[2];
290:                    optionsMap.put(AttrOptionConstants.OPT_ATTR_NAMES,
291:                            globalAttrNames);
292:                    if (optionsMap.containsKey(AttrOptionConstants.OPT_DN)) {
293:                        optionsMap.remove(AttrOptionConstants.OPT_DN);
294:                    }
295:                    //get authless uids. new and old
296:                    boolean valid = validateAuthlessUIDs();
297:                    if (valid) {
298:                        List uids = getAuthlessUIDValues();
299:                        log(Level.FINEST, "authless uids for saving " + uids);
300:                        log(Level.FINEST, "saving default UID "
301:                                + defaultAuthlessUID);
302:                        globalNameValues.put(AUTHORIZED_AUTHLESS_UIDS, uids);
303:                        globalNameValues.put(DEFAULT_AUTHLESS_UID,
304:                                getAttrValueAsList(defaultAuthlessUID));
305:                        Map valueMap = new HashMap();
306:                        valueMap.putAll(globalNameValues);
307:                        valueMap.putAll(nameValues);
308:                        params[0] = valueMap;
309:                        params[1] = optionsMap;
310:                        // Setting the params and signature
311:                        String[] signature = { "java.util.Map", "java.util.Map" };
312:                        try {
313:                            getMBeanServerConnection().invoke(objName,
314:                                    "setAttributes", params, signature);
315:                            alert = false;
316:                            authlessUIDs.clearObjectList();
317:                            pendingChanges = false;
318:                        } catch (MBeanException me) {
319:                            log(
320:                                    Level.SEVERE,
321:                                    "Exception in AuthlessUIDBean.saveAttributes()",
322:                                    me);
323:                            if (me.getCause() instanceof  PSMBeanException) {
324:                                PSMBeanException psmbe = (PSMBeanException) me
325:                                        .getCause();
326:                                alert = true;
327:                                alertType = "error";
328:                                alertSummary = getLocalizedString(RB_NAME,
329:                                        "svcattr.save.failed.summary");
330:                                alertDetail = psmbe.getMessage();
331:                            }
332:                        } catch (ReflectionException re) {
333:                            log(
334:                                    Level.SEVERE,
335:                                    "Exception in AuthlessUIDBean.saveAttributes()",
336:                                    re);
337:                            alert = true;
338:                            alertType = "error";
339:                            alertSummary = getLocalizedString(RB_NAME,
340:                                    "svcattr.save.failed.summary");
341:                        } catch (Exception e) {
342:                            log(
343:                                    Level.SEVERE,
344:                                    "Exception in AuthlessUIDBean.saveAttributes()",
345:                                    e);
346:                            alert = true;
347:                            alertType = "error";
348:                            alertSummary = getLocalizedString(RB_NAME,
349:                                    "svcattr.save.failed.summary");
350:                        }
351:                    }
352:                }
353:            }
354:
355:            private boolean isDNChanged() {
356:                boolean dnChanged = false;
357:                String dn = (String) getCurrentDN();
358:                if (!locationDN.equals(dn)) {
359:                    log(Level.FINEST, "changed dn:" + dn);
360:                    dnChanged = true;
361:                    locationDN = dn;
362:                }
363:                return dnChanged;
364:            }
365:
366:            public void resetAttributes() {
367:                authlessUIDs.clearObjectList();
368:                pendingChanges = false;
369:            }
370:
371:            private List getAuthlessUIDValues() {
372:                List uids = new ArrayList();
373:                //get uids from old list
374:
375:                List l = authlessUIDs.getList();
376:                for (int i = 0; i < l.size(); i++) {
377:                    AuthlessUID uid = (AuthlessUID) l.get(i);
378:                    if (uid.getDn() != null
379:                            && uid.getDn().length() != 0
380:                            && uid.getPassword() != null
381:                            && uid.getPassword().length() != 0
382:                            && !uid.getDn().equals(
383:                                    getLocalizedString(RB_NAME,
384:                                            DEFAULT_TEXT_KEY))) {
385:                        uids.add(uid.toString());
386:                    }
387:                }
388:                return uids;
389:            }
390:
391:            private boolean validateAuthlessUIDs() {
392:                boolean valid = true;
393:                authlessUIDs.commitChanges();
394:                List uids = new ArrayList();
395:                //get uids from old list
396:                List l = authlessUIDs.getList();
397:                for (int i = 0; i < l.size(); i++) {
398:                    AuthlessUID uid = (AuthlessUID) l.get(i);
399:                    if (uid.getDn() == null
400:                            || uid.getDn().length() == 0
401:                            || uid.getDn().equals(
402:                                    getLocalizedString(RB_NAME,
403:                                            DEFAULT_TEXT_KEY))) {
404:                        setupAlert(null,
405:                                "authlesstable.validateuid.failed.summary",
406:                                "authlesstable.validateuid.failed.emptydn",
407:                                "error");
408:                        valid = false;
409:                    }
410:                    if (uid.getPassword() == null
411:                            || uid.getPassword().length() == 0) {
412:                        setupAlert(
413:                                null,
414:                                "authlesstable.validateuid.failed.summary",
415:                                "authlesstable.validateuid.failed.emptypassword",
416:                                "error");
417:                        valid = false;
418:                    }
419:                    //(TODO) Validate User DN. 
420:                }
421:                return valid;
422:            }
423:
424:            private String getPortalId() {
425:                String portalID = (String) getSessionAttribute(ATTR_SELECTED_PORTAL);
426:                return portalID;
427:            }
428:
429:            private ObjectName getMBeanObjectName() {
430:                //get PortalMBean object name
431:                ObjectName objectName = null;
432:                try {
433:                    objectName = AdminUtil.getPortalMBeanObjectName(
434:                            getDomain(), getPortalId());
435:                } catch (MalformedObjectNameException e) {
436:                    //throw e;            
437:                    log(
438:                            Level.SEVERE,
439:                            "Exception in AuthlessUIDBean.getMBeanObjectName()",
440:                            e);
441:                }
442:                return objectName;
443:            }
444:
445:            private List getAttrValueAsList(String value) {
446:                List values = new ArrayList();
447:                values.add(value);
448:                return values;
449:            }
450:
451:            private String getStringValueFromList(String key) {
452:                String value = "";
453:                if (attrValues != null && !attrValues.isEmpty()) {
454:                    List values = (List) attrValues.get(key);
455:                    if (values != null && !values.isEmpty()) {
456:                        value = (String) values.get(0);
457:                    }
458:                }
459:                return value;
460:            }
461:
462:            public void rowAdded(TableDataProvider provider, RowKey row) {
463:            }
464:
465:            public void rowRemoved(TableDataProvider provider, RowKey row) {
466:            }
467:
468:            public void providerChanged(DataProvider provider) {
469:            }
470:
471:            public void valueChanged(TableDataProvider provider,
472:                    FieldKey fieldKey, RowKey row, Object oldValue,
473:                    Object newValue) {
474:                AuthlessUID changeduid = (AuthlessUID) ((ObjectListDataProvider) provider)
475:                        .getObject(row);
476:                if (newValue != null) {
477:                    String id = fieldKey.getFieldId();
478:                    List l = authlessUIDs.getList();
479:                    for (int index = 0; index < l.size(); index++) {
480:                        AuthlessUID uid = (AuthlessUID) l.get(index);
481:                        if (uid.getId().equals(changeduid.getId())
482:                                || uid.getDn().equals(changeduid.getDn())) {
483:                            if (id.equals("dnfield")) {
484:                                uid.setDn((String) newValue);
485:                            } else if (id.equals("passwdfield")) {
486:                                uid.setPassword((String) newValue);
487:                            }
488:                        }
489:                    }
490:                }
491:                authlessUIDs.commitChanges();
492:                pendingChanges = true;
493:
494:            }
495:
496:            public void valueChanged(DataProvider provider, FieldKey fieldKey,
497:                    Object oldValue, Object newValue) {
498:            }
499:
500:            ////////////////////end TableDataListener//////////////////////
501:
502:            //============================================================
503:            // Alert methods
504:            //============================================================
505:            public boolean isAlert() {
506:                boolean show = alert;
507:                if (!pendingChanges) {
508:                    alert = false;
509:                }
510:                return show;
511:            }
512:
513:            public void setAlert(boolean value) {
514:                alert = value;
515:            }
516:
517:            public String getAlertSummary() {
518:                return alertSummary;
519:            }
520:
521:            public void setAlertSummary(String summary) {
522:                alertSummary = summary;
523:            }
524:
525:            public String getAlertDetail() {
526:                return alertDetail;
527:            }
528:
529:            public void setAlertDetail(String detail) {
530:                alertDetail = detail;
531:            }
532:
533:            public String getAlertType() {
534:                return alertType;
535:            }
536:
537:            public void setAlertType(String type) {
538:                alertType = type;
539:            }
540:
541:            //============================================================
542:            // Alert Utility methods
543:            //============================================================
544:
545:            public void setupAlert(String token, String summary, String detail,
546:                    String type) {
547:
548:                String sm = getLocalizedString(RB_NAME, summary);
549:                String dm = null;
550:                if (detail != null) {
551:                    dm = getLocalizedString(RB_NAME, detail);
552:                    if (token != null) {
553:                        dm = dm + token;
554:                    }
555:                }
556:                alert = true;
557:                setAlertSummary(sm);
558:                setAlertDetail(dm);
559:                setAlertType(type);
560:            }
561:
562:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.