Source Code Cross Referenced for UserLDAP.java in  » J2EE » Expresso » com » jcorporate » expresso » ext » ldap » 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 » J2EE » Expresso » com.jcorporate.expresso.ext.ldap 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* ====================================================================
002:         * The Jcorporate Apache Style Software License, Version 1.2 05-07-2002
003:         *
004:         * Copyright (c) 1995-2002 Jcorporate Ltd. All rights reserved.
005:         *
006:         * Redistribution and use in source and binary forms, with or without
007:         * modification, are permitted provided that the following conditions
008:         * are met:
009:         *
010:         * 1. Redistributions of source code must retain the above copyright
011:         *    notice, this list of conditions and the following disclaimer.
012:         *
013:         * 2. Redistributions in binary form must reproduce the above copyright
014:         *    notice, this list of conditions and the following disclaimer in
015:         *    the documentation and/or other materials provided with the
016:         *    distribution.
017:         *
018:         * 3. The end-user documentation included with the redistribution,
019:         *    if any, must include the following acknowledgment:
020:         *       "This product includes software developed by Jcorporate Ltd.
021:         *        (http://www.jcorporate.com/)."
022:         *    Alternately, this acknowledgment may appear in the software itself,
023:         *    if and wherever such third-party acknowledgments normally appear.
024:         *
025:         * 4. "Jcorporate" and product names such as "Expresso" must
026:         *    not be used to endorse or promote products derived from this
027:         *    software without prior written permission. For written permission,
028:         *    please contact info@jcorporate.com.
029:         *
030:         * 5. Products derived from this software may not be called "Expresso",
031:         *    or other Jcorporate product names; nor may "Expresso" or other
032:         *    Jcorporate product names appear in their name, without prior
033:         *    written permission of Jcorporate Ltd.
034:         *
035:         * 6. No product derived from this software may compete in the same
036:         *    market space, i.e. framework, without prior written permission
037:         *    of Jcorporate Ltd. For written permission, please contact
038:         *    partners@jcorporate.com.
039:         *
040:         * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
041:         * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
042:         * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
043:         * DISCLAIMED.  IN NO EVENT SHALL JCORPORATE LTD OR ITS CONTRIBUTORS
044:         * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
045:         * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
046:         * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
047:         * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
048:         * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
049:         * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
050:         * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
051:         * SUCH DAMAGE.
052:         * ====================================================================
053:         *
054:         * This software consists of voluntary contributions made by many
055:         * individuals on behalf of the Jcorporate Ltd. Contributions back
056:         * to the project(s) are encouraged when you make modifications.
057:         * Please send them to support@jcorporate.com. For more information
058:         * on Jcorporate Ltd. and its products, please see
059:         * <http://www.jcorporate.com/>.
060:         *
061:         * Portions of this software are based upon other open source
062:         * products and are subject to their respective licenses.
063:         */
064:
065:        /**
066:         *
067:         * Copyright 2000, 2001 Jcorporate Ltd.
068:         */package com.jcorporate.expresso.ext.ldap;
069:
070:        import com.jcorporate.expresso.core.db.DBConnection;
071:        import com.jcorporate.expresso.core.db.DBException;
072:        import com.jcorporate.expresso.core.misc.ConfigManager;
073:        import com.jcorporate.expresso.core.misc.ConfigurationException;
074:        import com.jcorporate.expresso.core.misc.EMailSender;
075:        import com.jcorporate.expresso.core.misc.StringUtil;
076:        import com.jcorporate.expresso.core.misc.Base64;
077:        import com.jcorporate.expresso.core.security.UserInfo;
078:        import com.jcorporate.expresso.core.security.CryptoManager;
079:        import com.jcorporate.expresso.services.dbobj.DefaultUserInfo;
080:        import com.jcorporate.expresso.services.dbobj.Setup;
081:        import org.apache.log4j.Logger;
082:
083:        import javax.naming.AuthenticationException;
084:        import javax.naming.Context;
085:        import javax.naming.NamingEnumeration;
086:        import javax.naming.NamingException;
087:        import javax.naming.directory.Attribute;
088:        import javax.naming.directory.Attributes;
089:        import javax.naming.directory.DirContext;
090:        import javax.naming.directory.InitialDirContext;
091:        import javax.naming.directory.SearchControls;
092:        import javax.naming.directory.SearchResult;
093:        import java.util.Date;
094:        import java.util.Enumeration;
095:        import java.util.Hashtable;
096:        import java.util.Vector;
097:
098:        /**
099:         * UserLDAP is an LDAP-aware implementation of the UserInfo object - this allows user
100:         * information to be retrieved from an LDAP server, as opposed to simply retrieved
101:         * from the database. In order for this implementation to work, the following
102:         * properties must be set in the properties file for the specific db/context to be
103:         * user with LDAP:
104:         * ldapServer: the URL to the LDAP context via JNDI (e.g. ldap://localhost:389)
105:         * ldapUser: The username to use to access the LDAP server (cn=Directory Manager)
106:         * ldapPassword: The password to use when accessing the LDAP server (e.g. pass)
107:         * ldapRoot: The root for the entries we look up (e.g. o=javacorp.com)
108:         * <p/>
109:         * Creation date: (9/18/00 1:55:15 PM)
110:         *
111:         * @author Michael Nash
112:         */
113:        public class UserLDAP implements  UserInfo {
114:            private String dbName = "default";
115:
116:            /* Hashtable containing the environment for the JNDI call */
117:            private Hashtable env = null;
118:            private DirContext ctx = null;
119:            private String this Class = UserLDAP.class.getName() + ".";
120:            private String userName = null;
121:            private String email = null;
122:            private String lastName = null;
123:            private String firstName = null;
124:            private String descrip = null;
125:            private String ldapRoot = null;
126:            private String name = null;
127:
128:            private static Logger log = Logger.getLogger(UserLDAP.class);
129:
130:            /**
131:             * UserLDAP constructor comment.
132:             */
133:            public UserLDAP() {
134:                super ();
135:            } /* UserLDAP() */
136:
137:            /**
138:             * @throws DBException
139:             */
140:            public void add() throws DBException {
141:                String myName = this Class + "add()";
142:                throw new DBException(myName + ":Add not yet implemented");
143:            } /* add() */
144:
145:            /**
146:             * Deletes the User (Not implemented)
147:             */
148:            public void delete() throws DBException {
149:                String myName = this Class + "delete()";
150:                throw new java.lang.UnsupportedOperationException(myName
151:                        + ":Delete not yet implemented");
152:            } /* delete() */
153:
154:            /**
155:             * Find the LDAP user
156:             *
157:             * @return true if found
158:             */
159:            public boolean find() throws DBException {
160:                try {
161:                    retrieve();
162:                } catch (DBException de) {
163:                    return false;
164:                }
165:
166:                return true;
167:            } /* find() */
168:
169:            public String getAccountStatus() throws DBException {
170:                return "A";
171:            }
172:
173:            public Vector getAllUsers() throws DBException {
174:                return null;
175:            }
176:
177:            public String getCreateDate() throws DBException {
178:                return null;
179:            }
180:
181:            /**
182:             * Most often used for testing to peak into things.
183:             *
184:             * @return the Directory Context
185:             */
186:            public DirContext getContext() {
187:                return ctx;
188:            }
189:
190:            public String getEmail() throws DBException {
191:                return email;
192:            }
193:
194:            /**
195:             * Here we generate an authorization code that would be hard for someone to guess.
196:             * The idea is that the person has to check the email sent to them to get this
197:             * number, and then click on the specially encoded URL to ensure that he/she
198:             * actually is checking the email account used at registration.
199:             * <p/>
200:             * The little trick of getting the time in milliseconds that the person registered,
201:             * multiplying by some constant, and then rounding, is extremely weak. We need a
202:             * better method of generating a unique code that will "play nice" in a query
203:             * string.
204:             * <p/>
205:             * Creation date: (8/8/00 3:00:41 PM)
206:             * author Adam Rossi, PlatinumSolutions, Inc.
207:             *
208:             * @return java.lang.String
209:             */
210:            public String getEmailAuthCode() throws DBException {
211:                Date createDate = new Date();
212:                long dateLong = createDate.getTime();
213:                long emailAuthCode = Math.round(dateLong * 1.71);
214:
215:                return Long.toString(emailAuthCode);
216:            } /* getEmailAuthCode() */
217:
218:            public String getEmailValCode() throws DBException {
219:                return getField("EmailValCode");
220:            }
221:
222:            /**
223:             * getField method comment.
224:             *
225:             * @param fieldName The field name to retrieve
226:             * @return The field string
227:             */
228:            public String getField(String fieldName) throws DBException {
229:                String myName = this Class + "getField(String)";
230:
231:                if (fieldName.equals("UserName")) {
232:                    return userName;
233:                } else if (fieldName.equals("EMail")) {
234:                    return email;
235:                } else if (fieldName.equals("Descrip")) {
236:                    return descrip;
237:                } else if (fieldName.equals("FirstName")) {
238:                    return firstName;
239:                } else if (fieldName.equals("LastName")) {
240:                    return lastName;
241:                } else if (fieldName.equals("AccountStatus")) {
242:                    return "A";
243:                } else if (fieldName.equals("CreateDate")) {
244:                    return null;
245:                }
246:
247:                throw new DBException(myName + ":No such field as '"
248:                        + fieldName + "'");
249:            } /* getField(String) */
250:
251:            /**
252:             * @return java.util.Enumeration
253:             * @throws DBException upon Error
254:             */
255:            public Enumeration getFieldList() throws DBException {
256:                Vector v = new Vector();
257:                v.addElement("UserName");
258:                v.addElement("EMail");
259:                v.addElement("Descrip");
260:                v.addElement("FirstName");
261:                v.addElement("LastName");
262:                v.addElement("AccountStatus");
263:                v.addElement("CreateDate");
264:
265:                return v.elements();
266:            } /* getFieldList() */
267:
268:            /**
269:             * Get the groups associated with this User
270:             *
271:             * @return The group list
272:             */
273:            public java.util.Vector getGroups() throws DBException {
274:                SearchControls constraints = new SearchControls();
275:                constraints.setSearchScope(SearchControls.SUBTREE_SCOPE);
276:
277:                Vector v = new Vector();
278:
279:                try {
280:                    setDBName("default");
281:
282:                    NamingEnumeration results = ctx.search("o=" + ldapRoot,
283:                            "(uniquemember=" + name + ", o=" + ldapRoot + ")",
284:                            constraints);
285:
286:                    if (results == null) {
287:                        return v;
288:                    }
289:                    while (results.hasMore()) {
290:                        SearchResult sr = (SearchResult) results.next();
291:                        Attributes a = sr.getAttributes();
292:                        Attribute attr = a.get("cn");
293:
294:                        if (attr != null) {
295:                            NamingEnumeration vals = attr.getAll();
296:
297:                            if (vals.hasMoreElements()) {
298:                                v.addElement(vals.nextElement());
299:                            }
300:                        }
301:                    }
302:                } catch (NamingException ne) {
303:                    throw new DBException(ne);
304:                }
305:
306:                return v;
307:            } /* getGroups() */
308:
309:            public String getLoginName() throws DBException {
310:                return userName;
311:            }
312:
313:            public String getPassword() throws DBException {
314:                return null;
315:            }
316:
317:            public boolean getRegComplete() throws DBException {
318:
319:                // Always return true for now...
320:                return true;
321:            }
322:
323:            public String getRegistrationDomain() throws DBException {
324:                return "default";
325:            }
326:
327:            public String getRoot() {
328:                return ldapRoot;
329:            }
330:
331:            public int getUid() throws DBException {
332:                return 0;
333:            }
334:
335:            public String getUpdateDate() throws DBException {
336:                return null;
337:            }
338:
339:            public String getUserName() throws DBException {
340:                return firstName + " " + lastName;
341:            }
342:
343:            /**
344:             * Send this user a notification via e-mail.
345:             *
346:             * @param subject Subject of the e-mail
347:             * @param message Message to send in body of e-mail
348:             * @throws DBException If the mail message cannot be sent
349:             */
350:            public void notify(String subject, String message)
351:                    throws DBException {
352:                String myName = (this Class + "notify(String, String)");
353:                log.info("Notifying user " + getField("UserName") + " of "
354:                        + subject);
355:
356:                String sendToUser = getField("EMail");
357:
358:                try {
359:                    EMailSender ems = new EMailSender();
360:                    ems.setDBName("default");
361:                    ems.send(sendToUser, subject, message);
362:                } catch (Exception e) {
363:                    throw new DBException(myName
364:                            + ":Uncaught exception sending e-mail", e);
365:                }
366:            } /* notify(String, String) */
367:
368:            /**
369:             * Check if the given number is in the range of letters and
370:             * digits that we want to use for generating a password
371:             * Previously in com.jcorporate.expresso.ext.servlet.RegisterUser.java
372:             *
373:             * @param x the double random value
374:             * @return true if the number is a printable character
375:             */
376:            private boolean okNumber(double x) {
377:                int oneNumber = new Double(x).intValue();
378:
379:                if ((oneNumber >= 65) && (oneNumber <= 90)) {
380:                    return true;
381:                }
382:                if ((oneNumber >= 48) && (oneNumber <= 57)) {
383:                    return true;
384:                }
385:                if ((oneNumber >= 97) && (oneNumber <= 122)) {
386:                    return true;
387:                }
388:
389:                return false;
390:            } /* okNumber(double) */
391:
392:            /**
393:             * Checks if the supplied password equals the one on file
394:             *
395:             * @param tryPassword The password to check
396:             * @return true if the tryPassword equals the one on file
397:             */
398:            public boolean passwordEquals(String tryPassword)
399:                    throws DBException {
400:                String myName = this Class + "getField(String)";
401:                Hashtable env2 = new Hashtable();
402:                env2.put(Context.INITIAL_CONTEXT_FACTORY,
403:                        "com.sun.jndi.ldap.LdapCtxFactory");
404:
405:                String ldapServer = "";
406:
407:                try {
408:                    ldapServer = StringUtil.notNull(ConfigManager.getContext(
409:                            DBConnection.DEFAULT_DB_CONTEXT_NAME).getLdap()
410:                            .getServer());
411:                } catch (Exception e) {
412:                    throw new DBException(
413:                            myName
414:                                    + ":Must specify ldapServer property in properties file");
415:                }
416:
417:                if (ldapServer.equals("")) {
418:                    throw new DBException(
419:                            myName
420:                                    + ":Must specify ldapServer property in properties file");
421:                }
422:
423:                env2.put(Context.PROVIDER_URL, ldapServer);
424:                env2.put(Context.SECURITY_AUTHENTICATION, "simple");
425:
426:                if (userName.equals("")) {
427:                    throw new DBException(
428:                            myName
429:                                    + ":Must set UserName field before checking password");
430:                }
431:
432:                env2.put(Context.SECURITY_PRINCIPAL, name + ", o=" + ldapRoot);
433:
434:                if (StringUtil.notNull(tryPassword).equals("")) {
435:                    throw new DBException(myName
436:                            + ":Must specify non-blank password");
437:                }
438:
439:                env2.put(Context.SECURITY_CREDENTIALS, tryPassword);
440:
441:                try {
442:                    new InitialDirContext(env2);
443:
444:                    return true;
445:                } catch (AuthenticationException e) {
446:                    log.error(e);
447:
448:                    return false;
449:                } catch (NamingException ne) {
450:                    throw new DBException(ne);
451:                }
452:            } /* passwordEquals(String) */
453:
454:            /**
455:             * Generate a random password
456:             *
457:             * @return a random password of printable characters
458:             */
459:            public String randomPassword() {
460:                int passwordLength = 6;
461:                StringBuffer newPassword = new StringBuffer("");
462:                double oneNumber = 0;
463:                char oneChar;
464:                int iterations = 0;
465:
466:                //
467:                //Read the property value of minimum password length
468:                //
469:                String propValue = "";
470:                try {
471:                    propValue = StringUtil.notNull(ConfigManager.getContext(
472:                            DBConnection.DEFAULT_DB_CONTEXT_NAME)
473:                            .getMinPasswordSize());
474:                } catch (Exception e) {
475:                    passwordLength = 6;
476:                }
477:
478:                if (!propValue.equals("")) {
479:                    try {
480:                        passwordLength = Integer.parseInt(propValue, 10);
481:                    } catch (NumberFormatException ex) {
482:
483:                        //Bad number
484:                        passwordLength = 6;
485:                    }
486:                }
487:
488:                /////////////////////////////////
489:                //
490:                //Now Generate the new password.  (Code from servlet.RegisterUser) before)
491:                //
492:                while ((newPassword.length() < passwordLength)
493:                        && (iterations < 200)) {
494:                    iterations++;
495:                    oneNumber = Math.random() * 100;
496:
497:                    if (okNumber(oneNumber)) {
498:                        oneChar = (char) new Double(oneNumber).intValue();
499:                        newPassword.append(oneChar);
500:                    }
501:                }
502:
503:                return newPassword.toString();
504:            } /* randomPassword() */
505:
506:            /**
507:             * retrieve method comment.
508:             */
509:            public void retrieve() throws DBException {
510:                String myName = this Class + "retrieve()";
511:                SearchControls constraints = new SearchControls();
512:                constraints.setSearchScope(SearchControls.SUBTREE_SCOPE);
513:
514:                if (StringUtil.notNull(getField("UserName")).equals("")) {
515:                    throw new DBException(myName
516:                            + ":UserName must be specified before retrieve");
517:                }
518:                try {
519:                    setDBName("default");
520:
521:                    NamingEnumeration results = ctx.search("o=" + ldapRoot,
522:                            "(uid=" + userName + ")", constraints);
523:
524:                    if (results == null) {
525:                        throw new DBException(myName
526:                                + ":No results for search of LDAP server");
527:                    }
528:                    if (results.hasMore()) {
529:                        SearchResult sr = (SearchResult) results.next();
530:                        name = sr.getName();
531:
532:                        Attributes a = sr.getAttributes();
533:                        Attribute attr = a.get("mail");
534:
535:                        if (attr != null) {
536:                            NamingEnumeration vals = attr.getAll();
537:
538:                            if (vals.hasMoreElements()) {
539:                                email = (String) vals.nextElement();
540:                            }
541:                        }
542:
543:                        attr = a.get("sn");
544:
545:                        if (attr != null) {
546:                            NamingEnumeration vals = attr.getAll();
547:
548:                            if (vals.hasMoreElements()) {
549:                                lastName = (String) vals.nextElement();
550:                            }
551:                        }
552:
553:                        attr = a.get("fn");
554:
555:                        if (attr != null) {
556:                            NamingEnumeration vals = attr.getAll();
557:
558:                            if (vals.hasMoreElements()) {
559:                                firstName = (String) vals.nextElement();
560:                            }
561:                        }
562:
563:                        attr = a.get("cn");
564:
565:                        if (attr != null) {
566:                            NamingEnumeration vals = attr.getAll();
567:
568:                            if (vals.hasMoreElements()) {
569:                                descrip = (String) vals.nextElement();
570:                            }
571:                        }
572:                    } else {
573:                        throw new DBException(myName + ":No such user '"
574:                                + userName + "' found in LDAP server directory");
575:                    }
576:                } catch (NamingException ne) {
577:                    throw new DBException(myName, ne);
578:                }
579:            } /* retrieve() */
580:
581:            /**
582:             * Sends an Authorization Email to a new User.
583:             * The user must click on the link encoded in this email before
584:             * his account will be activated.
585:             */
586:            public void sendAuthEmail() throws DBException {
587:                try {
588:                    String dbContext = "default";
589:                    String authURL = Setup.getValue(dbContext,
590:                            "EmailValidateURL");
591:                    String emailAuthCode = getEmailAuthCode();
592:                    this .setEmailValCode(emailAuthCode);
593:                    this .update();
594:                    authURL = authURL + "?UserName=" + getField("UserName")
595:                            + "&EmailAuthCode=" + emailAuthCode;
596:
597:                    String subject = "New Account Validation - Please Respond";
598:                    StringBuffer sb = new StringBuffer();
599:
600:                    if (!"".equals(getField("Descrip"))) {
601:                        sb.append("Dear " + getField("Descrip") + ",");
602:                    }
603:
604:                    sb.append("\n");
605:                    sb.append("\n");
606:                    sb.append("Thank you for registering");
607:
608:                    String companyName = Setup.getValue(dbContext,
609:                            "CompanyName");
610:                    String homePageURL = Setup.getValue(dbContext,
611:                            "HomePageURL");
612:
613:                    if (companyName != null && !"".equals(companyName)) {
614:                        sb.append(" with " + companyName);
615:                    }
616:                    if (homePageURL != null && !"".equals(homePageURL)) {
617:                        sb.append(" at " + homePageURL);
618:                    }
619:
620:                    sb.append("!");
621:                    sb.append("\n");
622:                    sb.append("\n");
623:                    sb
624:                            .append("Your account has been successfully created. The final "
625:                                    + "step in the");
626:                    sb.append("\n");
627:                    sb
628:                            .append("registration process is to simply follow the link "
629:                                    + "below to let us");
630:                    sb.append("\n");
631:                    sb
632:                            .append("know that you received this message. You must follow "
633:                                    + "the link below");
634:                    sb.append("\n");
635:                    sb.append("before your account will be activated.");
636:                    sb.append("\n");
637:                    sb.append("\n");
638:                    sb.append("NOTE: If you did not register, you may safely");
639:                    sb.append("\n");
640:                    sb.append("ignore this message.");
641:                    sb.append("\n");
642:                    sb.append("\n");
643:                    sb
644:                            .append("In many email clients, you may simply click on the "
645:                                    + "link below to");
646:                    sb.append("\n");
647:                    sb
648:                            .append("complete the registration process. If your email "
649:                                    + "client does not");
650:                    sb.append("\n");
651:                    sb
652:                            .append("support this, cut-and-paste the link below into your "
653:                                    + "web browser's");
654:                    sb.append("\n");
655:                    sb.append("\"Location\" window:");
656:                    sb.append("\n");
657:                    sb.append("\n");
658:                    sb.append(authURL);
659:                    sb.append("\n");
660:                    sb.append("\n");
661:
662:                    if (companyName != null && !"".equals(companyName)) {
663:                        sb.append("Thank you from all of us at " + companyName
664:                                + ".");
665:                    }
666:
667:                    sb.append("\n");
668:
669:                    if (companyName != null && !"".equals(homePageURL)) {
670:                        sb.append(homePageURL);
671:                    }
672:
673:                    sb.append("\n");
674:
675:                    String message = sb.toString();
676:                    notify(subject, message);
677:                } catch (Exception e) {
678:                    throw new DBException(
679:                            "Error in sending account verification message to "
680:                                    + getField("UserName") + " at "
681:                                    + getField("EMail") + ": " + e.toString());
682:                }
683:            } /* sendAuthEmail() */
684:
685:            /**
686:             * Once a user has validated his email address through the email validation
687:             * servlet, the user will receive this message giving previously requested
688:             * username/password.
689:             * <p/>
690:             * Creation date: (8/8/00 11:44:26 PM)
691:             * author: Adam Rossi, PlatinumSolutions, Inc.
692:             *
693:             * @throws com.jcorporate.expresso.core.db.DBException
694:             *          The exception description.
695:             */
696:            public void sendFollowUpEmail() throws DBException {
697:                try {
698:                    String subject = "New Registration Complete - Welcome!";
699:                    String dbContext = "default";
700:
701:                    // We can't retrieve the passsword in plain text to transmit to the user
702:                    // So we just create and set a new passord and send that over.
703:                    String password = this .randomPassword();
704:                    this .setPassword(password);
705:                    this .update();
706:
707:                    StringBuffer sb = new StringBuffer();
708:
709:                    if (!"".equals(getField("Descrip"))) {
710:                        sb.append("Dear " + getField("Descrip") + ",");
711:                    }
712:
713:                    sb.append("\n");
714:                    sb.append("\n");
715:                    sb.append("Thank you for registering");
716:
717:                    String companyName = Setup.getValue(dbContext,
718:                            "CompanyName");
719:                    String homePageURL = Setup.getValue(dbContext,
720:                            "HomePageURL");
721:
722:                    if (companyName != null && !"".equals(companyName)) {
723:                        sb.append(" with " + companyName);
724:                    }
725:                    if (homePageURL != null && !"".equals(homePageURL)) {
726:                        sb.append(" at " + homePageURL);
727:                    }
728:
729:                    sb.append("!");
730:                    sb.append("\n");
731:                    sb.append("\n");
732:                    sb
733:                            .append("Your account is now active. Below is the information "
734:                                    + "you will need to log in.");
735:                    sb.append("\n");
736:                    sb
737:                            .append("Please keep this information in a safe place.We hope "
738:                                    + "you enjoy the site and");
739:                    sb.append("\n");
740:                    sb.append("look forward to your participation.");
741:                    sb.append("\n");
742:                    sb.append("\n");
743:                    sb.append("User Name: " + getField("UserName"));
744:                    sb.append("\n");
745:                    sb.append("Password: " + password);
746:                    sb.append("\n");
747:                    sb.append("\n");
748:
749:                    if (companyName != null && !"".equals(companyName)) {
750:                        sb.append("Thank you from all of us at " + companyName
751:                                + ".");
752:                    }
753:
754:                    sb.append("\n");
755:
756:                    if (companyName != null && !"".equals(homePageURL)) {
757:                        sb.append(homePageURL);
758:                    }
759:
760:                    sb.append("\n");
761:
762:                    String message = sb.toString();
763:                    notify(subject, message);
764:                } catch (Exception e) {
765:                    throw new DBException(
766:                            "Error in sending account verification follow up message to "
767:                                    + getField("UserName") + " at "
768:                                    + getField("EMail") + ": " + e.toString());
769:                }
770:            } /* sendFollowUpEmail() */
771:
772:            public void setAccountStatus(String name) throws DBException {
773:            }
774:
775:            public void setCreateDate(String name) throws DBException {
776:            }
777:
778:            /**
779:             * Sets the data context for this user
780:             *
781:             * @param newDBName The new data context
782:             */
783:            public void setDBName(String newDBName) throws DBException {
784:                String myName = this Class + "setDBName(String)";
785:                dbName = newDBName;
786:                env = new Hashtable();
787:                env.put(Context.INITIAL_CONTEXT_FACTORY,
788:                        "com.sun.jndi.ldap.LdapCtxFactory");
789:
790:                try {
791:                    String ldapServer = StringUtil.notNull(ConfigManager
792:                            .getContext(newDBName).getLdap().getServer());
793:
794:                    if (ldapServer.equals("")) {
795:                        throw new DBException(
796:                                myName
797:                                        + ":Must specify ldapServer property in properties file");
798:                    }
799:
800:                    env.put(Context.PROVIDER_URL, ldapServer);
801:                    env.put(Context.SECURITY_AUTHENTICATION, "simple");
802:
803:                    String ldapUser = StringUtil.notNull(ConfigManager
804:                            .getContext(newDBName).getLdap().getUser());
805:
806:                    if (ldapUser.equals("")) {
807:                        throw new DBException(
808:                                myName
809:                                        + ":Must specify ldapUser property in properties file");
810:                    }
811:
812:                    env.put(Context.SECURITY_PRINCIPAL, "cn=" + ldapUser);
813:
814:                    String ldapPassword = StringUtil.notNull(ConfigManager
815:                            .getContext(newDBName).getLdap().getPassword());
816:
817:                    if (ldapPassword.equals("")) {
818:                        throw new DBException(
819:                                myName
820:                                        + ":Must specify ldapPassword property in properties file");
821:                    }
822:
823:                    env.put(Context.SECURITY_CREDENTIALS, ldapPassword);
824:                    ldapRoot = StringUtil.notNull(ConfigManager.getContext(
825:                            newDBName).getLdap().getRoot());
826:
827:                    if (ldapRoot.equals("")) {
828:                        throw new DBException(
829:                                myName
830:                                        + ":Must specify ldapRoot property in properties file");
831:                    }
832:                    try {
833:                        ctx = new InitialDirContext(env);
834:                    } catch (NamingException ne) {
835:                        throw new DBException(ne);
836:                    }
837:                } catch (ConfigurationException ce) {
838:                    throw new DBException(ce);
839:                }
840:            } /* setDBName(String) */
841:
842:            public void setEmail(String name) throws DBException {
843:            }
844:
845:            public void setEmailAuthCode(String name) throws DBException {
846:            }
847:
848:            public void setEmailValCode(String code) throws DBException {
849:            }
850:
851:            public void setLoginName(String name) throws DBException {
852:                userName = name;
853:            }
854:
855:            public void setPassword(String password) throws DBException {
856:            }
857:
858:            public void setRegComplete(boolean status) throws DBException {
859:
860:                // Ignore for now...
861:            }
862:
863:            public void setRegistrationDomain(String domain) {
864:            }
865:
866:            public void setUid(int uid) throws DBException {
867:            } /* setUid(String) */
868:
869:            public void setUpdateDate(String name) throws DBException {
870:            }
871:
872:            public void setUserName(String name) throws DBException {
873:            }
874:
875:            /**
876:             * update method comment.
877:             */
878:            public void update() throws DBException {
879:                String myName = this Class + "update()";
880:                throw new DBException(myName + ":Update not yet implemented");
881:            } /* update() */
882:
883:            /**
884:             * Method to return a Vector of ValidValue
885:             * This method may be implemented by objects that want to provide a
886:             * list of valid values for other DB objects. It is strongly recommended
887:             * that the valid value list be cached (via the CacheManager) for performance.
888:             * The naming convention used in Expresso is to store the ValidValue list with
889:             * a cache name the same as the db objects class name with ".validValues" appended
890:             *
891:             * @return The vector of values
892:             * @todo Required to be implemented
893:             */
894:            public Vector getValues() throws DBException {
895:                throw new DBException(
896:                        "This object does not have valid values defined.");
897:            } /* getValues() */
898:
899:            /**
900:             * Return the name of the context/database connection that this DB object is using.
901:             * If none is set, then we are using the "default" database/context.
902:             *
903:             * @return a String containing the name of the DBName to use.
904:             */
905:            public String getDBName() {
906:                return this .dbName;
907:            } /* getDBName() */
908:
909:            /**
910:             * gets the DB context; can return null
911:             */
912:            public String getDataContext() {
913:                return this .dbName;
914:            }
915:
916:            /**
917:             * the primary group of this user is appropriate for unix-like purposes,
918:             * such as setting the group for a file permission
919:             *
920:             * @return name of the primary group of this user; null if no group is found
921:             */
922:            public String getPrimaryGroup() throws DBException {
923:                return DefaultUserInfo.getPrimaryGroup(this );
924:            }
925:
926:            /**
927:             * this returns an appropriately hashed password.
928:             * @param password to be hashed
929:             * @return appropriately hashed password.
930:             */
931:            public String hashEncodePassword(String password)
932:                    throws DBException {
933:                if (password == null) {
934:                    throw new DBException("Password Must not be NULL");
935:                }
936:                if (password.length() == 0) {
937:                    return password;
938:                }
939:                try {
940:                    return Base64.encode(CryptoManager.getInstance()
941:                            .getStringHash().produceHash(password.getBytes()));
942:                } catch (Exception ex) {
943:                    throw new DBException("Error hashing Password:"
944:                            + "  You may not have installed the"
945:                            + " Cryptography Extensions Properly:", ex);
946:                }
947:            }
948:
949:        } /* UserLDAP */
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.