001: /**
002: * $Id: ExchangeABStore.java,v 1.5 2006/04/25 20:14:35 rakeshn Exp $
003: * Copyright 2002 Sun Microsystems, Inc. All rights reserved. Use of this
004: * product is subject to license terms. Federal Acquisitions:
005: * Commercial Software -- Government Users Subject to Standard License Terms
006: * and Conditions.
007: *
008: * Sun, Sun Microsystems, the Sun logo, and Sun ONE are trademarks or
009: * registered trademarks of Sun Microsystems, Inc. in the United States
010: * and other countries.
011: */package com.sun.ssoadapter.ab.exchange;
012:
013: import com.sun.addressbook.ABSession;
014: import com.sun.addressbook.AddressBook;
015: import com.sun.addressbook.ABStoreException;
016: import com.sun.ssoadapter.ab.pim.JPimABStore;
017: import com.aligo.pim.exceptions.PimException;
018: import com.aligo.pim.interfaces.PimAddressBook;
019: import com.aligo.pim.interfaces.PimFolders;
020:
021: import com.sun.addressbook.MissingPropertiesException;
022:
023: import com.aligo.pim.PimContainerType;
024: import com.aligo.pim.PimUserInfoParameter;
025: import com.aligo.pim.interfaces.PimUserInfo;
026:
027: import java.util.StringTokenizer;
028:
029: public class ExchangeABStore extends JPimABStore {
030: /**
031: * Returns the Container Type corresponding to the exchange backend
032: */
033: public PimContainerType getPimContainerType(ABSession session) {
034: String pimInterfaceType = session
035: .getProperty(PIM_INTERFACE_TYPE);
036: if ((pimInterfaceType == null)
037: || (!pimInterfaceType.equals(PIM_CDO))) {
038: // Default to WEBDAV
039: return PimContainerType.EXCHANGE_WEBDAV;
040: } else {
041: return PimContainerType.EXCHANGE;
042: }
043: }
044:
045: public void init(ABSession session, PimUserInfo pimU)
046: throws MissingPropertiesException {
047: String userName = session.getProperty(USERNAME);
048: String userPasswd = session.getProperty(USERPASSWD);
049: String userDomain = session.getProperty(USERDOMAIN);
050: String jPimHost = session.getProperty(JPIMHOST);
051: String jPimPort = session.getProperty(JPIMPORT);
052: String ocxHost = session.getProperty(OCXHOST);
053: String authHost = session.getProperty(AUTHHOST);
054: String pimInterfaceType = session
055: .getProperty(PIM_INTERFACE_TYPE);
056: String usersBaseDn = session.getProperty(USERS_BASE_DN);
057:
058: if (userName == null) {
059: throw new MissingPropertiesException(
060: "Cannot connect to JPim server:: Missing Property: "
061: + USERNAME);
062: }
063:
064: if (userPasswd == null) {
065: throw new MissingPropertiesException(
066: "Cannot connect to JPim server:: Missing Property: "
067: + USERPASSWD);
068: }
069:
070: if (jPimHost == null) {
071: throw new MissingPropertiesException(
072: "Cannot connect to JPim server:: Missing Property: "
073: + JPIMHOST);
074: }
075:
076: if (jPimPort == null) {
077: jPimPort = EXCHANGE_DEFAULT_PORT;
078: }
079:
080: if (userDomain == null) {
081: throw new MissingPropertiesException(
082: "Cannot connect to JPim server:: Missing Property: "
083: + USERDOMAIN);
084: }
085:
086: //No easy way to turn the debug on, hence it is set to on for Aligo all the time
087: pimU.set(PimUserInfoParameter.DEBUG, "true");
088: if ((pimInterfaceType == null)
089: || (!pimInterfaceType.equals(PIM_CDO))) {
090: //Default to webdav
091: pimU.set(PimUserInfoParameter.EXCHANGE_USERNAME, userName);
092: pimU
093: .set(PimUserInfoParameter.EXCHANGE_PASSWORD,
094: userPasswd);
095: pimU.set(PimUserInfoParameter.EXCHANGE_MAILBOX, userName);
096: String webdav_url = "http://" + jPimHost + ":" + jPimPort;
097: pimU.set(PimUserInfoParameter.EXCHANGE_WEBDAV_URL,
098: webdav_url);
099:
100: //ldapUserName should be like "chertseydomain\a"
101: String ldapUserName = userDomain + "\\" + userName;
102:
103: if (usersBaseDn == null || usersBaseDn.equals("")) {
104: //it should be like CN=Users,dc=chertsey,dc=red,dc=iplanet,dc=com for Exchange 2000 and 2003
105: //cn=Recipients,ou=..... for 5.5 . Hence defaults to 2000
106: String ubaseDn = "CN=Users";
107: StringTokenizer strTok = new StringTokenizer(jPimHost,
108: ".");
109: while (strTok.hasMoreTokens()) {
110: ubaseDn += (",DC=" + strTok.nextToken());
111: }
112: usersBaseDn = ubaseDn;
113: }
114:
115: //System.out.println("ldap userName=" + ldapUserName+" usersBaseDn="+usersBaseDn);
116:
117: //For webdav the ocxhost contains the host name of the active directory
118: if ((ocxHost == null) || (ocxHost.length() == 0)) {
119: ocxHost = jPimHost;
120: }
121: pimU.set(PimUserInfoParameter.JNDI_LDAP_SERVER, ocxHost);
122: pimU.set(PimUserInfoParameter.JNDI_LDAP_USERNAME,
123: ldapUserName);
124: pimU.set(PimUserInfoParameter.JNDI_LDAP_PASSWORD,
125: userPasswd);
126: pimU.set(PimUserInfoParameter.JNDI_LDAP_PORT, "389");
127: pimU.set(PimUserInfoParameter.JNDI_LDAP_AB_BASE,
128: usersBaseDn);
129: pimU
130: .set(
131: PimUserInfoParameter.JNDI_LDAP_TRY_ANONYMOUS_FALLBACK,
132: "true");
133: } else {
134: pimU.set(PimUserInfoParameter.EXCHANGE_USERNAME, userName);
135: pimU
136: .set(PimUserInfoParameter.EXCHANGE_PASSWORD,
137: userPasswd);
138: pimU.set(PimUserInfoParameter.EXCHANGE_NT_DOMAIN,
139: userDomain);
140: pimU.set(PimUserInfoParameter.EXCHANGE_SERVER, jPimHost);
141: if (ocxHost != null) {
142: pimU.set(
143: PimUserInfoParameter.EXCHANGE_OCXHOST_LOCATION,
144: ocxHost);
145: }
146:
147: if (authHost != null) {
148: pimU
149: .set(
150: PimUserInfoParameter.EXCHANGE_ALIGOAUTH_LOCATION,
151: authHost);
152: }
153:
154: }
155: boolean debugEnabled = (new Boolean(session
156: .getProperty("ab.pim.debug"))).booleanValue();
157: if (debugEnabled) {
158: pimU.set(PimUserInfoParameter.DEBUG, "true");
159: }
160: }
161:
162: /**
163: * Method to retrieve a address book from the backend service.
164: *
165: * @param abID A specific address book ID. (Its not the same as name).
166: * @return The specified address book
167: *
168: * @exception ABStoreException if unable to load the specified calendar
169: */
170: public AddressBook openAddressBook(String abID)
171: throws ABStoreException {
172: PimAddressBook pBook = topLevelPimAB;
173:
174: if ((abID != null) && (!abID.trim().equals(""))) {
175: try {
176: PimFolders pimFolders = pBook.getFolders();
177: pBook = (PimAddressBook) pimFolders.getFolder(abID);
178: } catch (PimException pe) {
179: pe.printStackTrace();
180: throw new ABStoreException("getFolder() failed: " + pe);
181: }
182: }
183:
184: AddressBook aBook = new ExchangeAddressBook(this, pBook, abID);
185: return aBook;
186: }
187:
188: }
|