Source Code Cross Referenced for ScarabUserImpl.java in  » Issue-Tracking » scarab-0.21 » org » tigris » scarab » om » 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 » Issue Tracking » scarab 0.21 » org.tigris.scarab.om 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        package org.tigris.scarab.om;
0002:
0003:        /* ================================================================
0004:         * Copyright (c) 2000-2005 CollabNet.  All rights reserved.
0005:         * 
0006:         * Redistribution and use in source and binary forms, with or without
0007:         * modification, are permitted provided that the following conditions are
0008:         * met:
0009:         * 
0010:         * 1. Redistributions of source code must retain the above copyright
0011:         * notice, this list of conditions and the following disclaimer.
0012:         * 
0013:         * 2. Redistributions in binary form must reproduce the above copyright
0014:         * notice, this list of conditions and the following disclaimer in the
0015:         * documentation and/or other materials provided with the distribution.
0016:         * 
0017:         * 3. The end-user documentation included with the redistribution, if
0018:         * any, must include the following acknowlegement: "This product includes
0019:         * software developed by Collab.Net <http://www.Collab.Net/>."
0020:         * Alternately, this acknowlegement may appear in the software itself, if
0021:         * and wherever such third-party acknowlegements normally appear.
0022:         * 
0023:         * 4. The hosted project names must not be used to endorse or promote
0024:         * products derived from this software without prior written
0025:         * permission. For written permission, please contact info@collab.net.
0026:         * 
0027:         * 5. Products derived from this software may not use the "Tigris" or 
0028:         * "Scarab" names nor may "Tigris" or "Scarab" appear in their names without 
0029:         * prior written permission of Collab.Net.
0030:         * 
0031:         * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
0032:         * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
0033:         * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
0034:         * IN NO EVENT SHALL COLLAB.NET OR ITS CONTRIBUTORS BE LIABLE FOR ANY
0035:         * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
0036:         * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
0037:         * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0038:         * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
0039:         * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
0040:         * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
0041:         * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
0042:         *
0043:         * ====================================================================
0044:         * 
0045:         * This software consists of voluntary contributions made by many
0046:         * individuals on behalf of Collab.Net.
0047:         */
0048:
0049:        import java.io.Serializable;
0050:        import java.util.ArrayList;
0051:        import java.util.Arrays;
0052:        import java.util.Calendar;
0053:        import java.util.Collections;
0054:        import java.util.Comparator;
0055:        import java.util.Iterator;
0056:        import java.util.List;
0057:        import java.util.Locale;
0058:        import java.util.Map;
0059:        import java.util.Set;
0060:        import java.util.TreeSet;
0061:
0062:        import org.apache.commons.lang.RandomStringUtils;
0063:        import org.apache.fulcrum.security.TurbineSecurity;
0064:        import org.apache.fulcrum.security.entity.Group;
0065:        import org.apache.fulcrum.security.entity.Role;
0066:        import org.apache.fulcrum.security.entity.User;
0067:        import org.apache.fulcrum.security.impl.db.entity.TurbinePermissionPeer;
0068:        import org.apache.fulcrum.security.impl.db.entity.TurbineRolePeer;
0069:        import org.apache.fulcrum.security.impl.db.entity.TurbineRolePermissionPeer;
0070:        import org.apache.fulcrum.security.impl.db.entity.TurbineUserGroupRolePeer;
0071:        import org.apache.fulcrum.security.util.AccessControlList;
0072:        import org.apache.fulcrum.security.util.DataBackendException;
0073:        import org.apache.fulcrum.security.util.EntityExistsException;
0074:        import org.apache.fulcrum.security.util.GroupSet;
0075:        import org.apache.fulcrum.security.util.TurbineSecurityException;
0076:        import org.apache.log4j.Logger;
0077:        import org.apache.torque.TorqueException;
0078:        import org.apache.torque.util.Criteria;
0079:        import org.apache.turbine.Turbine;
0080:        import org.tigris.scarab.reports.ReportBridge;
0081:        import org.tigris.scarab.services.cache.ScarabCache;
0082:        import org.tigris.scarab.services.security.ScarabSecurity;
0083:        import org.tigris.scarab.tools.localization.L10NKeySet;
0084:        import org.tigris.scarab.util.AnonymousUserUtil;
0085:        import org.tigris.scarab.util.Log;
0086:        import org.tigris.scarab.util.ScarabException;
0087:
0088:        import com.workingdogs.village.DataSetException;
0089:
0090:        /**
0091:         * This class is an abstraction that is currently based around
0092:         * Turbine's code. We can change this later. It is here so
0093:         * that it is easier to change later to work under different
0094:         * implementation needs.
0095:         *
0096:         * @author <a href="mailto:jon@collab.net">Jon S. Stevens</a>
0097:         * @version $Id: ScarabUserImpl.java 10285 2006-09-08 16:48:22Z jorgeuriarte $
0098:         */
0099:        public class ScarabUserImpl extends BaseScarabUserImpl implements 
0100:                ScarabUser {
0101:            private static final Logger TORQUE_LOG = Logger
0102:                    .getLogger("org.apache.torque");
0103:
0104:            public static final String PASSWORD_EXPIRE = "PASSWORD_EXPIRE";
0105:
0106:            private AbstractScarabUser internalUser;
0107:
0108:            /**
0109:             * The maximum length for the unique identifier used at user
0110:             * creation time.
0111:             */
0112:            private static final int UNIQUE_ID_MAX_LEN = 10;
0113:
0114:            /**
0115:             * Call the superclass constructor to initialize this object.
0116:             */
0117:            public ScarabUserImpl() {
0118:                super ();
0119:
0120:                /*
0121:                 * Functionality that would be useful in any implementation of
0122:                 * ScarabUser is available in AbstractScarabUser (ASU).  This 
0123:                 * implementation must extend from TurbineUser, so TurbineUser 
0124:                 * would need to extend ASU to gain the functionality through
0125:                 * inheritance.  This is possible with some modifications to 
0126:                 * fulcrum's build process.  But until changes to fulcrum allow it,
0127:                 * we will wrap a instance of ASU.
0128:                 */
0129:                internalUser = new AbstractScarabUser() {
0130:                    public Integer getUserId() {
0131:                        return getPrivateUserId();
0132:                    }
0133:
0134:                    public String getEmail() {
0135:                        return getPrivateEmail();
0136:                    }
0137:
0138:                    public String getFirstName() {
0139:                        return getPrivateFirstName();
0140:                    }
0141:
0142:                    public String getLastName() {
0143:                        return getPrivateLastName();
0144:                    }
0145:
0146:                    protected List getRModuleUserAttributes(Criteria crit)
0147:                            throws TorqueException {
0148:                        return getPrivateRModuleUserAttributes(crit);
0149:                    }
0150:
0151:                    public boolean hasPermission(String perm, Module module) {
0152:                        return hasPrivatePermission(perm, module);
0153:                    }
0154:
0155:                    public List getModules() throws TorqueException {
0156:                        return getModules(false);
0157:                    }
0158:
0159:                    public List getModules(boolean showDeletedModules)
0160:                            throws TorqueException {
0161:                        List permList = ScarabSecurity.getAllPermissions();
0162:                        String[] perms = new String[permList.size()];
0163:                        perms = (String[]) permList.toArray(perms);
0164:
0165:                        Module[] modules = getPrivateModules(perms,
0166:                                showDeletedModules);
0167:                        return (modules == null || modules.length == 0 ? Collections.EMPTY_LIST
0168:                                : Arrays.asList(modules));
0169:                    }
0170:
0171:                    /**
0172:                     * @see org.tigris.scarab.om.ScarabUser#getModules(String)
0173:                     */
0174:                    public Module[] getModules(String permission) {
0175:                        return getPrivateModules(permission);
0176:                    }
0177:
0178:                    protected void deleteRModuleUserAttribute(
0179:                            final RModuleUserAttribute rmua)
0180:                            throws TorqueException, TurbineSecurityException {
0181:                        privateDeleteRModuleUserAttribute(rmua);
0182:                    }
0183:                };
0184:            }
0185:
0186:            // the following getPrivateFoo methods are to avoid naming conflicts when
0187:            // supplying implementations of the methods needed by AbstractScarabUser
0188:            // when instantiated in the constructor
0189:            private Integer getPrivateUserId() {
0190:                return getUserId();
0191:            }
0192:
0193:            private String getPrivateEmail() {
0194:                return getEmail();
0195:            }
0196:
0197:            private String getPrivateFirstName() {
0198:                return getFirstName();
0199:            }
0200:
0201:            private String getPrivateLastName() {
0202:                return getLastName();
0203:            }
0204:
0205:            public String getName() {
0206:                return internalUser.getName();
0207:            }
0208:
0209:            private List getPrivateRModuleUserAttributes(Criteria crit)
0210:                    throws TorqueException {
0211:                return getRModuleUserAttributes(crit);
0212:            }
0213:
0214:            private boolean hasPrivatePermission(String perm, Module module) {
0215:                return hasPermission(perm, module);
0216:            }
0217:
0218:            private Module[] getPrivateModules(String permission) {
0219:                String[] perms = { permission };
0220:                return getModules(perms);
0221:            }
0222:
0223:            private Module[] getPrivateModules(String[] permissions,
0224:                    boolean showDeletedModules) {
0225:                return getModules(permissions, showDeletedModules);
0226:            }
0227:
0228:            private void privateDeleteRModuleUserAttribute(
0229:                    final RModuleUserAttribute rmua) throws TorqueException,
0230:                    TurbineSecurityException {
0231:                rmua.delete(this );
0232:            }
0233:
0234:            /**
0235:             *   Utility method that takes a username and a confirmation code
0236:             *   and will return true if there is a match and false if no match.
0237:             *   <p>
0238:             *   If there is an Exception, it will also return false.
0239:             */
0240:            public static boolean checkConfirmationCode(String username,
0241:                    String confirm) {
0242:                // security check. :-)
0243:                if (confirm.equalsIgnoreCase(User.CONFIRM_DATA)) {
0244:                    return false;
0245:                }
0246:
0247:                try {
0248:                    Criteria criteria = new Criteria();
0249:                    criteria.add(ScarabUserImplPeer
0250:                            .getColumnName(User.USERNAME), username);
0251:                    criteria.add(ScarabUserImplPeer
0252:                            .getColumnName(User.CONFIRM_VALUE), confirm);
0253:                    criteria.setSingleRecord(true);
0254:                    List result = ScarabUserImplPeer.doSelect(criteria);
0255:                    if (result.size() > 0) {
0256:                        return true;
0257:                    }
0258:
0259:                    // FIXME: once i figure out how to build an OR in a Criteria i 
0260:                    // won't need this.
0261:                    // We check to see if the user is already confirmed because that
0262:                    // should result in a True as well.
0263:                    criteria = new Criteria();
0264:                    criteria.add(ScarabUserImplPeer
0265:                            .getColumnName(User.USERNAME), username);
0266:                    criteria.add(ScarabUserImplPeer
0267:                            .getColumnName(User.CONFIRM_VALUE),
0268:                            User.CONFIRM_DATA);
0269:                    criteria.setSingleRecord(true);
0270:                    result = ScarabUserImplPeer.doSelect(criteria);
0271:                    return (result.size() > 0);
0272:                } catch (Exception e) {
0273:                    return false;
0274:                }
0275:            }
0276:
0277:            /**
0278:             This method will mark username as confirmed.
0279:             returns true on success and false on any error
0280:             */
0281:            public static boolean confirmUser(String username) {
0282:                try {
0283:                    User user = TurbineSecurity.getUser(username);
0284:                    user.setConfirmed(User.CONFIRM_DATA);
0285:                    TurbineSecurity.saveUser(user);
0286:                    return true;
0287:                } catch (Exception e) {
0288:                    return false;
0289:                }
0290:            }
0291:
0292:            /**
0293:             * @see org.tigris.scarab.om.ScarabUser#hasPermission(String, Module)
0294:             * Determine if a user has a permission, either within the specified
0295:             * module or within the 'Global' module.
0296:             */
0297:            public boolean hasPermission(String perm, Module module) {
0298:                boolean hasPermission = false;
0299:                AccessControlList aclAnonymous = null;
0300:                try {
0301:                    if (AnonymousUserUtil.anonymousAccessAllowed()) {
0302:                        aclAnonymous = ((ScarabUser) AnonymousUserUtil
0303:                                .getAnonymousUser()).getACL();
0304:                    }
0305:                } catch (Exception e) {
0306:                    getLog().error("hasPermission: " + e);
0307:                }
0308:
0309:                if (TORQUE_LOG.isDebugEnabled()) {
0310:                    String name = (module == null) ? null : module.getName();
0311:                    TORQUE_LOG.debug("ScarabUserImpl.hasPermission(" + perm
0312:                            + ", " + name + ") started");
0313:                }
0314:
0315:                if (perm.equals(ScarabSecurity.USER__CHANGE_PASSWORD)
0316:                        && isUserAnonymous()) {
0317:                    return false;
0318:                }
0319:
0320:                // Cache permission check results internally, so that we do not have
0321:                // to ask the acl everytime.  FIXME!  This mechanism needs to be
0322:                // modified to allow for invalidating the cached results.  Possible
0323:                // candidates are the TurbineGlobalCacheService or JCS.  But keeping
0324:                // this in place for the moment while investigating other sql, so
0325:                // turbine's security sql does not dominate.
0326:                String moduleKey = (module == null) ? null : module
0327:                        .getQueryKey();
0328:                Object obj = getTemp("hasPermission" + perm + moduleKey);
0329:                if (obj == null) {
0330:                    try {
0331:                        AccessControlList acl = this .getACL();
0332:                        if (acl != null) {
0333:                            if (module != null) {
0334:                                // first check for the permission in the specified module
0335:                                hasPermission = acl.hasPermission(perm,
0336:                                        (Group) module);
0337:                                if (!hasPermission && aclAnonymous != null) {
0338:                                    hasPermission |= aclAnonymous
0339:                                            .hasPermission(perm, (Group) module);
0340:                                }
0341:
0342:                            }
0343:
0344:                            if (!hasPermission) {
0345:                                // check for the permission within the 'Global' module
0346:                                Module globalModule = ModuleManager
0347:                                        .getInstance(Module.ROOT_ID);
0348:                                hasPermission = acl.hasPermission(perm,
0349:                                        (Group) globalModule);
0350:                                if (!hasPermission && aclAnonymous != null) {
0351:                                    hasPermission |= aclAnonymous
0352:                                            .hasPermission(perm,
0353:                                                    (Group) globalModule);
0354:                                }
0355:                            }
0356:                        }
0357:                    } catch (Exception e) {
0358:                        hasPermission = false;
0359:                        getLog().error("Permission check failed on:" + perm, e);
0360:                    }
0361:
0362:                    Boolean b = hasPermission ? Boolean.TRUE : Boolean.FALSE;
0363:                    setTemp("hasPermission" + perm + moduleKey, b);
0364:                } else {
0365:                    hasPermission = ((Boolean) obj).booleanValue();
0366:                }
0367:
0368:                if (TORQUE_LOG.isDebugEnabled()) {
0369:                    String name = (module == null) ? null : module.getName();
0370:                    TORQUE_LOG.debug("ScarabUserImpl.hasPermission(" + perm
0371:                            + ", " + name + ") end\n");
0372:                }
0373:                return hasPermission;
0374:            }
0375:
0376:            /**
0377:             * @see org.tigris.scarab.om.ScarabUser#hasPermission(String, List)
0378:             */
0379:            public boolean hasPermission(String perm, List modules) {
0380:                return internalUser.hasPermission(perm, modules);
0381:            }
0382:
0383:            /**
0384:             * @see org.tigris.scarab.om.ScarabUser#getModules()
0385:             */
0386:            public List getModules() throws TorqueException {
0387:                return internalUser.getModules();
0388:            }
0389:
0390:            /**
0391:             * @see org.tigris.scarab.om.ScarabUser#getModules(boolean)
0392:             */
0393:            public List getModules(boolean showDeletedModules)
0394:                    throws TorqueException {
0395:                return internalUser.getModules(showDeletedModules);
0396:            }
0397:
0398:            public Module[] getModules(String permission)
0399:                    throws TorqueException {
0400:                return internalUser.getModules(permission);
0401:            }
0402:
0403:            private static final String GET_MODULES = "getModules";
0404:
0405:            /**
0406:             * @see org.tigris.scarab.om.ScarabUser#getModules(String[])
0407:             */
0408:            public Module[] getModules(String[] permissions) {
0409:                return getModules(permissions, false);
0410:            }
0411:
0412:            /**
0413:             * Get modules that user can copy an issue to.
0414:             */
0415:            public List getCopyToModules(Module currentModule)
0416:                    throws TorqueException {
0417:                return internalUser.getCopyToModules(currentModule);
0418:            }
0419:
0420:            public List getCopyToModules(Module currentModule, String action)
0421:                    throws TorqueException {
0422:                return internalUser.getCopyToModules(currentModule, action,
0423:                        null);
0424:            }
0425:
0426:            public List getCopyToModules(Module currentModule, String action,
0427:                    String searchString) throws TorqueException {
0428:                return internalUser.getCopyToModules(currentModule, action,
0429:                        searchString);
0430:            }
0431:
0432:            /**
0433:             * @see org.tigris.scarab.om.ScarabUser#getModules(String[], boolean)
0434:             */
0435:            public Module[] getModules(String[] permissions,
0436:                    boolean showDeletedModules) {
0437:                Module[] result = null;
0438:                Object obj = ScarabCache.get(this , GET_MODULES, permissions);
0439:                if (obj == null) {
0440:                    Criteria crit = new Criteria();
0441:                    crit.setDistinct();
0442:                    if (!showDeletedModules) {
0443:                        crit.add(ScarabModulePeer.DELETED, 0);
0444:                    }
0445:                    crit.addIn(TurbinePermissionPeer.PERMISSION_NAME,
0446:                            permissions);
0447:                    crit.addJoin(TurbinePermissionPeer.PERMISSION_ID,
0448:                            TurbineRolePermissionPeer.PERMISSION_ID);
0449:                    crit.addJoin(TurbineRolePermissionPeer.ROLE_ID,
0450:                            TurbineUserGroupRolePeer.ROLE_ID);
0451:                    crit.add(TurbineUserGroupRolePeer.USER_ID, getUserId());
0452:                    crit.addJoin(ScarabModulePeer.MODULE_ID,
0453:                            TurbineUserGroupRolePeer.GROUP_ID);
0454:
0455:                    try {
0456:                        List scarabModules = ScarabModulePeer.doSelect(crit);
0457:                        // check for permissions in global, if so get all modules
0458:                        for (int i = scarabModules.size() - 1; i >= 0; i--) {
0459:                            if (Module.ROOT_ID.equals(((Module) scarabModules
0460:                                    .get(i)).getModuleId())) {
0461:                                crit = new Criteria();
0462:                                if (!showDeletedModules) {
0463:                                    crit.add(ScarabModulePeer.DELETED, 0);
0464:                                }
0465:                                scarabModules = ScarabModulePeer.doSelect(crit);
0466:                                break;
0467:                            }
0468:                        }
0469:
0470:                        // Sort list of modules using a special comparator which
0471:                        // takes the name of the module and its parents in account
0472:                        Set sortedResult = new TreeSet(new Comparator() {
0473:                            public int compare(Object object1, Object object2) {
0474:                                Module m1 = (Module) object1;
0475:                                Module m2 = (Module) object2;
0476:                                return m1.getName().compareTo(m2.getName());
0477:                            }
0478:                        });
0479:                        sortedResult.addAll(scarabModules);
0480:
0481:                        result = (Module[]) sortedResult
0482:                                .toArray(new Module[sortedResult.size()]);
0483:                    } catch (Exception e) {
0484:                        getLog()
0485:                                .error(
0486:                                        "An exception prevented retrieving any modules",
0487:                                        e);
0488:                    }
0489:                    ScarabCache.put(result, this , GET_MODULES, permissions);
0490:                } else {
0491:                    result = (Module[]) obj;
0492:                }
0493:                return result;
0494:            }
0495:
0496:            /**
0497:             * @see org.tigris.scarab.om.ScarabUser#hasAnyRoleIn(Module)
0498:             */
0499:            public boolean hasAnyRoleIn(Module module) throws TorqueException {
0500:                return getRoles(module).size() != 0;
0501:            }
0502:
0503:            /**
0504:             * eturn the list of currently active roles.
0505:             * If no roles are active, reuturn an empty list.
0506:             * @return
0507:             */
0508:            public List getCurrentRoleNames() {
0509:                Module module = getCurrentModule();
0510:
0511:                List roles = null;
0512:                try {
0513:                    roles = getRoles(module);
0514:                } catch (Exception e) {
0515:                }
0516:
0517:                List result = new ArrayList();
0518:                if (roles != null) {
0519:                    int size = roles.size();
0520:                    if (size > 0) {
0521:                        for (int index = 0; index < size; index++) {
0522:                            Role role = (Role) roles.get(index);
0523:                            result.add(role.getName());
0524:                        }
0525:                    }
0526:                }
0527:                return result;
0528:
0529:            }
0530:
0531:            private static final String GET_ROLES = "getRoles";
0532:
0533:            /* *
0534:             * @see org.tigris.scarab.om.ScarabUser#getRoles(Module)
0535:             * !FIXME! need to define a Role interface (maybe the one in fulcrum is 
0536:             * sufficient?) before making a method like this public.   
0537:             * Right now it is only used in one place to determine
0538:             * if the user has any roles available, so we will use a more specific
0539:             * public method for that.
0540:             */
0541:            private List getRoles(Module module) throws TorqueException {
0542:                List result = null;
0543:                Object obj = ScarabCache.get(this , GET_ROLES, module);
0544:                if (obj == null) {
0545:                    Criteria crit = new Criteria();
0546:                    crit.setDistinct();
0547:                    crit.add(TurbineUserGroupRolePeer.USER_ID, getUserId());
0548:                    crit.add(TurbineUserGroupRolePeer.GROUP_ID, module
0549:                            .getModuleId());
0550:                    crit.addJoin(TurbineRolePeer.ROLE_ID,
0551:                            TurbineUserGroupRolePeer.ROLE_ID);
0552:                    result = TurbineRolePeer.doSelect(crit);
0553:
0554:                    ScarabCache.put(result, this , GET_ROLES, module);
0555:                } else {
0556:                    result = (List) obj;
0557:                }
0558:                return result;
0559:            }
0560:
0561:            /**
0562:             * @see org.tigris.scarab.om.ScarabUser#createNewUser()
0563:             */
0564:            public void createNewUser() throws TorqueException,
0565:                    DataBackendException, EntityExistsException {
0566:                // get a unique id for validating the user
0567:                final String uniqueId = RandomStringUtils
0568:                        .randomAlphanumeric(UNIQUE_ID_MAX_LEN);
0569:                // add it to the perm table
0570:                setConfirmed(uniqueId);
0571:                TurbineSecurity.addUser(this , getPassword());
0572:                setPasswordExpire();
0573:            }
0574:
0575:            /**
0576:             * @see org.tigris.scarab.om.ScarabUser#getEditableModules()
0577:             */
0578:            public List getEditableModules() throws TorqueException {
0579:                return internalUser.getEditableModules();
0580:            }
0581:
0582:            /**
0583:             * @see org.tigris.scarab.om.ScarabUser#getEditableModules(Module)
0584:             */
0585:            public List getEditableModules(Module currEditModule)
0586:                    throws TorqueException {
0587:                return internalUser.getEditableModules(currEditModule);
0588:            }
0589:
0590:            /**
0591:             * @see org.tigris.scarab.om.ScarabUser#getNonGlobalModules()
0592:             */
0593:            public List getNonGlobalModules() throws TorqueException {
0594:                List modules = new ArrayList();
0595:                for (Iterator it = internalUser.getModules().iterator(); it
0596:                        .hasNext();) {
0597:                    Module m = (Module) it.next();
0598:                    if (!m.isGlobalModule()) {
0599:                        modules.add(m);
0600:                    }
0601:                }
0602:                return modules;
0603:            }
0604:
0605:            /**
0606:             * @see org.tigris.scarab.om.ScarabUser#getRModuleUserAttributes(Module, IssueType)
0607:             */
0608:            public List getRModuleUserAttributes(Module module,
0609:                    IssueType issueType) throws TorqueException {
0610:                return internalUser.getRModuleUserAttributes(module, issueType);
0611:            }
0612:
0613:            /**
0614:             * @see org.tigris.scarab.om.ScarabUser#getRModuleUserAttribute(Module, Attribute, IssueType)
0615:             */
0616:            public RModuleUserAttribute getRModuleUserAttribute(
0617:                    final Module module, final Attribute attribute,
0618:                    final IssueType issueType) throws TorqueException,
0619:                    ScarabException {
0620:                return internalUser.getRModuleUserAttribute(module, attribute,
0621:                        issueType);
0622:            }
0623:
0624:            /**
0625:             * @see org.tigris.scarab.om.ScarabUser#getReportingIssue(String)
0626:             */
0627:            public Issue getReportingIssue(String key) throws TorqueException {
0628:                return internalUser.getReportingIssue(key);
0629:            }
0630:
0631:            /**
0632:             * @see org.tigris.scarab.om.ScarabUser#setReportingIssue(Issue)
0633:             */
0634:            public String setReportingIssue(Issue issue) throws ScarabException {
0635:                return internalUser.setReportingIssue(issue);
0636:            }
0637:
0638:            /**
0639:             * @see org.tigris.scarab.om.ScarabUser#setReportingIssue(String, Issue)
0640:             */
0641:            public void setReportingIssue(String key, Issue issue) {
0642:                internalUser.setReportingIssue(key, issue);
0643:            }
0644:
0645:            /**
0646:             * @see org.tigris.scarab.om.ScarabUser#getCurrentReport(String)
0647:             */
0648:            public ReportBridge getCurrentReport(String key)
0649:                    throws TorqueException {
0650:                return internalUser.getCurrentReport(key);
0651:            }
0652:
0653:            /**
0654:             * @see org.tigris.scarab.om.ScarabUser#setCurrentReport(ReportBridge)
0655:             */
0656:            public String setCurrentReport(ReportBridge report)
0657:                    throws ScarabException {
0658:                return internalUser.setCurrentReport(report);
0659:            }
0660:
0661:            /**
0662:             * @see org.tigris.scarab.om.ScarabUser#setCurrentReport(String, ReportBridge)
0663:             */
0664:            public void setCurrentReport(String key, ReportBridge report) {
0665:                internalUser.setCurrentReport(key, report);
0666:            }
0667:
0668:            /**
0669:             * Sets the password to expire with information from the scarab.properties
0670:             * scarab.login.password.expire value.
0671:             *
0672:             * @exception Exception if problem setting the password.
0673:             */
0674:            public void setPasswordExpire() throws TorqueException {
0675:                String expireDays = Turbine.getConfiguration().getString(
0676:                        "scarab.login.password.expire", null);
0677:
0678:                if (expireDays == null || expireDays.trim().length() == 0) {
0679:                    setPasswordExpire(null);
0680:                } else {
0681:                    Calendar expireDate = Calendar.getInstance();
0682:                    expireDate.add(Calendar.DATE, Integer.parseInt(expireDays));
0683:                    setPasswordExpire(expireDate);
0684:                }
0685:            }
0686:
0687:            /**
0688:             * Sets the password to expire on the specified date.
0689:             *
0690:             * @param expire a <code>Calendar</code> value specifying the expire date.  If
0691:             * this value is null, the password will be set to expire 10 years from the
0692:             * current year. Since Logging in resets this value, it should be ok to 
0693:             * have someone's password expire after 10 years.
0694:             *
0695:             * @exception Exception if problem updating the password.
0696:             */
0697:            public void setPasswordExpire(Calendar expire)
0698:                    throws TorqueException {
0699:                Integer userid = getUserId();
0700:                if (userid == null) {
0701:                    throw new TorqueException("Userid cannot be null"); //EXCEPTION
0702:                }
0703:                UserPreference up = UserPreferenceManager
0704:                        .getInstance(getUserId());
0705:                if (expire == null) {
0706:                    Calendar cal = Calendar.getInstance();
0707:                    cal.set(Calendar.YEAR, cal.get(Calendar.YEAR) + 10);
0708:                    up.setPasswordExpire(cal.getTime());
0709:                } else {
0710:                    up.setPasswordExpire(expire.getTime());
0711:                }
0712:                up.save();
0713:            }
0714:
0715:            /**
0716:             * Checks if the users password has expired.
0717:             *
0718:             * @exception Exception if problem querying for the password.
0719:             */
0720:            public boolean isPasswordExpired() throws TorqueException,
0721:                    ScarabException {
0722:                // Password for anonymous never expires.
0723:                if (isUserAnonymous()) {
0724:                    return false;
0725:                }
0726:
0727:                final Integer userid = getUserId();
0728:                if (userid == null) {
0729:                    return false; // throw new ScarabException (L10NKeySet.ExceptionGeneral,"Userid cannot be null"); //EXCEPTION
0730:                }
0731:                final Criteria crit = new Criteria();
0732:                crit.add(UserPreferencePeer.USER_ID, userid);
0733:                final Calendar cal = Calendar.getInstance();
0734:                crit.add(UserPreferencePeer.PASSWORD_EXPIRE, cal.getTime(),
0735:                        Criteria.LESS_THAN);
0736:                final List result = UserPreferencePeer.doSelect(crit);
0737:                return result.size() == 1 ? true : false;
0738:            }
0739:
0740:            /**
0741:             * Returns true if the user is the one set in scarab.anonymous.username, and
0742:             * false otherwise.
0743:             * @return
0744:             */
0745:            public boolean isUserAnonymous() {
0746:                boolean brdo = false;
0747:                String anonymous = Turbine.getConfiguration().getString(
0748:                        "scarab.anonymous.username", null);
0749:                String username = getUserName();
0750:                if (anonymous != null && username.equals(anonymous)) {
0751:                    brdo = true;
0752:                }
0753:                return brdo;
0754:            }
0755:
0756:            /**
0757:             * Returns integer representing user preference for
0758:             * Which screen to return to after entering an issue.
0759:             * 1 = Enter New Issue. 2 = Assign Issue (default)
0760:             * 3 = View Issue. 4 = Issue Types index.
0761:             */
0762:            public int getEnterIssueRedirect() throws TorqueException {
0763:                return internalUser.getEnterIssueRedirect();
0764:            }
0765:
0766:            /**
0767:             * Sets integer representing user preference for
0768:             * Which screen to return to after entering an issue.
0769:             * 1 = Enter New Issue. 2 = Assign Issue (default)
0770:             * 3 = View Issue. 4 = Issue Types index.
0771:             */
0772:            public void setEnterIssueRedirect(int templateCode)
0773:                    throws TorqueException {
0774:                internalUser.setEnterIssueRedirect(templateCode);
0775:            }
0776:
0777:            /**
0778:             * @see ScarabUser#getHomePage()
0779:             */
0780:            public String getHomePage() throws TorqueException {
0781:                return internalUser.getHomePage();
0782:            }
0783:
0784:            /**
0785:             * @see ScarabUser#getHomePage(Module)
0786:             */
0787:            public String getHomePage(Module module) throws TorqueException {
0788:                return internalUser.getHomePage(module);
0789:            }
0790:
0791:            /**
0792:             * @see ScarabUser#setHomePage(String)
0793:             */
0794:            public void setHomePage(String homePage) throws TorqueException,
0795:                    ScarabException {
0796:                internalUser.setHomePage(homePage);
0797:            }
0798:
0799:            /**
0800:             * @see ScarabUser#getQueryTarget()
0801:             */
0802:            public String getQueryTarget() {
0803:                return internalUser.getQueryTarget();
0804:            }
0805:
0806:            /**
0807:             * @see ScarabUser#setSingleIssueTypeQueryTarget(IssueType, String)
0808:             */
0809:            public void setSingleIssueTypeQueryTarget(IssueType type,
0810:                    String target) {
0811:                internalUser.setSingleIssueTypeQueryTarget(type, target);
0812:            }
0813:
0814:            /**
0815:             * @see ScarabUser#getMITLists()
0816:             */
0817:            public List getMITLists() throws TorqueException {
0818:                return internalUser.getMITLists();
0819:            }
0820:
0821:            /**
0822:             * @see ScarabUser#hasAnySearchableRMITs().
0823:             */
0824:            public boolean hasAnySearchableRMITs() throws TorqueException,
0825:                    DataSetException {
0826:                return internalUser.hasAnySearchableRMITs();
0827:            }
0828:
0829:            /**
0830:             * @see ScarabUser#getSearchableRMITs(String, String, String, String, Module)
0831:             */
0832:            public List getSearchableRMITs(String searchField,
0833:                    String searchString, String sortColumn,
0834:                    String sortPolarity, Module skipModule)
0835:                    throws TorqueException {
0836:                return internalUser.getSearchableRMITs(searchField,
0837:                        searchString, sortColumn, sortPolarity, skipModule);
0838:            }
0839:
0840:            /**
0841:             * @see ScarabUser#getUnusedRModuleIssueTypes(Module).
0842:             */
0843:            public List getUnusedRModuleIssueTypes(Module module)
0844:                    throws TorqueException {
0845:                return internalUser.getUnusedRModuleIssueTypes(module);
0846:            }
0847:
0848:            /**
0849:             * @see ScarabUser#getAllRModuleIssueTypes(Module).
0850:             */
0851:            public List getAllRModuleIssueTypes(Module module)
0852:                    throws TorqueException {
0853:                return internalUser.getAllRModuleIssueTypes(module);
0854:            }
0855:
0856:            /**
0857:             * @see ScarabUser#addRMITsToCurrentMITList(List)
0858:             */
0859:            public void addRMITsToCurrentMITList(List rmits)
0860:                    throws TorqueException {
0861:                internalUser.addRMITsToCurrentMITList(rmits);
0862:            }
0863:
0864:            /**
0865:             * @see ScarabUser#getCurrentMITList()
0866:             */
0867:            public MITList getCurrentMITList() {
0868:                MITList mitList = internalUser.getCurrentMITList();
0869:                return mitList;
0870:            }
0871:
0872:            /**
0873:             * @see ScarabUser#setCurrentMITList(MITList)
0874:             */
0875:            public void setCurrentMITList(MITList list) {
0876:                internalUser.setCurrentMITList(list);
0877:            }
0878:
0879:            /**
0880:             * @see ScarabUser#removeItemsFromCurrentMITList(String[])
0881:             */
0882:            public void removeItemsFromCurrentMITList(String[] ids) {
0883:                internalUser.removeItemsFromCurrentMITList(ids);
0884:            }
0885:
0886:            /**
0887:             * @see ScarabUser#lastEnteredIssueTypeOrTemplate()
0888:             */
0889:            public Object lastEnteredIssueTypeOrTemplate() {
0890:                return internalUser.lastEnteredIssueTypeOrTemplate();
0891:            }
0892:
0893:            /**
0894:             * @see ScarabUser#setLastEnteredIssueType(IssueType)
0895:             */
0896:            public void setLastEnteredIssueType(IssueType type) {
0897:                internalUser.setLastEnteredIssueType(type);
0898:            }
0899:
0900:            /**
0901:             * @see ScarabUser#setLastEnteredTemplate(Issue)
0902:             */
0903:            public void setLastEnteredTemplate(Issue template) {
0904:                internalUser.setLastEnteredTemplate(template);
0905:            }
0906:
0907:            /**
0908:             * @see org.tigris.scarab.om.ScarabUser#getMostRecentQuery()
0909:             */
0910:            public String getMostRecentQuery() {
0911:                return internalUser.getMostRecentQuery();
0912:            }
0913:
0914:            /**
0915:             * @see org.tigris.scarab.om.ScarabUser#setMostRecentQuery(String)
0916:             */
0917:            public void setMostRecentQuery(String queryString) {
0918:                internalUser.setMostRecentQuery(queryString.toLowerCase());
0919:            }
0920:
0921:            /**
0922:             * @see org.tigris.scarab.om.ScarabUser#hasMostRecentQuery()
0923:             */
0924:            public boolean hasMostRecentQuery() {
0925:                return internalUser.hasMostRecentQuery();
0926:            }
0927:
0928:            public Map getAssociatedUsersMap() throws TorqueException {
0929:                return internalUser.getAssociatedUsersMap();
0930:            }
0931:
0932:            public void setAssociatedUsersMap(Map associatedUsers)
0933:                    throws TorqueException {
0934:                internalUser.setAssociatedUsersMap(associatedUsers);
0935:            }
0936:
0937:            public Map getSelectedUsersMap() throws TorqueException {
0938:                return internalUser.getSelectedUsersMap();
0939:            }
0940:
0941:            public void setSelectedUsersMap(Map selectedUsers)
0942:                    throws TorqueException {
0943:                internalUser.setSelectedUsersMap(selectedUsers);
0944:            }
0945:
0946:            /**
0947:             * @see ScarabUser#getThreadKey()
0948:             */
0949:            public Object getThreadKey() {
0950:                return internalUser.getThreadKey();
0951:            }
0952:
0953:            /**
0954:             * @see ScarabUser#setThreadKey(Integer)
0955:             */
0956:            public void setThreadKey(Integer key) {
0957:                internalUser.setThreadKey(key);
0958:            }
0959:
0960:            /**
0961:             * The current module
0962:             */
0963:            public Module getCurrentModule() {
0964:                return internalUser.getCurrentModule();
0965:            }
0966:
0967:            /**
0968:             * The current module
0969:             */
0970:            public void setCurrentModule(Module v) {
0971:                internalUser.setCurrentModule(v);
0972:            }
0973:
0974:            /**
0975:             * The current issue type
0976:             */
0977:            public IssueType getCurrentIssueType() throws TorqueException {
0978:                return internalUser.getCurrentIssueType();
0979:            }
0980:
0981:            /**
0982:             * The current issue type
0983:             */
0984:            public void setCurrentIssueType(IssueType v) {
0985:                internalUser.setCurrentIssueType(v);
0986:            }
0987:
0988:            /**
0989:             * @see ScarabUser#getCurrentRModuleIssueType()
0990:             */
0991:            public RModuleIssueType getCurrentRModuleIssueType()
0992:                    throws TorqueException {
0993:                return internalUser.getCurrentRModuleIssueType();
0994:            }
0995:
0996:            /**
0997:             * @see org.tigris.scarab.om.ScarabUser#updateIssueListAttributes(List)
0998:             */
0999:            public void updateIssueListAttributes(List attributes)
1000:                    throws TorqueException, TurbineSecurityException {
1001:                internalUser.updateIssueListAttributes(attributes);
1002:            }
1003:
1004:            public List getRoleNames(Module module) throws TorqueException {
1005:                return null;
1006:            }
1007:
1008:            /**
1009:             * Report on size of several maps
1010:             */
1011:            public String getStats() {
1012:                return internalUser.getStats() + "; TempStorage="
1013:                        + getTempStorage().size() + "; PermStorage="
1014:                        + getPermStorage().size();
1015:            }
1016:
1017:            /**
1018:             * Set the user's locale to a new value.
1019:             */
1020:            public void setLocale(Locale newLocale) {
1021:                internalUser.setLocale(newLocale);
1022:            }
1023:
1024:            /**
1025:             * Get the user's current locale. If it is not set, retrieve the
1026:             * preferred Locale instead.
1027:             */
1028:            public Locale getLocale() {
1029:                return internalUser.getLocale();
1030:            }
1031:
1032:            /**
1033:             * Get the user's preferred locale.
1034:             */
1035:            public Locale getPreferredLocale() {
1036:                return internalUser.getPreferredLocale();
1037:            }
1038:
1039:            /**
1040:             * @see org.tigris.scarab.om.ScarabUser#isShowOtherModulesInIssueTypeList()
1041:             */
1042:            public boolean isShowOtherModulesInIssueTypeList() {
1043:                return internalUser.isShowOtherModulesInIssueTypeList();
1044:            }
1045:
1046:            /**
1047:             * @see org.tigris.scarab.om.ScarabUser#setShowOtherModulesInIssueTypeList(boolean)
1048:             */
1049:            public void setShowOtherModulesInIssueTypeList(
1050:                    boolean newShowOtherModulesInIssueTypeList) {
1051:                internalUser
1052:                        .setShowOtherModulesInIssueTypeList(newShowOtherModulesInIssueTypeList);
1053:            }
1054:
1055:            public List getAssignIssuesList() {
1056:                List issues = null;
1057:                try {
1058:                    Map userMap = this .getAssociatedUsersMap();
1059:                    if (userMap != null && userMap.size() > 0) {
1060:                        issues = new ArrayList();
1061:                        Iterator iter = userMap.keySet().iterator();
1062:                        while (iter.hasNext()) {
1063:                            issues.add(IssueManager.getInstance((Long) iter
1064:                                    .next()));
1065:                        }
1066:                    }
1067:                } catch (Exception te) {
1068:                    getLog().error("getAssignIssuesList(): " + te);
1069:                }
1070:                return issues;
1071:            }
1072:
1073:            /**
1074:             * Return the AccessControlList for this user.
1075:             * TODO: This should go wrapped in a fulcrum-independent interface, with Role and others.
1076:             * 
1077:             */
1078:            public AccessControlList getACL() {
1079:                AccessControlList acl = (AccessControlList) ScarabUserManager
1080:                        .getMethodResult().get(this .getUserName(),
1081:                                ScarabUserManager.GET_ACL);
1082:                if (acl == null) {
1083:                    try {
1084:                        acl = TurbineSecurity.getACL(this );
1085:                        ScarabUserManager.getMethodResult().put(acl,
1086:                                this .getUserName(), ScarabUserManager.GET_ACL);
1087:                    } catch (Exception e) {
1088:                    }
1089:                }
1090:                return acl;
1091:            }
1092:
1093:            public boolean hasRoleInModule(Role role, Module module) {
1094:                boolean bRdo = false;
1095:                Boolean cached = (Boolean) ScarabUserManager.getMethodResult()
1096:                        .get(this .getUserName(),
1097:                                ScarabUserManager.HAS_ROLE_IN_MODULE,
1098:                                role.getName(), module.getModuleId());
1099:                if (cached == null) {
1100:                    AccessControlList acl = this .getACL();
1101:                    GroupSet allGroups;
1102:                    try {
1103:                        allGroups = TurbineSecurity.getAllGroups();
1104:                        Group group = allGroups.getGroup(module.getName());
1105:                        bRdo = acl.hasRole(role, group);
1106:                        ScarabUserManager.getMethodResult().put(
1107:                                Boolean.valueOf(bRdo), this .getUserName(),
1108:                                ScarabUserManager.HAS_ROLE_IN_MODULE,
1109:                                role.getName(), module.getModuleId());
1110:                    } catch (DataBackendException e) {
1111:                        Log.get().error("hasRoleInModule: " + e);
1112:                    }
1113:                } else {
1114:                    bRdo = cached.booleanValue();
1115:                }
1116:                return bRdo;
1117:            }
1118:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.