portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tay...@apache.org
Subject svn commit: r209687 - in /portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/userinfo: UserInfoManager.java impl/MultiSourceUserInfoManagerImpl.java impl/UserManagerUserAttributeSourceImpl.java
Date Fri, 08 Jul 2005 01:03:23 GMT
Author: taylor
Date: Thu Jul  7 18:03:21 2005
New Revision: 209687

URL: http://svn.apache.org/viewcvs?rev=209687&view=rev
Log:
Implemented JS2-301
Also moved the interfaces for UserInfo into Jetspeed API

http://issues.apache.org/jira/browse/JS2-301

Im going to leave this issue open since the unit test is failing currently
Will get it fixed in next 24 hrs

Added:
    portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/userinfo/impl/MultiSourceUserInfoManagerImpl.java
    portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/userinfo/impl/UserManagerUserAttributeSourceImpl.java
Removed:
    portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/userinfo/UserInfoManager.java

Added: portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/userinfo/impl/MultiSourceUserInfoManagerImpl.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/userinfo/impl/MultiSourceUserInfoManagerImpl.java?rev=209687&view=auto
==============================================================================
--- portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/userinfo/impl/MultiSourceUserInfoManagerImpl.java
(added)
+++ portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/userinfo/impl/MultiSourceUserInfoManagerImpl.java
Thu Jul  7 18:03:21 2005
@@ -0,0 +1,117 @@
+/* Copyright 2004 Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jetspeed.userinfo.impl;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import javax.portlet.PortletRequest;
+import javax.security.auth.Subject;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.jetspeed.components.portletregistry.PortletRegistry;
+import org.apache.jetspeed.om.common.portlet.MutablePortletApplication;
+import org.apache.jetspeed.request.RequestContext;
+import org.apache.jetspeed.userinfo.UserAttributeRetrievalException;
+import org.apache.jetspeed.userinfo.UserAttributeSource;
+import org.apache.jetspeed.userinfo.UserInfoManager;
+import org.apache.jetspeed.userinfo.impl.AbstractUserInfoManagerImpl;
+import org.apache.pluto.om.common.ObjectID;
+
+/**
+ * Multisource User Information manager
+ * One or more sources are assembled in Spring configuration and setter injected
+ * 
+ * @author <a href="mailto:KeithGarry.Boyce@bcbsma.com">Keith Garry Boyce </a>
+ * @author <a href="mailto:taylor@apache.org">David Sean Taylor </a>
+ * @version $Id: $
+ */
+public class MultiSourceUserInfoManagerImpl extends AbstractUserInfoManagerImpl
+        implements UserInfoManager
+{
+
+    /** Logger */
+    private static final Log log = LogFactory
+            .getLog(MultiSourceUserInfoManagerImpl.class);
+
+    private List sources;
+
+    private PortletRegistry portletRegistry;
+   
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.jetspeed.userinfo.UserInfoManager#getUserInfoMap(org.apache.pluto.om.common.ObjectID,
+     *      org.apache.jetspeed.request.RequestContext)
+     */
+    public Map getUserInfoMap(ObjectID oid, RequestContext context)
+    {
+
+        try
+        {
+            Map userInfoMap = new HashMap();
+            Subject subject = context.getSubject();
+            MutablePortletApplication pa = portletRegistry
+                    .getPortletApplication(oid);
+System.out.println("*** PA = " + pa);            
+            if (null == pa)
+            {
+                log.debug(PortletRequest.USER_INFO + " is set to null");
+                return null;
+            }
+            Collection userAttributes = pa.getUserAttributes();
+            Collection userAttributeRefs = pa.getUserAttributeRefs();
+            Collection linkedUserAttributes = mapLinkedUserAttributes(
+                    userAttributes, userAttributeRefs);
+            for (Iterator iter = sources.iterator(); iter.hasNext();)
+            {
+                UserAttributeSource source = (UserAttributeSource) iter.next();
+                Map sourceMap;
+
+                sourceMap = source.getUserAttributeMap(subject,
+                        linkedUserAttributes, context);
+                userInfoMap.putAll(sourceMap);
+            }
+            return userInfoMap;
+        } catch (UserAttributeRetrievalException e)
+        {
+            // Until external api is changed return
+            e.printStackTrace();            
+            return null;
+        }
+    }
+
+    /**
+     * @param sources
+     *            The sources to set.
+     */
+    public void setSources(List sources)
+    {
+        this.sources = sources;
+    }
+
+    /**
+     * @param portletRegistry
+     *            The portletRegistry to set.
+     */
+    public void setPortletRegistry(PortletRegistry portletRegistry)
+    {
+        this.portletRegistry = portletRegistry;
+    }
+}

Added: portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/userinfo/impl/UserManagerUserAttributeSourceImpl.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/userinfo/impl/UserManagerUserAttributeSourceImpl.java?rev=209687&view=auto
==============================================================================
--- portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/userinfo/impl/UserManagerUserAttributeSourceImpl.java
(added)
+++ portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/userinfo/impl/UserManagerUserAttributeSourceImpl.java
Thu Jul  7 18:03:21 2005
@@ -0,0 +1,115 @@
+/* Copyright 2004 Apache Software Foundation
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.apache.jetspeed.userinfo.impl;
+
+import java.security.Principal;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.prefs.Preferences;
+
+import javax.security.auth.Subject;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.jetspeed.om.common.UserAttributeRef;
+import org.apache.jetspeed.request.RequestContext;
+import org.apache.jetspeed.security.SecurityException;
+import org.apache.jetspeed.security.SecurityHelper;
+import org.apache.jetspeed.security.User;
+import org.apache.jetspeed.security.UserManager;
+import org.apache.jetspeed.security.UserPrincipal;
+import org.apache.jetspeed.userinfo.UserAttributeRetrievalException;
+import org.apache.jetspeed.userinfo.UserAttributeSource;
+
+/**
+ * Default implementation of a UserAttribute source 
+ * Provides users attributes from standard prefs implementation
+ * 
+ * @author <a href="mailto:KeithGarry.Boyce@bcbsma.com">Keith Garry Boyce</a>
+ * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
+ * @version $Id: $
+ */
+public class UserManagerUserAttributeSourceImpl implements UserAttributeSource
+{
+
+    /** Logger */
+    private static final Log log = LogFactory
+            .getLog(UserManagerUserAttributeSourceImpl.class);
+
+    /** The user manager */
+    private UserManager userManager;
+
+    /**
+     * @param userManager
+     *            The userManager to set.
+     */
+    public void setUserManager(UserManager userManager)
+    {
+        this.userManager = userManager;
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.jetspeed.userinfo.UserAttributeSource#getUserAttributeMap(javax.security.auth.Subject,
+     *      java.util.Set)
+     */
+    public Map getUserAttributeMap(Subject subject,
+            Collection userAttributeRefs, RequestContext context)
+            throws UserAttributeRetrievalException
+    {
+
+        Map userAttributeMap = new HashMap();
+        Principal userPrincipal = SecurityHelper.getPrincipal(subject,
+                UserPrincipal.class);
+        if (null != userPrincipal)
+        {
+            log.debug("Got user principal: " + userPrincipal.getName());
+            try
+            {
+                if (userManager.userExists(userPrincipal.getName()))
+                {
+                    User user = userManager.getUser(userPrincipal.getName());
+                    Preferences userInfoPrefs = user.getPreferences();
+                    for (Iterator iter = userAttributeRefs.iterator(); 
+                                        iter.hasNext();)
+                    {
+                        UserAttributeRef currentAttributeRef = 
+                            (UserAttributeRef) iter.next();
+                        Object value = userInfoPrefs.get(currentAttributeRef
+                                .getName(), null);
+                        if (value != null)
+                        {
+                            userAttributeMap.put(currentAttributeRef.getName(),
+                                    value);
+                        }
+
+                    }
+                }
+            } catch (SecurityException sex)
+            {
+                log
+                        .warn(
+                                "Unexpected SecurityException in UserInfoManager",
+                                sex);
+            }
+        }
+
+        return userAttributeMap;
+    }
+
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-dev-help@portals.apache.org


Mime
View raw message