001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.jetspeed.userinfo.impl;
018:
019: import java.util.Collection;
020: import java.util.HashMap;
021: import java.util.Iterator;
022: import java.util.List;
023: import java.util.Map;
024:
025: import javax.portlet.PortletRequest;
026: import javax.security.auth.Subject;
027:
028: import org.apache.commons.logging.Log;
029: import org.apache.commons.logging.LogFactory;
030: import org.apache.jetspeed.components.portletregistry.PortletRegistry;
031: import org.apache.jetspeed.om.common.portlet.MutablePortletApplication;
032: import org.apache.jetspeed.request.RequestContext;
033: import org.apache.jetspeed.userinfo.UserAttributeRetrievalException;
034: import org.apache.jetspeed.userinfo.UserAttributeSource;
035: import org.apache.jetspeed.userinfo.UserInfoManager;
036: import org.apache.jetspeed.userinfo.impl.AbstractUserInfoManagerImpl;
037: import org.apache.pluto.om.common.ObjectID;
038:
039: /**
040: * Multisource User Information manager
041: * One or more sources are assembled in Spring configuration and setter injected
042: *
043: * @author <a href="mailto:KeithGarry.Boyce@bcbsma.com">Keith Garry Boyce </a>
044: * @author <a href="mailto:taylor@apache.org">David Sean Taylor </a>
045: * @version $Id: $
046: */
047: public class MultiSourceUserInfoManagerImpl extends
048: AbstractUserInfoManagerImpl implements UserInfoManager {
049:
050: /** Logger */
051: private static final Log log = LogFactory
052: .getLog(MultiSourceUserInfoManagerImpl.class);
053:
054: private List sources;
055:
056: private PortletRegistry portletRegistry;
057:
058: /*
059: * (non-Javadoc)
060: *
061: * @see org.apache.jetspeed.userinfo.UserInfoManager#getUserInfoMap(org.apache.pluto.om.common.ObjectID,
062: * org.apache.jetspeed.request.RequestContext)
063: */
064: public Map getUserInfoMap(ObjectID oid, RequestContext context) {
065:
066: try {
067: Map userInfoMap = new HashMap();
068: Subject subject = context.getSubject();
069: MutablePortletApplication pa = portletRegistry
070: .getPortletApplication(oid);
071: //System.out.println("*** PA = " + pa);
072: if (null == pa) {
073: log.debug(PortletRequest.USER_INFO + " is set to null");
074: return null;
075: }
076: Collection userAttributes = pa.getUserAttributes();
077: Collection userAttributeRefs = pa.getUserAttributeRefs();
078: Collection linkedUserAttributes = mapLinkedUserAttributes(
079: userAttributes, userAttributeRefs);
080: for (Iterator iter = sources.iterator(); iter.hasNext();) {
081: UserAttributeSource source = (UserAttributeSource) iter
082: .next();
083: Map sourceMap;
084:
085: sourceMap = source.getUserAttributeMap(subject,
086: linkedUserAttributes, context);
087: userInfoMap.putAll(sourceMap);
088: }
089: return userInfoMap;
090: } catch (UserAttributeRetrievalException e) {
091: // Until external api is changed return
092: e.printStackTrace();
093: return null;
094: }
095: }
096:
097: /**
098: * @param sources
099: * The sources to set.
100: */
101: public void setSources(List sources) {
102: this .sources = sources;
103: }
104:
105: /**
106: * @param portletRegistry
107: * The portletRegistry to set.
108: */
109: public void setPortletRegistry(PortletRegistry portletRegistry) {
110: this.portletRegistry = portletRegistry;
111: }
112: }
|