portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tay...@apache.org
Subject cvs commit: jakarta-jetspeed-2/applications/security/src/java/org/apache/jetspeed/portlets/security/groups GroupDetails.java GroupBrowser.java
Date Mon, 25 Apr 2005 07:28:57 GMT
taylor      2005/04/25 00:28:57

  Modified:    applications/security/src/java/org/apache/jetspeed/portlets/security/groups
                        GroupDetails.java GroupBrowser.java
  Log:
  http://issues.apache.org/jira/browse/JS2-237
  - roles maintainance, add users to roles
  
  Revision  Changes    Path
  1.2       +159 -135  jakarta-jetspeed-2/applications/security/src/java/org/apache/jetspeed/portlets/security/groups/GroupDetails.java
  
  Index: GroupDetails.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed-2/applications/security/src/java/org/apache/jetspeed/portlets/security/groups/GroupDetails.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- GroupDetails.java	23 Apr 2005 19:08:13 -0000	1.1
  +++ GroupDetails.java	25 Apr 2005 07:28:57 -0000	1.2
  @@ -15,10 +15,14 @@
   package org.apache.jetspeed.portlets.security.groups;
   
   import java.io.IOException;
  +import java.security.Principal;
   import java.sql.Types;
   import java.util.ArrayList;
  +import java.util.Enumeration;
   import java.util.Iterator;
   import java.util.List;
  +import java.util.ResourceBundle;
  +import java.util.StringTokenizer;
   
   import javax.portlet.ActionRequest;
   import javax.portlet.ActionResponse;
  @@ -27,19 +31,13 @@
   import javax.portlet.PortletMode;
   import javax.portlet.RenderRequest;
   import javax.portlet.RenderResponse;
  -import javax.security.auth.Subject;
  -import javax.servlet.http.HttpServletRequest;
   
  -import org.apache.jetspeed.PortalReservedParameters;
   import org.apache.jetspeed.portlets.security.SecurityResources;
  -import org.apache.jetspeed.request.RequestContext;
  +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.jetspeed.security.UserPrincipal;
   import org.apache.portals.gems.browser.BrowserIterator;
   import org.apache.portals.gems.browser.DatabaseBrowserIterator;
   import org.apache.portals.gems.browser.BrowserPortlet;
  @@ -48,7 +46,7 @@
   import org.apache.velocity.context.Context;
   
   /**
  - * SSODetails
  + * Group Details
    * 
    * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
    * @version $Id$
  @@ -73,7 +71,6 @@
               throw new PortletException("Failed to find the Group Manager on portlet initialization");
           }        
       }
  -       
       
       public void getRows(RenderRequest request, String sql, int windowSize)
       throws Exception
  @@ -82,23 +79,27 @@
           List resultSetTypeList = new ArrayList();
           try
           {
  -            List list = null;
  +            List list = new ArrayList();
               resultSetTypeList.add(String.valueOf(Types.VARCHAR));
  -            resultSetTitleList.add("User");
  +            resultSetTitleList.add("Users in Group");
               
               String selectedGroup = (String)PortletMessaging.receive(request, SecurityResources.TOPIC_GROUPS,
SecurityResources.MESSAGE_SELECTED);
               if (selectedGroup != null)
               {
  -                list = new ArrayList();
  -            }
  -            else
  -            {
  -                list = new ArrayList();
  +                Iterator users = userManager.getUsersInGroup(selectedGroup).iterator();
                                   
  +                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("Users in Group");
           }
           catch (Exception e)
           {
  @@ -106,8 +107,9 @@
               e.printStackTrace();
               throw e;
           }        
  +        
       }
  -   
  +           
       public void doView(RenderRequest request, RenderResponse response)
       throws PortletException, IOException
       {
  @@ -116,162 +118,184 @@
           { 
               this.clearBrowserIterator(request);
           }
  -        Context context = this.getContext(request);        
  +        Context context = this.getContext(request);
  +                
           String selectedGroup = (String)PortletMessaging.receive(request, SecurityResources.TOPIC_GROUPS,
SecurityResources.MESSAGE_SELECTED);
           if (selectedGroup != null)
           {        
  -            context.put("currentGroup", selectedGroup);
  +            context.put("group", selectedGroup);
           }        
           
  -        // get relative link, TODO: encapsulate Jetspeed links access into component
  -        String userChooser = getAbsoluteUrl(request, "/Administrative/choosers/users.psml");
  -        String groupChooser = getAbsoluteUrl(request, "/Administrative/choosers/groups.psml");
  -        
  +        String userChooser = SecurityUtil.getAbsoluteUrl(request, "/Administrative/choosers/multiusers.psml");
       
           context.put("userChooser", userChooser);
  -        context.put("groupChooser", groupChooser);
           
  -        StatusMessage msg = (StatusMessage)PortletMessaging.consume(request, "SSODetails",
"status");
  +        StatusMessage msg = (StatusMessage)PortletMessaging.consume(request, SecurityResources.TOPIC_GROUPS_USERS,
SecurityResources.MESSAGE_STATUS);
           if (msg != null)
           {
               this.getContext(request).put("statusMsg", msg);            
           }
  +          
  +        String refresh = (String)PortletMessaging.consume(request, SecurityResources.TOPIC_GROUPS_USERS,
SecurityResources.MESSAGE_REFRESH); 
  +        if (refresh != null)
  +        {        
  +            this.clearBrowserIterator(request);
  +        }                
           
           super.doView(request, response);
       }
  -    
  -    public String getAbsoluteUrl(RenderRequest renderRequest, String relativePath)
  -    {
  -        RequestContext requestContext = (RequestContext) renderRequest.getAttribute(PortalReservedParameters.REQUEST_CONTEXT_ATTRIBUTE);
  -        HttpServletRequest request = requestContext.getRequest();
  -        StringBuffer path = new StringBuffer();
  -        return path.append(request.getScheme()).append("://").append(request.getServerName()).append(":").append(
  -                request.getServerPort()).append(request.getContextPath()).append(request.getServletPath()).append(
  -                relativePath).toString();
  -    }
  -    
  +        
       
       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)
  +            String groupAction = request.getParameter("group.action");
  +            String users = request.getParameter("users");
  +            
  +            System.out.println("group.action = " + groupAction);
  +            System.out.println("users = " + users);
  +            if (users != null && users.length() > 0)
  +            {
  +                addUsersToGroup(request, users);
  +            }
  +            else if (groupAction != null && groupAction.equals("Add New Group"))
  +            {
  +                PortletMessaging.cancel(request, SecurityResources.TOPIC_GROUPS, SecurityResources.MESSAGE_SELECTED);
               
  +            }
  +            else if (groupAction != null && groupAction.equals("Remove Checked
Users"))
  +            {
  +                removeUsersFromGroup(request);
  +            }
  +            else if (groupAction != null && groupAction.equals("Remove Group"))
  +            {
  +                removeGroup(request);
  +            }
  +            else if (groupAction != null && groupAction.equals("Save"))
  +            {
  +                addGroup(request);
  +            }
  +            
  +        }
  +        super.processAction(request, response);            
  +    }
  +
  +    protected void addGroup(ActionRequest actionRequest)
  +    {
  +        String group = actionRequest.getParameter("group");
  +        if (!SecurityUtil.isEmpty(group)) 
  +        {
  +            try
  +            {            
  +                groupManager.addGroup(group);
  +                PortletMessaging.publish(actionRequest, 
  +                        SecurityResources.TOPIC_GROUPS, 
  +                        SecurityResources.MESSAGE_REFRESH, "true");
  +            }            
  +            catch (Exception se)
  +            {
  +                ResourceBundle bundle = ResourceBundle.getBundle("org.apache.jetspeed.portlets.security.resources.UsersResources",actionRequest.getLocale());
               
  +                SecurityUtil.publishErrorMessage(actionRequest, bundle.getString("user.exists"));
  +            }
  +        }
  +    }
  +
  +    protected void removeGroup(ActionRequest actionRequest)
  +    {
  +        String group = actionRequest.getParameter("group");
  +        if (!SecurityUtil.isEmpty(group)) 
  +        {
  +            try
  +            {            
  +                groupManager.removeGroup(group);
  +                PortletMessaging.publish(actionRequest, 
  +                        SecurityResources.TOPIC_GROUPS, 
  +                        SecurityResources.MESSAGE_REFRESH, "true");
  +                PortletMessaging.cancel(actionRequest, SecurityResources.TOPIC_GROUPS,
SecurityResources.MESSAGE_SELECTED);                                                
  +            }
  +            catch (Exception se)
               {
  -                this.clearBrowserIterator(request);
  +                ResourceBundle bundle = ResourceBundle.getBundle("org.apache.jetspeed.portlets.security.resources.UsersResources",actionRequest.getLocale());
               
  +                SecurityUtil.publishErrorMessage(actionRequest, bundle.getString("user.exists"));
               }
  -            else if (delete != null && !(isEmpty(delete)))
  +        }
  +    }
  +    
  +    protected void addUsersToGroup(ActionRequest request, String users)
  +    {
  +        String group = request.getParameter("group");
  +        if (group != null)
  +        {
  +            int count = 0;
  +            StringTokenizer tokenizer = new StringTokenizer(users, ",");
  +            while (tokenizer.hasMoreTokens())
               {
  +                String user = tokenizer.nextToken();
                   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)
  +                    if (user.startsWith("box_"))
                       {
  -                        // User doesn't exist -- maybe a group
  -                        user =null;
  +                        user = user.substring("box_".length());
  +                        groupManager.addUserToGroup(user, group);
  +                        count++;
                       }
  -                    
  -                    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)
  +                catch (Exception e)
                   {
  -                    publishStatusMessage(request, "SSODetails", "status", e, "Could not
remove credentials");
  +                    System.err.println("failed to add user to group: " + user);
                   }
               }
  -            else if (add != null)
  +            if (count > 0)
               {
  -                // 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
  +                {
  +                    PortletMessaging.publish(request, 
  +                            SecurityResources.TOPIC_GROUPS_USERS, 
  +                            SecurityResources.MESSAGE_REFRESH, "true");
  +                }
  +                catch (Exception e)
  +                {}
  +            }
  +        }
  +    }
  +
  +    protected void removeUsersFromGroup(ActionRequest request)
  +    {
  +        String group = request.getParameter("group");
  +        if (group != null)
  +        {
  +            int count = 0;
  +            Enumeration e = request.getParameterNames();
  +            while (e.hasMoreElements())
  +            {
  +                String name = (String)e.nextElement();
  +                if (name.startsWith("box_"))
                   {
  +                    String user = name.substring("box_".length());
                       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);
  -                        }
  +                        groupManager.removeUserFromGroup(user, group);                
       
  +                        count++;
                       }
  -                    catch (SSOException e)
  +                    catch (Exception e1)
                       {
  -                        publishStatusMessage(request, "SSODetails", "status", e, "Could
not add credentials");
  +                        System.err.println("failed to remove user from group: " + user);
                       }
  -                    catch (SecurityException se)
  -                    {
  -                        publishStatusMessage(request, "SSODetails", "status", se, "Could
not add credentials");
  -                    }                    
  +                    
                   }
  -            }            
  +            }
  +            if (count > 0)
  +            {
  +                try
  +                {
  +                    PortletMessaging.publish(request, 
  +                            SecurityResources.TOPIC_GROUPS_USERS, 
  +                            SecurityResources.MESSAGE_REFRESH, "true");
  +                }
  +                catch (Exception e2)
  +                {}
  +            }
           }
  -        super.processAction(request, response);
  -            
  -    }
  -
  -    private boolean isEmpty(String s)
  -    {
  -        if (s == null) return true;
  -        
  -        if (s.trim().equals("")) return true;
  -        
  -        return false;
       }
       
   }
  
  
  
  1.6       +9 -85     jakarta-jetspeed-2/applications/security/src/java/org/apache/jetspeed/portlets/security/groups/GroupBrowser.java
  
  Index: GroupBrowser.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed-2/applications/security/src/java/org/apache/jetspeed/portlets/security/groups/GroupBrowser.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- GroupBrowser.java	23 Apr 2005 20:33:36 -0000	1.5
  +++ GroupBrowser.java	25 Apr 2005 07:28:57 -0000	1.6
  @@ -107,13 +107,13 @@
       public void doView(RenderRequest request, RenderResponse response)
       throws PortletException, IOException
       {
  -        String selected = (String)PortletMessaging.receive(request, "group", "selected");
  +        String selected = (String)PortletMessaging.receive(request, SecurityResources.TOPIC_GROUPS,
SecurityResources.MESSAGE_SELECTED);
           if (selected != null)
           {        
               Context context = this.getContext(request);
               context.put("selected", selected);
           }
  -        StatusMessage msg = (StatusMessage)PortletMessaging.consume(request, "GroupBrowser",
"status");
  +        StatusMessage msg = (StatusMessage)PortletMessaging.consume(request, SecurityResources.TOPIC_GROUPS,
SecurityResources.MESSAGE_STATUS);
           if (msg != null)
           {
               this.getContext(request).put("statusMsg", msg);            
  @@ -123,7 +123,12 @@
           if (filtered != null)
           {
               this.getContext(request).put(FILTERED, "on");            
  -        }
  +        }        
  +        String refresh = (String)PortletMessaging.consume(request, SecurityResources.TOPIC_GROUPS,
SecurityResources.MESSAGE_REFRESH); 
  +        if (refresh != null)
  +        {        
  +            this.clearBrowserIterator(request);
  +        }                
           
           
           super.doView(request, response);
  @@ -144,80 +149,8 @@
                       PortletMessaging.publish(request, SecurityResources.TOPIC_GROUPS, SecurityResources.MESSAGE_CHANGED,
selected);
                   }
               }
  -            String refresh = request.getParameter("group.refresh");
  -            String save = request.getParameter("group.save");
  -            String neue = request.getParameter("group.new");
  -            String delete = request.getParameter("groupDelete");
  -            
  -            if (refresh != null)
  -            {
  -                this.clearBrowserIterator(request);
  -            }
  -            else if (neue != null)
  -            {
  -                PortletMessaging.cancel(request, "group", "selected");
  -            }
  -            else if (delete != null && (!(isEmpty(delete))))
  -            {
  -                try
  -                {
  -                    Group group = lookupGroup(delete);
  -                    if (group != null)
  -                    {
  -                        groupManager.removeGroup(delete);
  -                        this.clearBrowserIterator(request);
  -                        PortletMessaging.cancel(request, "group", "selected");
  -                        PortletMessaging.publish(request, SecurityResources.TOPIC_GROUPS,
"groups", "refresh");
  -                    }
  -                }
  -                catch (Exception e)
  -                {
  -                    publishStatusMessage(request, "GroupBrowser", "status", e, "Could not
remove group");
  -                }
  -            }
  -            else if (save != null)
  -            {
  -                String groupName = request.getParameter("group.name");                
  -                if (!(isEmpty(groupName)))
  -                {
  -                    try
  -                    {
  -                        Group group = null;
  -                        String old = (String)PortletMessaging.receive(request, "group",
"selected");
  -                        if (old != null)
  -                        {
  -                            group = lookupGroup(old);
  -                        }
  -                        else
  -                        {
  -                            group = lookupGroup(groupName);
  -                        }                        
  -                        if (group != null)
  -                        {
  -                            if (old != null && !old.equals(groupName))
  -                            {
  -                                groupManager.removeGroup(old);
  -                                groupManager.addGroup(groupName);                     
      
  -                                this.clearBrowserIterator(request);
  -                                PortletMessaging.publish(request, "group", "selected",
groupName);
  -                            }
  -                        }
  -                        else
  -                        {
  -                            groupManager.addGroup(groupName);
  -                            this.clearBrowserIterator(request);
  -                        }
  -                        PortletMessaging.publish(request, SecurityResources.TOPIC_GROUPS,
"groups", "refresh");
  -                    }
  -                    catch (Exception e)
  -                    {
  -                        publishStatusMessage(request, "GroupBrowser", "status", e, "Could
not store group");
  -                    }
  -                }
  -            }            
           }
           
  -        // TODO: if request parameters were working correctly we could replace this with
render parameters
           String filtered = (String)request.getParameter(FILTERED);
           if (filtered != null)
           {
  @@ -244,13 +177,4 @@
           }
       }
       
  -    private boolean isEmpty(String s)
  -    {
  -        if (s == null) return true;
  -        
  -        if (s.trim().equals("")) return true;
  -        
  -        return false;
  -    }
  -    
   }
  
  
  

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