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/pam/src/java/org/apache/jetspeed/portlets/security UserBrowserPortlet.java UserDetailsPortlet.java
Date Fri, 03 Dec 2004 07:12:25 GMT
taylor      2004/12/02 23:12:25

  Modified:    applications/pam/src/webapp/WEB-INF/view user-browser.jsp
                        user-details.jsp
               applications/pam/src/java/org/apache/jetspeed/portlets/security
                        UserBrowserPortlet.java UserDetailsPortlet.java
  Log:
  implemented add and remove user features
  
  Revision  Changes    Path
  1.3       +30 -0     jakarta-jetspeed-2/applications/pam/src/webapp/WEB-INF/view/user-browser.jsp
  
  Index: user-browser.jsp
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed-2/applications/pam/src/webapp/WEB-INF/view/user-browser.jsp,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- user-browser.jsp	17 Sep 2004 18:44:06 -0000	1.2
  +++ user-browser.jsp	3 Dec 2004 07:12:24 -0000	1.3
  @@ -30,3 +30,33 @@
         styleUnselected="tree-control-unselected"
         --%>
   
  +<h3 class="portlet-section-subheader">Add User</h3>
  +
  +<div class="portlet-section-text">
  +
  +<portlet:actionURL var="addUser" />
  +
  +<form action="<c:out value="${addUser}"/>" method="post">
  +<input type='hidden' name='browser.action' value='adduser'/>
  +<table>
  +  <tr colspan="2" align="right">
  +    <td nowrap class="portlet-section-alternate" align="right">New User Name:&nbsp;</td>
  +    <td class="portlet-section-body" align="left">
  +      <input type="text" name="jetspeed.user" size="30" value="" class="portlet-form-label-field">
  +    </td>
  +  </tr>
  +  <tr colspan="2" align="right">
  +    <td nowrap class="portlet-section-alternate" align="right">Password:&nbsp;</td>
  +    <td class="portlet-section-body" align="left">
  +      <input type="password" name="jetspeed.password" size="30" value="" class="portlet-form-label-field">
  +    </td>
  +  </tr>
  +  
  +</table>
  +<br/>
  +<input type="submit" value="Add User" class="portlet-form-button"/>
  +</form>
  +<c:if test="${errorMessage != null}">
  +  <li style="color:red"><c:out value="${errorMessage}"/></li>
  +</c:if>
  +  
  \ No newline at end of file
  
  
  
  1.13      +10 -2     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.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- user-details.jsp	25 Nov 2004 02:25:57 -0000	1.12
  +++ user-details.jsp	3 Dec 2004 07:12:24 -0000	1.13
  @@ -346,11 +346,19 @@
   </c:if>
   <%--End of Profile tab data--%>
   
  +<portlet:actionURL var="removeUser" />
  +<form action="<c:out value="${removeUser}"/>" method="post">
  +<input type="hidden" name="portlet_action" value="remove.user"/>
  +<br/>
  +<input type="submit" value="Remove User" class="portlet-form-button"/>
  +</form>
  +
  +<br />
  +<br />
   
   <%--End of User check --%>
   </c:if>
  -
  -<br />
   <br />
  +
   
   
  
  
  
  1.6       +69 -18    jakarta-jetspeed-2/applications/pam/src/java/org/apache/jetspeed/portlets/security/UserBrowserPortlet.java
  
  Index: UserBrowserPortlet.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed-2/applications/pam/src/java/org/apache/jetspeed/portlets/security/UserBrowserPortlet.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- UserBrowserPortlet.java	6 Oct 2004 23:45:05 -0000	1.5
  +++ UserBrowserPortlet.java	3 Dec 2004 07:12:24 -0000	1.6
  @@ -35,6 +35,7 @@
   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;
   
  @@ -84,7 +85,19 @@
       {
           response.setContentType("text/html");
   
  -        TreeControl control = (TreeControl) request.getPortletSession().getAttribute(TREE_CONTROL);
  +        String errorMessage = (String)PortletMessaging.consume(request, "user.error");
  +        if (errorMessage != null)
  +        {
  +            request.setAttribute("errorMessage", errorMessage);            
  +        }
  +        
  +        TreeControl control = null;
  +        String refresh = (String)PortletMessaging.consume(request, "users", "refresh");
  +        if (refresh == null)
  +        {        
  +            control = (TreeControl) request.getPortletSession().getAttribute(TREE_CONTROL);
  +        }
  +        
           try
           {
               if (control == null)
  @@ -104,9 +117,42 @@
   
       }
   
  -    public void processAction(ActionRequest actionRequest, ActionResponse actionResponse)
throws PortletException,
  -            IOException
  +    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
  +                {            
  +                    manager.addUser(userName, password);
  +                    TreeControl control = (TreeControl) actionRequest.getPortletSession().getAttribute(TREE_CONTROL);
  +                    Iterator users = manager.getUsers(USER_FILTER);
  +                    control = buildTree(users, actionRequest.getLocale());
  +                    actionRequest.getPortletSession().setAttribute(TREE_CONTROL, control);
  +                    selectNode(actionRequest, control, userName);                    
  +                }
  +                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)
  @@ -126,25 +172,30 @@
               String selectedNode = actionRequest.getParameter(PortletApplicationResources.REQUEST_SELECT_NODE);
               if (selectedNode != null)
               {
  -                control.selectNode(selectedNode);
  -                TreeControlNode child = control.findNode(selectedNode);
  -                if (child != 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)
                   {
  -                    String domain = child.getDomain();
  -                    if (domain.equals(USER_DETAIL_DOMAIN))
  -                    {
  -                        if (selectedNode != null)
  -                        {
  -                            actionRequest.getPortletSession().setAttribute(
  -                                    PortletApplicationResources.PAM_CURRENT_USER, selectedNode,
  -                                    PortletSession.APPLICATION_SCOPE);
  -                        }
  -                    }
  +                    actionRequest.getPortletSession().setAttribute(
  +                            PortletApplicationResources.PAM_CURRENT_USER, selectedNode,
  +                            PortletSession.APPLICATION_SCOPE);
                   }
               }
           }
       }
  -
  +    
       private TreeControl buildTree(Iterator users, Locale locale)
       {
   
  
  
  
  1.14      +28 -2     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.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- UserDetailsPortlet.java	25 Nov 2004 02:25:58 -0000	1.13
  +++ UserDetailsPortlet.java	3 Dec 2004 07:12:24 -0000	1.14
  @@ -48,6 +48,7 @@
   import org.apache.jetspeed.security.SecurityException;
   import org.apache.jetspeed.security.UserPrincipal;
   import org.apache.portals.bridges.common.GenericServletPortlet;
  +import org.apache.portals.messaging.PortletMessaging;
   
   /**
    * This portlet is a tabbed editor user interface for editing user attributes
  @@ -218,7 +219,11 @@
               }            
           }             
           String action = actionRequest.getParameter(PortletApplicationResources.PORTLET_ACTION);
  -        if (action != null && isUserPortletAction(action))
  +        if (action != null && action.equals("remove.user"))
  +        {
  +            removeUser(actionRequest, actionResponse);
  +        }
  +        else if (action != null && isUserPortletAction(action))
           {
               action = getAction(USER_ACTION_PREFIX, action);                
               if (action.endsWith(ACTION_UPDATE_ATTRIBUTE))
  @@ -263,6 +268,27 @@
               }
           }
       }    
  +    
  +    public void removeUser(ActionRequest actionRequest, ActionResponse actionResponse)

  +    throws PortletException
  +    {
  +        String userName = (String)
  +            actionRequest.getPortletSession().getAttribute(PortletApplicationResources.PAM_CURRENT_USER,

  +                             PortletSession.APPLICATION_SCOPE);
  +        User user = lookupUser(userName);
  +        if (user != null)
  +        {
  +            try
  +            {
  +                userManager.removeUser(userName);
  +                PortletMessaging.publish(actionRequest, "users", "refresh", "all");
  +            }
  +            catch (Exception e)
  +            {
  +                
  +            }
  +        }
  +    }
       
       public Principal createPrincipal(Subject subject, Class classe)
       {
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jetspeed-dev-help@jakarta.apache.org


Mime
View raw message