You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jetspeed-dev@portals.apache.org by ta...@apache.org on 2002/06/19 23:20:32 UTC

cvs commit: jakarta-jetspeed/src/java/org/apache/jetspeed/modules/actions/portlets/security UserRoleUpdateAction.java

taylor      2002/06/19 14:20:32

  Modified:    src/java/org/apache/jetspeed/modules/actions/portlets/security
                        Tag: security_14 UserRoleUpdateAction.java
  Log:
  Added code to buildUserRoleContext and to update it also.
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.4.2.3   +32 -46    jakarta-jetspeed/src/java/org/apache/jetspeed/modules/actions/portlets/security/UserRoleUpdateAction.java
  
  Index: UserRoleUpdateAction.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/modules/actions/portlets/security/UserRoleUpdateAction.java,v
  retrieving revision 1.4.2.2
  retrieving revision 1.4.2.3
  diff -u -r1.4.2.2 -r1.4.2.3
  --- UserRoleUpdateAction.java	17 Jun 2002 21:27:01 -0000	1.4.2.2
  +++ UserRoleUpdateAction.java	19 Jun 2002 21:20:32 -0000	1.4.2.3
  @@ -56,6 +56,8 @@
   
   // java util
   import java.util.Vector;
  +import java.util.List;
  +import java.util.Iterator;
   
   // velocity
   import org.apache.velocity.context.Context;
  @@ -66,10 +68,6 @@
   import org.apache.turbine.util.StringUtils;
   import org.apache.turbine.util.DynamicURI;
   
  -
  -// turbine security
  -import org.apache.turbine.util.security.AccessControlList;
  -
   // turbine om
   import org.apache.jetspeed.om.security.Role;
   import org.apache.jetspeed.om.security.JetspeedUser;
  @@ -187,9 +185,6 @@
       public void doUpdate(RunData rundata, Context context)
           throws Exception
       {
  -        // TODO: if the user is the current user, we will need to refresh the
  -        // rundata's ACL list as described in the constructor for AccessControlList.java
  -
           String entityid = rundata.getParameters().getString(SecurityConstants.PARAM_ENTITY_ID);
           if (entityid == null || entityid.trim().length() == 0)
           {
  @@ -215,8 +210,8 @@
   
           try
           {
  -            Role[] roles = (Role[])rundata.getUser().getTemp(SecurityConstants.CONTEXT_ROLES);
  -            Vector selected = (Vector)rundata.getUser().getTemp(SecurityConstants.CONTEXT_SELECTED);
  +            List roles = (List)rundata.getUser().getTemp(SecurityConstants.CONTEXT_ROLES);
  +            List selected = (List)rundata.getUser().getTemp(SecurityConstants.CONTEXT_SELECTED);
   
               if (roles == null || selected == null)
               {
  @@ -231,23 +226,24 @@
               // walk thru all the roles, see if anything changed
               // if changed, update the database
               //
  -            for (int ix = 0; ix < roles.length; ix++)
  +            for (int ix = 0; ix < roles.size(); ix++)
               {
  -                boolean newValue = rundata.getParameters().getBoolean("box_" + roles[ix].getName(), false);
  -                boolean oldValue = ((Boolean)selected.elementAt(ix + 1)).booleanValue();
  +                boolean newValue = rundata.getParameters().getBoolean("box_" + ((Role)roles.get(ix)).getName(), false);
  +                boolean oldValue = ((Boolean)selected.get(ix + 1)).booleanValue();
  +                //System.out.println("In role:"+((Role)roles.get(ix)).getName()+" newValue="+newValue+" oldValue="+oldValue);
                   if (newValue != oldValue)
                   {
                       if (newValue == true)
                       {
                           // grant a role to a user
                           JetspeedSecurity.grantRole( user.getUserName(),
  -                                                roles[ix].getName() );
  +                                                ((Role)roles.get(ix)).getName() );
                       }
                       else
                       {
                           // revoke a role from a user
  -                        JetspeedSecurity.revokeRole( user.getUserName(),                                                
  -                                                    roles[ix].getName() );
  +                        JetspeedSecurity.revokeRole( user.getUserName(),
  +                                                    ((Role)roles.get(ix)).getName() );
                       }
                   }
               }
  @@ -289,50 +285,40 @@
                                          String userid)
           throws Exception
       {
  -        /*
  -        // get master list of roles
  -        Iterator master = JetspeedSecurity.getRoles();
  -
           // get the user object
           JetspeedUser user = JetspeedSecurity.getUser(userid);
           if (null == user)
           {
  -            // no ACL found
  +            // no User found
               Log.error("UserRoleBrowser: Failed to get user: " + userid );
               return;
           }
  -        // get the access control list for the given user
  -        AccessControlList acl = JetspeedSecurity.getACL(user);
  -        if (null == acl)
  -        {
  -            // no ACL found
  -            Log.error("RoleBrowser: NO ACL found for user: " + user.getUserName() );
  -            return;
  -        }
  -        // get all the roles for this user in the Jetspeed Group
  -        Group jetGroup = JetspeedSecurity.getGroup(JetspeedSecurity.JETSPEED_GROUP);
  -        RoleSet userRoles = acl.getRoles( jetGroup );
  -
  -        Role[] roles = master.getRolesArray();
  -        Vector selected = new Vector(master.size()+1);
  -
  -        selected.add(0, new Boolean(false));
  +        // get master list of roles
  +        Iterator roles = JetspeedSecurity.getRoles();
  +        Vector masterRoles = new Vector();
  +        Vector selected = new Vector();
  +        int ix = 0;
           boolean sel = false;
  -        for ( int ix = 0; ix < roles.length; ix++ )
  +        selected.add(ix, new Boolean(sel));
  +        while(roles.hasNext())
           {
  -            if (null != userRoles)
  -                sel = userRoles.contains(roles[ix].getName());
  -            else
  -                sel = false;
  -            selected.add(ix + 1, new Boolean(sel));
  +            Role role = (Role)roles.next();
  +            //System.out.println("In buildUserRoleContext role="+role.getName());
  +            masterRoles.add(role);
  +            sel = JetspeedSecurity.hasRole(user.getUserName(), role.getName());
  +            //System.out.println("In buildUserRoleContext sel="+sel);
  +            ix = ix + 1;
  +            selected.add(ix, new Boolean(sel));
           }
  +        masterRoles.trimToSize();
  +        selected.trimToSize();
   
  -        rundata.getUser().setTemp(SecurityConstants.CONTEXT_ROLES, roles);
  +        rundata.getUser().setTemp(SecurityConstants.CONTEXT_ROLES, masterRoles);
           rundata.getUser().setTemp(SecurityConstants.CONTEXT_SELECTED, selected);
           context.put(SecurityConstants.CONTEXT_USER, user);
  -        context.put(SecurityConstants.CONTEXT_ROLES, roles);
  +        context.put(SecurityConstants.CONTEXT_ROLES, masterRoles);
           context.put(SecurityConstants.CONTEXT_SELECTED, selected);
  -        */
  +
       }
   
   
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>