1/*2 * Licensed to the Apache Software Foundation (ASF) under one or more3 * contributor license agreements. See the NOTICE file distributed with4 * this work for additional information regarding copyright ownership.5 * The ASF licenses this file to You under the Apache License, Version 2.06 * (the "License"); you may not use this file except in compliance with7 * the License. You may obtain a copy of the License at8 *9 * http://www.apache.org/licenses/LICENSE-2.010 *11 * Unless required by applicable law or agreed to in writing, software12 * distributed under the License is distributed on an "AS IS" BASIS,13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.14 * See the License for the specific language governing permissions and15 * limitations under the License.16 */17packageorg.apache.jetspeed.userinfo.impl;
1819import java.util.Collection;
20import java.util.HashMap;
21import java.util.Iterator;
22import java.util.List;
23import java.util.Map;
2425import javax.portlet.PortletRequest;
26import javax.security.auth.Subject;
2728import org.apache.commons.logging.Log;
29import org.apache.commons.logging.LogFactory;
30import org.apache.jetspeed.components.portletregistry.PortletRegistry;
31import org.apache.jetspeed.om.common.portlet.MutablePortletApplication;
32import org.apache.jetspeed.request.RequestContext;
33import org.apache.jetspeed.userinfo.UserAttributeRetrievalException;
34import org.apache.jetspeed.userinfo.UserAttributeSource;
35import org.apache.jetspeed.userinfo.UserInfoManager;
36import org.apache.jetspeed.userinfo.impl.AbstractUserInfoManagerImpl;
37import org.apache.pluto.om.common.ObjectID;
3839/***40 * Multisource User Information manager41 * One or more sources are assembled in Spring configuration and setter injected42 * 43 * @author <a href="mailto:KeithGarry.Boyce@bcbsma.com">Keith Garry Boyce </a>44 * @author <a href="mailto:taylor@apache.org">David Sean Taylor </a>45 * @version $Id: $46 */47publicclassMultiSourceUserInfoManagerImplextendsAbstractUserInfoManagerImpl48 implements UserInfoManager
49 {
5051/*** Logger */52privatestaticfinal Log log = LogFactory
53 .getLog(MultiSourceUserInfoManagerImpl.class);
5455private List sources;
5657private PortletRegistry portletRegistry;
5859/*60 * (non-Javadoc)61 * 62 * @see org.apache.jetspeed.userinfo.UserInfoManager#getUserInfoMap(org.apache.pluto.om.common.ObjectID,63 * org.apache.jetspeed.request.RequestContext)64 */65public Map getUserInfoMap(ObjectID oid, RequestContext context)
66 {
6768try69 {
70 Map userInfoMap = new HashMap();
71 Subject subject = context.getSubject();
72 MutablePortletApplication pa = portletRegistry
73 .getPortletApplication(oid);
74//System.out.println("*** PA = " + pa); 75if (null == pa)
76 {
77 log.debug(PortletRequest.USER_INFO + " is set to null");
78returnnull;
79 }
80 Collection userAttributes = pa.getUserAttributes();
81 Collection userAttributeRefs = pa.getUserAttributeRefs();
82 Collection linkedUserAttributes = mapLinkedUserAttributes(
83 userAttributes, userAttributeRefs);
84for (Iterator iter = sources.iterator(); iter.hasNext();)
85 {
86 UserAttributeSource source = (UserAttributeSource) iter.next();
87 Map sourceMap;
8889 sourceMap = source.getUserAttributeMap(subject,
90 linkedUserAttributes, context);
91 userInfoMap.putAll(sourceMap);
92 }
93return userInfoMap;
94 } catch (UserAttributeRetrievalException e)
95 {
96// Until external api is changed return97 e.printStackTrace();
98returnnull;
99 }
100 }
101102/***103 * @param sources104 * The sources to set.105 */106publicvoid setSources(List sources)
107 {
108this.sources = sources;
109 }
110111/***112 * @param portletRegistry113 * The portletRegistry to set.114 */115publicvoid setPortletRegistry(PortletRegistry portletRegistry)
116 {
117this.portletRegistry = portletRegistry;
118 }
119 }