1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.jetspeed.userinfo.impl;
18
19 import java.util.Collection;
20 import java.util.HashMap;
21 import java.util.Iterator;
22 import java.util.List;
23 import java.util.Map;
24
25 import javax.portlet.PortletRequest;
26 import javax.security.auth.Subject;
27
28 import org.apache.commons.logging.Log;
29 import org.apache.commons.logging.LogFactory;
30 import org.apache.jetspeed.components.portletregistry.PortletRegistry;
31 import org.apache.jetspeed.om.common.portlet.MutablePortletApplication;
32 import org.apache.jetspeed.request.RequestContext;
33 import org.apache.jetspeed.userinfo.UserAttributeRetrievalException;
34 import org.apache.jetspeed.userinfo.UserAttributeSource;
35 import org.apache.jetspeed.userinfo.UserInfoManager;
36 import org.apache.jetspeed.userinfo.impl.AbstractUserInfoManagerImpl;
37 import org.apache.pluto.om.common.ObjectID;
38
39 /***
40 * Multisource User Information manager
41 * One or more sources are assembled in Spring configuration and setter injected
42 *
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 */
47 public class MultiSourceUserInfoManagerImpl extends AbstractUserInfoManagerImpl
48 implements UserInfoManager
49 {
50
51 /*** Logger */
52 private static final Log log = LogFactory
53 .getLog(MultiSourceUserInfoManagerImpl.class);
54
55 private List sources;
56
57 private PortletRegistry portletRegistry;
58
59
60
61
62
63
64
65 public Map getUserInfoMap(ObjectID oid, RequestContext context)
66 {
67
68 try
69 {
70 Map userInfoMap = new HashMap();
71 Subject subject = context.getSubject();
72 MutablePortletApplication pa = portletRegistry
73 .getPortletApplication(oid);
74
75 if (null == pa)
76 {
77 log.debug(PortletRequest.USER_INFO + " is set to null");
78 return null;
79 }
80 Collection userAttributes = pa.getUserAttributes();
81 Collection userAttributeRefs = pa.getUserAttributeRefs();
82 Collection linkedUserAttributes = mapLinkedUserAttributes(
83 userAttributes, userAttributeRefs);
84 for (Iterator iter = sources.iterator(); iter.hasNext();)
85 {
86 UserAttributeSource source = (UserAttributeSource) iter.next();
87 Map sourceMap;
88
89 sourceMap = source.getUserAttributeMap(subject,
90 linkedUserAttributes, context);
91 userInfoMap.putAll(sourceMap);
92 }
93 return userInfoMap;
94 } catch (UserAttributeRetrievalException e)
95 {
96
97 e.printStackTrace();
98 return null;
99 }
100 }
101
102 /***
103 * @param sources
104 * The sources to set.
105 */
106 public void setSources(List sources)
107 {
108 this.sources = sources;
109 }
110
111 /***
112 * @param portletRegistry
113 * The portletRegistry to set.
114 */
115 public void setPortletRegistry(PortletRegistry portletRegistry)
116 {
117 this.portletRegistry = portletRegistry;
118 }
119 }