Source Code Cross Referenced for CUserManager.java in  » Portal » uPortal_rel-2-6-1-GA » org » jasig » portal » channels » cusermanager » 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 » uPortal_rel 2 6 1 GA » org.jasig.portal.channels.cusermanager 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* Copyright 2005 The JA-SIG Collaborative.  All rights reserved.
002:         *  See license distributed with this file and
003:         *  available online at http://www.uportal.org/license.html
004:         */
005:        package org.jasig.portal.channels.cusermanager;
006:
007:        import java.util.Enumeration;
008:        import java.text.MessageFormat;
009:
010:        import org.jasig.portal.IChannel;
011:
012:        import org.jasig.portal.security.IPerson;
013:        import org.jasig.portal.security.IPermission;
014:        import org.jasig.portal.security.provider.PersonImpl; //import edu.cornell.uportal.channels.cusermanager.provider.PersonImpl;
015:
016:        import org.jasig.portal.ChannelStaticData;
017:        import org.jasig.portal.ChannelRuntimeData;
018:        import org.jasig.portal.ChannelRuntimeProperties;
019:        import org.jasig.portal.PortalEvent;
020:        import org.jasig.portal.PortalException;
021:        import org.jasig.portal.IPermissible;
022:        import org.jasig.portal.AuthorizationException;
023:
024:        import org.jasig.portal.utils.XSLT;
025:        import org.jasig.portal.utils.DocumentFactory;
026:
027:        import org.w3c.dom.Document;
028:        import org.w3c.dom.Element;
029:
030:        import org.xml.sax.ContentHandler;
031:
032:        /**
033:         * @author smb1@cornell.edu
034:         * @author apetro@unicon.net
035:         * @version $Revision: 42096 $ $Date: 2007-06-14 12:09:46 -0700 (Thu, 14 Jun 2007) $
036:         */
037:        public class CUserManager extends CUserManagerPermissions implements 
038:                IChannel, IPermissible {
039:
040:            private IDataHandler dataHandler;
041:
042:            private String mode = Constants.MODEDISPLAY;
043:
044:            private ChannelStaticData channelStaticData;
045:            private ChannelRuntimeData channelRuntimeData;
046:
047:            private boolean managerMode = false;
048:            private boolean passwordChangeMode = true;
049:
050:            private PortalEvent lastEvent;
051:
052:            /** for pwd chng mode, we want to cache the user's info because
053:             *  there will be many more of these than admin channels
054:             */
055:            private Document personalDocument = null;
056:
057:            private ChannelRuntimeDataToPersonConverter channelRuntimeDataToPersonConverter = new ChannelRuntimeDataToPersonConverter();
058:
059:            /**
060:             */
061:            public CUserManager() {
062:            }// CUserManager
063:
064:            public ChannelRuntimeProperties getRuntimeProperties() {
065:                return new ChannelRuntimeProperties();
066:            }// getRuntimeProperties
067:
068:            public void receiveEvent(PortalEvent ev) {
069:
070:                this .lastEvent = ev;
071:
072:            }// receiveEvent
073:
074:            public void setStaticData(ChannelStaticData sd) {
075:                channelStaticData = sd;
076:
077:                String dataHandlerClassName = Constants.DEFAULTDATAHANDLER;
078:
079:                String dataHandlerClassNameFromChannelStaticData = channelStaticData
080:                        .getParameter(Constants.CHNPARAMDATAHANDLER);
081:
082:                if (dataHandlerClassNameFromChannelStaticData != null) {
083:                    dataHandlerClassName = dataHandlerClassNameFromChannelStaticData;
084:                }
085:
086:                try {
087:                    dataHandler = (IDataHandler) Class.forName(
088:                            dataHandlerClassName).newInstance();
089:                } catch (Exception e) {
090:                    throw new PortalException(
091:                            "Unable to instantiate CUserManager IDataHandler implementation ["
092:                                    + dataHandlerClassName + "]", e);
093:                }
094:
095:                // Ignore since 2.0 (2003.04.21)
096:                //    if( CSD.getParameter( Constants.CHNPARAMNOTMGR ) != null )
097:                //      ManagerMode = false;
098:
099:                // let determine the user's rights
100:                try {
101:
102:                    IPermission[] perms = channelStaticData
103:                            .getAuthorizationPrincipal().getAllPermissions(
104:                                    Constants.PERMISSION_OWNERTOKEN, null,
105:                                    Constants.PERMISSION_OWNERTARGET);
106:
107:                    for (int i = 0; i < perms.length; i++) {
108:
109:                        if (perms[i].getActivity().equals(
110:                                Constants.PERMISSION_MNGRRIGHT)
111:                                && perms[i].getType().equals(
112:                                        IPermission.PERMISSION_TYPE_GRANT))
113:                            managerMode = true;
114:
115:                        if (perms[i].getActivity().equals(
116:                                Constants.PERMISSION_PWDCHNGRIGHT)
117:                                && perms[i].getType().equals(
118:                                        IPermission.PERMISSION_TYPE_DENY))
119:                            passwordChangeMode = false;
120:
121:                    }// for
122:                } catch (AuthorizationException ae) {
123:                    log.error(ae, ae);
124:                }
125:
126:            }// setStaticData
127:
128:            public void setRuntimeData(ChannelRuntimeData rd) {
129:                channelRuntimeData = rd;
130:            }// setRuntimeData
131:
132:            public void renderXML(ContentHandler out) throws PortalException {
133:
134:                // first, be sure they are allowed to be here
135:                if (!managerMode && !passwordChangeMode)
136:                    throw new AuthorizationException(MessageFormat
137:                            .format(Constants.ERRMSG_NORIGHTS,
138:                                    new Object[] { (String) channelStaticData
139:                                            .getPerson().getAttribute(
140:                                                    IPerson.USERNAME) }));
141:
142:                try {
143:
144:                    String message_to_user_about_action = ""; // these always start blank
145:                    Document doc = null;
146:                    IPerson[] people = null;
147:                    mode = Constants.MODEDISPLAY;
148:
149:                    // now, b4 we get going, there may have been an event to deal with
150:                    if (channelRuntimeData.getParameter(Constants.FORMACTION) == null
151:                            && lastEvent != null) {
152:
153:                        if (lastEvent.getEventNumber() == PortalEvent.ABOUT_BUTTON_EVENT)
154:                            channelRuntimeData.setParameter(
155:                                    Constants.FORMACTION, "10");
156:
157:                        if (lastEvent.getEventNumber() == PortalEvent.HELP_BUTTON_EVENT)
158:                            channelRuntimeData.setParameter(
159:                                    Constants.FORMACTION, "11");
160:
161:                        lastEvent = null; // don't need that anymore
162:                    }// if, null & !null
163:
164:                    // see if we have form data to process
165:                    if (channelRuntimeData.getParameter(Constants.FORMACTION) != null) {
166:
167:                        log.debug("form.action="
168:                                + channelRuntimeData
169:                                        .getParameter(Constants.FORMACTION));
170:
171:                        switch (Integer.parseInt(channelRuntimeData
172:                                .getParameter(Constants.FORMACTION))) {
173:
174:                        case 1: { // update
175:
176:                            this .dataHandler
177:                                    .setUserInformation(channelRuntimeDataToPersonConverter
178:                                            .channelRuntimeDataToPerson(channelRuntimeData));
179:                            message_to_user_about_action = Constants.MSG_SAVED;
180:
181:                            break;
182:                        }// 1
183:
184:                        case 2: { // choose
185:
186:                            mode = Constants.MODEDISPLAY;
187:                            break;
188:                        }// 2
189:
190:                        case 3: { // choose
191:
192:                            people = this .dataHandler.getAllUsers();
193:                            mode = Constants.MODECHOOSE;
194:
195:                            break;
196:                        }// 3
197:
198:                        case 4: { // search
199:
200:                            if (channelRuntimeData
201:                                    .getParameter(Constants.FORMSRCHSTR) == null) {
202:                                people = new PersonImpl[0];
203:                                mode = Constants.MODESEARCH;
204:                            } else {
205:
206:                                // if they did not enter a src str, display mode
207:                                people = this .dataHandler
208:                                        .getAllUsersLike(channelRuntimeData
209:                                                .getParameter(Constants.FORMSRCHSTR));
210:
211:                                if (people.length == 1) {
212:
213:                                    // this will cause a second lookup but the user experience will benifit
214:                                    mode = Constants.MODEDISPLAY;
215:
216:                                    channelRuntimeData
217:                                            .setParameter(
218:                                                    Constants.UNFIELD,
219:                                                    (String) people[0]
220:                                                            .getAttribute(Constants.UNFIELD));
221:
222:                                } else
223:                                    mode = Constants.MODECHOOSE; // they will need to select to narrow
224:                            }// if
225:
226:                            break;
227:                        }// 4
228:
229:                        case 5: { // prepare add new user
230:
231:                            channelRuntimeData.setParameter(Constants.UNFIELD,
232:                                    (String) channelStaticData.getPerson()
233:                                            .getAttribute(
234:                                                    Constants.ATTRUSERNAME));
235:                            mode = Constants.MODEADD;
236:
237:                            break;
238:                        }// 5
239:
240:                        case 6: { // add new user
241:
242:                            try {
243:                                this .dataHandler
244:                                        .addUser(channelRuntimeDataToPersonConverter
245:                                                .channelRuntimeDataToPerson(channelRuntimeData));
246:                            } catch (Exception adde) {
247:
248:                                if (adde.getMessage().indexOf(
249:                                        Constants.ALREADY_EXISTS) > -1)
250:                                    message_to_user_about_action = adde
251:                                            .getMessage();
252:                                else
253:                                    throw adde;
254:
255:                            }// catch
256:
257:                            mode = Constants.MODEDISPLAY;
258:
259:                            break;
260:                        }// 6
261:
262:                        case 7: { // prepare password chng
263:
264:                            people = new IPerson[] { this .dataHandler
265:                                    .getUser(channelRuntimeData
266:                                            .getParameter(Constants.UNFIELD)) };
267:
268:                            mode = Constants.MODEPWDCHNG;
269:
270:                            break;
271:                        }// 7
272:
273:                        case 8: { // password chng
274:
275:                            message_to_user_about_action = Constants.MSG_PWD_SAVED;
276:
277:                            try {
278:                                this .dataHandler
279:                                        .setUserPassword(
280:                                                channelRuntimeDataToPersonConverter
281:                                                        .channelRuntimeDataToPerson(channelRuntimeData),
282:                                                (managerMode ? null
283:                                                        : channelRuntimeData
284:                                                                .getParameter(Constants.PWDFIELD)));
285:                            } catch (Exception pwdchng) {
286:
287:                                if (pwdchng.getMessage().equals(
288:                                        Constants.ERRMSG_PWDNOTMATACHED))
289:                                    message_to_user_about_action = pwdchng
290:                                            .getMessage();
291:                                else
292:                                    throw pwdchng;
293:
294:                            }// catch
295:
296:                            mode = Constants.MODEDISPLAY;
297:
298:                            personalDocument = null;
299:
300:                            break;
301:                        }// 8
302:
303:                        case 9: { // delete user
304:
305:                            this .dataHandler
306:                                    .removeUser(channelRuntimeDataToPersonConverter
307:                                            .channelRuntimeDataToPerson(channelRuntimeData));
308:
309:                            mode = Constants.MODEDISPLAY;
310:
311:                            personalDocument = null;
312:
313:                            break;
314:                        }// 9
315:
316:                        case 10: { // about
317:
318:                            mode = Constants.MODEABOUT;
319:
320:                            break;
321:                        }// 10
322:
323:                        case 11: { // help
324:
325:                            mode = Constants.MODEHELP;
326:
327:                            break;
328:                        }// 11
329:
330:                        default: {
331:                            mode = Constants.MODEDISPLAY;
332:                            channelRuntimeData.remove(Constants.UNFIELD);
333:                        }// default
334:
335:                        }// switch
336:                    }// if
337:
338:                    if (!managerMode && personalDocument == null
339:                            && !mode.equals(Constants.MODEABOUT)
340:                            && !mode.equals(Constants.MODEHELP)) // always override
341:                        mode = Constants.MODEDISPLAY; // force a read
342:
343:                    // look up the person we are supposed to display
344:                    if (mode.equals(Constants.MODEDISPLAY)
345:                            || mode.equals(Constants.MODEADD))
346:                        people = new IPerson[] { this .dataHandler
347:                                .getUser((channelRuntimeData
348:                                        .getParameter(Constants.FORMCHOSEN) == null ? (channelRuntimeData
349:                                        .getParameter(Constants.UNFIELD) == null ? (String) channelStaticData
350:                                        .getPerson().getAttribute(
351:                                                Constants.ATTRUSERNAME)
352:                                        : channelRuntimeData
353:                                                .getParameter(Constants.UNFIELD))
354:                                        : channelRuntimeData
355:                                                .getParameter(Constants.FORMCHOSEN))) };
356:
357:                    if (!managerMode && !mode.equals(Constants.MODEABOUT)
358:                            && !mode.equals(Constants.MODEHELP)) // always override
359:                        mode = Constants.MODEPWDCHNG;
360:
361:                    if ((managerMode || (!managerMode && personalDocument == null))
362:                            && !mode.equals(Constants.MODEABOUT)
363:                            && !mode.equals(Constants.MODEHELP)) {
364:                        doc = DocumentFactory.getNewDocument();
365:
366:                        // fill in info about the user
367:                        Element outtermost = doc.createElement("people");
368:                        Element person;
369:
370:                        for (int i = 0; i < people.length; i++) {
371:
372:                            person = doc.createElement("person");
373:                            Element attr = null;
374:
375:                            String worker = null;
376:                            Enumeration E = people[i].getAttributeNames();
377:                            while (E.hasMoreElements()) {
378:
379:                                worker = (String) E.nextElement();
380:
381:                                attr = doc.createElement(worker);
382:                                attr.appendChild(doc
383:                                        .createTextNode((String) people[i]
384:                                                .getAttribute(worker)));
385:
386:                                person.appendChild(attr);
387:                            }// while
388:
389:                            outtermost.appendChild(person);
390:                        }// for
391:
392:                        doc.appendChild(outtermost);
393:                        // end - fill in info about the user
394:
395:                        if (!managerMode)
396:                            personalDocument = doc;
397:
398:                    } else {
399:
400:                        doc = personalDocument;
401:                    }// if
402:
403:                    // Create a new XSLT styling engine
404:                    XSLT xslt = XSLT.getTransformer(this , channelRuntimeData
405:                            .getLocales());
406:                    //     XSLT xslt = new XSLT( this );
407:
408:                    // we could have a blank document, help and about
409:                    if (doc == null) {
410:                        doc = DocumentFactory.getNewDocument();
411:                        doc.appendChild(doc.createElement(mode)); // null;
412:                    }// doc null
413:
414:                    // pass the result XML to the styling engine.
415:                    xslt.setXML(doc);
416:
417:                    // specify the stylesheet selector
418:                    xslt.setXSL(Constants.SSLFILE, mode, channelRuntimeData
419:                            .getBrowserInfo());
420:
421:                    // set parameters that the stylesheet needs.
422:                    xslt.setStylesheetParameter(Constants.BASEACTION,
423:                            channelRuntimeData.getBaseActionURL());
424:                    xslt.setStylesheetParameter(Constants.MODE, mode);
425:                    xslt.setStylesheetParameter(Constants.DISPLAYMESSAGE,
426:                            message_to_user_about_action);
427:
428:                    String MM = (!managerMode ? "yes" : "no");
429:                    xslt.setStylesheetParameter(Constants.MODEUSRPWDCHNG, MM);
430:
431:                    /** If I write the above as shown below it does not work.  Wasted a .5hr on that! */
432:                    //     xslt.setStylesheetParameter( Constants.MODEUSRPWDCHNG, (!ManagerMode?"yes":"no"));
433:                    // set the output Handler for the output.
434:                    xslt.setTarget(out);
435:
436:                    // do the deed
437:                    xslt.transform();
438:
439:                } catch (Exception e) {
440:                    log.error(e, e);
441:
442:                    throw new PortalException((e.getMessage() != null ? e
443:                            .getMessage() : e.toString()));
444:                }// catch
445:            }// renderXML
446:
447:        }// eoc
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.