001: /**
002: * $Id: CMCUserImplBase.java,v 1.2 2007/01/26 03:47:48 portalbld Exp $
003: * Copyright 2005 Sun Microsystems, Inc. All
004: * rights reserved. Use of this product is subject
005: * to license terms. Federal Acquisitions:
006: * Commercial Software -- Government Users
007: * Subject to Standard License Terms and
008: * Conditions.
009: *
010: * Sun, Sun Microsystems, the Sun logo, and Sun ONE
011: * are trademarks or registered trademarks of Sun Microsystems,
012: * Inc. in the United States and other countries.
013: */package com.sun.portal.community.mc.impl.am;
014:
015: import com.sun.portal.community.mc.CMCException;
016: import com.sun.portal.community.mc.CMCPrincipal;
017: import com.sun.portal.community.mc.CMCUser;
018: import com.sun.portal.community.mc.CMCNode;
019: import com.sun.portal.community.mc.ConfigTable;
020: import com.sun.portal.community.mc.ConfigTable.ConfigKey;
021: import com.sun.portal.community.mc.CMCRolePrincipal;
022: import com.sun.portal.community.mc.impl.Debug;
023: import com.sun.portal.community.mc.CMCFactory;
024: import java.io.File;
025: import java.util.HashSet;
026: import java.util.Iterator;
027: import java.util.Properties;
028: import java.util.Set;
029: import java.util.Collections;
030: import com.iplanet.am.sdk.AMUser;
031: import com.iplanet.am.sdk.AMRole;
032: import com.iplanet.am.sdk.AMFilteredRole;
033: import com.iplanet.am.sdk.AMOrganization;
034: import com.iplanet.sso.SSOException;
035: import com.iplanet.am.sdk.AMException;
036: import com.iplanet.am.util.SystemProperties;
037:
038: /**
039: * AM community user contributor, base class
040: *
041: * This class is extended by all AM community user
042: * contributors.
043: */
044: public abstract class CMCUserImplBase extends CMCImplBase implements
045: CMCUser {
046: private String userId;
047: private AMUser amUser;
048:
049: public void init(Properties p, String userId) throws CMCException {
050: this .userId = userId;
051:
052: try {
053: amUser = adminConnection.getUser(getUserId());
054: } catch (SSOException ssoe) {
055: throw new CMCException(ssoe);
056: }
057: }
058:
059: protected AMUser getAMUser() {
060: return amUser;
061: }
062:
063: public String getUserId() {
064: return userId;
065: }
066:
067: public Set getMembership() throws CMCException {
068: return getMembershipByName();
069: }
070:
071: public abstract Set getMembershipByName() throws CMCException;
072:
073: public Set getMembershipByName(Set rolePrincipals)
074: throws CMCException {
075: return getMembershipByName();
076: }
077:
078: public Set getMembershipByRole() throws CMCException {
079: return Collections.EMPTY_SET;
080: }
081:
082: public Set getMembershipByRole(Set rolePrincipals)
083: throws CMCException {
084: return getMembershipByRole();
085: }
086:
087: public abstract String getType();
088:
089: public Set getMembership(Set rolePrincipals) throws CMCException {
090: // one role
091: return getMembership();
092: }
093:
094: public Set getAvailable() throws CMCException {
095: // available is same as membership for AM
096: Set available = new HashSet();
097: for (Iterator i = getMembership().iterator(); i.hasNext();) {
098: ConfigKey ck = (ConfigKey) i.next();
099: available.add(ck.getCommunityPrincipal());
100: }
101:
102: return available;
103: }
104:
105: public boolean hasRole(CMCPrincipal cp, CMCRolePrincipal rp)
106: throws CMCException {
107: ConfigKey ck = new ConfigKey(cp, rp);
108: if (!getMembership().contains(ck)) {
109: return false;
110: }
111:
112: return true;
113: }
114:
115: public long getRoleCreationTime(CMCPrincipal cp,
116: CMCRolePrincipal rolePrincipal)
117: throws UnsupportedOperationException {
118: throw new UnsupportedOperationException(
119: "not supported: RoleCreationTime");
120: }
121:
122: /**
123: * Fill in the last read times for all values in the dps table.
124: */
125: protected static void fillLastReadTimes(ConfigTable lastReadTimes,
126: ConfigTable dps) {
127: for (Iterator i = dps.getConfigKeys().iterator(); i.hasNext();) {
128: ConfigKey ck = (ConfigKey) i.next();
129: lastReadTimes.put(ck, new Long(System.currentTimeMillis()));
130: }
131: }
132:
133: public ConfigTable getDPDocuments(ConfigTable lastReadTimes)
134: throws CMCException {
135: Set membership = getMembership();
136: return getDPDocuments(lastReadTimes, membership);
137: }
138:
139: public ConfigTable getDPDocuments(ConfigTable lastReadTimes,
140: Set membership) throws CMCException {
141: ConfigTable dpDocuments = new ConfigTable();
142:
143: for (Iterator i = membership.iterator(); i.hasNext();) {
144: ConfigKey ck = (ConfigKey) i.next();
145: CMCPrincipal cp = ck.getCommunityPrincipal();
146: if (!cp.getType().equals(getType())) {
147: // skip it if they pass something other than this type
148: continue;
149: }
150: CMCNode cn = CMCFactory.getInstance().getCMCNode(cp);
151: ConfigTable lastModifiedTimes = cn
152: .getDPDocumentsLastModified(Collections
153: .singleton(CMCRolePrincipal.MEMBER_ROLE));
154:
155: //
156: // determine if we need to fetch the document
157: //
158: Long lastRead = (Long) lastReadTimes.get(ck);
159: if (lastRead != null && lastRead.longValue() != -1) {
160: //
161: // this means the client passed us a last read time
162: // if the last modified time is less than the
163: // last read time, the client already read the
164: // most recent version, so do not return it to them
165: // again
166: //
167: Long lastModified = (Long) lastModifiedTimes.get(ck);
168: if (lastModified != null) {
169: long lm = lastModified.longValue();
170: long lr = lastRead.longValue();
171: if (lm <= lr) {
172: continue;
173: }
174: }
175: }
176:
177: ConfigTable ct = cn.getDPDocuments(Collections
178: .singleton(CMCRolePrincipal.MEMBER_ROLE));
179: dpDocuments.putAll(ct);
180: }
181:
182: fillLastReadTimes(lastReadTimes, dpDocuments);
183: return dpDocuments;
184: }
185: }
|