portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tay...@apache.org
Subject svn commit: r348854 [8/16] - in /portals/jetspeed-2/trunk/applications/j2-admin: ./ src/java/org/apache/jetspeed/portlets/entityeditor/ src/java/org/apache/jetspeed/portlets/localeselector/ src/java/org/apache/jetspeed/portlets/localeselector/resources...
Date Fri, 25 Nov 2005 02:25:20 GMT
Added: portals/jetspeed-2/trunk/applications/j2-admin/src/java/org/apache/jetspeed/portlets/security/sso/SSOBrowser.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/applications/j2-admin/src/java/org/apache/jetspeed/portlets/security/sso/SSOBrowser.java?rev=348854&view=auto
==============================================================================
--- portals/jetspeed-2/trunk/applications/j2-admin/src/java/org/apache/jetspeed/portlets/security/sso/SSOBrowser.java (added)
+++ portals/jetspeed-2/trunk/applications/j2-admin/src/java/org/apache/jetspeed/portlets/security/sso/SSOBrowser.java Thu Nov 24 18:24:19 2005
@@ -0,0 +1,231 @@
+/* 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.portlets.security.sso;
+
+import java.io.IOException;
+import java.sql.Types;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.portlet.ActionRequest;
+import javax.portlet.ActionResponse;
+import javax.portlet.PortletConfig;
+import javax.portlet.PortletException;
+import javax.portlet.PortletMode;
+import javax.portlet.RenderRequest;
+import javax.portlet.RenderResponse;
+
+import org.apache.jetspeed.CommonPortletServices;
+import org.apache.jetspeed.sso.SSOException;
+import org.apache.jetspeed.sso.SSOProvider;
+import org.apache.jetspeed.sso.SSOSite;
+import org.apache.portals.gems.browser.BrowserIterator;
+import org.apache.portals.gems.browser.DatabaseBrowserIterator;
+import org.apache.portals.gems.browser.BrowserPortlet;
+import org.apache.portals.gems.util.StatusMessage;
+import org.apache.portals.messaging.PortletMessaging;
+import org.apache.velocity.context.Context;
+
+/**
+ * SSOBrowser
+ * 
+ * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
+ * @version $Id: SSOBrowser.java 348264 2005-11-22 22:06:45Z taylor $
+ */
+public class SSOBrowser extends BrowserPortlet
+{
+    private SSOProvider sso;
+    
+    public void init(PortletConfig config)
+    throws PortletException 
+    {
+        super.init(config);
+        sso = (SSOProvider)getPortletContext().getAttribute(CommonPortletServices.CPS_SSO_COMPONENT);
+        if (null == sso)
+        {
+            throw new PortletException("Failed to find the SSO Provider on portlet initialization");
+        }
+    }
+       
+    
+    public void getRows(RenderRequest request, String sql, int windowSize)
+    throws Exception
+    {
+        List resultSetTitleList = new ArrayList();
+        List resultSetTypeList = new ArrayList();
+        try
+        {
+            Iterator sites = sso.getSites("");
+            
+            // List userObjectList = (List)getParameterFromTemp(portlet, rundata, USER_OBJECTS);
+
+            //
+            // Add MetaData headers, types
+            //
+            
+            resultSetTypeList.add(String.valueOf(Types.VARCHAR));
+            resultSetTypeList.add(String.valueOf(Types.VARCHAR));
+            resultSetTitleList.add(0, "Url");
+            resultSetTitleList.add(1, "Site");
+
+            //subPopulate(rundata, qResult, repo, folder, null);
+
+            List list = new ArrayList();
+            while (sites.hasNext())
+            {
+                List row = new ArrayList(2);
+                SSOSite site = (SSOSite)sites.next();
+                row.add(0, site.getSiteURL());                     
+                row.add(1, site.getName());
+                list.add(row);
+            }            
+            BrowserIterator iterator = new DatabaseBrowserIterator(
+                    list, resultSetTitleList, resultSetTypeList,
+                    windowSize);
+            setBrowserIterator(request, iterator);
+            iterator.sort("Site");
+        }
+        catch (Exception e)
+        {
+            //log.error("Exception in CMSBrowserAction.getRows: ", e);
+            e.printStackTrace();
+            throw e;
+        }        
+    }
+   
+    public void doView(RenderRequest request, RenderResponse response)
+    throws PortletException, IOException
+    {
+        String selectedSite = (String)PortletMessaging.receive(request, "site", "selectedUrl");
+        if (selectedSite != null)
+        {        
+            Context context = this.getContext(request);
+            context.put("currentUrl", selectedSite);
+            String selectedName = (String)PortletMessaging.receive(request, "site", "selectedName");
+            context.put("currentName", selectedName);            
+        }
+        StatusMessage msg = (StatusMessage)PortletMessaging.consume(request, "SSOBrowser", "status");
+        if (msg != null)
+        {
+            this.getContext(request).put("statusMsg", msg);            
+        }
+        
+        super.doView(request, response);
+    }
+    
+    public void processAction(ActionRequest request, ActionResponse response)
+    throws PortletException, IOException
+    {
+        if (request.getPortletMode() == PortletMode.VIEW)
+        {
+            String selectedSite = request.getParameter("ssoSite");
+            if (selectedSite != null)
+            {
+                SSOSite site = sso.getSite(selectedSite);
+                if (site != null)
+                {
+                    PortletMessaging.publish(request, "site", "selectedUrl", selectedSite);
+                    PortletMessaging.publish(request, "site", "selectedName", site.getName());
+                    PortletMessaging.publish(request, "site", "change", selectedSite);
+                }
+            }
+            String refresh = request.getParameter("sso.refresh");
+            String save = request.getParameter("sso.save");
+            String neue = request.getParameter("sso.new");
+            String delete = request.getParameter("ssoDelete");
+            
+            if (refresh != null)
+            {
+                this.clearBrowserIterator(request);
+            }
+            else if (neue != null)
+            {
+                PortletMessaging.cancel(request, "site", "selected");
+                PortletMessaging.cancel(request, "site", "selectedUrl");                                
+            }
+            else if (delete != null && (!(isEmpty(delete))))
+            {
+                try
+                {
+                    SSOSite site = null;
+                    site = sso.getSite(delete);
+                    if (site != null)
+                    {
+                        sso.removeSite(site);
+                        this.clearBrowserIterator(request);
+                        PortletMessaging.cancel(request, "site", "selected");
+                        PortletMessaging.cancel(request, "site", "selectedUrl");                                
+                    }
+                }
+                catch (SSOException e)
+                {
+                    publishStatusMessage(request, "SSOBrowser", "status", e, "Could not remove site");
+                }
+            }
+            else if (save != null)
+            {
+                String siteName = request.getParameter("site.name");                
+                String siteUrl = request.getParameter("site.url");
+                if (!(isEmpty(siteName) || isEmpty(siteUrl)))
+                {
+                    try
+                    {
+                        SSOSite site = null;
+                        String old = (String)PortletMessaging.receive(request, "site", "selectedUrl");
+                        if (old != null)
+                        {
+                            site = sso.getSite(old);
+                        }
+                        else
+                        {
+                            site = sso.getSite(siteUrl);
+                        }                        
+                        if (site != null)
+                        {
+                            site.setName(siteName);
+                            site.setSiteURL(siteUrl);
+                            sso.updateSite(site);
+                            this.clearBrowserIterator(request);
+                            PortletMessaging.publish(request, "site", "selectedName", siteName);
+                            PortletMessaging.publish(request, "site", "selectedUrl", siteUrl);                            
+                        }
+                        else
+                        {
+                            sso.addSite(siteName, siteUrl);
+                            this.clearBrowserIterator(request);
+                        }
+                    }
+                    catch (SSOException e)
+                    {
+                        publishStatusMessage(request, "SSOBrowser", "status", e, "Could not store site");
+                    }
+                }
+            }            
+        }
+        super.processAction(request, response);
+            
+    }
+
+    private boolean isEmpty(String s)
+    {
+        if (s == null) return true;
+        
+        if (s.trim().equals("")) return true;
+        
+        return false;
+    }
+    
+}

Added: portals/jetspeed-2/trunk/applications/j2-admin/src/java/org/apache/jetspeed/portlets/security/sso/SSODetails.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/applications/j2-admin/src/java/org/apache/jetspeed/portlets/security/sso/SSODetails.java?rev=348854&view=auto
==============================================================================
--- portals/jetspeed-2/trunk/applications/j2-admin/src/java/org/apache/jetspeed/portlets/security/sso/SSODetails.java (added)
+++ portals/jetspeed-2/trunk/applications/j2-admin/src/java/org/apache/jetspeed/portlets/security/sso/SSODetails.java Thu Nov 24 18:24:19 2005
@@ -0,0 +1,275 @@
+/* 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.portlets.security.sso;
+
+import java.io.IOException;
+import java.sql.Types;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.portlet.ActionRequest;
+import javax.portlet.ActionResponse;
+import javax.portlet.PortletConfig;
+import javax.portlet.PortletException;
+import javax.portlet.PortletMode;
+import javax.portlet.RenderRequest;
+import javax.portlet.RenderResponse;
+import javax.security.auth.Subject;
+
+import org.apache.jetspeed.CommonPortletServices;
+import org.apache.jetspeed.portlets.security.SecurityUtil;
+import org.apache.jetspeed.security.GroupManager;
+import org.apache.jetspeed.security.SecurityException;
+import org.apache.jetspeed.security.User;
+import org.apache.jetspeed.security.UserManager;
+import org.apache.jetspeed.sso.SSOException;
+import org.apache.jetspeed.sso.SSOProvider;
+import org.apache.jetspeed.sso.SSOSite;
+import org.apache.portals.gems.browser.BrowserIterator;
+import org.apache.portals.gems.browser.DatabaseBrowserIterator;
+import org.apache.portals.gems.browser.BrowserPortlet;
+import org.apache.portals.gems.util.StatusMessage;
+import org.apache.portals.messaging.PortletMessaging;
+import org.apache.velocity.context.Context;
+
+/**
+ * SSODetails
+ * 
+ * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
+ * @version $Id: SSODetails.java 348264 2005-11-22 22:06:45Z taylor $
+ */
+public class SSODetails extends BrowserPortlet
+{
+    private SSOProvider sso;
+    private UserManager userManager;
+    private GroupManager groupManager;
+        
+    public void init(PortletConfig config)
+    throws PortletException 
+    {
+        super.init(config);
+        sso = (SSOProvider)getPortletContext().getAttribute(CommonPortletServices.CPS_SSO_COMPONENT);
+        if (null == sso)
+        {
+            throw new PortletException("Failed to find the SSO Provider on portlet initialization");
+        }
+        userManager = (UserManager) getPortletContext().getAttribute(CommonPortletServices.CPS_USER_MANAGER_COMPONENT);
+        if (null == userManager)
+        {
+            throw new PortletException("Failed to find the User Manager on portlet initialization");
+        }
+        groupManager = (GroupManager) getPortletContext().getAttribute(CommonPortletServices.CPS_GROUP_MANAGER_COMPONENT);
+        if (null == groupManager)
+        {
+            throw new PortletException("Failed to find the Group Manager on portlet initialization");
+        }        
+    }
+       
+    
+    public void getRows(RenderRequest request, String sql, int windowSize)
+    throws Exception
+    {
+        List resultSetTitleList = new ArrayList();
+        List resultSetTypeList = new ArrayList();
+        try
+        {
+            SSOSite site = null;
+            Iterator principals = null;
+            List list = null;
+            resultSetTypeList.add(String.valueOf(Types.VARCHAR));
+            resultSetTitleList.add("Principal");
+            resultSetTypeList.add(String.valueOf(Types.VARCHAR));
+            resultSetTitleList.add("Remote");
+            
+            String selectedSite = (String)PortletMessaging.receive(request, "site", "selectedUrl");
+            if (selectedSite != null)
+            {
+                site = sso.getSite(selectedSite);
+                list = sso.getPrincipalsForSite(site);
+            }
+            else
+            {
+                list = new ArrayList();
+            }
+            BrowserIterator iterator = new DatabaseBrowserIterator(
+                    list, resultSetTitleList, resultSetTypeList,
+                    windowSize);
+            setBrowserIterator(request, iterator);
+        }
+        catch (Exception e)
+        {
+            //log.error("Exception in CMSBrowserAction.getRows: ", e);
+            e.printStackTrace();
+            throw e;
+        }        
+    }
+   
+    public void doView(RenderRequest request, RenderResponse response)
+    throws PortletException, IOException
+    {
+        String change = (String)PortletMessaging.consume(request, "site", "change");
+        if (change != null)
+        { 
+            this.clearBrowserIterator(request);
+        }
+        Context context = this.getContext(request);        
+        String selectedSite = (String)PortletMessaging.receive(request, "site", "selectedUrl");
+        if (selectedSite != null)
+        {        
+            context.put("currentSite", selectedSite);
+        }        
+        
+        // get relative link, TODO: encapsulate Jetspeed links access into component
+        String userChooser = SecurityUtil.getAbsoluteUrl(request, "/Administrative/choosers/users.psml");
+        String groupChooser = SecurityUtil.getAbsoluteUrl(request, "/Administrative/choosers/groups.psml");
+        
+        context.put("userChooser", userChooser);
+        context.put("groupChooser", groupChooser);
+        
+        StatusMessage msg = (StatusMessage)PortletMessaging.consume(request, "SSODetails", "status");
+        if (msg != null)
+        {
+            this.getContext(request).put("statusMsg", msg);            
+        }
+        
+        super.doView(request, response);
+    }
+        
+    public void processAction(ActionRequest request, ActionResponse response)
+    throws PortletException, IOException
+    {
+        if (request.getPortletMode() == PortletMode.VIEW)
+        {
+            String refresh = request.getParameter("sso.refresh");
+            String add = request.getParameter("sso.add");
+            String delete = request.getParameter("ssoDelete");
+           
+            if (refresh != null)
+            {
+                this.clearBrowserIterator(request);
+            }
+            else if (delete != null && !(isEmpty(delete)))
+            {
+                try
+                {
+                    String siteName = (String)PortletMessaging.receive(request, "site", "selectedUrl");                                            
+                    SSOSite site = sso.getSite(siteName);
+                    User user = null;
+                    try
+                    {
+                        user = userManager.getUser(delete);   
+                    }
+                    catch(SecurityException se)
+                    {
+                        // User doesn't exist -- maybe a group
+                        user =null;
+                    }
+                    
+                    if ( site != null )
+                    {
+                        /*
+	                     * If the user is null try to remove a group
+	                     */
+	                    if ( user != null)
+	                    {
+	                        // Remove USER
+	                        Subject subject = user.getSubject(); 
+	                        sso.removeCredentialsForSite(subject, site.getSiteURL());
+	                        this.clearBrowserIterator(request);
+	                    }
+	                    else
+	                    {
+	                        // Try group removal
+	                        String fullPath = "/group/" + delete;
+	                        sso.removeCredentialsForSite(fullPath, site.getSiteURL());
+	                        this.clearBrowserIterator(request);
+	                    }  
+	                 }
+                }
+                catch (SSOException e)
+                {
+                    publishStatusMessage(request, "SSODetails", "status", e, "Could not remove credentials");
+                }
+            }
+            else if (add != null)
+            {
+                // Roger: here is the principal type
+                String principalType = request.getParameter("principal.type");  //group user
+                String portalPrincipal = request.getParameter("portal.principal");                
+                String remotePrincipal = request.getParameter("remote.principal");
+                String remoteCredential = request.getParameter("remote.credential");
+                
+                // The principal type can benull if the user just typed the name instead of
+                // using the choosers.
+                
+                if (principalType == null || principalType.length() == 0 )
+                    principalType = "user";
+                
+                if (!(isEmpty(remotePrincipal) || isEmpty(remotePrincipal) || isEmpty(remoteCredential)))
+                {
+                    try
+                    {
+                        String siteName = (String)PortletMessaging.receive(request, "site", "selectedUrl");                        
+                        SSOSite site = sso.getSite(siteName);
+                        Subject subject = null;
+                        String groupFullPath = null;
+                        
+                        if (principalType.compareTo("user") == 0)
+                        {
+                            User user = userManager.getUser(portalPrincipal);    
+                            subject = user.getSubject();
+                        }
+                        else
+                        {
+                            // Create fullPath
+                            groupFullPath = "/group/" + portalPrincipal;
+                          }
+                        
+                        if (site != null && (subject != null || groupFullPath != null) )
+                        {
+                            if (subject != null )
+                                sso.addCredentialsForSite(subject, remotePrincipal, site.getSiteURL(), remoteCredential);
+                            else
+                                sso.addCredentialsForSite(groupFullPath, remotePrincipal, site.getSiteURL(), remoteCredential);
+                            
+                            this.clearBrowserIterator(request);
+                        }
+                    }
+                    catch (SSOException e)
+                    {
+                        publishStatusMessage(request, "SSODetails", "status", e, "Could not add credentials");
+                    }
+                    catch (SecurityException se)
+                    {
+                        publishStatusMessage(request, "SSODetails", "status", se, "Could not add credentials");
+                    }                    
+                }
+            }            
+        }
+        super.processAction(request, response);
+            
+    }
+
+    private boolean isEmpty(String s)
+    {
+        if (s == null) return true;
+        
+        if (s.trim().equals("")) return true;
+        
+        return false;
+    }
+    
+}

Added: portals/jetspeed-2/trunk/applications/j2-admin/src/java/org/apache/jetspeed/portlets/security/users/GroupChooserPortlet.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/applications/j2-admin/src/java/org/apache/jetspeed/portlets/security/users/GroupChooserPortlet.java?rev=348854&view=auto
==============================================================================
--- portals/jetspeed-2/trunk/applications/j2-admin/src/java/org/apache/jetspeed/portlets/security/users/GroupChooserPortlet.java (added)
+++ portals/jetspeed-2/trunk/applications/j2-admin/src/java/org/apache/jetspeed/portlets/security/users/GroupChooserPortlet.java Thu Nov 24 18:24:19 2005
@@ -0,0 +1,93 @@
+/* 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.portlets.security.users;
+
+import java.security.Principal;
+import java.sql.Types;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.portlet.PortletConfig;
+import javax.portlet.PortletException;
+import javax.portlet.RenderRequest;
+
+import org.apache.jetspeed.CommonPortletServices;
+import org.apache.jetspeed.security.Group;
+import org.apache.jetspeed.security.GroupManager;
+import org.apache.portals.gems.browser.BrowserIterator;
+import org.apache.portals.gems.browser.DatabaseBrowserIterator;
+import org.apache.portals.gems.browser.BrowserPortlet;
+
+/**
+ * GroupChooserPortlet
+ * 
+ * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
+ * @version $Id: GroupChooserPortlet.java 348264 2005-11-22 22:06:45Z taylor $
+ */
+public class GroupChooserPortlet extends BrowserPortlet
+{
+    private GroupManager groupManager;
+    
+    public void init(PortletConfig config)
+    throws PortletException 
+    {
+        super.init(config);
+        groupManager = (GroupManager) 
+            getPortletContext().getAttribute(CommonPortletServices.CPS_GROUP_MANAGER_COMPONENT);
+        if (null == groupManager)
+        {
+            throw new PortletException("Failed to find the User Manager on portlet initialization");
+        }
+    }
+           
+    public void getRows(RenderRequest request, String sql, int windowSize)
+    throws Exception
+    {
+        List resultSetTitleList = new ArrayList();
+        List resultSetTypeList = new ArrayList();
+        try
+        {
+            Iterator groups = groupManager.getGroups("");
+                        
+            
+            resultSetTypeList.add(String.valueOf(Types.VARCHAR));
+            resultSetTitleList.add("Group");
+
+            // TODO: need to try to normalize List/Collection/Iterators
+            List list = new ArrayList();
+            while (groups.hasNext())
+            {
+                Group group = (Group)groups.next();
+                
+                Principal principal = group.getPrincipal();                
+                list.add(principal.getName());
+            }            
+            
+            BrowserIterator iterator = new DatabaseBrowserIterator(
+                    list, resultSetTitleList, resultSetTypeList,
+                    windowSize);
+            setBrowserIterator(request, iterator);
+            iterator.sort("Group");
+        }
+        catch (Exception e)
+        {
+            //log.error("Exception in CMSBrowserAction.getRows: ", e);
+            e.printStackTrace();
+            throw e;
+        }        
+    }
+       
+}

Added: portals/jetspeed-2/trunk/applications/j2-admin/src/java/org/apache/jetspeed/portlets/security/users/JetspeedUserBean.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/applications/j2-admin/src/java/org/apache/jetspeed/portlets/security/users/JetspeedUserBean.java?rev=348854&view=auto
==============================================================================
--- portals/jetspeed-2/trunk/applications/j2-admin/src/java/org/apache/jetspeed/portlets/security/users/JetspeedUserBean.java (added)
+++ portals/jetspeed-2/trunk/applications/j2-admin/src/java/org/apache/jetspeed/portlets/security/users/JetspeedUserBean.java Thu Nov 24 18:24:19 2005
@@ -0,0 +1,97 @@
+/*
+ * Copyright 2000-2004 The 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.portlets.security.users;
+
+import java.security.Principal;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.prefs.BackingStoreException;
+import java.util.prefs.Preferences;
+
+import javax.security.auth.Subject;
+
+import org.apache.jetspeed.security.User;
+import org.apache.jetspeed.security.UserPrincipal;
+
+/**
+ * User state.
+ *
+ * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
+ * @version $Id: JetspeedUserBean.java 348264 2005-11-22 22:06:45Z taylor $
+ */
+public class JetspeedUserBean
+{
+    private String principal;    
+    private Map attributes = new LinkedHashMap();
+    
+    public JetspeedUserBean(User user)
+    {
+        Principal userPrincipal = createPrincipal(user.getSubject(), UserPrincipal.class);             
+        this.principal = userPrincipal.getName();
+        try
+        {
+            Preferences userAttributes = user.getUserAttributes();
+            String[] keys = userAttributes.keys();
+            for (int ix = 0; ix < keys.length; ix++)
+            {
+                attributes.put(keys[ix], userAttributes.get(keys[ix], null));
+            }
+        }
+        catch (BackingStoreException e)
+        {
+        }
+    }
+    
+    /**
+     * @return Returns the principal.
+     */
+    public String getPrincipal()
+    {
+        return principal;
+    }
+    /**
+     * @param principal The principal to set.
+     */
+    public void setPrincipal(String principal)
+    {
+        this.principal = principal;
+    }
+    
+    public Principal createPrincipal(Subject subject, Class classe)
+    {
+        Principal principal = null;
+        Iterator principals = subject.getPrincipals().iterator();
+        while (principals.hasNext())
+        {
+            Principal p = (Principal) principals.next();
+            if (classe.isInstance(p))
+            {
+                principal = p;
+                break;
+            }
+        }
+        return principal;
+    }
+    
+    /**
+     * @return Returns the attributes.
+     */
+    public Map getAttributes()
+    {
+        return attributes;
+    }
+}
\ No newline at end of file

Added: portals/jetspeed-2/trunk/applications/j2-admin/src/java/org/apache/jetspeed/portlets/security/users/RoleChooserPortlet.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/applications/j2-admin/src/java/org/apache/jetspeed/portlets/security/users/RoleChooserPortlet.java?rev=348854&view=auto
==============================================================================
--- portals/jetspeed-2/trunk/applications/j2-admin/src/java/org/apache/jetspeed/portlets/security/users/RoleChooserPortlet.java (added)
+++ portals/jetspeed-2/trunk/applications/j2-admin/src/java/org/apache/jetspeed/portlets/security/users/RoleChooserPortlet.java Thu Nov 24 18:24:19 2005
@@ -0,0 +1,92 @@
+/* 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.portlets.security.users;
+
+import java.security.Principal;
+import java.sql.Types;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.portlet.PortletConfig;
+import javax.portlet.PortletException;
+import javax.portlet.RenderRequest;
+
+import org.apache.jetspeed.CommonPortletServices;
+import org.apache.jetspeed.security.Role;
+import org.apache.jetspeed.security.RoleManager;
+import org.apache.portals.gems.browser.BrowserIterator;
+import org.apache.portals.gems.browser.DatabaseBrowserIterator;
+import org.apache.portals.gems.browser.BrowserPortlet;
+
+/**
+ * RoleChooserPortlet
+ * 
+ * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
+ * @version $Id: RoleChooserPortlet.java 348264 2005-11-22 22:06:45Z taylor $
+ */
+public class RoleChooserPortlet extends BrowserPortlet
+{
+    private RoleManager roleManager;
+    
+    public void init(PortletConfig config)
+    throws PortletException 
+    {
+        super.init(config);
+        roleManager = (RoleManager) 
+            getPortletContext().getAttribute(CommonPortletServices.CPS_GROUP_MANAGER_COMPONENT);
+        if (null == roleManager)
+        {
+            throw new PortletException("Failed to find the User Manager on portlet initialization");
+        }
+    }
+           
+    public void getRows(RenderRequest request, String sql, int windowSize)
+    throws Exception
+    {
+        List resultSetTitleList = new ArrayList();
+        List resultSetTypeList = new ArrayList();
+        try
+        {
+            Iterator roles = roleManager.getRoles("");
+                        
+            
+            resultSetTypeList.add(String.valueOf(Types.VARCHAR));
+            resultSetTitleList.add("Role");
+
+            // TODO: need to try to normalize List/Collection/Iterators
+            List list = new ArrayList();
+            while (roles.hasNext())
+            {
+                Role role = (Role)roles.next();
+                
+                Principal principal = role.getPrincipal();                
+                list.add(principal.getName());
+            }            
+            BrowserIterator iterator = new DatabaseBrowserIterator(
+                    list, resultSetTitleList, resultSetTypeList,
+                    windowSize);
+            setBrowserIterator(request, iterator);
+            iterator.sort("Role");
+        }
+        catch (Exception e)
+        {
+            //log.error("Exception in CMSBrowserAction.getRows: ", e);
+            e.printStackTrace();
+            throw e;
+        }        
+    }
+       
+}

Added: portals/jetspeed-2/trunk/applications/j2-admin/src/java/org/apache/jetspeed/portlets/security/users/UserBean.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/applications/j2-admin/src/java/org/apache/jetspeed/portlets/security/users/UserBean.java?rev=348854&view=auto
==============================================================================
--- portals/jetspeed-2/trunk/applications/j2-admin/src/java/org/apache/jetspeed/portlets/security/users/UserBean.java (added)
+++ portals/jetspeed-2/trunk/applications/j2-admin/src/java/org/apache/jetspeed/portlets/security/users/UserBean.java Thu Nov 24 18:24:19 2005
@@ -0,0 +1,62 @@
+/*
+ * Copyright 2000-2004 The 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.portlets.security.users;
+
+/**
+ * User state.
+ *
+ * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
+ * @version $Id: UserBean.java 348264 2005-11-22 22:06:45Z taylor $
+ */
+public class UserBean
+{
+    private String first;
+    private String last;
+    
+    public UserBean(String first, String last)
+    {
+        this.first = first;
+        this.last = last;
+    }
+    
+    public void setFirst(String first)
+    {
+        this.first = first;
+    }
+
+    
+    /**
+     * @return Returns the last.
+     */
+    public String getLast()
+    {
+        return last;
+    }
+    /**
+     * @param last The last to set.
+     */
+    public void setLast(String last)
+    {
+        this.last = last;
+    }
+    /**
+     * @return Returns the first.
+     */
+    public String getFirst()
+    {
+        return first;
+    }
+}
\ No newline at end of file

Added: portals/jetspeed-2/trunk/applications/j2-admin/src/java/org/apache/jetspeed/portlets/security/users/UserBrowser.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/applications/j2-admin/src/java/org/apache/jetspeed/portlets/security/users/UserBrowser.java?rev=348854&view=auto
==============================================================================
--- portals/jetspeed-2/trunk/applications/j2-admin/src/java/org/apache/jetspeed/portlets/security/users/UserBrowser.java (added)
+++ portals/jetspeed-2/trunk/applications/j2-admin/src/java/org/apache/jetspeed/portlets/security/users/UserBrowser.java Thu Nov 24 18:24:19 2005
@@ -0,0 +1,169 @@
+/* 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.portlets.security.users;
+
+import java.io.IOException;
+import java.security.Principal;
+import java.sql.Types;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.portlet.ActionRequest;
+import javax.portlet.ActionResponse;
+import javax.portlet.PortletConfig;
+import javax.portlet.PortletException;
+import javax.portlet.PortletMode;
+import javax.portlet.RenderRequest;
+import javax.portlet.RenderResponse;
+
+import org.apache.jetspeed.CommonPortletServices;
+import org.apache.jetspeed.portlets.security.SecurityUtil;
+import org.apache.jetspeed.portlets.security.SecurityResources;
+import org.apache.jetspeed.security.User;
+import org.apache.jetspeed.security.UserManager;
+import org.apache.jetspeed.security.UserPrincipal;
+import org.apache.portals.gems.browser.BrowserIterator;
+import org.apache.portals.gems.browser.BrowserPortlet;
+import org.apache.portals.gems.browser.DatabaseBrowserIterator;
+import org.apache.portals.gems.util.StatusMessage;
+import org.apache.portals.messaging.PortletMessaging;
+import org.apache.velocity.context.Context;
+
+/**
+ * Role Browser - flat non-hierarchical view
+ * 
+ * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
+ * @version $Id: UserBrowser.java 348264 2005-11-22 22:06:45Z taylor $
+ */
+public class UserBrowser extends BrowserPortlet
+{
+    protected UserManager userManager;
+
+    // view context
+    public static final String STATUS = "statusMsg";
+    public static final String SELECTED = "selected";
+
+    public void init(PortletConfig config)
+    throws PortletException 
+    {
+        super.init(config);
+        userManager = (UserManager) 
+            getPortletContext().getAttribute(CommonPortletServices.CPS_USER_MANAGER_COMPONENT);
+        if (null == userManager)
+        {
+            throw new PortletException("Failed to find the User Manager on portlet initialization");
+        }
+    }
+
+    public void doView(RenderRequest request, RenderResponse response)
+    throws PortletException, IOException
+    {
+        String selected = (String)PortletMessaging.receive(request, SecurityResources.TOPIC_USERS, SecurityResources.MESSAGE_SELECTED);
+        if (selected != null)
+        {        
+            Context context = this.getContext(request);
+            context.put(SELECTED, selected);
+        }
+        StatusMessage msg = (StatusMessage)PortletMessaging.consume(request, SecurityResources.TOPIC_USERS, SecurityResources.MESSAGE_STATUS);
+        if (msg != null)
+        {
+            this.getContext(request).put(STATUS, msg);            
+        }
+        String refresh = (String)PortletMessaging.consume(request, SecurityResources.TOPIC_USERS, SecurityResources.MESSAGE_REFRESH); 
+        if (refresh != null)
+        {        
+            this.clearBrowserIterator(request);
+        }                
+        
+        String filtered = (String)PortletMessaging.receive(request, SecurityResources.TOPIC_USERS, SecurityResources.MESSAGE_FILTERED);
+        if (filtered != null)
+        {
+            this.getContext(request).put(FILTERED, "on");            
+        }
+        
+        super.doView(request, response);
+    }
+        
+    public void processAction(ActionRequest request, ActionResponse response)
+    throws PortletException, IOException
+    {
+        if (request.getPortletMode() == PortletMode.VIEW)
+        {
+            String selected = request.getParameter("user");
+            if (selected != null)
+            {
+                PortletMessaging.publish(request, SecurityResources.TOPIC_USERS, SecurityResources.MESSAGE_SELECTED, selected);
+            }
+        }
+        
+        // TODO: if request parameters were working correctly we could replace this with render parameters
+        String filtered = (String)request.getParameter(FILTERED);
+        if (filtered != null)
+        {
+            PortletMessaging.publish(request, SecurityResources.TOPIC_USERS, SecurityResources.MESSAGE_FILTERED, "on");            
+        }
+        else
+        {
+            PortletMessaging.cancel(request, SecurityResources.TOPIC_USERS, SecurityResources.MESSAGE_FILTERED);
+        }
+        
+        super.processAction(request, response);
+            
+    }
+      
+    public void getRows(RenderRequest request, String sql, int windowSize)
+    throws Exception
+    {
+        getRows(request, sql, windowSize, "");
+    }
+
+    public void getRows(RenderRequest request, String sql, int windowSize, String filter)
+    throws Exception
+    {
+        List resultSetTitleList = new ArrayList();
+        List resultSetTypeList = new ArrayList();
+        try
+        {
+            Iterator users = userManager.getUsers(filter);
+                        
+            
+            resultSetTypeList.add(String.valueOf(Types.VARCHAR));
+            resultSetTitleList.add("User");
+
+            List list = new ArrayList();
+            while (users.hasNext())
+            {
+                User user = (User)users.next();
+                Principal principal = SecurityUtil.getPrincipal(user.getSubject(),
+                        UserPrincipal.class);                
+                list.add(principal.getName());
+            }            
+            BrowserIterator iterator = new DatabaseBrowserIterator(
+                    list, resultSetTitleList, resultSetTypeList,
+                    windowSize);
+            setBrowserIterator(request, iterator);
+            iterator.sort("User");
+        }
+        catch (Exception e)
+        {
+            //log.error("Exception in CMSBrowserAction.getRows: ", e);
+            e.printStackTrace();
+            throw e;
+        }        
+        
+    }
+    
+}

Added: portals/jetspeed-2/trunk/applications/j2-admin/src/java/org/apache/jetspeed/portlets/security/users/UserBrowserPortlet.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/applications/j2-admin/src/java/org/apache/jetspeed/portlets/security/users/UserBrowserPortlet.java?rev=348854&view=auto
==============================================================================
--- portals/jetspeed-2/trunk/applications/j2-admin/src/java/org/apache/jetspeed/portlets/security/users/UserBrowserPortlet.java (added)
+++ portals/jetspeed-2/trunk/applications/j2-admin/src/java/org/apache/jetspeed/portlets/security/users/UserBrowserPortlet.java Thu Nov 24 18:24:19 2005
@@ -0,0 +1,352 @@
+/*
+ * Copyright 2000-2004 The 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.portlets.security.users;
+
+import java.io.IOException;
+import java.security.Principal;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Locale;
+
+import javax.portlet.ActionRequest;
+import javax.portlet.ActionResponse;
+import javax.portlet.PortletConfig;
+import javax.portlet.PortletException;
+import javax.portlet.PortletSession;
+import javax.portlet.RenderRequest;
+import javax.portlet.RenderResponse;
+import javax.security.auth.Subject;
+
+import org.apache.jetspeed.CommonPortletServices;
+import org.apache.jetspeed.portlets.security.SecurityResources;
+import org.apache.jetspeed.profiler.Profiler;
+import org.apache.jetspeed.security.Role;
+import org.apache.jetspeed.security.RoleManager;
+import org.apache.jetspeed.security.SecurityException;
+import org.apache.jetspeed.security.User;
+import org.apache.jetspeed.security.UserManager;
+import org.apache.jetspeed.security.UserPrincipal;
+import org.apache.portals.bridges.common.GenericServletPortlet;
+import org.apache.portals.messaging.PortletMessaging;
+import org.apache.webapp.admin.TreeControl;
+import org.apache.webapp.admin.TreeControlNode;
+
+/**
+ * This portlet is a browser over all the portlet applications in the system.
+ *
+ * @deprecated 
+ * @see UserBrowser.java (new implementation)
+ * @author <a href="mailto:taylor@apache.org">David Sean Taylor </a>
+ * @version $Id: UserBrowserPortlet.java 348264 2005-11-22 22:06:45Z taylor $
+ */
+public class UserBrowserPortlet extends GenericServletPortlet
+{
+    private UserManager userManager;
+    private RoleManager roleManager;
+    private Profiler    profiler;
+    
+    /** the id of the tree control */
+    private static final String TREE_CONTROL = "j2_tree";
+
+    /** the id of the roles control */
+    private static final String ROLES_CONTROL = "jetspeedRoles";
+
+    /** the id of the rules control */
+    private static final String RULES_CONTROL = "jetspeedRules";
+    
+    /** query filter for selecting users */
+    private static final String USER_FILTER = "";
+
+    /** the id of the root node of the tree control */
+    private static final String SECURITY_NODE_ID = "SECURITY-NODE";
+
+    /** the domain of the security sub-tree */
+    private static final String SECURITY_DOMAIN = "SECURITY_DOMAIN";
+
+    /** the id of the user node of the tree control */
+    private static final String USER_NODE_ID = "USER-NODE";
+
+    /** the domain of the user sub-tree */
+    private static final String USER_DOMAIN = "USER_DOMAIN";
+
+    /** the domain of the users leaf nodes */
+    private static final String USER_DETAIL_DOMAIN = "USER_DETAIL_DOMAIN";
+
+    public void init(PortletConfig config) throws PortletException
+    {
+        super.init(config);
+        userManager = (UserManager) getPortletContext()
+                .getAttribute(CommonPortletServices.CPS_USER_MANAGER_COMPONENT);
+        if (null == userManager)
+        {
+            throw new PortletException("Failed to find the User Manager on portlet initialization");
+        }
+        roleManager = (RoleManager) getPortletContext()
+        			.getAttribute(CommonPortletServices.CPS_ROLE_MANAGER_COMPONENT);
+        if (null == roleManager)
+        {
+        		throw new PortletException("Failed to find the Role Manager on portlet initialization");
+        }
+        profiler = (Profiler)getPortletContext().getAttribute(CommonPortletServices.CPS_PROFILER_COMPONENT);
+        if (null == profiler)
+        {
+            throw new PortletException("Failed to find the Profiler on portlet initialization");
+        }        
+    }
+
+    public void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException
+    {
+        response.setContentType("text/html");
+
+        String errorMessage = (String)PortletMessaging.consume(request, "user.error");
+        if (errorMessage != null)
+        {
+            request.setAttribute("errorMessage", errorMessage);            
+        }
+        
+        // check for refresh on users list
+        TreeControl control = null;
+        String refresh = (String)PortletMessaging.consume(request, "users", "refresh");
+        if (refresh == null)
+        {        
+            control = (TreeControl) request.getPortletSession().getAttribute(TREE_CONTROL);
+        }
+        
+        // build the tree control and provide it to the view
+        try
+        {
+            if (control == null)
+            {
+                Iterator users = userManager.getUsers(USER_FILTER);
+                control = buildTree(users, request.getLocale());
+                request.getPortletSession().setAttribute(TREE_CONTROL, control);
+            }
+        }
+        catch (SecurityException se)
+        {
+            throw new PortletException(se);
+        }        
+        request.setAttribute(TREE_CONTROL, control);
+
+        // check for refresh on roles list
+        String refreshRoles = (String)PortletMessaging.consume(request, "roles", "refresh");
+        List roles = null;
+        if (refreshRoles == null)
+        {        
+            roles = (List) request.getPortletSession().getAttribute(ROLES_CONTROL);
+        }
+        
+        // build the roles control and provide it to the view
+        try
+        {
+            if (roles == null)
+            {
+                roles = new LinkedList();
+                Iterator fullRoles = roleManager.getRoles("");
+                while (fullRoles.hasNext())
+                {
+                    Role role = (Role)fullRoles.next();
+                    roles.add(role.getPrincipal().getName());
+                }
+                request.getPortletSession().setAttribute(ROLES_CONTROL, roles);
+            }
+        }
+        catch (SecurityException se)
+        {
+            throw new PortletException(se);
+        }        
+        request.setAttribute(ROLES_CONTROL, roles);
+
+        // check for refresh on profiles list
+        String refreshProfiles = (String)PortletMessaging.consume(request, "profiles", "refresh");
+        Collection rules = null;
+        if (refreshProfiles == null)
+        {        
+            rules = (Collection) request.getPortletSession().getAttribute(RULES_CONTROL);
+        }
+        
+        // build the profiles control and provide it to the view
+        if (rules == null)
+        {
+            rules = profiler.getRules();
+            request.getPortletSession().setAttribute(RULES_CONTROL, rules);
+        }
+        request.setAttribute(RULES_CONTROL, rules);
+        
+        super.doView(request, response);
+    }
+
+    private boolean isEmpty(String s)
+    {
+        if (s == null) return true;
+        
+        if (s.trim().equals("")) return true;
+        
+        return false;
+    }
+    
+    public void processAction(ActionRequest actionRequest, ActionResponse actionResponse) 
+    throws PortletException,
+          IOException
+    {
+        String browserAction = actionRequest.getParameter("browser.action");
+        if (browserAction != null)
+        {
+            String userName = actionRequest.getParameter("jetspeed.user");
+            String password = actionRequest.getParameter("jetspeed.password");            
+            if (!isEmpty(userName) && !isEmpty(password)) 
+            {
+                try
+                {            
+                    userManager.addUser(userName, password);
+                    TreeControl control = (TreeControl) actionRequest.getPortletSession().getAttribute(TREE_CONTROL);
+                    Iterator users = userManager.getUsers(USER_FILTER);
+                    control = buildTree(users, actionRequest.getLocale());
+                    actionRequest.getPortletSession().setAttribute(TREE_CONTROL, control);
+                    selectNode(actionRequest, control, userName);
+                    
+                    User user = userManager.getUser(userName);
+                    String role = actionRequest.getParameter(ROLES_CONTROL);
+                    if (!isEmpty(role) && user != null) 
+                    {
+                        roleManager.addRoleToUser(userName, role);
+                    }
+
+                    String rule = actionRequest.getParameter(RULES_CONTROL);
+                    if (!isEmpty(rule) && user != null) 
+                    {
+                        Principal principal = getPrincipal(user.getSubject(), UserPrincipal.class);                         
+                        profiler.setRuleForPrincipal(principal, profiler.getRule(rule), "page");
+                    }
+                    
+                }
+                catch (SecurityException se)
+                {
+                    PortletMessaging.publish(actionRequest, "user.error", se.getMessage());
+                }
+                
+            }
+                        
+            
+            return;
+        }
+        TreeControl control = (TreeControl) actionRequest.getPortletSession().getAttribute(TREE_CONTROL);
+        //assert control != null
+        if (control != null)
+        {
+            // expand or contact non-leaf nodes
+            String node = actionRequest.getParameter(SecurityResources.REQUEST_NODE);
+            if (node != null)
+            {
+                TreeControlNode controlNode = control.findNode(node);
+                if (controlNode != null)
+                {
+                    controlNode.setExpanded(!controlNode.isExpanded());
+                }
+            }
+
+            // select a node
+            String selectedNode = actionRequest.getParameter(SecurityResources.REQUEST_SELECT_NODE);
+            if (selectedNode != null)
+            {
+                selectNode(actionRequest, control, selectedNode);
+            }
+        }
+    }
+
+    private void selectNode(ActionRequest actionRequest, TreeControl control, String selectedNode)
+    {
+        control.selectNode(selectedNode);
+        TreeControlNode child = control.findNode(selectedNode);
+        if (child != null)
+        {
+            String domain = child.getDomain();
+            if (domain.equals(USER_DETAIL_DOMAIN))
+            {
+                if (selectedNode != null)
+                {
+                    actionRequest.getPortletSession().setAttribute(
+                            SecurityResources.PAM_CURRENT_USER, selectedNode,
+                            PortletSession.APPLICATION_SCOPE);
+                }
+            }
+        }
+    }
+    
+    private TreeControl buildTree(Iterator users, Locale locale)
+    {
+
+        TreeControlNode root = new TreeControlNode(SECURITY_NODE_ID, // node id
+                null, // icon
+                getMessage(MSG_SECURITY_ROOT, locale), // title
+                SecurityResources.PORTLET_URL, null, // target window
+                true, // expand initially
+                SECURITY_DOMAIN); // domain
+
+        TreeControl control = new TreeControl(root);
+
+        TreeControlNode userTree = new TreeControlNode(USER_NODE_ID, // node id
+                null, // icon
+                getMessage(MSG_USER_ROOT, locale), // title
+                SecurityResources.PORTLET_URL, null, // target window
+                false, // expand initially
+                USER_DOMAIN); // domain
+        root.addChild(userTree);
+
+        while (users.hasNext())
+        {
+            User user = (User) users.next();
+            Principal principal = getPrincipal(user.getSubject(), UserPrincipal.class);
+
+            TreeControlNode userNode = new TreeControlNode(principal.getName(), null, principal.getName(),
+                    SecurityResources.PORTLET_URL, null, false, USER_DETAIL_DOMAIN);
+            userTree.addChild(userNode);
+        }
+
+        return control;
+    }
+
+    private Principal getPrincipal(Subject subject, Class classe)
+    {
+        Principal principal = null;
+        Iterator principals = subject.getPrincipals().iterator();
+        while (principals.hasNext())
+        {
+            Principal p = (Principal) principals.next();
+            if (classe.isInstance(p))
+            {
+                principal = p;
+                break;
+            }
+        }
+        return principal;
+    }
+
+    /** Messages */
+    private static final String MSG_SECURITY_ROOT = "tree.security.root";
+
+    private static final String MSG_USER_ROOT = "tree.user.root";
+
+    private String getMessage(String key, Locale locale)
+    {
+        return getResourceBundle(locale).getString(key);
+    }
+    
+    
+
+}
\ No newline at end of file

Added: portals/jetspeed-2/trunk/applications/j2-admin/src/java/org/apache/jetspeed/portlets/security/users/UserChooserPortlet.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/applications/j2-admin/src/java/org/apache/jetspeed/portlets/security/users/UserChooserPortlet.java?rev=348854&view=auto
==============================================================================
--- portals/jetspeed-2/trunk/applications/j2-admin/src/java/org/apache/jetspeed/portlets/security/users/UserChooserPortlet.java (added)
+++ portals/jetspeed-2/trunk/applications/j2-admin/src/java/org/apache/jetspeed/portlets/security/users/UserChooserPortlet.java Thu Nov 24 18:24:19 2005
@@ -0,0 +1,93 @@
+/* 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.portlets.security.users;
+
+import java.security.Principal;
+import java.sql.Types;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.portlet.PortletConfig;
+import javax.portlet.PortletException;
+import javax.portlet.RenderRequest;
+
+import org.apache.jetspeed.CommonPortletServices;
+import org.apache.jetspeed.portlets.security.SecurityUtil;
+import org.apache.jetspeed.security.User;
+import org.apache.jetspeed.security.UserManager;
+import org.apache.jetspeed.security.UserPrincipal;
+import org.apache.portals.gems.browser.BrowserIterator;
+import org.apache.portals.gems.browser.DatabaseBrowserIterator;
+
+/**
+ * SSOBrowser
+ * 
+ * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
+ * @version $Id: UserChooserPortlet.java 348264 2005-11-22 22:06:45Z taylor $
+ */
+public class UserChooserPortlet extends SecurityUtil
+{
+    private UserManager userManager;
+    
+    public void init(PortletConfig config)
+    throws PortletException 
+    {
+        super.init(config);
+        userManager = (UserManager) 
+            getPortletContext().getAttribute(CommonPortletServices.CPS_USER_MANAGER_COMPONENT);
+        if (null == userManager)
+        {
+            throw new PortletException("Failed to find the User Manager on portlet initialization");
+        }
+    }
+           
+    public void getRows(RenderRequest request, String sql, int windowSize)
+    throws Exception
+    {
+        List resultSetTitleList = new ArrayList();
+        List resultSetTypeList = new ArrayList();
+        try
+        {
+            Iterator users = userManager.getUsers("");
+                        
+            
+            resultSetTypeList.add(String.valueOf(Types.VARCHAR));
+            resultSetTitleList.add("User");
+
+            // TODO: need to try to normalize List/Collection/Iterators
+            List list = new ArrayList();
+            while (users.hasNext())
+            {
+                User user = (User)users.next();
+                Principal principal = getPrincipal(user.getSubject(),
+                        UserPrincipal.class);                
+                list.add(principal.getName());
+            }            
+            BrowserIterator iterator = new DatabaseBrowserIterator(
+                    list, resultSetTitleList, resultSetTypeList,
+                    windowSize);
+            setBrowserIterator(request, iterator);
+            iterator.sort("User");
+        }
+        catch (Exception e)
+        {
+            //log.error("Exception in CMSBrowserAction.getRows: ", e);
+            e.printStackTrace();
+            throw e;
+        }        
+    }
+       
+}



---------------------------------------------------------------------
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