View Javadoc

1   /*
2    * Copyright 2000-2004 The Apache Software Foundation.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.apache.jetspeed.om.security.ldap;
18  
19  import java.io.ByteArrayOutputStream;
20  import java.io.PrintWriter;
21  import java.util.Date;
22  import java.util.Enumeration;
23  import java.util.Hashtable;
24  import java.util.Vector;
25  import javax.naming.directory.Attribute;
26  import javax.naming.directory.Attributes;
27  import javax.naming.directory.BasicAttribute;
28  import javax.naming.directory.BasicAttributes;
29  import javax.servlet.http.HttpSessionBindingEvent;
30  import javax.servlet.http.HttpSessionBindingListener;
31  
32  import org.apache.jetspeed.om.security.JetspeedUser;
33  import org.apache.jetspeed.services.JetspeedAuthentication;
34  import org.apache.jetspeed.services.JetspeedLDAP;
35  import org.apache.jetspeed.services.JetspeedUserManagement;
36  import org.apache.jetspeed.services.ldap.LDAPURL;
37  import org.apache.jetspeed.services.logging.JetspeedLogFactoryService;
38  import org.apache.jetspeed.services.logging.JetspeedLogger;
39  import org.apache.jetspeed.services.resources.JetspeedResources;
40  import org.apache.jetspeed.services.security.JetspeedSecurityException;
41  import org.apache.jetspeed.services.security.UserException;
42  
43  import org.apache.turbine.om.security.User;
44  import org.apache.turbine.util.ObjectUtils;
45  
46  /***
47   *
48   * @author <a href="mailto:ender@kilicoglu.nom.tr">Ender KILICOGLU</a>
49   * @author <a href="mailto:sami.leino@netorek.fi">Sami Leino</a>
50   * 
51   * @version $Id: LDAPUser.java,v 1.7 2004/02/23 03:12:13 jford Exp $ 
52   * 
53   */
54  public class LDAPUser extends BaseLDAPObject implements JetspeedUser, HttpSessionBindingListener 
55  {
56  
57      /***
58       * Static initialization of the logger for this class
59       */    
60      private static final JetspeedLogger logger = JetspeedLogFactoryService.getLogger(LDAPUser.class.getName());    
61      
62      // ---------------------------- Constants ----------------------------
63  
64      protected static final String OBJECT_CLASS            = "jetspeeduser";
65      protected static final String ORGANIZATIONAL_UNIT     = "ou=users";
66  
67      protected static final String ATTR_UID                = "uid";
68      protected static final String ATTR_UID_NUMBER         = "uidNumber";
69      protected static final String ATTR_USER_PASSWORD      = "userPassword";
70      protected static final String ATTR_NAME               = "name";
71      protected static final String ATTR_GIVEN_NAME         = "givenName";
72      protected static final String ATTR_SN                 = "sn";
73      protected static final String ATTR_MAIL               = "mail";
74      protected static final String ATTR_OBJECT_DATA        = "objectdata";
75      protected static final String ATTR_OBJECT_CLASS       = "objectClass";
76      protected static final String ATTR_USER_GROUP_ROLE    = "usergrouprole";
77      protected static final String ATTR_LAST_LOGIN_DATE    = "lastlogindate";
78      protected static final String ATTR_LAST_MODIFIED_DATE = "lastmodifieddate";
79      protected static final String ATTR_CREATION_DATE      = "creationdate";
80      protected static final String ATTR_CONFIRMED          = "confirm";
81      protected static final String ATTR_DISABLED           = "disabled";
82  
83      // ------------------------- Member variables ------------------------
84  
85      /*** The date on which the user account was created. */
86      private Date createDate = null;
87  
88      /*** The date on which the user last accessed the application. */
89      private Date lastAccessDate = null;
90  
91      /*** The date on which the user last changed his password. */
92      private Date passwordChanged = null;
93  
94      /*** This is data that will survive a servlet engine restart. */
95      private Hashtable permStorage = null;
96  
97      /*** This is data that will not survive a servlet engine restart. */
98      private Hashtable tempStorage = null;
99  
100     /*** Name of the user */
101     protected String name = "";
102 
103     /*** Is this object "new" or does it already exist in the datastore? */
104     protected boolean isNew = false;
105 
106     /*** User's roles. */
107     protected Vector groupRoles = null;
108 
109     // --------------------------- Constructors --------------------------
110 
111     public LDAPUser()
112     {
113         this("TempUser", true);
114     }
115 
116     /***
117      * Constructor.
118      * Create a new User and set the createDate.
119      */
120     public LDAPUser(String username, boolean isNew)
121     {
122         super.ldapurl = JetspeedLDAP.buildURL(ATTR_UID + "=" + username + "," + ORGANIZATIONAL_UNIT);
123         this.isNew = isNew;
124 
125         createDate = new Date();
126         lastAccessDate = createDate;
127         tempStorage = new Hashtable(20);
128         permStorage = new Hashtable(50);
129         groupRoles = new Vector();
130         setHasLoggedIn(Boolean.FALSE);
131 
132         if (isNew)
133         {
134             setDisabled(false);
135             setUserName(username);
136 	    	String uidNumber = new Long(System.currentTimeMillis()).toString();
137 	    	setUserId(uidNumber);
138             myAttrs = new BasicAttributes();
139             myAttrs.put(ATTR_UID, username);
140             myAttrs.put(ATTR_UID_NUMBER, uidNumber);
141             Attribute oc = new BasicAttribute(ATTR_OBJECT_CLASS);
142             oc.add("jetspeeduser");
143             myAttrs.put(oc);
144         }
145         else
146         {
147             myAttrs = JetspeedLDAP.read(ldapurl);
148             fillObject(myAttrs);
149         }
150     }
151 
152     public LDAPUser(LDAPURL ldapurl)
153     {
154         fillObject(JetspeedLDAP.read(ldapurl));
155     }
156 
157     public LDAPUser(Attributes attributes)
158     {
159             fillObject(attributes);
160     }
161 
162     private void fillObject(Attributes attributes)
163     {	
164         tempStorage = new Hashtable(20);
165         permStorage = new Hashtable(50);
166         setHasLoggedIn(Boolean.FALSE);
167 
168         myAttrs = attributes;
169 
170         try
171         {
172             setPermStorage(deserializePerm(getutil(ATTR_OBJECT_DATA, attributes)));
173         }
174         catch (Exception e)
175         {
176             logger.error("fillobject()" , e);
177         }
178 
179         setUserName(getutil(ATTR_UID, attributes));
180         setUserId(getutil(ATTR_UID_NUMBER, attributes));
181         setEmail(getutil(ATTR_MAIL, attributes));
182         setFirstName(getutil(ATTR_GIVEN_NAME, attributes));
183         setLastName(getutil(ATTR_SN, attributes));
184         // setName(getutil(ATTR_NAME, attributes));
185         setConfirmed(getutil(ATTR_CONFIRMED, attributes));
186 
187         setLastLogin(parseDate(getutil(ATTR_LAST_LOGIN_DATE, attributes)));
188         lastAccessDate = parseDate(getutil(ATTR_LAST_MODIFIED_DATE, attributes));
189         setCreateDate(parseDate(getutil(ATTR_CREATION_DATE, attributes)));
190         String temp = getutil(ATTR_DISABLED, attributes);
191         if (temp != null && temp.equals("TRUE")) setDisabled(true);
192         else setDisabled(false);
193 
194         try
195         {
196             setPassword(new String ((byte[]) attributes.get(ATTR_USER_PASSWORD).getAll().nextElement()));
197         }
198         catch (Exception e)
199         {
200             logger.error("fillobject() could not set password" , e);
201         }
202 
203         this.groupRoles = getutil( ATTR_USER_GROUP_ROLE, attributes, true );
204         ldapurl = JetspeedLDAP.buildURL(ATTR_UID + "=" + getUserName() + "," + ORGANIZATIONAL_UNIT);
205     }
206 
207     // --------------------- Persistence operations ----------------------
208 
209     public void update(boolean create)
210 	throws JetspeedSecurityException
211     {
212         removeutil("createTimeStamp", false);
213         removeutil("modifyTimeStamp", false);
214 
215         setutil(ATTR_USER_PASSWORD,(String)getPerm(User.PASSWORD) );
216         setutil(ATTR_MAIL,(String)getPerm(User.EMAIL));
217         setutil(ATTR_CONFIRMED,(String)getPerm(User.CONFIRM_VALUE));
218         setutil(ATTR_SN,(String)getPerm(User.LAST_NAME));
219         setutil(ATTR_GIVEN_NAME,(String)getPerm(User.FIRST_NAME));
220         setutil(ATTR_USER_GROUP_ROLE, this.getGroupRoles(), create);
221         // setutilMulti(ATTR_USER_GROUP_ROLE, groupRoles);
222         setutil(ATTR_LAST_LOGIN_DATE, formatDate(getLastLogin()));
223         setutil(ATTR_LAST_MODIFIED_DATE, formatDate(getLastAccessDate()));
224         setutil(ATTR_CREATION_DATE, formatDate(getCreateDate()));
225         if (getDisabled() == true) setutil(ATTR_DISABLED, "TRUE");
226         else setutil(ATTR_DISABLED, "FALSE");
227 
228         try
229         {
230             setutil(ATTR_OBJECT_DATA, serializePerm(permStorage));
231 	}
232 	catch (Exception e)
233 	{
234             logger.warn("Could not serialize object data!" , e);
235 	}
236 		
237         if (create)
238         {
239             ldapurl = JetspeedLDAP.buildURL("uid=" + (String)getPerm(User.USERNAME) + ",ou=users");
240             setutil(ATTR_UID, (String)getPerm(User.USERNAME));
241             if (JetspeedLDAP.addEntry(ldapurl, myAttrs) == false) throw new UserException("Could not insert user data to LDAP!");
242         }
243         else if (JetspeedLDAP.exists(ldapurl))
244         {
245             JetspeedLDAP.deleteAttrs(ldapurl, rmAttrs);
246             if (JetspeedLDAP.updateEntry(ldapurl, myAttrs) == false) throw new UserException("Could not update user data to LDAP!");
247         }
248     }
249 
250     // ------------------------ Accessor methods -------------------------
251 
252     public Vector getGroupRoles()
253     {
254         return this.groupRoles;
255     }
256 
257     public void addGroupRole(String groupName, String roleName)
258     {
259         groupRoles.add(groupName + "," + roleName);
260     }
261 
262     public void removeGroup(String groupName)
263     {
264         for (Enumeration enum = groupRoles.elements();enum.hasMoreElements();)
265         {
266             String groupRoleStr = (String)enum.nextElement();
267             if (groupRoleStr.startsWith(groupName + ","))
268             {
269                 groupRoles.remove(groupRoleStr);
270             }
271 		}
272 	}
273 	
274     public void removeGroupRole(String groupName, String roleName)
275     {
276         for (Enumeration enum = groupRoles.elements(); enum.hasMoreElements();)
277         {
278             String groupRoleStr = (String)enum.nextElement();
279             if (groupRoleStr.equalsIgnoreCase(groupName + "," + roleName))
280             {
281                 groupRoles.remove(groupRoleStr);
282             }
283         }
284     }
285 
286     /***
287      * Returns the primary principle for this User, the user id.
288      *
289 
290      * @return the user id.
291      */
292     public String getUserId()
293     {
294         String tmp = null;
295 
296         try
297         {
298             tmp = (String) getPerm (JetspeedUser.USER_ID);
299             if ( tmp.length() == 0 )
300             {
301                 tmp = null;
302             }
303         }
304         catch (Exception e)
305         {
306             logger.error("getUserId():" , e);
307         }
308         return tmp;
309     }
310 
311     public void setUserId(String id)
312     {
313         if (getUserId() == null)
314         {
315             setPerm(JetspeedUser.USER_ID, id);
316         }
317     }
318 
319     /***
320      * Gets the access counter for a user during a session.
321      *
322      * @return The access counter for the user for the session.
323      */
324     public int getAccessCounterForSession()
325     {
326         try
327         {
328             return ((Integer) getTemp(User.SESSION_ACCESS_COUNTER)).intValue();
329         }
330         catch (Exception e)
331         {
332             logger.error("getAccessCounterForSession():" , e);
333             return 0;
334         }
335     }
336 
337     /***
338      * Gets the access counter for a user from perm storage.
339      *
340      * @return The access counter for the user.
341      */
342     public int getAccessCounter()
343     {
344         try
345         {
346             return ((Integer) getPerm(User.ACCESS_COUNTER)).intValue();
347         }
348         catch (Exception e)
349         {
350             logger.error("getAccessCounter():" , e);
351             return 0;
352 
353         }
354     }
355 
356     /***
357      * Gets the create date for this User.  This is the time at which
358      * the user object was created.
359      *
360      * @return A Java Date with the date of creation for the user.
361      */
362     public java.util.Date getCreateDate()
363     {
364         return createDate;
365     }
366 
367     /***
368      * Gets the last access date for this User.  This is the last time
369      * that the user object was referenced.
370      *
371      * @return A Java Date with the last access date for the user.
372      */
373     public java.util.Date getLastAccessDate()
374     {
375         if (lastAccessDate == null)
376         {
377             setLastAccessDate();
378         }
379         return lastAccessDate;
380     }
381 
382     /***
383 
384      * Get last login date/time for this user.
385      *
386      * @return A Java Date with the last login date for the user.
387      */
388     public java.util.Date getLastLogin()
389     {
390         return (java.util.Date) getPerm(User.LAST_LOGIN);
391     }
392 
393     /***
394      * Get password for this user.
395      *
396      * @return A String with the password for the user.
397      */
398     public String getPassword()
399     {
400         return (String) getPerm(User.PASSWORD);
401     }
402 
403     /***
404      * Get an object from permanent storage.
405      *
406      * @param name The object's name.
407      * @return An Object with the given name.
408      */
409     public Object getPerm(String name)
410     {
411         return permStorage.get(name);
412     }
413 
414     /***
415      * Get an object from permanent storage; return default if value
416      * is null.
417      *
418      * @param name The object's name.
419      * @param def A default value to return.
420      * @return An Object with the given name.
421      */
422     public Object getPerm(String name, Object def)
423     {
424         try
425         {
426             Object val = permStorage.get (name);
427 
428             return (val == null ? def : val);
429         }
430         catch (Exception e)
431         {
432             logger.error("getPerm():" , e);
433             return def;
434         }
435     }
436 
437     /***
438      * This should only be used in the case where we want to save the
439      * data to the database.
440      *
441      * @return A Hashtable.
442      */
443     public Hashtable getPermStorage()
444     {
445         if (this.permStorage == null)
446         {
447             this.permStorage = new Hashtable(50);
448         }
449         return this.permStorage;
450     }
451 
452     /***
453      * Get an object from temporary storage.
454      *
455      * @param name The object's name.
456      * @return An Object with the given name.
457      */
458     public Object getTemp(String name)
459     {
460         return tempStorage.get(name);
461     }
462 
463     /***
464      * Get an object from temporary storage; return default if value
465      * is null.
466      *
467      * @param name The object's name.
468      * @param def A default value to return.
469      * @return An Object with the given name.
470      */
471     public Object getTemp(String name, Object def)
472     {
473         Object val;
474         try
475         {
476             val = tempStorage.get(name);
477             if (val == null)
478             {
479                 val = def;
480             }
481         }
482         catch (Exception e)
483         {
484             logger.error("getTemp():" , e);
485             val = def;
486         }
487         return val;
488 
489     }
490 
491     /***
492      * Returns the username for this user.  If this is defined, then
493      * the user is considered logged in.
494      *
495      * @return A String with the username.
496      */
497     public String getUserName()
498     {
499         String tmp = null;
500         try
501         {
502             tmp = (String) getPerm (User.USERNAME);
503             if ( tmp.length() == 0 )
504             {
505                 tmp = null;
506             }
507         }
508         catch (Exception e)
509         {
510             logger.error("getUserName():" , e);
511         }
512 
513         return tmp;
514     }
515 
516     /***
517      * Returns the first name for this user.  If this is defined, then
518      * the user is considered logged in.
519      *
520      * @return A String with the user's first name.
521      */
522     public String getFirstName()
523     {
524         String tmp = null;
525 
526         try
527         {
528             tmp = (String) getPerm (User.FIRST_NAME);
529             if (tmp.length() == 0)
530             {
531                 tmp = null;
532             }
533         }
534         catch (Exception e)
535         {
536             logger.error("getFirstName():" , e);
537         }
538         return tmp;
539     }
540 
541     /***
542      * Returns the last name for this user.  If this is defined, then
543      * the user is considered logged in.
544      *
545      * @return A String with the user's last name.
546      */
547     public String getLastName()
548     {
549         String tmp = null;
550 
551         try
552         {
553             tmp = (String) getPerm (User.LAST_NAME);
554             if (tmp.length() == 0) tmp = null;
555         }
556         catch (Exception e)
557         {
558             logger.error("getLastName():" , e);
559         }
560 
561         return tmp;
562     }
563 
564     /***
565      * The user is considered logged in if they have not timed out.
566 
567      *
568      * @return Whether the user has logged in.
569      */
570     public boolean hasLoggedIn()
571     {
572 
573         Boolean loggedIn = getHasLoggedIn();
574         return (loggedIn != null && loggedIn.booleanValue());
575     }
576 
577     /***
578      * Returns the email address for this user.
579 
580      *
581      * @return A String with the user's email address.
582      */
583     public String getEmail()
584     {
585         return (String)getPerm(User.EMAIL);
586     }
587 
588     /***
589      * Increments the permanent hit counter for the user.
590      */
591     public void incrementAccessCounter()
592     {
593         setAccessCounter(getAccessCounter() + 1);
594     }
595 
596     /***
597      * Increments the session hit counter for the user.
598      */
599     public void incrementAccessCounterForSession()
600     {
601         setAccessCounterForSession(getAccessCounterForSession() + 1);
602     }
603 
604     /***
605      * Remove an object from temporary storage and return the object.
606      *
607      * @param name The name of the object to remove.
608      * @return An Object.
609      */
610     public Object removeTemp(String name)
611     {
612         return tempStorage.remove(name);
613     }
614 
615     /***
616      * Sets the access counter for a user, saved in perm storage.
617      *
618      * @param cnt The new count.
619      */
620     public void setAccessCounter(int cnt)
621     {
622         setPerm(User.ACCESS_COUNTER, new Integer(cnt));
623     }
624 
625     /***
626      * Sets the session access counter for a user, saved in temp
627      * storage.
628      *
629      * @param cnt The new count.
630      */
631     public void setAccessCounterForSession(int cnt)
632     {
633         setTemp(User.SESSION_ACCESS_COUNTER, new Integer(cnt));
634     }
635 
636     /***
637      * Sets the last access date for this User. This is the last time
638      * that the user object was referenced.
639      */
640     public void setLastAccessDate()
641     {
642         lastAccessDate = new java.util.Date();
643     }
644 
645     /***
646      * Sets the create date for this User. This is the time at which
647      * the user object was created.
648      *
649      * @param date The create date.
650      */
651     public void setCreateDate(java.util.Date date)
652     {
653         createDate = date;
654     }
655 
656     /***
657      * Set last login date/time.
658      *
659      * @param date The last login date.
660      */
661     public void setLastLogin(java.util.Date date)
662     {
663         setPerm(User.LAST_LOGIN, date);
664     }
665 
666     /***
667      * Set password.
668      *
669      * @param password The new password.
670      */
671     public void setPassword(String password)
672     {
673         setPerm(User.PASSWORD, password);
674     }
675 
676     /***
677      * Put an object into permanent storage. If the value is null,
678      * it will convert that to a "" because the underlying storage
679      * mechanism within TurbineUser is currently a Hashtable and
680      * null is not a valid value.
681      *
682      * @param name The object's name.
683      * @param value The object.
684      */
685     public void setPerm(String name, Object value)
686     {
687         ObjectUtils.safeAddToHashtable(getPermStorage(), name, value);
688     }
689 
690     /***
691      * This should only be used in the case where we want to save the
692      * data to the database.
693      *
694      * @param stuff A Hashtable.
695      */
696     public void setPermStorage(Hashtable stuff)
697     {
698         this.permStorage = stuff;
699     }
700 
701     /***
702      * This should only be used in the case where we want to save the
703      * data to the database.
704      *
705      * @return A Hashtable.
706      */
707     public Hashtable getTempStorage()
708     {
709         if (this.tempStorage == null)
710         {
711             this.tempStorage = new Hashtable(20);
712         }
713         return this.tempStorage;
714     }
715 
716     /***
717      * This should only be used in the case where we want to save the
718      * data to the database.
719      *
720      * @param storage A Hashtable.
721      */
722     public void setTempStorage(Hashtable storage)
723     {
724         this.tempStorage = storage;
725     }
726 
727     /***
728      * This gets whether or not someone has logged in.  hasLoggedIn()
729      * returns this value as a boolean.  This is private because you
730      * should use hasLoggedIn() instead.
731      *
732      * @return True if someone has logged in.
733 
734      */
735     private Boolean getHasLoggedIn()
736     {
737         return (Boolean) getTemp (User.HAS_LOGGED_IN);
738     }
739 
740     /***
741      * This sets whether or not someone has logged in.  hasLoggedIn()
742      * returns this value.
743      *
744      * @param value Whether someone has logged in or not.
745      */
746     public void setHasLoggedIn (Boolean value)
747     {
748         setTemp (User.HAS_LOGGED_IN, value);
749     }
750 
751     /***
752      * Put an object into temporary storage. If the value is null,
753      * it will convert that to a "" because the underlying storage
754      * mechanism within TurbineUser is currently a Hashtable and
755      * null is not a valid value.
756      *
757      * @param name The object's name.
758      * @param value The object.
759      */
760     public void setTemp(String name, Object value)
761     {
762         ObjectUtils.safeAddToHashtable(tempStorage, name, value);
763     }
764 
765     /***
766      * Sets the username for this user.
767      *
768      * @param username The user's username.
769      */
770     public void setUserName(String username)
771     {
772         setPerm (User.USERNAME, username);
773     }
774 
775     /***
776      * Sets the first name for this user.
777      *
778      * @param firstName User's first name.
779      */
780     public void setFirstName(String firstName)
781     {
782         setPerm(User.FIRST_NAME, firstName);
783     }
784 
785     /***
786      * Sets the last name for this user.
787      *
788      * @param lastName User's last name.
789      */
790     public void setLastName(String lastName)
791     {
792         setPerm(User.LAST_NAME, lastName);
793     }
794 
795     /***
796      * Sets the email address.
797      *
798      * @param address The email address.
799      */
800     public void setEmail(String address)
801     {
802         setPerm(User.EMAIL, address);
803     }
804 
805     /***
806      * This method reports whether or not the user has been confirmed
807      * in the system by checking the User.CONFIRM_VALUE
808      * column in the users record to see if it is equal to
809      * User.CONFIRM_DATA.
810      *
811      * @return True if the user has been confirmed.
812      */
813     public boolean isConfirmed()
814     {
815         String value = getConfirmed();
816         return (value != null && value.equals(User.CONFIRM_DATA));
817     }
818 
819     /***
820      * Sets the confirmation value. The value should
821      * be either a random string or User.CONFIRM_DATA
822      *
823      * @param value The confirmation key value.
824      */
825     public void setConfirmed(String value)
826     {
827         String val = "";
828         if (value != null)
829         {
830             val = value;
831         }
832         setPerm(User.CONFIRM_VALUE, val);
833     }
834 
835     /***
836      * Gets the confirmation value.
837      *
838      * @return status The confirmation value for this User
839      */
840     public String getConfirmed()
841     {
842         return (String)getPerm(User.CONFIRM_VALUE);
843     }
844 
845     /***
846      * Updates the last login date in the database.
847      *
848      * @exception Exception, a generic exception.
849      */
850     public void updateLastLogin()
851         throws Exception
852     {
853         setPerm( User.LAST_LOGIN, new java.util.Date() );
854     }
855 
856     /***
857      * Implement this method if you wish to be notified when the User
858      * has been Bound to the session.
859      *
860      * @param hsbe The HttpSessionBindingEvent.
861      */
862     public void valueBound(HttpSessionBindingEvent hsbe)
863     {
864     }
865 
866     /***
867      * Implement this method if you wish to be notified when the User
868      * has been Unbound from the session.
869      *
870      * @param hsbe The HttpSessionBindingEvent.
871      */
872     public void valueUnbound(HttpSessionBindingEvent hsbe)
873     {
874 		try
875         {
876             java.util.Date now = new java.util.Date();
877 
878             if (this.hasLoggedIn())
879             {
880                 if ( JetspeedResources.getBoolean("automatic.logout.save", false) )
881                 {
882                     JetspeedUserManagement.saveUser(this);
883                 }
884 
885                 JetspeedAuthentication.logout();
886             }
887         }
888         catch ( Exception e )
889         {
890             logger.error("LDAPUser.valueUnbound(): " + e.getMessage(), e);
891 
892             // To prevent messages being lost in case the logging system
893             // goes away before sessions get unbound on servlet container
894             // shutdown, print the stcktrace to the container's console.
895             ByteArrayOutputStream ostr = new ByteArrayOutputStream();
896             e.printStackTrace(new PrintWriter(ostr,true));
897             String stackTrace = ostr.toString();
898             System.out.println(stackTrace);
899         }
900     }
901 
902     /***
903      * Saves this object to the data store.
904      */
905     public void save()
906         throws Exception
907     {
908         if (this.isNew())
909         {
910             JetspeedUserManagement.saveUser(this);
911         }
912         else
913         {
914             JetspeedUserManagement.addUser(this);
915         }
916     }
917 
918     /***
919      * Returns the disabled status for the user
920      *
921      * @return True when the account is disabled
922      */
923     public boolean getDisabled()
924     {
925         boolean disabled = false;
926 
927         try
928         {
929             String tmp = (String) getPerm (JetspeedUser.DISABLED);
930             if ( tmp != null && tmp.length() > 0 )
931             {
932                 if (tmp.equalsIgnoreCase("T"))
933                 disabled = true;
934             }
935         }
936         catch (Exception e)
937         {
938             logger.error("getDisabled():" , e);
939         }
940 
941         return disabled;
942     }
943 
944     public void setDisabled(boolean disabled)
945     {
946         setPerm(JetspeedUser.DISABLED, (disabled) ? "T" : "F");
947     }
948 
949     public String getName()
950     {
951         return name;
952     }
953 
954     public void setName(String name)
955     {
956         this.name = name;
957     }
958 
959 
960     public boolean isNew()
961     {
962         return isNew;
963     }
964 
965     void setNew(boolean isNew)
966     {
967         this.isNew = isNew;
968     }
969 
970     /***
971      * Returns the date of last password change
972      *
973      * @return date
974 
975      */
976     public Date getPasswordChanged()
977     {
978         return this.passwordChanged;
979     }
980  
981     /***
982      * Sets the date of last password change
983      * 
984      * @param value  Date
985      */
986     public void setPasswordChanged(Date value)
987     {
988         this.passwordChanged = value;
989     }
990 
991 }