taylor      2004/12/22 14:59:40

  Modified:    
applications/security/src/java/org/apache/jetspeed/portlets/security/users
                        UserDetailsPortlet.java UserBrowserPortlet.java
               applications/security/src/webapp/WEB-INF/security/users
                        user-browser.jsp user-details.jsp
  Log:
  implemented
  
  http://nagoya.apache.org/jira/browse/JS2-175
  
  Revision  Changes    Path
  1.2       +73 -4     
jakarta-jetspeed-2/applications/security/src/java/org/apache/jetspeed/portlets/security/users/UserDetailsPortlet.java
  
  Index: UserDetailsPortlet.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-jetspeed-2/applications/security/src/java/org/apache/jetspeed/portlets/security/users/UserDetailsPortlet.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- UserDetailsPortlet.java   22 Dec 2004 17:50:09 -0000      1.1
  +++ UserDetailsPortlet.java   22 Dec 2004 22:59:40 -0000      1.2
  @@ -39,8 +39,10 @@
   import 
org.apache.jetspeed.portlets.security.users.JetspeedUserBean.StringAttribute;
   import org.apache.jetspeed.profiler.Profiler;
   import org.apache.jetspeed.profiler.rules.PrincipalRule;
  +import org.apache.jetspeed.security.Group;
   import org.apache.jetspeed.security.GroupManager;
   import org.apache.jetspeed.security.PasswordCredential;
  +import org.apache.jetspeed.security.Role;
   import org.apache.jetspeed.security.RoleManager;
   import org.apache.jetspeed.security.User;
   import org.apache.jetspeed.security.UserManager;
  @@ -86,6 +88,13 @@
       private final String TAB_PROFILE = "user_profile";
       private final String TAB_CREDENTIAL = "user_credential";
       
  +    /** the id of the roles control */
  +    private static final String ROLES_CONTROL = "jetspeedRoles";
  +
  +    /** the id of the groups control */
  +    private static final String GROUPS_CONTROL = "jetspeedGroups";
  +    
  +    
       private UserManager  userManager;
       private RoleManager  roleManager;
       private GroupManager groupManager;
  @@ -182,12 +191,72 @@
               JetspeedUserBean bean = new JetspeedUserBean(user);
               request.setAttribute(VIEW_USER, bean);
               if (selectedTab.getId().equals(TAB_ROLE))
  -            {
  -                request.setAttribute(VIEW_ROLES, getRoles(userName));        
        
  +            {                
  +                request.setAttribute(VIEW_ROLES, getRoles(userName));
  +                
  +                // 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);
  +                
               }
               else if (selectedTab.getId().equals(TAB_GROUP))
               {
  -                request.setAttribute(VIEW_GROUPS, getGroups(userName));  
  +                request.setAttribute(VIEW_GROUPS, getGroups(userName));
  +                
  +                // check for refresh on groups list
  +                String refreshGroups = 
(String)PortletMessaging.consume(request, "groups", "refresh");
  +                List groups = null;
  +                if (refreshGroups == null)
  +                {        
  +                    groups = (List) 
request.getPortletSession().getAttribute(GROUPS_CONTROL);
  +                }
  +                
  +                // build the groups control and provide it to the view
  +                try
  +                {
  +                    if (groups == null)
  +                    {
  +                        groups = new LinkedList();
  +                        Iterator fullGroups = groupManager.getGroups("");
  +                        while (fullGroups.hasNext())
  +                        {
  +                            Group group = (Group)fullGroups.next();
  +                            groups.add(group.getPrincipal().getName());
  +                        }
  +                        
request.getPortletSession().setAttribute(GROUPS_CONTROL, groups);
  +                    }
  +                }
  +                catch (SecurityException se)
  +                {
  +                    throw new PortletException(se);
  +                }        
  +                request.setAttribute(GROUPS_CONTROL, groups);
  +                
               }
               else if (selectedTab.getId().equals(TAB_PROFILE))
               {
  
  
  
  1.2       +50 -3     
jakarta-jetspeed-2/applications/security/src/java/org/apache/jetspeed/portlets/security/users/UserBrowserPortlet.java
  
  Index: UserBrowserPortlet.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-jetspeed-2/applications/security/src/java/org/apache/jetspeed/portlets/security/users/UserBrowserPortlet.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- UserBrowserPortlet.java   22 Dec 2004 17:50:10 -0000      1.1
  +++ UserBrowserPortlet.java   22 Dec 2004 22:59:40 -0000      1.2
  @@ -17,6 +17,7 @@
   
   import java.io.IOException;
   import java.security.Principal;
  +import java.util.Collection;
   import java.util.Iterator;
   import java.util.LinkedList;
   import java.util.List;
  @@ -32,6 +33,7 @@
   import javax.security.auth.Subject;
   
   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;
  @@ -53,12 +55,16 @@
   {
       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 = "jetspeed.roles";
  +    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 = "";
  @@ -93,6 +99,11 @@
           {
                        throw new PortletException("Failed to find the Role 
Manager on portlet initialization");
           }
  +        profiler = 
(Profiler)getPortletContext().getAttribute(SecurityResources.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
  @@ -157,6 +168,22 @@
               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);
       }
  @@ -188,13 +215,31 @@
                       Iterator users = userManager.getUsers(USER_FILTER);
                       control = buildTree(users, actionRequest.getLocale());
                       
actionRequest.getPortletSession().setAttribute(TREE_CONTROL, control);
  -                    selectNode(actionRequest, control, userName);            
        
  +                    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);
  @@ -298,5 +343,7 @@
       {
           return getResourceBundle(locale).getString(key);
       }
  +    
  +    
   
   }
  
  
  
  1.3       +26 -21    
jakarta-jetspeed-2/applications/security/src/webapp/WEB-INF/security/users/user-browser.jsp
  
  Index: user-browser.jsp
  ===================================================================
  RCS file: 
/home/cvs/jakarta-jetspeed-2/applications/security/src/webapp/WEB-INF/security/users/user-browser.jsp,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- user-browser.jsp  22 Dec 2004 19:07:27 -0000      1.2
  +++ user-browser.jsp  22 Dec 2004 22:59:40 -0000      1.3
  @@ -51,34 +51,39 @@
         <input type="password" name="jetspeed.password" size="30" value="" 
class="portlet-form-label-field">
       </td>
     </tr>
  -  <!--
  +  
  +  <!-- Select Roles -->
     <tr colspan="2" align="right">
       <td nowrap class="portlet-section-alternate" align="right">Default 
Role:&nbsp;</td>
       <td class="portlet-section-body" align="left">
  -             <select name="jetspeed.role" class="portlet-form-label-field">  
        
  -                     <option value="" <c:if test="! ${selectedPDef}"> 
selected="true"</c:if> >
  -                             <fmt:message key="pam.details.choose_portlet"/>
  -                     </option>
  -                     <c:forEach var="portletDef" 
items="${pa.portletDefinitions}">
  -                         <c:set var="pdefName" value="${portletDef.name}"/>
  -                         
  -                         <%--We must do this since portlet taglib doesn't 
support expressions--%>
  -                         <% String pdefName = (String) 
pageContext.getAttribute("pdefName"); %>
  -                         
  -                         <option value="<c:out value="${portletDef.name}"/>" 
<c:if test="${selectedPDef.name == portletDef.name}">selected="true"</c:if>>
  -                               <c:out value="${portletDef.name}"/>
  +             <select name="jetspeedRoles" class="portlet-form-label-field">  
        
  +                     <option value=""/>                              
  +                     <c:forEach var="roleName" items="${jetspeedRoles}">     
                    
  +                         <option value="<c:out value='${roleName}'/>"
  +                         <c:if test="${roleName == 
'user'}">selected="true"</c:if>>                      
  +                               <c:out value="${roleName}"/>
                            </option>
  -                             <%--
  -                         <a href="<c:out value="${select_portlet_link}"/>">
  -                             <c:out value="${portletDef.name}" /><br />
  -                         </a>
  -                         --%>
                        </c:forEach>
  -             </select>
  -      
  +             </select>      
       </td>
     </tr>
  -  -->
  +
  +  <!-- Select Profiling Rules -->
  +  <tr colspan="2" align="right">
  +    <td nowrap class="portlet-section-alternate" align="right">Profiling 
Rule:&nbsp;</td>
  +    <td class="portlet-section-body" align="left">
  +             <select name="jetspeedRules" class="portlet-form-label-field">  
        
  +                     <option value=""/>              
  +                     <c:forEach var="ruleName" items="${jetspeedRules}">
  +                         <option value="<c:out value='${ruleName}'/>"
  +                         <c:if test="${ruleName == 
'role-fallback'}">selected="true"</c:if>>
  +                               <c:out value="${ruleName}"/>
  +                         </option>
  +                     </c:forEach>
  +             </select>      
  +    </td>
  +  </tr>
  +  
   </table>
   <br/>
   <input type="submit" value="Add User" class="portlet-form-button"/>
  
  
  
  1.4       +19 -7     
jakarta-jetspeed-2/applications/security/src/webapp/WEB-INF/security/users/user-details.jsp
  
  Index: user-details.jsp
  ===================================================================
  RCS file: 
/home/cvs/jakarta-jetspeed-2/applications/security/src/webapp/WEB-INF/security/users/user-details.jsp,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- user-details.jsp  22 Dec 2004 19:07:27 -0000      1.3
  +++ user-details.jsp  22 Dec 2004 22:59:40 -0000      1.4
  @@ -222,9 +222,15 @@
                                <td class="portlet-section-alternate" >
                                        <fmt:message key="security.rolename"/>
                                </td>
  -                             <td class="portlet-section-body" >
  -                                     <input type="text" name="role_name" 
value=""/>
  -                             </td>
  +                         <td class="portlet-section-body" align="left">
  +                                     <select name="role_name" 
class="portlet-form-label-field">              
  +                                             <c:forEach var="roleName" 
items="${jetspeedRoles}">                         
  +                                                 <option value="<c:out 
value='${roleName}'/>">
  +                                                       <c:out 
value="${roleName}"/>                                              
  +                                                 </option>
  +                                             </c:forEach>
  +                                     </select>      
  +                         </td>                               
                        </tr>
                </table>
                <input type="submit" value="<fmt:message key="security.add"/>" 
class="portlet-form-button" />
  @@ -254,7 +260,7 @@
                                </td>
                                <td class="portlet-section-body" >
                                        <c:out value="${group.principal.name}"/>
  -                             </td>
  +                             </td>                           
                        </tr>
                </c:forEach>
                </table>
  @@ -268,9 +274,15 @@
                                <td class="portlet-section-alternate" >
                                        <fmt:message key="security.groupname"/>
                                </td>
  -                             <td class="portlet-section-body" >
  -                                     <input type="text" name="group_name" 
value=""/>
  -                             </td>
  +                         <td class="portlet-section-body" align="left">
  +                                     <select name="group_name" 
class="portlet-form-label-field">             
  +                                             <c:forEach var="groupName" 
items="${jetspeedGroups}">                       
  +                                                 <option value="<c:out 
value='${groupName}'/>">
  +                                                       <c:out 
value="${groupName}"/>                                             
  +                                                 </option>
  +                                             </c:forEach>
  +                                     </select>      
  +                         </td>                                               
                
                        </tr>
                </table>
                <input type="submit" value="<fmt:message key="security.add"/>" 
class="portlet-form-button" />
  
  
  

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

Reply via email to