KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > tigris > scarab > om > ScarabUserImpl


1 package org.tigris.scarab.om;
2
3 /* ================================================================
4  * Copyright (c) 2000-2002 CollabNet. All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are
8  * met:
9  *
10  * 1. Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  *
13  * 2. Redistributions in binary form must reproduce the above copyright
14  * notice, this list of conditions and the following disclaimer in the
15  * documentation and/or other materials provided with the distribution.
16  *
17  * 3. The end-user documentation included with the redistribution, if
18  * any, must include the following acknowlegement: "This product includes
19  * software developed by Collab.Net <http://www.Collab.Net/>."
20  * Alternately, this acknowlegement may appear in the software itself, if
21  * and wherever such third-party acknowlegements normally appear.
22  *
23  * 4. The hosted project names must not be used to endorse or promote
24  * products derived from this software without prior written
25  * permission. For written permission, please contact info@collab.net.
26  *
27  * 5. Products derived from this software may not use the "Tigris" or
28  * "Scarab" names nor may "Tigris" or "Scarab" appear in their names without
29  * prior written permission of Collab.Net.
30  *
31  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
32  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
33  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
34  * IN NO EVENT SHALL COLLAB.NET OR ITS CONTRIBUTORS BE LIABLE FOR ANY
35  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
37  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
38  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
39  * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
40  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
41  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42  *
43  * ====================================================================
44  *
45  * This software consists of voluntary contributions made by many
46  * individuals on behalf of Collab.Net.
47  */

48
49 import java.util.ArrayList JavaDoc;
50 import java.util.Arrays JavaDoc;
51 import java.util.Comparator JavaDoc;
52 import java.util.List JavaDoc;
53 import java.util.Locale JavaDoc;
54 import java.util.Map JavaDoc;
55 import java.util.Calendar JavaDoc;
56 import java.util.Collections JavaDoc;
57 import java.util.Set JavaDoc;
58 import java.util.TreeSet JavaDoc;
59 import java.util.Vector JavaDoc;
60
61 import org.apache.commons.lang.RandomStringUtils;
62 import org.apache.fulcrum.security.entity.Role;
63 import org.apache.fulcrum.security.entity.User;
64 import org.apache.fulcrum.security.entity.Group;
65 import org.apache.fulcrum.security.TurbineSecurity;
66 import org.apache.fulcrum.security.impl.db.entity.TurbinePermissionPeer;
67 import org.apache.fulcrum.security.impl.db.entity.TurbineRolePermissionPeer;
68 import org.apache.fulcrum.security.impl.db.entity.TurbineRolePeer;
69 import org.apache.fulcrum.security.impl.db.entity.TurbineUserGroupRolePeer;
70 import org.apache.fulcrum.security.util.AccessControlList;
71 import org.apache.torque.TorqueException;
72 import org.apache.torque.util.Criteria;
73
74 import org.tigris.scarab.reports.ReportBridge;
75 import org.tigris.scarab.services.security.ScarabSecurity;
76 import org.tigris.scarab.services.cache.ScarabCache;
77 import org.tigris.scarab.util.ScarabException;
78
79 import org.apache.turbine.Turbine;
80 import org.apache.log4j.Logger;
81
82
83 /**
84  * This class is an abstraction that is currently based around
85  * Turbine's code. We can change this later. It is here so
86  * that it is easier to change later to work under different
87  * implementation needs.
88  *
89  * @author <a HREF="mailto:jon@collab.net">Jon S. Stevens</a>
90  * @version $Id: ScarabUserImpl.java 9651 2005-04-26 20:56:29Z jorgeuriarte $
91  */

92 public class ScarabUserImpl
93     extends BaseScarabUserImpl
94     implements ScarabUser
95 {
96     private static final Logger TORQUE_LOG =
97         Logger.getLogger("org.apache.torque");
98
99     public static final String JavaDoc PASSWORD_EXPIRE = "PASSWORD_EXPIRE";
100     
101     private AbstractScarabUser internalUser;
102     
103     /**
104      * The maximum length for the unique identifier used at user
105      * creation time.
106      */

107     private static final int UNIQUE_ID_MAX_LEN = 10;
108
109     /**
110      * Call the superclass constructor to initialize this object.
111      */

112     public ScarabUserImpl()
113     {
114         super();
115         
116         /*
117          * Functionality that would be useful in any implementation of
118          * ScarabUser is available in AbstractScarabUser (ASU). This
119          * implementation must extend from TurbineUser, so TurbineUser
120          * would need to extend ASU to gain the functionality through
121          * inheritance. This is possible with some modifications to
122          * fulcrum's build process. But until changes to fulcrum allow it,
123          * we will wrap a instance of ASU.
124          */

125         internalUser = new AbstractScarabUser()
126         {
127             public Integer JavaDoc getUserId()
128             {
129                 return getPrivateUserId();
130             }
131             
132             public String JavaDoc getEmail()
133             {
134                 return getPrivateEmail();
135             }
136             
137             public String JavaDoc getFirstName()
138             {
139                 return getPrivateFirstName();
140             }
141             
142             public String JavaDoc getLastName()
143             {
144                 return getPrivateLastName();
145             }
146
147             protected List JavaDoc getRModuleUserAttributes(Criteria crit)
148                 throws TorqueException
149             {
150                 return getPrivateRModuleUserAttributes(crit);
151             }
152             
153             public boolean hasPermission(String JavaDoc perm, Module module)
154             {
155                 return hasPrivatePermission(perm, module);
156             }
157             
158             public List JavaDoc getModules()
159                 throws Exception JavaDoc
160             {
161                 return getModules(false);
162             }
163             
164             public List JavaDoc getModules(boolean showDeletedModules)
165                 throws Exception JavaDoc
166             {
167                 List JavaDoc permList = ScarabSecurity.getAllPermissions();
168                 String JavaDoc[] perms = new String JavaDoc[permList.size()];
169                 perms = (String JavaDoc[])permList.toArray(perms);
170                 
171                 Module[] modules = getPrivateModules(perms, showDeletedModules);
172                 return (modules == null || modules.length == 0
173                         ? Collections.EMPTY_LIST : Arrays.asList(modules));
174             }
175
176             /**
177              * @see org.tigris.scarab.om.ScarabUser#getModules(String)
178              */

179             public Module[] getModules(String JavaDoc permission)
180             {
181                 return getPrivateModules(permission);
182             }
183
184             protected void
185                 deleteRModuleUserAttribute(RModuleUserAttribute rmua)
186                 throws Exception JavaDoc
187             {
188                 privateDeleteRModuleUserAttribute(rmua);
189             }
190         };
191     }
192     
193     // the following getPrivateFoo methods are to avoid naming conflicts when
194
// supplying implementations of the methods needed by AbstractScarabUser
195
// when instantiated in the constructor
196
private Integer JavaDoc getPrivateUserId()
197     {
198         return getUserId();
199     }
200     private String JavaDoc getPrivateEmail()
201     {
202         return getEmail();
203     }
204     private String JavaDoc getPrivateFirstName()
205     {
206         return getFirstName();
207     }
208     private String JavaDoc getPrivateLastName()
209     {
210         return getLastName();
211     }
212     public String JavaDoc getName()
213     {
214         return internalUser.getName();
215     }
216     private List JavaDoc getPrivateRModuleUserAttributes(Criteria crit)
217         throws TorqueException
218     {
219         return getRModuleUserAttributes(crit);
220     }
221     private boolean hasPrivatePermission(String JavaDoc perm, Module module)
222     {
223         return hasPermission(perm, module);
224     }
225     private Module[] getPrivateModules(String JavaDoc permission)
226     {
227         String JavaDoc[] perms = {permission};
228         return getModules(perms);
229     }
230     private Module[] getPrivateModules(String JavaDoc[] permissions, boolean showDeletedModules)
231     {
232         return getModules(permissions, showDeletedModules);
233     }
234
235     private void privateDeleteRModuleUserAttribute(RModuleUserAttribute rmua)
236         throws Exception JavaDoc
237     {
238         rmua.delete(this);
239     }
240
241     /**
242      * Utility method that takes a username and a confirmation code
243      * and will return true if there is a match and false if no match.
244      * <p>
245      * If there is an Exception, it will also return false.
246      */

247     public static boolean checkConfirmationCode (String JavaDoc username,
248                                                  String JavaDoc confirm)
249     {
250         // security check. :-)
251
if (confirm.equalsIgnoreCase(User.CONFIRM_DATA))
252         {
253             return false;
254         }
255         
256         try
257         {
258             Criteria criteria = new Criteria();
259             criteria.add (ScarabUserImplPeer.getColumnName(User.USERNAME),
260                           username);
261             criteria.add (ScarabUserImplPeer.getColumnName(User.CONFIRM_VALUE),
262                           confirm);
263             criteria.setSingleRecord(true);
264             List JavaDoc result = ScarabUserImplPeer.doSelect(criteria);
265             if (result.size() > 0)
266             {
267                 return true;
268             }
269
270             // FIXME: once i figure out how to build an OR in a Criteria i
271
// won't need this.
272
// We check to see if the user is already confirmed because that
273
// should result in a True as well.
274
criteria = new Criteria();
275             criteria.add (ScarabUserImplPeer.getColumnName(User.USERNAME),
276                           username);
277             criteria.add (ScarabUserImplPeer.getColumnName(User.CONFIRM_VALUE),
278                           User.CONFIRM_DATA);
279             criteria.setSingleRecord(true);
280             result = ScarabUserImplPeer.doSelect(criteria);
281             return (result.size() > 0);
282         }
283         catch (Exception JavaDoc e)
284         {
285             return false;
286         }
287     }
288
289     /**
290      This method will mark username as confirmed.
291      returns true on success and false on any error
292      */

293     public static boolean confirmUser (String JavaDoc username)
294     {
295         try
296         {
297             User user = TurbineSecurity.getUser(username);
298             user.setConfirmed(User.CONFIRM_DATA);
299             TurbineSecurity.saveUser(user);
300             return true;
301         }
302         catch (Exception JavaDoc e)
303         {
304             return false;
305         }
306     }
307
308     /**
309      * @see org.tigris.scarab.om.ScarabUser#hasPermission(String, Module)
310      * Determine if a user has a permission, either within the specified
311      * module or within the 'Global' module.
312      */

313     public boolean hasPermission(String JavaDoc perm, Module module)
314     {
315         boolean hasPermission = false;
316         
317         if (TORQUE_LOG.isDebugEnabled())
318         {
319             String JavaDoc name = (module == null) ? null : module.getName();
320             TORQUE_LOG.debug("ScarabUserImpl.hasPermission(" + perm + ", " +
321                             name + ") started");
322         }
323     
324         if (perm.equals(ScarabSecurity.USER__CHANGE_PASSWORD) && isUserAnonymous())
325         {
326             return false;
327         }
328         
329         // Cache permission check results internally, so that we do not have
330
// to ask the acl everytime. FIXME! This mechanism needs to be
331
// modified to allow for invalidating the cached results. Possible
332
// candidates are the TurbineGlobalCacheService or JCS. But keeping
333
// this in place for the moment while investigating other sql, so
334
// turbine's security sql does not dominate.
335
String JavaDoc moduleKey = (module == null) ? null : module.getQueryKey();
336         Object JavaDoc obj = getTemp("hasPermission" + perm + moduleKey);
337         if (obj == null)
338         {
339         try
340         {
341             AccessControlList acl = TurbineSecurity.getACL(this);
342             if (acl != null)
343             {
344                 if (module != null)
345                 {
346                     // first check for the permission in the specified module
347
hasPermission = acl.hasPermission(perm, (Group)module);
348                 }
349                 
350                 if (!hasPermission)
351                 {
352                     // check for the permission within the 'Global' module
353
Module globalModule = ModuleManager
354                         .getInstance(Module.ROOT_ID);
355                     hasPermission = acl.hasPermission(perm,
356                                                       (Group)globalModule);
357                 }
358             }
359         }
360         catch (Exception JavaDoc e)
361         {
362             hasPermission = false;
363             getLog().error("Permission check failed on:" + perm, e);
364         }
365         
366         Boolean JavaDoc b = hasPermission ? Boolean.TRUE : Boolean.FALSE;
367         setTemp("hasPermission" + perm + moduleKey, b);
368         }
369         else
370         {
371             hasPermission = ((Boolean JavaDoc)obj).booleanValue();
372         }
373         
374         if (TORQUE_LOG.isDebugEnabled())
375         {
376             String JavaDoc name = (module == null) ? null : module.getName();
377             TORQUE_LOG.debug("ScarabUserImpl.hasPermission(" + perm + ", " +
378                             name + ") end\n");
379         }
380         return hasPermission;
381     }
382     
383     /**
384      * @see org.tigris.scarab.om.ScarabUser#hasPermission(String, List)
385      */

386     public boolean hasPermission(String JavaDoc perm, List JavaDoc modules)
387     {
388         return internalUser.hasPermission(perm, modules);
389     }
390         
391     /**
392      * @see org.tigris.scarab.om.ScarabUser#getModules()
393      */

394     public List JavaDoc getModules() throws Exception JavaDoc
395     {
396         return internalUser.getModules();
397     }
398
399     /**
400      * @see org.tigris.scarab.om.ScarabUser#getModules(boolean)
401      */

402     public List JavaDoc getModules(boolean showDeletedModules)
403         throws Exception JavaDoc
404     {
405         return internalUser.getModules(showDeletedModules);
406     }
407
408
409     public Module[] getModules(String JavaDoc permission) throws Exception JavaDoc
410     {
411         return internalUser.getModules(permission);
412     }
413
414     private static final String JavaDoc GET_MODULES =
415         "getModules";
416
417     /**
418      * @see org.tigris.scarab.om.ScarabUser#getModules(String[])
419      */

420     public Module[] getModules(String JavaDoc[] permissions)
421     {
422         return getModules(permissions, false);
423     }
424     
425     /**
426      * Get modules that user can copy an issue to.
427      */

428     public List JavaDoc getCopyToModules(Module currentModule) throws Exception JavaDoc
429     {
430          return internalUser.getCopyToModules(currentModule);
431     }
432     public List JavaDoc getCopyToModules(Module currentModule, String JavaDoc action) throws Exception JavaDoc
433     {
434          return internalUser.getCopyToModules(currentModule, action, null);
435     }
436     public List JavaDoc getCopyToModules(Module currentModule, String JavaDoc action,
437                                  String JavaDoc searchString)
438         throws Exception JavaDoc
439     {
440          return internalUser.getCopyToModules(currentModule, action, searchString);
441     }
442
443    
444     /**
445      * @see org.tigris.scarab.om.ScarabUser#getModules(String[], boolean)
446      */

447     public Module[] getModules(String JavaDoc[] permissions, boolean showDeletedModules)
448     {
449         Module[] result = null;
450         Object JavaDoc obj = ScarabCache.get(this, GET_MODULES, permissions);
451         if (obj == null)
452         {
453             Criteria crit = new Criteria();
454             crit.setDistinct();
455             if (!showDeletedModules)
456             {
457                 crit.add(ScarabModulePeer.DELETED, 0);
458             }
459             crit.addIn(TurbinePermissionPeer.PERMISSION_NAME, permissions);
460             crit.addJoin(TurbinePermissionPeer.PERMISSION_ID,
461                      TurbineRolePermissionPeer.PERMISSION_ID);
462             crit.addJoin(TurbineRolePermissionPeer.ROLE_ID,
463                          TurbineUserGroupRolePeer.ROLE_ID);
464             crit.add(TurbineUserGroupRolePeer.USER_ID, getUserId());
465             crit.addJoin(ScarabModulePeer.MODULE_ID,
466                          TurbineUserGroupRolePeer.GROUP_ID);
467             
468             try
469             {
470                 List JavaDoc scarabModules = ScarabModulePeer.doSelect(crit);
471                 // check for permissions in global, if so get all modules
472
for (int i=scarabModules.size()-1; i>=0; i--)
473                 {
474                     if (Module.ROOT_ID.equals(
475                      ((Module)scarabModules.get(i)).getModuleId()))
476                     {
477                         crit = new Criteria();
478                         if (!showDeletedModules)
479                         {
480                             crit.add(ScarabModulePeer.DELETED, 0);
481                         }
482                         scarabModules = ScarabModulePeer.doSelect(crit);
483                         break;
484                     }
485                 }
486                 
487                 // Sort list of modules using a special comparator which
488
// takes the name of the module and its parents in account
489
Set JavaDoc sortedResult = new TreeSet JavaDoc(new Comparator JavaDoc() {
490                   public int compare(Object JavaDoc object1, Object JavaDoc object2) {
491                     Module m1 = (Module)object1;
492                     Module m2 = (Module)object2;
493                     return m1.getName().compareTo(m2.getName());
494                   }
495                 });
496                 sortedResult.addAll(scarabModules);
497                 
498                 result = (Module[])sortedResult.toArray(new Module[sortedResult.size()]);
499             }
500             catch (Exception JavaDoc e)
501             {
502                 getLog().error("An exception prevented retrieving any modules", e);
503             }
504             ScarabCache.put(result, this, GET_MODULES, permissions);
505         }
506         else
507         {
508             result = (Module[])obj;
509         }
510         return result;
511     }
512     
513     /**
514      * @see org.tigris.scarab.om.ScarabUser#hasAnyRoleIn(Module)
515      */

516     public boolean hasAnyRoleIn(Module module)
517         throws Exception JavaDoc
518     {
519         return getRoles(module).size() != 0;
520     }
521     
522     /**
523      * eturn the list of currently active roles.
524      * If no roles are active, reuturn an empty list.
525      * @return
526      */

527     public List JavaDoc getCurrentRoleNames()
528     {
529         Module module = getCurrentModule();
530         
531         List JavaDoc roles=null;
532         try
533         {
534             roles = getRoles(module);
535         }
536         catch (Exception JavaDoc e){}
537
538         List JavaDoc result = new ArrayList JavaDoc();
539         if(roles!=null)
540         {
541             int size = roles.size();
542             if(size>0)
543             {
544                 for(int index=0; index< size; index++)
545                 {
546                     Role role = (Role)roles.get(index);
547                     result.add (role.getName());
548                 }
549             }
550         }
551         return result;
552         
553     }
554     
555     private static final String JavaDoc GET_ROLES =
556         "getRoles";
557
558     /* *
559      * @see org.tigris.scarab.om.ScarabUser#getRoles(Module)
560      * !FIXME! need to define a Role interface (maybe the one in fulcrum is
561      * sufficient?) before making a method like this public.
562      * Right now it is only used in one place to determine
563      * if the user has any roles available, so we will use a more specific
564      * public method for that.
565      */

566     private List JavaDoc getRoles(Module module)
567         throws Exception JavaDoc
568     {
569         List JavaDoc result = null;
570         Object JavaDoc obj = ScarabCache.get(this, GET_ROLES, module);
571         if (obj == null)
572         {
573             Criteria crit = new Criteria();
574             crit.setDistinct();
575             crit.add(TurbineUserGroupRolePeer.USER_ID, getUserId());
576             crit.add(TurbineUserGroupRolePeer.GROUP_ID, module.getModuleId());
577             crit.addJoin(TurbineRolePeer.ROLE_ID,
578                      TurbineUserGroupRolePeer.ROLE_ID);
579             result = TurbineRolePeer.doSelect(crit);
580             
581             ScarabCache.put(result, this, GET_ROLES, module);
582         }
583         else
584         {
585             result = (List JavaDoc)obj;
586         }
587         return result;
588     }
589     
590     /**
591      * @see org.tigris.scarab.om.ScarabUser#createNewUser()
592      */

593     public void createNewUser()
594         throws Exception JavaDoc
595     {
596         // get a unique id for validating the user
597
String JavaDoc uniqueId = RandomStringUtils
598                 .randomAlphanumeric(UNIQUE_ID_MAX_LEN);
599         // add it to the perm table
600
setConfirmed(uniqueId);
601         TurbineSecurity.addUser (this, getPassword());
602         setPasswordExpire();
603     }
604     
605     /**
606      * @see org.tigris.scarab.om.ScarabUser#getEditableModules()
607      */

608     public List JavaDoc getEditableModules() throws Exception JavaDoc
609     {
610         return internalUser.getEditableModules();
611     }
612
613     /**
614      * @see org.tigris.scarab.om.ScarabUser#getEditableModules(Module)
615      */

616     public List JavaDoc getEditableModules(Module currEditModule)
617         throws Exception JavaDoc
618     {
619         return internalUser.getEditableModules(currEditModule);
620     }
621     
622     /**
623      * @see org.tigris.scarab.om.ScarabUser#getRModuleUserAttributes(Module, IssueType)
624      */

625     public List JavaDoc getRModuleUserAttributes(Module module,
626                                          IssueType issueType)
627         throws Exception JavaDoc
628     {
629         return internalUser.getRModuleUserAttributes(module, issueType);
630     }
631     
632     
633     /**
634      * @see org.tigris.scarab.om.ScarabUser#getRModuleUserAttribute(Module, Attribute, IssueType)
635      */

636     public RModuleUserAttribute getRModuleUserAttribute(Module module,
637                                                         Attribute attribute,
638                                                         IssueType issueType)
639         throws Exception JavaDoc
640     {
641         return internalUser
642             .getRModuleUserAttribute(module, attribute, issueType);
643     }
644     
645     
646     /**
647      * @see org.tigris.scarab.om.ScarabUser#getReportingIssue(String)
648      */

649     public Issue getReportingIssue(String JavaDoc key)
650         throws Exception JavaDoc
651     {
652         return internalUser.getReportingIssue(key);
653     }
654     
655     /**
656      * @see org.tigris.scarab.om.ScarabUser#setReportingIssue(Issue)
657      */

658     public String JavaDoc setReportingIssue(Issue issue)
659         throws ScarabException
660     {
661         return internalUser.setReportingIssue(issue);
662     }
663     
664     /**
665      * @see org.tigris.scarab.om.ScarabUser#setReportingIssue(String, Issue)
666      */

667     public void setReportingIssue(String JavaDoc key, Issue issue)
668     {
669         internalUser.setReportingIssue(key, issue);
670     }
671     
672     /**
673      * @see org.tigris.scarab.om.ScarabUser#getCurrentReport(String)
674      */

675     public ReportBridge getCurrentReport(String JavaDoc key)
676         throws Exception JavaDoc
677     {
678         return internalUser.getCurrentReport(key);
679     }
680     
681     /**
682      * @see org.tigris.scarab.om.ScarabUser#setCurrentReport(ReportBridge)
683      */

684     public String JavaDoc setCurrentReport(ReportBridge report)
685         throws ScarabException
686     {
687         return internalUser.setCurrentReport(report);
688     }
689     
690     /**
691      * @see org.tigris.scarab.om.ScarabUser#setCurrentReport(String, ReportBridge)
692      */

693     public void setCurrentReport(String JavaDoc key, ReportBridge report)
694     {
695         internalUser.setCurrentReport(key, report);
696     }
697     
698     /**
699      * Sets the password to expire with information from the scarab.properties
700      * scarab.login.password.expire value.
701      *
702      * @exception Exception if problem setting the password.
703      */

704     public void setPasswordExpire()
705         throws Exception JavaDoc
706     {
707         String JavaDoc expireDays = Turbine.getConfiguration()
708             .getString("scarab.login.password.expire", null);
709         
710         if (expireDays == null || expireDays.trim().length() == 0)
711         {
712             setPasswordExpire(null);
713         }
714         else
715         {
716             Calendar JavaDoc expireDate = Calendar.getInstance();
717             expireDate.add(Calendar.DATE, Integer.parseInt(expireDays));
718             setPasswordExpire(expireDate);
719         }
720     }
721     
722     /**
723      * Sets the password to expire on the specified date.
724      *
725      * @param expire a <code>Calendar</code> value specifying the expire date. If
726      * this value is null, the password will be set to expire 10 years from the
727      * current year. Since Logging in resets this value, it should be ok to
728      * have someone's password expire after 10 years.
729      *
730      * @exception Exception if problem updating the password.
731      */

732     public void setPasswordExpire(Calendar JavaDoc expire)
733         throws Exception JavaDoc
734     {
735         Integer JavaDoc userid = getUserId();
736         if (userid == null)
737         {
738             throw new Exception JavaDoc("Userid cannot be null"); //EXCEPTION
739
}
740         UserPreference up = UserPreferenceManager.getInstance(getUserId());
741         if (expire == null)
742         {
743             Calendar JavaDoc cal = Calendar.getInstance();
744             cal.set(Calendar.YEAR, cal.get(Calendar.YEAR) + 10);
745             up.setPasswordExpire(cal.getTime());
746         }
747         else
748         {
749             up.setPasswordExpire(expire.getTime());
750         }
751         up.save();
752     }
753
754     /**
755      * Checks if the users password has expired.
756      *
757      * @exception Exception if problem querying for the password.
758      */

759     public boolean isPasswordExpired()
760         throws Exception JavaDoc
761     {
762         // Password for anonymous never expires.
763
if (isUserAnonymous())
764         {
765             return false;
766         }
767         
768         Integer JavaDoc userid = getUserId();
769         if (userid == null)
770         {
771             throw new Exception JavaDoc ("Userid cannot be null"); //EXCEPTION
772
}
773         Criteria crit = new Criteria();
774         crit.add(UserPreferencePeer.USER_ID, userid);
775         Calendar JavaDoc cal = Calendar.getInstance();
776         crit.add(UserPreferencePeer.PASSWORD_EXPIRE,
777                  cal.getTime() , Criteria.LESS_THAN);
778         List JavaDoc result = UserPreferencePeer.doSelect(crit);
779         return result.size() == 1 ? true : false;
780     }
781
782     /**
783      * Returns true if the user is the one set in scarab.anonymous.username, and
784      * false otherwise.
785      * @return
786      */

787     public boolean isUserAnonymous()
788     {
789         boolean brdo = false;
790         String JavaDoc anonymous = Turbine.getConfiguration().getString("scarab.anonymous.username", null);
791         if (anonymous != null && getUserName().equals(anonymous))
792         {
793             brdo = true;
794         }
795         return brdo;
796     }
797     
798     /**
799      * Returns integer representing user preference for
800      * Which screen to return to after entering an issue.
801      * 1 = Enter New Issue. 2 = Assign Issue (default)
802      * 3 = View Issue. 4 = Issue Types index.
803      */

804     public int getEnterIssueRedirect()
805         throws Exception JavaDoc
806     {
807         return internalUser.getEnterIssueRedirect();
808     }
809     
810
811     /**
812      * Sets integer representing user preference for
813      * Which screen to return to after entering an issue.
814      * 1 = Enter New Issue. 2 = Assign Issue (default)
815      * 3 = View Issue. 4 = Issue Types index.
816      */

817     public void setEnterIssueRedirect(int templateCode)
818         throws Exception JavaDoc
819     {
820         internalUser.setEnterIssueRedirect(templateCode);
821     }
822                 
823     /**
824      * @see ScarabUser#getHomePage()
825      */

826     public String JavaDoc getHomePage()
827         throws Exception JavaDoc
828     {
829         return internalUser.getHomePage();
830     }
831     
832     /**
833      * @see ScarabUser#getHomePage(Module)
834      */

835     public String JavaDoc getHomePage(Module module)
836         throws Exception JavaDoc
837     {
838         return internalUser.getHomePage(module);
839     }
840
841     /**
842      * @see ScarabUser#setHomePage(String)
843      */

844     public void setHomePage(String JavaDoc homePage)
845         throws Exception JavaDoc
846     {
847         internalUser.setHomePage(homePage);
848     }
849
850                 
851     /**
852      * @see ScarabUser#getQueryTarget()
853      */

854     public String JavaDoc getQueryTarget()
855     {
856         return internalUser.getQueryTarget();
857     }
858     
859     /**
860      * @see ScarabUser#setSingleIssueTypeQueryTarget(IssueType, String)
861      */

862     public void setSingleIssueTypeQueryTarget(IssueType type, String JavaDoc target)
863     {
864         internalUser.setSingleIssueTypeQueryTarget(type, target);
865     }
866
867     /**
868      * @see ScarabUser#getMITLists()
869      */

870     public List JavaDoc getMITLists()
871         throws TorqueException
872     {
873         return internalUser.getMITLists();
874     }
875
876     /**
877      * @see ScarabUser#hasAnySearchableRMITs().
878      */

879     public boolean hasAnySearchableRMITs()
880         throws Exception JavaDoc
881     {
882         return internalUser.hasAnySearchableRMITs();
883     }
884   
885     /**
886      * @see ScarabUser#getSearchableRMITs(String, String, String, String, Module)
887      */

888     public List JavaDoc getSearchableRMITs(String JavaDoc searchField, String JavaDoc searchString,
889                                    String JavaDoc sortColumn, String JavaDoc sortPolarity,
890                                    Module skipModule)
891         throws Exception JavaDoc
892     {
893         return internalUser.getSearchableRMITs(searchField, searchString,
894             sortColumn, sortPolarity, skipModule);
895     }
896
897     /**
898      * @see ScarabUser#getUnusedRModuleIssueTypes(Module).
899      */

900     public List JavaDoc getUnusedRModuleIssueTypes(Module module)
901         throws Exception JavaDoc
902     {
903         return internalUser.getUnusedRModuleIssueTypes(module);
904     }
905
906     /**
907      * @see ScarabUser#addRMITsToCurrentMITList(List)
908      */

909     public void addRMITsToCurrentMITList(List JavaDoc rmits)
910         throws TorqueException
911     {
912         internalUser.addRMITsToCurrentMITList(rmits);
913     }
914
915     /**
916      * @see ScarabUser#getCurrentMITList()
917      */

918     public MITList getCurrentMITList()
919     {
920         MITList mitList = internalUser.getCurrentMITList();
921         return mitList;
922     }
923
924     /**
925      * @see ScarabUser#setCurrentMITList(MITList)
926      */

927     public void setCurrentMITList(MITList list)
928     {
929         internalUser.setCurrentMITList(list);
930     }
931
932     /**
933      * @see ScarabUser#removeItemsFromCurrentMITList(String[])
934      */

935     public void removeItemsFromCurrentMITList(String JavaDoc[] ids)
936     {
937         internalUser.removeItemsFromCurrentMITList(ids);
938     }
939
940     /**
941      * @see ScarabUser#lastEnteredIssueTypeOrTemplate()
942      */

943     public Object JavaDoc lastEnteredIssueTypeOrTemplate()
944     {
945         return internalUser.lastEnteredIssueTypeOrTemplate();
946     }
947
948     /**
949      * @see ScarabUser#setLastEnteredIssueType(IssueType)
950      */

951     public void setLastEnteredIssueType(IssueType type)
952     {
953         internalUser.setLastEnteredIssueType(type);
954     }
955
956     /**
957      * @see ScarabUser#setLastEnteredTemplate(Issue)
958      */

959     public void setLastEnteredTemplate(Issue template)
960     {
961         internalUser.setLastEnteredTemplate(template);
962     }
963
964
965     /**
966      * @see org.tigris.scarab.om.ScarabUser#getMostRecentQuery()
967      */

968     public String JavaDoc getMostRecentQuery()
969     {
970         return internalUser.getMostRecentQuery();
971     }
972
973     /**
974      * @see org.tigris.scarab.om.ScarabUser#setMostRecentQuery(String)
975      */

976     public void setMostRecentQuery(String JavaDoc queryString)
977     {
978         internalUser.setMostRecentQuery(queryString.toLowerCase());
979     }
980
981     /**
982      * @see org.tigris.scarab.om.ScarabUser#hasMostRecentQuery()
983      */

984     public boolean hasMostRecentQuery()
985     {
986         return internalUser.hasMostRecentQuery();
987     }
988
989     public Map JavaDoc getAssociatedUsersMap()
990         throws Exception JavaDoc
991     {
992         return internalUser.getAssociatedUsersMap();
993     }
994
995     public void setAssociatedUsersMap(Map JavaDoc associatedUsers)
996         throws Exception JavaDoc
997     {
998         internalUser.setAssociatedUsersMap(associatedUsers);
999     }
1000
1001    public Map JavaDoc getSelectedUsersMap()
1002        throws Exception JavaDoc
1003    {
1004        return internalUser.getSelectedUsersMap();
1005    }
1006
1007    public void setSelectedUsersMap(Map JavaDoc selectedUsers)
1008        throws Exception JavaDoc
1009    {
1010        internalUser.setSelectedUsersMap(selectedUsers);
1011    }
1012    
1013    
1014    /**
1015     * @see ScarabUser#getThreadKey()
1016     */

1017    public Object JavaDoc getThreadKey()
1018    {
1019        return internalUser.getThreadKey();
1020    }
1021
1022    /**
1023     * @see ScarabUser#setThreadKey(Integer)
1024     */

1025    public void setThreadKey(Integer JavaDoc key)
1026    {
1027        internalUser.setThreadKey(key);
1028    }
1029
1030
1031    /**
1032     * The current module
1033     */

1034    public Module getCurrentModule()
1035    {
1036        return internalUser.getCurrentModule();
1037    }
1038    
1039    /**
1040     * The current module
1041     */

1042    public void setCurrentModule(Module v)
1043    {
1044        internalUser.setCurrentModule(v);
1045    }
1046     
1047    /**
1048     * The current issue type
1049     */

1050    public IssueType getCurrentIssueType()
1051        throws Exception JavaDoc
1052    {
1053        return internalUser.getCurrentIssueType();
1054    }
1055    
1056    /**
1057     * The current issue type
1058     */

1059    public void setCurrentIssueType(IssueType v)
1060    {
1061        internalUser.setCurrentIssueType(v);
1062    }
1063    
1064    /**
1065     * @see ScarabUser#getCurrentRModuleIssueType()
1066     */

1067    public RModuleIssueType getCurrentRModuleIssueType()
1068        throws Exception JavaDoc
1069    {
1070        return internalUser.getCurrentRModuleIssueType();
1071    }
1072
1073    /**
1074     * @see org.tigris.scarab.om.ScarabUser#updateIssueListAttributes(List)
1075     */

1076    public void updateIssueListAttributes(List JavaDoc attributes)
1077        throws Exception JavaDoc
1078    {
1079        internalUser.updateIssueListAttributes(attributes);
1080    }
1081
1082    public List JavaDoc getRoleNames(Module module)
1083       throws Exception JavaDoc
1084    {
1085       return null;
1086    }
1087
1088    /**
1089     * Report on size of several maps
1090     */

1091    public String JavaDoc getStats()
1092    {
1093        return internalUser.getStats()
1094            + "; TempStorage=" + getTempStorage().size()
1095            + "; PermStorage=" + getPermStorage().size();
1096    }
1097
1098    /**
1099     * Set the user's locale to a new value.
1100     */

1101    public void setLocale(Locale JavaDoc newLocale)
1102    {
1103        internalUser.setLocale(newLocale);
1104    }
1105
1106    /**
1107     * Get the user's current locale. If it is not set, retrieve the
1108     * preferred Locale instead.
1109     */

1110    public Locale JavaDoc getLocale()
1111    {
1112        return internalUser.getLocale();
1113    }
1114
1115    /**
1116     * Get the user's preferred locale.
1117     */

1118    public Locale JavaDoc getPreferredLocale()
1119    {
1120        return internalUser.getPreferredLocale();
1121    }
1122
1123    /**
1124     * @see org.tigris.scarab.om.ScarabUser#isShowOtherModulesInIssueTypeList()
1125     */

1126    public boolean isShowOtherModulesInIssueTypeList()
1127    {
1128        return internalUser.isShowOtherModulesInIssueTypeList();
1129    }
1130
1131    /**
1132     * @see org.tigris.scarab.om.ScarabUser#setShowOtherModulesInIssueTypeList(boolean)
1133     */

1134    public void setShowOtherModulesInIssueTypeList(
1135        boolean newShowOtherModulesInIssueTypeList)
1136    {
1137        internalUser.setShowOtherModulesInIssueTypeList(
1138            newShowOtherModulesInIssueTypeList);
1139    }
1140}
1141
Popular Tags