Source Code Cross Referenced for HMailServer.java in  » Groupware » ivatagroupware » com » ivata » groupware » business » mail » server » 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 » Groupware » ivatagroupware » com.ivata.groupware.business.mail.server 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*
0002:         * Copyright (c) 2001 - 2005 ivata limited.
0003:         * All rights reserved.
0004:         * -----------------------------------------------------------------------------
0005:         * ivata groupware may be redistributed under the GNU General Public
0006:         * License as published by the Free Software Foundation;
0007:         * version 2 of the License.
0008:         *
0009:         * These programs are free software; you can redistribute them and/or
0010:         * modify them under the terms of the GNU General Public License
0011:         * as published by the Free Software Foundation; version 2 of the License.
0012:         *
0013:         * These programs are distributed in the hope that they will be useful,
0014:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
0015:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
0016:         *
0017:         * See the GNU General Public License in the file LICENSE.txt for more
0018:         * details.
0019:         *
0020:         * If you would like a copy of the GNU General Public License write to
0021:         *
0022:         * Free Software Foundation, Inc.
0023:         * 59 Temple Place - Suite 330
0024:         * Boston, MA 02111-1307, USA.
0025:         *
0026:         *
0027:         * To arrange commercial support and licensing, contact ivata at
0028:         *                  http://www.ivata.com/contact.jsp
0029:         * -----------------------------------------------------------------------------
0030:         * $Log: HMailServer.java,v $
0031:         * Revision 1.9  2005/10/14 14:01:58  colinmacleod
0032:         * Changed password checking routines to return boolean, rather than throwing
0033:         * an exception.
0034:         *
0035:         * Revision 1.8  2005/10/10 16:06:39  colinmacleod
0036:         * Merged in changes from releases 0.11.2 and 0.11.3.
0037:         *
0038:         * Revision 1.7  2005/10/09 09:39:27  colinmacleod
0039:         * Merged changes from ivata groupware v0.11.2 back into main trunk.
0040:         *
0041:         * Revision 1.6  2005/10/03 10:21:15  colinmacleod
0042:         * Fixed some style and javadoc issues.
0043:         *
0044:         * Revision 1.5  2005/10/02 14:08:59  colinmacleod
0045:         * Added/improved log4j logging.
0046:         *
0047:         * Revision 1.4  2005/09/14 16:16:52  colinmacleod
0048:         * Removed unused local and class variables.
0049:         * Added serialVersionUID.
0050:         *
0051:         * Revision 1.3.2.1  2005/10/08 17:32:58  colinmacleod
0052:         * Extended for hMailServer v4.x
0053:         *
0054:         * Revision 1.3  2005/04/10 19:32:52  colinmacleod
0055:         * Removed extra blank lines.
0056:         *
0057:         * Revision 1.2  2005/04/09 17:20:01  colinmacleod
0058:         * Changed copyright text to GPL v2 explicitly.
0059:         *
0060:         * Revision 1.1.1.1  2005/03/10 17:51:22  colinmacleod
0061:         * Restructured ivata op around Hibernate/PicoContainer.
0062:         * Renamed ivata groupware.
0063:         *
0064:         * -----------------------------------------------------------------------------
0065:         */
0066:        package com.ivata.groupware.business.mail.server;
0067:
0068:        import java.util.Collection;
0069:        import java.util.HashMap;
0070:        import java.util.Iterator;
0071:        import java.util.List;
0072:        import java.util.Map;
0073:        import java.util.Vector;
0074:
0075:        import jp.ne.so_net.ga2.no_ji.jcom.IDispatch;
0076:        import jp.ne.so_net.ga2.no_ji.jcom.JComException;
0077:        import jp.ne.so_net.ga2.no_ji.jcom.ReleaseManager;
0078:
0079:        import org.apache.log4j.Logger;
0080:
0081:        import com.ivata.groupware.admin.security.server.SecuritySession;
0082:        import com.ivata.groupware.admin.setting.Settings;
0083:        import com.ivata.groupware.business.addressbook.AddressBook;
0084:        import com.ivata.mask.util.SystemException;
0085:
0086:        /**
0087:         * <p>
0088:         * On <strong>Microsoft Windows</strong> platforms, we recommend you use the
0089:         * open source <a href='http://www.hmailserver.com/'>hMailServer</a>. This class
0090:         * provides an interface to that system.
0091:         * </p>
0092:         *
0093:         * <p>
0094:         * <strong>Note:</strong> this code indirectly uses
0095:         * <a href='http://www.microsoft.com/com/default.mspx'>Microsoft COM</a>
0096:         * and will only work on <strong>Microsoft Windows</strong>. For UNIX Systems,
0097:         * use the {@link com.ivata.groupware.business.mail.server.ScriptMailServer
0098:         * ScriptMailServer}.
0099:         * </p>
0100:         *
0101:         * <p>
0102:         * This version of the code has been tested to work with <strong>hMailServer
0103:         * versions 3.x and 4.x</strong>.
0104:         * </p>
0105:         *
0106:         * @since ivata groupware 0.10 (2005-02-21)
0107:         * @author Colin MacLeod
0108:         * <a href="mailto:colin.macleod@ivata.com">colin.macleod@ivata.com</a>
0109:         * @version $Revision: 1.9 $
0110:         */
0111:        public class HMailServer extends JavaMailServer implements  MailServer {
0112:            /**
0113:             * Serialization version (for <code>Serializable</code> interface).
0114:             */
0115:            private static final long serialVersionUID = 1L;
0116:            /**
0117:             * Name of the COM object we'll be using for <strong>hMailServer
0118:             * v3.x</strong>.
0119:             */
0120:            private static final String V3_BASE_APP_NAME = "HCOM.BaseApp";
0121:            /**
0122:             * Name of the Domains COM object we'll be using for <strong>hMailServer
0123:             * v4.x</strong>.
0124:             */
0125:            private static final String V4_DOMAINS_NAME = "hMailServer.Domains";
0126:
0127:            /**
0128:             * Stores the only instance of the base app - through which we communicate
0129:             * to hMailServer. <strong>This is only used for hMailServer v3.x.</strong>.
0130:             */
0131:            private static IDispatch baseApp = null;
0132:            /**
0133:             * Logger for this class.
0134:             */
0135:            private static final Logger logger = Logger
0136:                    .getLogger(HMailServer.class);
0137:            /**
0138:             * JCom release object. See <a
0139:             * href='http://sourceforge.net/project/showfiles.php?group_id=12841'>jcom
0140:             * docs</a>.
0141:             */
0142:            private static ReleaseManager releaseManager;
0143:            static {
0144:                try {
0145:                    releaseManager = new ReleaseManager();
0146:                } catch (Exception e) {
0147:                    logger.error(e.getClass().getName()
0148:                            + " trying to create JCom ReleaseManager.");
0149:                    throw new RuntimeException(e);
0150:                }
0151:                IDispatch domains;
0152:                try {
0153:                    domains = new IDispatch(releaseManager, V4_DOMAINS_NAME);
0154:                } catch (Exception e) {
0155:                    logger
0156:                            .error(
0157:                                    e.getClass().getName()
0158:                                            + " trying to retrieve hMailServer domains from COM "
0159:                                            + "object '" + V4_DOMAINS_NAME
0160:                                            + "'.", e);
0161:                    // null case handled below
0162:                    domains = null;
0163:                }
0164:                if (domains != null) {
0165:                    if (logger.isDebugEnabled()) {
0166:                        logger.debug("Identified hMailServer v4.x domains.");
0167:                    }
0168:                } else {
0169:                    try {
0170:                        baseApp = new IDispatch(releaseManager,
0171:                                V3_BASE_APP_NAME);
0172:                    } catch (Exception e) {
0173:                        if (logger.isDebugEnabled()) {
0174:                            logger.debug(
0175:                                    "Could not find hMailServer v3.x COM object '"
0176:                                            + V3_BASE_APP_NAME
0177:                                            + "'. Trying v4.x", e);
0178:                        }
0179:                        baseApp = null;
0180:                    }
0181:                    if (baseApp == null) {
0182:                        String message = "No hMailServer v3.x Base App found "
0183:                                + "with COM NAME '"
0184:                                + V3_BASE_APP_NAME
0185:                                + "', and no hMailServer 4.x Domains object found "
0186:                                + "with COM NAME '" + V4_DOMAINS_NAME + "'";
0187:                        logger.error(message);
0188:                        throw new NullPointerException(message);
0189:                    }
0190:                    if (logger.isDebugEnabled()) {
0191:                        logger.debug("Identified hMailServer v3.x base app.");
0192:                    }
0193:                    try {
0194:                        logger.info("Using hMailServer version "
0195:                                + baseApp.get("Version"));
0196:                    } catch (Exception e) {
0197:                        logger
0198:                                .error(
0199:                                        e.getClass().getName()
0200:                                                + " trying to retrieve hMailServer version.",
0201:                                        e);
0202:                    }
0203:                }
0204:            }
0205:
0206:            /**
0207:             * Get all the domains of the mail server.
0208:             *
0209:             * @return Returns the mail server domains.
0210:             * @throws SystemException If the domains cannot be retrieved for any
0211:             * reason.
0212:             */
0213:            public static IDispatch getDomains() throws SystemException {
0214:                if (logger.isDebugEnabled()) {
0215:                    logger.debug("getDomains() - start");
0216:                }
0217:                IDispatch domains;
0218:
0219:                // if we're using v3, just get it from the baseApp
0220:                if (baseApp != null) {
0221:                    try {
0222:                        domains = (IDispatch) baseApp.get("Domains");
0223:                    } catch (JComException e) {
0224:                        logger.error(
0225:                                "Retrieving domains from hMailServer v3.x", e);
0226:                        throw new SystemException(e);
0227:                    }
0228:                } else {
0229:                    try {
0230:                        domains = new IDispatch(releaseManager, V4_DOMAINS_NAME);
0231:                    } catch (JComException e) {
0232:                        logger.error(
0233:                                "Retrieving domains from hMailServer v4.x, COM "
0234:                                        + "name '" + V4_DOMAINS_NAME + "'.", e);
0235:                        throw new SystemException(e);
0236:                    }
0237:                }
0238:
0239:                if (logger.isDebugEnabled()) {
0240:                    logger.debug("getDomains() - end - return value = "
0241:                            + domains);
0242:                }
0243:                return domains;
0244:            }
0245:
0246:            /**
0247:             * Simple test routine, to check this class is working on
0248:             * <strong>Windows</strong>.
0249:             *
0250:             * @param args Program arguments - not used, in this program.
0251:             */
0252:            public static void main(final String[] args) {
0253:                if (logger.isDebugEnabled()) {
0254:                    logger.debug("main(String[] args = " + args + ") - start");
0255:                }
0256:
0257:                HMailServer mailTest = null;
0258:                try {
0259:                    mailTest = new HMailServer("win.ivata.com", null, null);
0260:                } catch (Exception e) {
0261:                    logger.error("Cannot instantiate HMailServer", e);
0262:                    System.exit(-1);
0263:                }
0264:
0265:                try {
0266:                    mailTest.removeUser(null, "test");
0267:                } catch (Exception e) {
0268:                    logger.warn("No previous test user", e);
0269:                }
0270:                try {
0271:                    mailTest.addUser(null, "test", "test name");
0272:                    mailTest.setPassword(null, "test", "mytest");
0273:                    mailTest.checkPassword(null, "test", "mytest");
0274:                    mailTest.setVacationMessage(null, "test",
0275:                            "This is a vacation message.");
0276:                    logger.info("Vacation message is "
0277:                            + mailTest.getVacationMessage(null, "test"));
0278:                } catch (Exception e) {
0279:                    logger.error("TEST ERROR", e);
0280:                    System.exit(-1);
0281:                }
0282:                System.exit(0);
0283:
0284:                if (logger.isDebugEnabled()) {
0285:                    logger.debug("main(String[]) - end");
0286:                }
0287:            }
0288:
0289:            /**
0290:             * <copyDoc>Refer to {@link HMailServer()}.</copyDoc>
0291:             */
0292:            private String domainName;
0293:
0294:            /**
0295:             * Constructor. Create a connection to <strong>hMailServer</strong>.
0296:             *
0297:             * @param domainNameParam hMailServer domain name.
0298:             * @param addressBook {@inheritDoc}
0299:             * @param settings {@inheritDoc}
0300:             */
0301:            public HMailServer(final String domainNameParam,
0302:                    final AddressBook addressBook, final Settings settings) {
0303:                super (addressBook, settings);
0304:                domainName = domainNameParam;
0305:            }
0306:
0307:            /**
0308:             * {@inheritDoc}
0309:             *
0310:             * @param securitySession {@inheritDoc}
0311:             * @param userNameParam {@inheritDoc}
0312:             * @param fullNameParam {@inheritDoc}
0313:             * @throws SystemException If the user already exists.
0314:             */
0315:            public void addUser(final SecuritySession securitySession,
0316:                    final String userNameParam, final String fullNameParam)
0317:                    throws SystemException {
0318:                if (logger.isDebugEnabled()) {
0319:                    logger.debug("addUser(SecuritySession securitySession = "
0320:                            + securitySession + ", String userNameParam = "
0321:                            + userNameParam + ", String fullNameParam = "
0322:                            + fullNameParam + ") - start");
0323:                }
0324:
0325:                try {
0326:                    IDispatch accounts = getDomainAccounts();
0327:                    String address = getSystemUserName(securitySession,
0328:                            userNameParam);
0329:                    // first check this is a unique address
0330:                    if (isUser(securitySession, userNameParam)) {
0331:                        throw new SystemException(
0332:                                "User address must be unique: " + "address '"
0333:                                        + address + "' already exists.");
0334:                    }
0335:
0336:                    IDispatch newAccount = (IDispatch) accounts.method("Add",
0337:                            new Object[] {});
0338:                    newAccount.put("Address", getSystemUserName(
0339:                            securitySession, userNameParam));
0340:                    newAccount.put("Active", Boolean.TRUE);
0341:                    newAccount.method("Save", new Object[] {});
0342:                } catch (SystemException e) {
0343:                    logger.error("addUser(SecuritySession, String, String)", e);
0344:
0345:                    throw e;
0346:                } catch (Exception e) {
0347:                    logger.error("addUser(SecuritySession, String, String)", e);
0348:
0349:                    throw new SystemException(e);
0350:                }
0351:
0352:                if (logger.isDebugEnabled()) {
0353:                    logger
0354:                            .debug("addUser(SecuritySession, String, String) - end");
0355:                }
0356:            }
0357:
0358:            /**
0359:             * <copyDoc>Refer to {@link }.</copyDoc>
0360:             *
0361:             * @param securitySession {@inheritDoc}
0362:             * @param userNameParam {@inheritDoc}
0363:             * @param passwordParam {@inheritDoc}
0364:             * @throws SystemException If the password doesn't match, or there is
0365:             * a technical problem communicating with hMailServer.
0366:             * @return {@inheritDoc}
0367:             */
0368:            public boolean checkPassword(final SecuritySession securitySession,
0369:                    final String userNameParam, final String passwordParam)
0370:                    throws SystemException {
0371:                if (logger.isDebugEnabled()) {
0372:                    logger
0373:                            .debug("checkPassword(SecuritySession securitySession = "
0374:                                    + securitySession
0375:                                    + ", String userNameParam = "
0376:                                    + userNameParam
0377:                                    + ", String passwordParam = "
0378:                                    + passwordParam + ") - start");
0379:                }
0380:
0381:                try {
0382:                    String address = getSystemUserName(securitySession,
0383:                            userNameParam);
0384:                    IDispatch accounts = getDomainAccounts();
0385:                    IDispatch account = (IDispatch) accounts.get(
0386:                            "ItemByAddress", new Object[] { address });
0387:                    // if we're using v3, use the utilities from the baseApp
0388:                    if (baseApp != null) {
0389:                        if (logger.isDebugEnabled()) {
0390:                            logger
0391:                                    .debug("Checking the password for account '"
0392:                                            + userNameParam
0393:                                            + "' via hMailServer v3.x.");
0394:                        }
0395:                        IDispatch utilities;
0396:                        try {
0397:                            utilities = (IDispatch) baseApp.get("Utilities");
0398:                        } catch (JComException e) {
0399:                            logger.error("Getting the utilities object from "
0400:                                    + "hMailServer v3.x", e);
0401:                            throw new SystemException(e);
0402:                        }
0403:                        String passwordCheck = (String) utilities.method("MD5",
0404:                                new Object[] { passwordParam });
0405:                        boolean returnValue = passwordCheck.equals(account
0406:                                .get("Password"));
0407:                        if (logger.isDebugEnabled()) {
0408:                            logger
0409:                                    .debug("checkPassword() - end - return value = "
0410:                                            + returnValue);
0411:                        }
0412:                        return returnValue;
0413:                    } else {
0414:                        // v4.x uses the account object
0415:                        if (logger.isDebugEnabled()) {
0416:                            logger
0417:                                    .debug("Checking the password for account '"
0418:                                            + userNameParam
0419:                                            + "' via hMailServer v4.x.");
0420:                        }
0421:                        Boolean validatePassword = (Boolean) account.method(
0422:                                "ValidatePassword",
0423:                                new Object[] { passwordParam });
0424:                        boolean returnValue = Boolean.TRUE
0425:                                .equals(validatePassword);
0426:                        if (logger.isDebugEnabled()) {
0427:                            logger
0428:                                    .debug("checkPassword() - end - return value = "
0429:                                            + returnValue);
0430:                        }
0431:                        return returnValue;
0432:                    }
0433:                } catch (SystemException e) {
0434:                    logger
0435:                            .error(
0436:                                    "checkPassword(SecuritySession, String, String)",
0437:                                    e);
0438:
0439:                    throw e;
0440:                } catch (Exception e) {
0441:                    logger
0442:                            .error(
0443:                                    "checkPassword(SecuritySession, String, String)",
0444:                                    e);
0445:
0446:                    throw new SystemException(e);
0447:                }
0448:            }
0449:
0450:            /**
0451:             * Private helper. Get the with the given name (in the constructor). Throw
0452:             * an exception if the  domain doesn't exist.
0453:             *
0454:             *  @return the domain with the name given.
0455:             *  @throws JComException Thrown if the domains collection cannot be
0456:             *  retreived from hMailServer.
0457:             *  @throws SystemException If there is no domain with the name
0458:             *  provided.
0459:             */
0460:            private IDispatch getDomain() throws JComException, SystemException {
0461:                if (logger.isDebugEnabled()) {
0462:                    logger.debug("getDomain() - start");
0463:                }
0464:
0465:                IDispatch domain = null;
0466:                IDispatch domains = getDomains();
0467:                try {
0468:                    domain = (IDispatch) domains.method("ItemByName",
0469:                            new Object[] { domainName });
0470:                } catch (JComException e) {
0471:                    logger.error("getDomain()", e);
0472:
0473:                    throw new SystemException(
0474:                            "Could not find hMailServer domain " + "called '"
0475:                                    + domainName + "'", e);
0476:                }
0477:
0478:                if (logger.isDebugEnabled()) {
0479:                    logger
0480:                            .debug("getDomain() - end - return value = "
0481:                                    + domain);
0482:                }
0483:                return domain;
0484:            }
0485:
0486:            /**
0487:             * Private helper. Get the accounts collection for the domain with the given
0488:             * name. Throw an exception if the domain doesn't exist.
0489:             *
0490:             * @return Domain accounts object.
0491:             * @throws JComException if the domain cannot be retrieved, or there is no
0492:             * accounts object.
0493:             * @throws SystemException <copyDoc>Refer to {@link #getDomain}.</copyDoc>
0494:             */
0495:            private IDispatch getDomainAccounts() throws JComException,
0496:                    SystemException {
0497:                if (logger.isDebugEnabled()) {
0498:                    logger.debug("getDomainAccounts() - start");
0499:                }
0500:
0501:                IDispatch domain = getDomain();
0502:                IDispatch accounts = (IDispatch) domain.get("Accounts");
0503:
0504:                if (logger.isDebugEnabled()) {
0505:                    logger.debug("getDomainAccounts() - end - return value = "
0506:                            + accounts);
0507:                }
0508:                return accounts;
0509:            }
0510:
0511:            /**
0512:             * Private helper. Get the aliases collection for the domain with the given
0513:             * name. Throw an exception if the domain doesn't exist.
0514:             *
0515:             * @return Domain aliases object.
0516:             * @throws SystemException <copyDoc>Refer to {@link #getDomain}.</copyDoc>
0517:             * @throws JComException If the aliases cannot be retrieved from the
0518:             * domain.
0519:             */
0520:            private IDispatch getDomainAliases() throws JComException,
0521:                    SystemException {
0522:                if (logger.isDebugEnabled()) {
0523:                    logger.debug("getDomainAliases() - start");
0524:                }
0525:
0526:                IDispatch domain = getDomain();
0527:                IDispatch aliases = (IDispatch) domain.get("Aliases");
0528:
0529:                if (logger.isDebugEnabled()) {
0530:                    logger.debug("getDomainAliases() - end - return value = "
0531:                            + aliases);
0532:                }
0533:                return aliases;
0534:            }
0535:
0536:            /**
0537:             * On <strong>hMailServer</strong>, the system user name is the user
0538:             * followed by the 'at sign' and the domain name.
0539:             *
0540:             * {@inheritDoc}
0541:             *
0542:             * @param securitySession {@inheritDoc}
0543:             * @param userNameParam {@inheritDoc}
0544:             * @return always returns <code>userNameParam</code> followed by the at
0545:             * sign and the domain name.
0546:             */
0547:            public String getSystemUserName(
0548:                    final SecuritySession securitySession,
0549:                    final String userNameParam) {
0550:                if (logger.isDebugEnabled()) {
0551:                    logger
0552:                            .debug("getSystemUserName(SecuritySession securitySession = "
0553:                                    + securitySession
0554:                                    + ", String userNameParam = "
0555:                                    + userNameParam + ") - start");
0556:                }
0557:
0558:                String systemUserName = userNameParam + "@" + domainName;
0559:                if (logger.isDebugEnabled()) {
0560:                    logger.debug("Returning '" + systemUserName
0561:                            + "' as system user name for plain user name '"
0562:                            + userNameParam + "'");
0563:                }
0564:                return systemUserName;
0565:            }
0566:
0567:            ////////////////////////////////////////////////////////////////////////////
0568:
0569:            /**
0570:             * {@inheritDoc}
0571:             *
0572:             * @param securitySession {@inheritDoc}
0573:             * @param userNameParam {@inheritDoc}
0574:             * @throws SystemException If there is a technical problem or the domain
0575:             * aliases cannot be retrieved.
0576:             */
0577:            public List getUserAliases(final SecuritySession securitySession,
0578:                    final String userNameParam) throws SystemException {
0579:                if (logger.isDebugEnabled()) {
0580:                    logger
0581:                            .debug("getUserAliases(SecuritySession securitySession = "
0582:                                    + securitySession
0583:                                    + ", String userNameParam = "
0584:                                    + userNameParam + ") - start");
0585:                }
0586:
0587:                List userAliases = new Vector();
0588:                try {
0589:                    IDispatch aliases = getDomainAliases();
0590:                    int count = ((Integer) aliases.get("Count")).intValue();
0591:                    String address = getSystemUserName(securitySession,
0592:                            userNameParam);
0593:                    String atDomain = "@" + domainName;
0594:
0595:                    for (int i = 0; i < count; ++i) {
0596:                        IDispatch alias = (IDispatch) aliases.get("Item",
0597:                                new Object[] { new Integer(i) });
0598:                        String value = (String) alias.get("Value");
0599:                        // we're only interested in aliases for this one user
0600:                        if (!address.equals(value)) {
0601:                            continue;
0602:                        }
0603:                        // we only want aliases to this domain
0604:                        String name = (String) alias.get("Name");
0605:                        int pos = name.indexOf(atDomain);
0606:                        if (pos == -1) {
0607:                            continue;
0608:                        }
0609:                        userAliases.add(name.substring(0, pos - 1));
0610:                    }
0611:                } catch (SystemException e) {
0612:                    logger.error("getUserAliases(SecuritySession, String)", e);
0613:
0614:                    throw e;
0615:                } catch (Exception e) {
0616:                    logger.error("getUserAliases(SecuritySession, String)", e);
0617:
0618:                    throw new SystemException(e);
0619:                }
0620:
0621:                if (logger.isDebugEnabled()) {
0622:                    logger.debug("getUserAliases - end - return value = "
0623:                            + userAliases);
0624:                }
0625:                return userAliases;
0626:            }
0627:
0628:            /**
0629:             * {@inheritDoc}
0630:             *
0631:             * @param securitySession {@inheritDoc}
0632:             * @param userNameParam {@inheritDoc}
0633:             * @return Never returns. This method has not been implemeneted and only
0634:             * ever throws an exception.
0635:             * @throws SystemException Always thrown as this method is not implemented
0636:             * for hMailServer.
0637:             */
0638:            public String getUserForwarding(
0639:                    final SecuritySession securitySession,
0640:                    final String userNameParam) throws SystemException {
0641:                if (logger.isDebugEnabled()) {
0642:                    logger
0643:                            .debug("getUserForwarding(SecuritySession securitySession = "
0644:                                    + securitySession
0645:                                    + ", String userNameParam = "
0646:                                    + userNameParam + ") - start");
0647:                }
0648:
0649:                throw new SystemException(
0650:                        "getUserForwarding not implemented for "
0651:                                + "HMailServer");
0652:            }
0653:
0654:            /**
0655:             * Returns the username, the part before the 'at sign' in the system
0656:             * user name.
0657:             *
0658:             * {@inheritDoc}
0659:             *
0660:             * @param securitySession {@inheritDoc}
0661:             * @param systemUserNameParam {@inheritDoc}
0662:             * @return always returns <code>systemUserNameParam</code> before 'at sign'.
0663:             */
0664:            public String getUserNameFromSystemUserName(
0665:                    final SecuritySession securitySession,
0666:                    final String systemUserNameParam) {
0667:                if (logger.isDebugEnabled()) {
0668:                    logger.debug("getUserNameFromSystemUserName = "
0669:                            + securitySession
0670:                            + ", String systemUserNameParam = "
0671:                            + systemUserNameParam + ") - start");
0672:                }
0673:
0674:                int atPos = systemUserNameParam.indexOf('@');
0675:                if (atPos != -1) {
0676:                    String returnString = systemUserNameParam.substring(0,
0677:                            atPos);
0678:                    if (logger.isDebugEnabled()) {
0679:                        logger.debug("getUserNameFromSystemUserName - end - "
0680:                                + "return value = " + returnString);
0681:                    }
0682:                    return returnString;
0683:                }
0684:
0685:                if (logger.isDebugEnabled()) {
0686:                    logger
0687:                            .debug("getUserNameFromSystemUserName - end - return value = "
0688:                                    + systemUserNameParam);
0689:                }
0690:                return systemUserNameParam;
0691:            }
0692:
0693:            /**
0694:             * {@inheritDoc}
0695:             *
0696:             * @param securitySession {@inheritDoc}
0697:             * @param userNameParam {@inheritDoc}
0698:             * @return The vacation string for this user.
0699:             * @throws SystemException If there is a technical problem or the domain
0700:             * aliases cannot be retrieved.
0701:             */
0702:            public String getVacationMessage(
0703:                    final SecuritySession securitySession,
0704:                    final String userNameParam) throws SystemException {
0705:                if (logger.isDebugEnabled()) {
0706:                    logger
0707:                            .debug("getVacationMessage(SecuritySession securitySession = "
0708:                                    + securitySession
0709:                                    + ", String userNameParam = "
0710:                                    + userNameParam + ") - start");
0711:                }
0712:
0713:                try {
0714:                    String address = getSystemUserName(securitySession,
0715:                            userNameParam);
0716:                    IDispatch accounts = getDomainAccounts();
0717:                    IDispatch account = (IDispatch) accounts.get(
0718:                            "ItemByAddress", new Object[] { address });
0719:                    String returnString = (String) account
0720:                            .get("VacationMessage");
0721:                    if (logger.isDebugEnabled()) {
0722:                        logger
0723:                                .debug("getVacationMessage - end - return value = "
0724:                                        + returnString);
0725:                    }
0726:                    return returnString;
0727:                } catch (SystemException e) {
0728:                    logger.error("getVacationMessage(SecuritySession, String)",
0729:                            e);
0730:
0731:                    throw e;
0732:                } catch (Exception e) {
0733:                    logger.error("getVacationMessage(SecuritySession, String)",
0734:                            e);
0735:
0736:                    throw new SystemException(e);
0737:                }
0738:            }
0739:
0740:            /**
0741:             * {@inheritDoc}
0742:             *
0743:             * @param securitySession {@inheritDoc}
0744:             * @param userNameParam {@inheritDoc}
0745:             * @return <code>true</code> if the user exists.
0746:             * @throws SystemException If there is a technical problem or the domain
0747:             * aliases cannot be retrieved.
0748:             */
0749:            public boolean isUser(final SecuritySession securitySession,
0750:                    final String userNameParam) throws SystemException {
0751:                if (logger.isDebugEnabled()) {
0752:                    logger.debug("isUser(SecuritySession securitySession = "
0753:                            + securitySession + ", String userNameParam = "
0754:                            + userNameParam + ") - start");
0755:                }
0756:
0757:                try {
0758:                    boolean exists = false;
0759:                    String address = getSystemUserName(securitySession,
0760:                            userNameParam);
0761:                    IDispatch accounts = getDomainAccounts();
0762:                    int count = ((Integer) accounts.get("Count")).intValue();
0763:                    for (int i = 0; i < count; ++i) {
0764:                        IDispatch account = (IDispatch) accounts.get("Item",
0765:                                new Object[] { new Integer(i) });
0766:                        if (address.equals(account.get("Address"))) {
0767:                            exists = true;
0768:                            break;
0769:                        }
0770:                    }
0771:
0772:                    if (logger.isDebugEnabled()) {
0773:                        logger.debug("isUser - end - return value = " + exists);
0774:                    }
0775:                    return exists;
0776:                } catch (SystemException e) {
0777:                    logger.error("isUser(SecuritySession, String)", e);
0778:
0779:                    throw e;
0780:                } catch (Exception e) {
0781:                    logger.error("isUser(SecuritySession, String)", e);
0782:
0783:                    throw new SystemException(e);
0784:                }
0785:            }
0786:
0787:            /**
0788:             * {@inheritDoc}
0789:             *
0790:             * @param securitySession {@inheritDoc}
0791:             * @param nameParam {@inheritDoc}
0792:             * @throws SystemException Always thrown as this method is not implemented
0793:             * for hMailServer.
0794:             */
0795:            public void removeList(final SecuritySession securitySession,
0796:                    final String nameParam) throws SystemException {
0797:                if (logger.isDebugEnabled()) {
0798:                    logger
0799:                            .debug("removeList(SecuritySession securitySession = "
0800:                                    + securitySession
0801:                                    + ", String nameParam = "
0802:                                    + nameParam + ") - start");
0803:                }
0804:
0805:                if (logger.isDebugEnabled()) {
0806:                    logger.debug("removeList(SecuritySession, String) - end");
0807:                }
0808:                throw new SystemException("removeList not implemented for "
0809:                        + "HMailServer");
0810:            }
0811:
0812:            /**
0813:             * {@inheritDoc}
0814:             *
0815:             * @param securitySession {@inheritDoc}
0816:             * @param userNameParam {@inheritDoc}
0817:             * @throws SystemException If there is a technical problem or the domain
0818:             * aliases cannot be retrieved.
0819:             */
0820:            public void removeUser(final SecuritySession securitySession,
0821:                    final String userNameParam) throws SystemException {
0822:                if (logger.isDebugEnabled()) {
0823:                    logger
0824:                            .debug("removeUser(SecuritySession securitySession = "
0825:                                    + securitySession
0826:                                    + ", String userNameParam = "
0827:                                    + userNameParam + ") - start");
0828:                }
0829:
0830:                try {
0831:                    IDispatch accounts = getDomainAccounts();
0832:                    IDispatch account = null;
0833:                    String address = getSystemUserName(securitySession,
0834:                            userNameParam);
0835:                    try {
0836:                        account = (IDispatch) accounts.get("ItemByAddress",
0837:                                new Object[] { address });
0838:                    } catch (JComException e) {
0839:                        logger.error("removeUser(SecuritySession, String)", e);
0840:
0841:                        throw new SystemException(
0842:                                "No user found with address '" + address + "'",
0843:                                e);
0844:                    }
0845:                    accounts.method("DeleteByDBID", new Object[] { account
0846:                            .get("ID") });
0847:                } catch (SystemException e) {
0848:                    logger.error("removeUser(SecuritySession, String)", e);
0849:
0850:                    throw e;
0851:                } catch (Exception e) {
0852:                    logger.error("removeUser(SecuritySession, String)", e);
0853:
0854:                    throw new SystemException(e);
0855:                }
0856:
0857:                if (logger.isDebugEnabled()) {
0858:                    logger.debug("removeUser(SecuritySession, String) - end");
0859:                }
0860:            }
0861:
0862:            /**
0863:             * {@inheritDoc}
0864:             *
0865:             * @param securitySession {@inheritDoc}
0866:             * @param nameParam {@inheritDoc}
0867:             * @param usersParam {@inheritDoc}
0868:             * @throws SystemException Always thrown as this method is not implemented
0869:             * for hMailServer.
0870:             */
0871:            public void setList(final SecuritySession securitySession,
0872:                    final String nameParam, final Collection usersParam)
0873:                    throws SystemException {
0874:                if (logger.isDebugEnabled()) {
0875:                    logger.debug("setList(SecuritySession securitySession = "
0876:                            + securitySession + ", String nameParam = "
0877:                            + nameParam + ", Collection usersParam = "
0878:                            + usersParam + ") - start");
0879:                }
0880:
0881:                if (logger.isDebugEnabled()) {
0882:                    logger
0883:                            .debug("setList(SecuritySession, String, Collection) - end");
0884:                }
0885:                throw new SystemException("setList not implemented for "
0886:                        + "HMailServer");
0887:            }
0888:
0889:            /**
0890:             * {@inheritDoc}
0891:             *
0892:             * @param securitySession {@inheritDoc}
0893:             * @param userNameParam {@inheritDoc}
0894:             * @param passwordParam {@inheritDoc}
0895:             * @throws SystemException If there is a technical problem or the domain
0896:             * aliases cannot be retrieved.
0897:             */
0898:            public void setPassword(final SecuritySession securitySession,
0899:                    final String userNameParam, final String passwordParam)
0900:                    throws SystemException {
0901:                if (logger.isDebugEnabled()) {
0902:                    logger
0903:                            .debug("setPassword(SecuritySession securitySession = "
0904:                                    + securitySession
0905:                                    + ", String userNameParam = "
0906:                                    + userNameParam
0907:                                    + ", String passwordParam = "
0908:                                    + passwordParam + ") - start");
0909:                }
0910:
0911:                try {
0912:                    String address = getSystemUserName(securitySession,
0913:                            userNameParam);
0914:                    IDispatch accounts = getDomainAccounts();
0915:                    IDispatch account = (IDispatch) accounts.get(
0916:                            "ItemByAddress", new Object[] { address });
0917:                    account.put("Password", passwordParam);
0918:                    account.method("Save", new Object[] {});
0919:                } catch (SystemException e) {
0920:                    logger.error(
0921:                            "setPassword(SecuritySession, String, String)", e);
0922:
0923:                    throw e;
0924:                } catch (Exception e) {
0925:                    logger.error(
0926:                            "setPassword(SecuritySession, String, String)", e);
0927:
0928:                    throw new SystemException(e);
0929:                }
0930:
0931:                if (logger.isDebugEnabled()) {
0932:                    logger
0933:                            .debug("setPassword(SecuritySession, String, String) - end");
0934:                }
0935:            }
0936:
0937:            /**
0938:             * {@inheritDoc}
0939:             *
0940:             * @param securitySession {@inheritDoc}
0941:             * @param userNameParam {@inheritDoc}
0942:             * @param aliasesParam {@inheritDoc}
0943:             * @throws SystemException If there is a technical problem or the domain
0944:             * aliases cannot be retrieved.
0945:             */
0946:            public void setUserAliases(final SecuritySession securitySession,
0947:                    final String userNameParam, final Collection aliasesParam)
0948:                    throws SystemException {
0949:                if (logger.isDebugEnabled()) {
0950:                    logger
0951:                            .debug("setUserAliases(SecuritySession securitySession = "
0952:                                    + securitySession
0953:                                    + ", String userNameParam = "
0954:                                    + userNameParam
0955:                                    + ", Collection aliasesParam = "
0956:                                    + aliasesParam + ") - start");
0957:                }
0958:
0959:                try {
0960:                    IDispatch aliases = getDomainAliases();
0961:                    int count = ((Integer) aliases.get("Count")).intValue();
0962:                    String address = getSystemUserName(securitySession,
0963:                            userNameParam);
0964:                    String atDomain = "@" + domainName;
0965:
0966:                    // first get all existing aliases in one handy sized map
0967:                    Map allAliases = new HashMap();
0968:                    for (int i = 0; i < count; ++i) {
0969:                        IDispatch alias = (IDispatch) aliases.get("Item",
0970:                                new Object[] { new Integer(i) });
0971:                        allAliases.put(alias.get("Name"), alias.get("Value"));
0972:                    }
0973:
0974:                    // ok, this is a bit sloppy but for now, if the alias is already
0975:                    // taken by someone else, it is just changed to this guy or gal
0976:                    Iterator aliasIterator = aliasesParam.iterator();
0977:                    while (aliasIterator.hasNext()) {
0978:                        String fullAlias = aliasIterator.next() + atDomain;
0979:                        String existing = (String) allAliases.get(fullAlias);
0980:                        IDispatch alias;
0981:                        if (existing != null) {
0982:                            // if it is already set to this user, safe to ignore
0983:                            // otherwise, we'll just quietly take it over
0984:                            if (address.equals(existing)) {
0985:                                continue;
0986:                            }
0987:                            alias = (IDispatch) aliases.get("ItemByName",
0988:                                    new Object[] { fullAlias });
0989:                        } else {
0990:                            // new alias here
0991:                            alias = (IDispatch) aliases.method("Add",
0992:                                    new Object[] {});
0993:                            alias.put("Name", fullAlias);
0994:                        }
0995:                        alias.put("Value", address);
0996:                        alias.put("Active", Boolean.TRUE);
0997:                        alias.method("Save", new Object[] {});
0998:                    }
0999:                } catch (SystemException e) {
1000:                    logger
1001:                            .error(
1002:                                    "setUserAliases(SecuritySession, String, Collection)",
1003:                                    e);
1004:                    throw e;
1005:                } catch (Exception e) {
1006:                    logger
1007:                            .error(
1008:                                    "setUserAliases(SecuritySession, String, Collection)",
1009:                                    e);
1010:                    throw new SystemException(e);
1011:                }
1012:
1013:                if (logger.isDebugEnabled()) {
1014:                    logger.debug("setUserAliases - end");
1015:                }
1016:            }
1017:
1018:            /**
1019:             * {@inheritDoc}
1020:             *
1021:             * @param securitySession {@inheritDoc}
1022:             * @param userNameParam {@inheritDoc}
1023:             * @param addressParam {@inheritDoc}
1024:             * @throws SystemException Always thrown as this method is not implemented
1025:             * for hMailServer.
1026:             */
1027:            public void setUserForwarding(
1028:                    final SecuritySession securitySession,
1029:                    final String userNameParam, final String addressParam)
1030:                    throws SystemException {
1031:                if (logger.isDebugEnabled()) {
1032:                    logger
1033:                            .debug("setUserForwarding(SecuritySession securitySession = "
1034:                                    + securitySession
1035:                                    + ", String userNameParam = "
1036:                                    + userNameParam
1037:                                    + ", String addressParam = "
1038:                                    + addressParam
1039:                                    + ") - start");
1040:                }
1041:
1042:                if (logger.isDebugEnabled()) {
1043:                    logger.debug("setUserForwarding - end");
1044:                }
1045:                throw new SystemException(
1046:                        "setUserForwarding not implemented for "
1047:                                + "HMailServer");
1048:            }
1049:
1050:            /**
1051:             * {@inheritDoc}
1052:             *
1053:             * @param securitySession {@inheritDoc}
1054:             * @param userNameParam {@inheritDoc}
1055:             * @param messageParam {@inheritDoc}
1056:             * @throws SystemException If there is a technical problem or the domain
1057:             * aliases cannot be retrieved.
1058:             */
1059:            public void setVacationMessage(
1060:                    final SecuritySession securitySession,
1061:                    final String userNameParam, final String messageParam)
1062:                    throws SystemException {
1063:                if (logger.isDebugEnabled()) {
1064:                    logger
1065:                            .debug("setVacationMessage(SecuritySession securitySession = "
1066:                                    + securitySession
1067:                                    + ", String userNameParam = "
1068:                                    + userNameParam
1069:                                    + ", String messageParam = "
1070:                                    + messageParam
1071:                                    + ") - start");
1072:                }
1073:
1074:                try {
1075:                    String address = getSystemUserName(securitySession,
1076:                            userNameParam);
1077:                    IDispatch accounts = getDomainAccounts();
1078:                    IDispatch account = (IDispatch) accounts.get(
1079:                            "ItemByAddress", new Object[] { address });
1080:                    account.put("VacationMessage", messageParam);
1081:                    account.method("Save", new Object[] {});
1082:                } catch (SystemException e) {
1083:                    logger.error("setVacationMessage", e);
1084:
1085:                    throw e;
1086:                } catch (Exception e) {
1087:                    logger.error("setVacationMessage", e);
1088:
1089:                    throw new SystemException(e);
1090:                }
1091:
1092:                if (logger.isDebugEnabled()) {
1093:                    logger.debug("setVacationMessage - end");
1094:                }
1095:            }
1096:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.