taylor      2004/10/21 11:43:07

  Modified:    applications/pam/src/webapp/WEB-INF/view user-details.jsp
               
applications/pam/src/java/org/apache/jetspeed/portlets/security/resources
                        SecurityResources_it.properties
                        SecurityResources_en.properties
                        SecurityResources.properties
               applications/pam/src/java/org/apache/jetspeed/portlets/security
                        UserDetailsPortlet.java
  Log:
  reworked the User Manager->Profile tab to account for model change in Principal 
Rules (1 principal ... many rules)
  
  Revision  Changes    Path
  1.9       +43 -13    
jakarta-jetspeed-2/applications/pam/src/webapp/WEB-INF/view/user-details.jsp
  
  Index: user-details.jsp
  ===================================================================
  RCS file: 
/home/cvs/jakarta-jetspeed-2/applications/pam/src/webapp/WEB-INF/view/user-details.jsp,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- user-details.jsp  24 Sep 2004 22:21:15 -0000      1.8
  +++ user-details.jsp  21 Oct 2004 18:43:07 -0000      1.9
  @@ -209,34 +209,64 @@
   <%--Beginning Profile tab data--%>
   <%--TODO:  switch to c:choose --%>
   <c:if test="${selectedTab.id == 'user_profile'}">
  -  <div id="Profile">
  -  <portlet:actionURL var="edit_role_link" />
  +  <div id="Profile"> 
  +  <portlet:actionURL var="edit_profile_link" />
     
  -     <form name="Edit_Group_Form" action="<c:out value="${edit_role_link}"/>" 
method="post">
  -             <input type="hidden" name="portlet_action" 
value="security_user.update_user_rule"/>             
  +     <form name="Edit_Profile_Form" action="<c:out value="${edit_profile_link}"/>" 
method="post">
  +             <input type="hidden" name="portlet_action" 
value="security_user.remove_user_rule"/>             
                <table>
                        <tr>
                                <th>&nbsp;</th>
  -                             <th><fmt:message key="security.profile.rules"/></th>
  -                             <th>&nbsp;</th>
  +                             <th><fmt:message key="security.name"/></th>
  +                             <th><fmt:message key="security.rule"/></th>
                        </tr>
                <c:forEach var="rule" items="${rules}">
                        <tr>                    
                                <td>
  -                                     <input type="radio" name="user_profile_id"  
<c:if test="${rule.id == selectedRule}">checked</c:if>  value="<c:out 
value="${rule.id}"/>"/>
  +                                     <input type="checkbox" name="user_profile_id" 
value="<c:out value="${rule.locatorName}"/>"/>
                                </td>
                                <td>
  -                                     <c:out value="${rule.id}"/>
  +                                     <c:out value="${rule.locatorName}"/>
                                </td>
                                <td>
  -                                     <c:out value="${rule.title}"/>
  -                             </td>                           
  +                                     <c:out value="${rule.profilingRule}"/>
  +                             </td>
                        </tr>
                </c:forEach>
                </table>
  -     <input type="submit" value="<fmt:message key="security.update"/>" 
onClick="this.form.portlet_action.value = 'security_user.update_user_rule'"/>
  -    </form>
  -  </div>
  +             <input type="submit" value="<fmt:message key="security.remove"/>" 
onClick="this.form.portlet_action.value = 'security_user.remove_user_rule'"/>
  +     </form>
  +     <form name="Add_Profile_Form" action="<c:out value="${edit_profile_link}"/>" 
method="post">
  +             <input type="hidden" name="portlet_action" 
value="security_user.add_rule"/>
  +             
  +             <table>
  +                     <tr>
  +                             <td>
  +                                     <fmt:message key="security.name"/>
  +                             </td>
  +                             <td>
  +                                     <input type="text" name="locator_name" 
value=""/>
  +                                     Common Locator Names: [page,docset]
  +                             </td>
  +                     </tr>
  +                     <tr>
  +                             <td>
  +                                     <fmt:message key="security.rule"/>
  +                             </td>
  +                             <td>
  +                                     <select name="select_rule">                    
                                         
  +                                             <c:forEach var="prule" 
items="${prules}">                                                                     
                              
  +                                                 <option value="<c:out 
value="${prule.id}"/>">
  +                                                       <c:out value="${prule.id}"/>
  +                                                 </option>
  +                                             </c:forEach>
  +                                     </select>
  +                             </td>
  +                     </tr>
  +             </table>
  +             <input type="submit" value="<fmt:message key="security.add"/>"/>
  +     </form>
  +  </div>     
   </c:if>
   <%--End of Profile tab data--%>
   
  
  
  
  1.2       +2 -1      
jakarta-jetspeed-2/applications/pam/src/java/org/apache/jetspeed/portlets/security/resources/SecurityResources_it.properties
  
  Index: SecurityResources_it.properties
  ===================================================================
  RCS file: 
/home/cvs/jakarta-jetspeed-2/applications/pam/src/java/org/apache/jetspeed/portlets/security/resources/SecurityResources_it.properties,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- SecurityResources_it.properties   14 Oct 2004 12:14:31 -0000      1.1
  +++ SecurityResources_it.properties   21 Oct 2004 18:43:07 -0000      1.2
  @@ -19,6 +19,7 @@
   ## general security strings
   security.name=Nome
   security.value=Valore
  +security.rule=Regole
   security.update=Aggiorna
   security.remove=Rimuovi
   security.add=Aggiungi
  
  
  
  1.6       +2 -1      
jakarta-jetspeed-2/applications/pam/src/java/org/apache/jetspeed/portlets/security/resources/SecurityResources_en.properties
  
  Index: SecurityResources_en.properties
  ===================================================================
  RCS file: 
/home/cvs/jakarta-jetspeed-2/applications/pam/src/java/org/apache/jetspeed/portlets/security/resources/SecurityResources_en.properties,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- SecurityResources_en.properties   20 Sep 2004 07:25:23 -0000      1.5
  +++ SecurityResources_en.properties   21 Oct 2004 18:43:07 -0000      1.6
  @@ -18,6 +18,7 @@
   ## general security strings
   security.name=Name
   security.value=Value
  +security.rule=Rule
   security.update=Update
   security.remove=Remove
   security.add=Add
  
  
  
  1.7       +2 -1      
jakarta-jetspeed-2/applications/pam/src/java/org/apache/jetspeed/portlets/security/resources/SecurityResources.properties
  
  Index: SecurityResources.properties
  ===================================================================
  RCS file: 
/home/cvs/jakarta-jetspeed-2/applications/pam/src/java/org/apache/jetspeed/portlets/security/resources/SecurityResources.properties,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- SecurityResources.properties      20 Sep 2004 07:25:23 -0000      1.6
  +++ SecurityResources.properties      21 Oct 2004 18:43:07 -0000      1.7
  @@ -18,6 +18,7 @@
   ## general security strings
   security.name=Name
   security.value=Value
  +security.rule=Rule
   security.update=Update
   security.remove=Remove
   security.add=Add
  
  
  
  1.10      +69 -36    
jakarta-jetspeed-2/applications/pam/src/java/org/apache/jetspeed/portlets/security/UserDetailsPortlet.java
  
  Index: UserDetailsPortlet.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-jetspeed-2/applications/pam/src/java/org/apache/jetspeed/portlets/security/UserDetailsPortlet.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- UserDetailsPortlet.java   8 Oct 2004 06:49:37 -0000       1.9
  +++ UserDetailsPortlet.java   21 Oct 2004 18:43:07 -0000      1.10
  @@ -39,6 +39,8 @@
   import org.apache.jetspeed.portlets.security.users.JetspeedUserBean.StringAttribute;
   import org.apache.jetspeed.profiler.ProfileLocator;
   import org.apache.jetspeed.profiler.Profiler;
  +import org.apache.jetspeed.profiler.ProfilerException;
  +import org.apache.jetspeed.profiler.rules.PrincipalRule;
   import org.apache.jetspeed.profiler.rules.ProfilingRule;
   import org.apache.jetspeed.security.GroupManager;
   import org.apache.jetspeed.security.RoleManager;
  @@ -62,6 +64,7 @@
       private final String VIEW_ROLES = "roles";
       private final String VIEW_GROUPS = "groups";
       private final String VIEW_RULES = "rules";
  +    private final String VIEW_ALL_RULES = "prules";
       private final String VIEW_SELECTED_RULE = "selectedRule";
       
       private final String USER_ACTION_PREFIX = "security_user.";
  @@ -72,7 +75,8 @@
       private final String ACTION_ADD_ROLE = "add_user_role";
       private final String ACTION_REMOVE_GROUP = "remove_user_group";
       private final String ACTION_ADD_GROUP = "add_user_group";
  -    private final String ACTION_UPDATE_RULE = "update_user_rule";
  +    private final String ACTION_REMOVE_RULE = "remove_user_rule";
  +    private final String ACTION_ADD_RULE = "add_rule";
       
       private final String TAB_ATTRIBUTES = "user_attributes";
       private final String TAB_ROLE = "user_role";
  @@ -161,14 +165,8 @@
               }
               else if (selectedTab.getId().equals(TAB_PROFILE))
               {
  -                Principal userPrincipal = createPrincipal(user.getSubject(), 
UserPrincipal.class);      
  -                // TODO: incorporate locator_name
  -                ProfilingRule rule = profiler.getRuleForPrincipal(userPrincipal, 
ProfileLocator.PAGE_LOCATOR);
  -                if (rule != null)
  -                {
  -                    request.setAttribute(VIEW_SELECTED_RULE, rule.getId());
  -                }
  -                request.setAttribute(VIEW_RULES, getProfilerRules());               
   
  +                request.setAttribute(VIEW_RULES, getRules(user));
  +                request.setAttribute(VIEW_ALL_RULES, getProfilerRules());
               }
              
               request.setAttribute(PortletApplicationResources.REQUEST_SELECT_TAB, 
selectedTab);
  @@ -222,9 +220,13 @@
               {
                   addUserGroup(actionRequest, actionResponse);
               }
  -            else if (action.endsWith(this.ACTION_UPDATE_RULE))
  +            else if (action.endsWith(this.ACTION_ADD_RULE))
               {
  -                updateUserProfile(actionRequest, actionResponse);
  +                addUserProfile(actionRequest, actionResponse);
  +            }
  +            else if (action.endsWith(this.ACTION_REMOVE_RULE))
  +            {
  +                removeUserProfile(actionRequest, actionResponse);
               }
           }
       }    
  @@ -496,7 +498,13 @@
           return profiler.getRules();
       }
       
  -    private void updateUserProfile(ActionRequest actionRequest, ActionResponse 
actionResponse)
  +    private Collection getRules(User user)
  +    {
  +        Principal userPrincipal = createPrincipal(user.getSubject(), 
UserPrincipal.class);
  +        return profiler.getRulesForPrincipal(userPrincipal);
  +    }
  +
  +    private void addUserProfile(ActionRequest actionRequest, ActionResponse 
actionResponse)
       {
           String userName = (String)
               
actionRequest.getPortletSession().getAttribute(PortletApplicationResources.PAM_CURRENT_USER,
 
  @@ -504,37 +512,62 @@
           User user = lookupUser(userName);
           if (user != null)
           {
  -            String profileId = actionRequest.getParameter("user_profile_id");
  -
  -            if(profileId != null)
  +            String locatorName = actionRequest.getParameter("locator_name");
  +            if (locatorName != null && locatorName.trim().length() > 0)
               {
                   try
                   {
  -                    Principal userPrincipal = createPrincipal(user.getSubject(), 
UserPrincipal.class);      
  -                    ProfilingRule rule = profiler.getRule(profileId);
  -                    if (userPrincipal != null)
  +                    Principal userPrincipal = createPrincipal(user.getSubject(), 
UserPrincipal.class);                          
  +                    String ruleName = actionRequest.getParameter("select_rule");
  +                    profiler.setRuleForPrincipal(userPrincipal, 
  +                            profiler.getRule(ruleName),
  +                            locatorName);                                           
              
  +                }
  +                catch (Exception e)
  +                {
  +                    // TODO: logging
  +                    System.err.println("failed to set rule for principal: " + 
userName + ", "  + locatorName + e);                       
  +                }
  +            }
  +            
  +        }
  +    }
  +    
  +    private void removeUserProfile(ActionRequest actionRequest, ActionResponse 
actionResponse)
  +    {
  +        String userName = (String)
  +            
actionRequest.getPortletSession().getAttribute(PortletApplicationResources.PAM_CURRENT_USER,
 
  +                                     PortletSession.APPLICATION_SCOPE);
  +        User user = lookupUser(userName);
  +        if (user != null)
  +        {
  +            String[] locatorNames = 
actionRequest.getParameterValues("user_profile_id");
  +
  +            if(locatorNames != null)
  +            {
  +                Principal userPrincipal = createPrincipal(user.getSubject(), 
UserPrincipal.class);                                              
  +                Collection rules = profiler.getRulesForPrincipal(userPrincipal);
  +                for (int ix = 0; ix < locatorNames.length; ix++)
  +                {
  +                    try
                       {
  -                        if (rule == null)
  +                        Iterator it = rules.iterator();
  +                        while (it.hasNext())
                           {
  -                            profiler.setRuleForPrincipal(userPrincipal, 
  -                                                         profiler.getDefaultRule(),
  -                                                         
ProfileLocator.PAGE_LOCATOR);                                                         
  -                        }
  -                        else
  -                        {
  -                            // TODO: only support the page locator for now
  -                            profiler.setRuleForPrincipal(userPrincipal,
  -                                                         rule,
  -                                                         
ProfileLocator.PAGE_LOCATOR);
  +                            PrincipalRule rule = (PrincipalRule)it.next();
  +                            if (rule.getLocatorName().equals(locatorNames[ix]))
  +                            {
  +                                profiler.deletePrincipalRule(rule);
  +                            }
                           }
                       }
  +                    catch (Exception e)
  +                    {
  +                        // TODO: logging
  +                        System.err.println("failed to remove rule for principal: " 
+ userName + ", "  + locatorNames[ix] + e);                       
  +                    }                
                   }
  -                catch (Exception e)
  -                {
  -                    // TODO: logging
  -                    System.err.println("failed to update user + profile: " + 
userName + ", "  + profileId + e);                       
  -                }                
  -            }            
  +            }                                    
           }
       }        
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to