taylor      2005/01/21 14:09:22

  Modified:    
applications/security/src/java/org/apache/jetspeed/portlets/security/resources
                        SecurityResources_en.properties
                        SecurityResources_zh.properties
                        SecurityResources_it.properties
                        SecurityResources_ja.properties
                        SecurityResources.properties
               applications/security/src/webapp/WEB-INF/security/sso
                        sites-view.vm sites-details.vm
               
applications/security/src/java/org/apache/jetspeed/portlets/security/sso
                        SSODetails.java SSOBrowser.java
               applications/security/src/webapp/WEB-INF portlet.xml
  Added:       
applications/security/src/java/org/apache/jetspeed/portlets/security/roles
                        RoleBrowser.java
               applications/security/src/webapp/WEB-INF/security/roles
                        roles-view.vm
               applications/security/src/webapp/WEB-INF/view
                        status-include.vm
               
applications/security/src/java/org/apache/jetspeed/portlets/security/groups
                        GroupBrowser.java
               applications/security/src/webapp/WEB-INF/security/groups
                        groups-view.vm
  Log:
  http://issues.apache.org/jira/browse/JS2-121
  
  - role and group admin portlets  implemented for FLAT view only
  
  Revision  Changes    Path
  1.2       +7 -1      
jakarta-jetspeed-2/applications/security/src/java/org/apache/jetspeed/portlets/security/resources/SecurityResources_en.properties
  
  Index: SecurityResources_en.properties
  ===================================================================
  RCS file: 
/home/cvs/jakarta-jetspeed-2/applications/security/src/java/org/apache/jetspeed/portlets/security/resources/SecurityResources_en.properties,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- SecurityResources_en.properties   22 Dec 2004 17:50:10 -0000      1.1
  +++ SecurityResources_en.properties   21 Jan 2005 22:09:22 -0000      1.2
  @@ -34,6 +34,12 @@
   security.credential.last.logon=Last Logon
   security.credential.expires=Expires
   
  +security.refresh = Refresh
  +security.new = New
  +security.save = Save
  +security.delete = Delete
  +security.deleteQuestion = OK to delete?
  +
   ## User Information Tabs
   pam.details.tabs.user_attributes=Attributes
   pam.details.tabs.user_role=Role
  
  
  
  1.2       +7 -1      
jakarta-jetspeed-2/applications/security/src/java/org/apache/jetspeed/portlets/security/resources/SecurityResources_zh.properties
  
  Index: SecurityResources_zh.properties
  ===================================================================
  RCS file: 
/home/cvs/jakarta-jetspeed-2/applications/security/src/java/org/apache/jetspeed/portlets/security/resources/SecurityResources_zh.properties,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- SecurityResources_zh.properties   22 Dec 2004 17:50:10 -0000      1.1
  +++ SecurityResources_zh.properties   21 Jan 2005 22:09:22 -0000      1.2
  @@ -28,6 +28,12 @@
   security.groupname=\u7ec4\u7fa4\u540d\u79f0
   security.profile.rules=\u81ea\u5b9a\u4e49\u9009\u9879\u89c4\u5219
   
  +security.refresh = Refresh
  +security.new = New
  +security.save = Save
  +security.delete = Delete
  +security.deleteQuestion = OK to delete?
  +
   ## User Information Tabs
   pam.details.tabs.user_attributes=\u5c5e\u6027
   pam.details.tabs.user_role=\u89d2\u8272
  
  
  
  1.2       +7 -1      
jakarta-jetspeed-2/applications/security/src/java/org/apache/jetspeed/portlets/security/resources/SecurityResources_it.properties
  
  Index: SecurityResources_it.properties
  ===================================================================
  RCS file: 
/home/cvs/jakarta-jetspeed-2/applications/security/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   22 Dec 2004 17:50:10 -0000      1.1
  +++ SecurityResources_it.properties   21 Jan 2005 22:09:22 -0000      1.2
  @@ -27,6 +27,12 @@
   security.groupname=Nome gruppo
   security.profile.rules=Regole profilo
   
  +security.refresh = Refresh
  +security.new = New
  +security.save = Save
  +security.delete = Delete
  +security.deleteQuestion = OK to delete?
  +
   ## User Information Tabs
   pam.details.tabs.user_attributes=Attributi
   pam.details.tabs.user_role=Ruolo
  
  
  
  1.2       +7 -1      
jakarta-jetspeed-2/applications/security/src/java/org/apache/jetspeed/portlets/security/resources/SecurityResources_ja.properties
  
  Index: SecurityResources_ja.properties
  ===================================================================
  RCS file: 
/home/cvs/jakarta-jetspeed-2/applications/security/src/java/org/apache/jetspeed/portlets/security/resources/SecurityResources_ja.properties,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- SecurityResources_ja.properties   22 Dec 2004 17:50:10 -0000      1.1
  +++ SecurityResources_ja.properties   21 Jan 2005 22:09:22 -0000      1.2
  @@ -27,6 +27,12 @@
   security.groupname=\u30b0\u30eb\u30fc\u30d7\u540d
   
security.profile.rules=\u30d7\u30ed\u30d5\u30a1\u30a4\u30eb\u30fb\u30eb\u30fc\u30eb
   
  +security.refresh = Refresh
  +security.new = New
  +security.save = Save
  +security.delete = Delete
  +security.deleteQuestion = OK to delete?
  +
   ## User Information Tabs
   pam.details.tabs.user_attributes=\u5c5e\u6027
   pam.details.tabs.user_role=\u30ed\u30fc\u30eb
  
  
  
  1.2       +7 -1      
jakarta-jetspeed-2/applications/security/src/java/org/apache/jetspeed/portlets/security/resources/SecurityResources.properties
  
  Index: SecurityResources.properties
  ===================================================================
  RCS file: 
/home/cvs/jakarta-jetspeed-2/applications/security/src/java/org/apache/jetspeed/portlets/security/resources/SecurityResources.properties,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- SecurityResources.properties      22 Dec 2004 17:50:10 -0000      1.1
  +++ SecurityResources.properties      21 Jan 2005 22:09:22 -0000      1.2
  @@ -16,6 +16,12 @@
   #
   
   ## general security strings
  +security.refresh = Refresh
  +security.new = New
  +security.save = Save
  +security.delete = Delete
  +security.deleteQuestion = OK to delete?
  +
   security.name=Name
   security.value=Value
   security.rule=Rule
  
  
  
  1.1                  
jakarta-jetspeed-2/applications/security/src/java/org/apache/jetspeed/portlets/security/roles/RoleBrowser.java
  
  Index: RoleBrowser.java
  ===================================================================
  /* Copyright 2004 Apache Software Foundation
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
  *     http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
  package org.apache.jetspeed.portlets.security.roles;
  
  import java.io.IOException;
  import java.security.Principal;
  import java.sql.Types;
  import java.util.ArrayList;
  import java.util.Iterator;
  import java.util.List;
  
  import javax.portlet.ActionRequest;
  import javax.portlet.ActionResponse;
  import javax.portlet.PortletConfig;
  import javax.portlet.PortletException;
  import javax.portlet.PortletMode;
  import javax.portlet.RenderRequest;
  import javax.portlet.RenderResponse;
  
  import org.apache.jetspeed.portlets.security.SecurityResources;
  import org.apache.jetspeed.security.Role;
  import org.apache.jetspeed.security.RoleManager;
  import org.apache.jetspeed.security.SecurityException;
  import org.apache.portals.gems.browser.BrowserIterator;
  import org.apache.portals.gems.browser.DatabaseBrowserIterator;
  import org.apache.portals.gems.browser.BrowserPortlet;
  import org.apache.portals.gems.util.StatusMessage;
  import org.apache.portals.messaging.PortletMessaging;
  import org.apache.velocity.context.Context;
  
  /**
   * Role Browser - flat non-hierarchical view
   * 
   * @author <a href="mailto:[EMAIL PROTECTED]">David Sean Taylor</a>
   * @version $Id: RoleBrowser.java,v 1.1 2005/01/21 22:09:22 taylor Exp $
   */
  public class RoleBrowser extends BrowserPortlet
  {
      private RoleManager roleManager;
      
      public void init(PortletConfig config)
      throws PortletException 
      {
          super.init(config);
          roleManager = (RoleManager) 
              
getPortletContext().getAttribute(SecurityResources.CPS_ROLE_MANAGER_COMPONENT);
          if (null == roleManager)
          {
              throw new PortletException("Failed to find the Role Manager on 
portlet initialization");
          }
      }
             
      public void getRows(RenderRequest request, String sql, int windowSize)
      throws Exception
      {
          List resultSetTitleList = new ArrayList();
          List resultSetTypeList = new ArrayList();
          try
          {
              Iterator roles = roleManager.getRoles("");
                          
              
              resultSetTypeList.add(String.valueOf(Types.VARCHAR));
              resultSetTitleList.add("Role");
  
              List list = new ArrayList();
              while (roles.hasNext())
              {
                  Role role = (Role)roles.next();
                  
                  Principal principal = role.getPrincipal();                
                  list.add(principal.getName());
              }            
              
              BrowserIterator iterator = new DatabaseBrowserIterator(
                      list, resultSetTitleList, resultSetTypeList,
                      windowSize);
              setBrowserIterator(request, iterator);
              iterator.sort("Role");
          }
          catch (Exception e)
          {
              //log.error("Exception in CMSBrowserAction.getRows: ", e);
              e.printStackTrace();
              throw e;
          }        
      }
         
      public void doView(RenderRequest request, RenderResponse response)
      throws PortletException, IOException
      {
          String selected = (String)PortletMessaging.receive(request, "role", 
"selected");
          if (selected != null)
          {        
              Context context = this.getContext(request);
              context.put("selected", selected);
          }
          StatusMessage msg = (StatusMessage)PortletMessaging.consume(request, 
"RoleBrowser", "status");
          if (msg != null)
          {
              this.getContext(request).put("statusMsg", msg);            
          }
          
          super.doView(request, response);
      }
  
      public void processAction(ActionRequest request, ActionResponse response)
      throws PortletException, IOException
      {
          if (request.getPortletMode() == PortletMode.VIEW)
          {
              String selected = request.getParameter("role");
              if (selected != null)
              {
                  Role role = lookupRole(selected);
                  if (role != null)
                  {
                      PortletMessaging.publish(request, "role", "selected", 
selected);
                      PortletMessaging.publish(request, "role", "change", 
selected);
                  }
              }
              String refresh = request.getParameter("role.refresh");
              String save = request.getParameter("role.save");
              String neue = request.getParameter("role.new");
              String delete = request.getParameter("roleDelete");
              
              if (refresh != null)
              {
                  this.clearBrowserIterator(request);
              }
              else if (neue != null)
              {
                  PortletMessaging.cancel(request, "role", "selected");
              }
              else if (delete != null && (!(isEmpty(delete))))
              {
                  try
                  {
                      Role role = lookupRole(delete);
                      if (role != null)
                      {
                          roleManager.removeRole(delete);
                          this.clearBrowserIterator(request);
                          PortletMessaging.cancel(request, "role", "selected");
                      }
                  }
                  catch (Exception e)
                  {
                      publishStatusMessage(request, "RoleBrowser", "status", e, 
"Could not remove role");
                  }
              }
              else if (save != null)
              {
                  String roleName = request.getParameter("role.name");          
      
                  if (!(isEmpty(roleName)))
                  {
                      try
                      {
                          Role role = null;
                          String old = 
(String)PortletMessaging.receive(request, "role", "selected");
                          if (old != null)
                          {
                              role = lookupRole(old);
                          }
                          else
                          {
                              role = lookupRole(roleName);
                          }                        
                          if (role != null)
                          {
                              if (old != null && !old.equals(roleName))
                              {
                                  roleManager.removeRole(old);
                                  roleManager.addRole(roleName);                
            
                                  this.clearBrowserIterator(request);
                                  PortletMessaging.publish(request, "role", 
"selected", roleName);
                              }
                          }
                          else
                          {
                              roleManager.addRole(roleName);
                              this.clearBrowserIterator(request);
                          }
                      }
                      catch (Exception e)
                      {
                          publishStatusMessage(request, "RoleBrowser", 
"status", e, "Could not store role");
                      }
                  }
              }            
          }
          super.processAction(request, response);
              
      }
  
      private Role lookupRole(String roleName)
      {
          try
          {
              return roleManager.getRole(roleName);
          }
          catch (SecurityException e)
          {
              return null;
          }
      }
      
      private boolean isEmpty(String s)
      {
          if (s == null) return true;
          
          if (s.trim().equals("")) return true;
          
          return false;
      }
      
  }
  
  
  
  1.1                  
jakarta-jetspeed-2/applications/security/src/webapp/WEB-INF/security/roles/roles-view.vm
  
  Index: roles-view.vm
  ===================================================================
  #*
  Copyright 2004 The Apache Software Foundation
  
  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at
  
      http://www.apache.org/licenses/LICENSE-2.0
  
  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
  *#
  
  #**
  
  @author <a href="mailto:[EMAIL PROTECTED]">David Sean Taylor</a>
  @version $Id: roles-view.vm,v 1.1 2005/01/21 22:09:22 taylor Exp $
  
  *#
  
  <script language='JavaScript' 
src='/security/scripts/jetspeed-security.js'></script>
  
  #set ($MESSAGES = $portletConfig.getResourceBundle($renderRequest.Locale))
  
  #if ($statusMsg)
  #parse ('/WEB-INF/view/status-include.vm')
  #end
  
  <table cellpadding=0 cellspacing=1 border=0 width='100%' >
    <tr>
      <td width='12' class="jetdbHeadNoLink"></td>      
      #set ($column = $title.get(0))
          #set ($columnLink = $renderResponse.createRenderURL())
          $columnLink.setParameter("js_dbcolumn",$column)
  ##      <td align='center' class="jetdbHeadNoLink" width="40%" nowrap 
onClick="window.location.href='$columnLink'">
        <td align='center' class="jetdbHeadNoLink" width="40%" nowrap>
          $column
        </td>
      <td width='24' class="jetdbHeadNoLink">&nbsp;</td>    
      <td class=""></td>        
    </tr>
    #foreach ( $role in $table )
    <tr>
       #if ($selected == $role)
         #set ($rowstyle = "jetdbLight")
         <td class="$rowstyle" nowrap width='12'>
           <img src="/security/images/selected.gif" width="7" height="12" 
border="0" vspace="2"/>
         </td>
         #else
        #set ($rowstyle = "jetdbOdd")
         <td class="$rowstyle" nowrap width='12'>
           &nbsp;
         </td>      
         #end            
        <td class="$rowstyle" nowrap width="40%">
          #set ($action = $renderResponse.createActionURL())
          $action.setParameter('role', $role)
          <div align="center"><a href='$action'>$role</a></div>
        </td>    
         <td class="$rowstyle" nowrap width='24' align='center'>
           <a href="javascript:YesNoPopup('Confirm to Delete Role:','Confirm 
Delete','roleForm','roleDelete','$role','YesNoReturnMethod()');">
             <img src="/security/images/waste_bin.gif" width="20" height="15" 
border="0"/>            
           </a>
         </td>      
      <td class="">&nbsp;</td>               
     </tr>
    #end
    <tr>
      <td width='12' class="jetdbHeadNoLink"></td>      
        <td align='center' class="jetdbHeadNoLink" width="75%" nowrap>
        </td>
      <td width='24' class="jetdbHeadNoLink">&nbsp;</td>    
      <td class=""></td>        
    </tr>
  </table>
  <br/>
  <form name='roleForm' action="$renderResponse.createActionURL()" 
method="post">
  <table>
    <tr colspan="2" align="right">
      <td nowrap class="portlet-section-alternate" align="right">Role 
Name:&nbsp;</td>
      <td class="portlet-section-body" align="left">
        <input type="text" name="role.name" size="40" value="$!selected" 
class="portlet-form-field-label">
      </td>
    </tr>
  </table>
  <br/>
  <input name='roleDelete' type='hidden' value=''/>
  <input name='role.save' type="submit" 
value="$MESSAGES.getString('security.save')" class="portlet-form-button"/>
  <input name='role.refresh' class="portlet-form-button" type="submit" 
value="$MESSAGES.getString('security.refresh')" />
  <input name='role.new' class="portlet-form-button" type="submit" 
value="$MESSAGES.getString('security.new')" />
  
  </form>             
  
  
  
  
  1.1                  
jakarta-jetspeed-2/applications/security/src/webapp/WEB-INF/view/status-include.vm
  
  Index: status-include.vm
  ===================================================================
  #*
  Copyright 2004 The Apache Software Foundation
  
  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at
  
      http://www.apache.org/licenses/LICENSE-2.0
  
  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
  *#
  <br/>
  <table width="100%" cellpadding="0" cellspacing="0" border="0">
  <tr>
        <div class="$statusMsg.Type">$statusMsg.Text</div>
  </tr>
  </table>
  
  
  
  1.5       +5 -1      
jakarta-jetspeed-2/applications/security/src/webapp/WEB-INF/security/sso/sites-view.vm
  
  Index: sites-view.vm
  ===================================================================
  RCS file: 
/home/cvs/jakarta-jetspeed-2/applications/security/src/webapp/WEB-INF/security/sso/sites-view.vm,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- sites-view.vm     14 Jan 2005 01:55:47 -0000      1.4
  +++ sites-view.vm     21 Jan 2005 22:09:22 -0000      1.5
  @@ -25,6 +25,10 @@
   
   #set ($MESSAGES = $portletConfig.getResourceBundle($renderRequest.Locale))
   
  +#if ($statusMsg)
  +#parse ('/WEB-INF/view/status-include.vm')
  +#end
  +
   <table cellpadding=0 cellspacing=1 border=0 width='100%' >
     <tr>
       <td width='12' class="jetdbHeadNoLink"></td>      
  
  
  
  1.8       +5 -1      
jakarta-jetspeed-2/applications/security/src/webapp/WEB-INF/security/sso/sites-details.vm
  
  Index: sites-details.vm
  ===================================================================
  RCS file: 
/home/cvs/jakarta-jetspeed-2/applications/security/src/webapp/WEB-INF/security/sso/sites-details.vm,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- sites-details.vm  14 Jan 2005 05:53:32 -0000      1.7
  +++ sites-details.vm  21 Jan 2005 22:09:22 -0000      1.8
  @@ -35,6 +35,10 @@
   
   #set ($MESSAGES = $portletConfig.getResourceBundle($renderRequest.Locale))
   
  +#if ($statusMsg)
  +#parse ('/WEB-INF/view/status-include.vm')
  +#end
  +
   #if ($currentSite)
   <table cellpadding=0 cellspacing=1 border=0 width='100%' >
     <tr>
  
  
  
  1.8       +12 -9     
jakarta-jetspeed-2/applications/security/src/java/org/apache/jetspeed/portlets/security/sso/SSODetails.java
  
  Index: SSODetails.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-jetspeed-2/applications/security/src/java/org/apache/jetspeed/portlets/security/sso/SSODetails.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- SSODetails.java   14 Jan 2005 05:44:22 -0000      1.7
  +++ SSODetails.java   21 Jan 2005 22:09:22 -0000      1.8
  @@ -43,6 +43,7 @@
   import org.apache.portals.gems.browser.BrowserIterator;
   import org.apache.portals.gems.browser.DatabaseBrowserIterator;
   import org.apache.portals.gems.browser.BrowserPortlet;
  +import org.apache.portals.gems.util.StatusMessage;
   import org.apache.portals.messaging.PortletMessaging;
   import org.apache.velocity.context.Context;
   
  @@ -140,6 +141,12 @@
           context.put("userChooser", userChooser);
           context.put("groupChooser", groupChooser);
           
  +        StatusMessage msg = (StatusMessage)PortletMessaging.consume(request, 
"SSODetails", "status");
  +        if (msg != null)
  +        {
  +            this.getContext(request).put("statusMsg", msg);            
  +        }
  +        
           super.doView(request, response);
       }
       
  @@ -183,13 +190,11 @@
                   }
                   catch (SecurityException e)
                   {
  -                    // TODO: exception handling
  -                    System.err.println("Exception storing site: " + e);      
                  
  +                    publishStatusMessage(request, "SSODetails", "status", e, 
"Could not remove credentials");
                   }
                   catch (SSOException e)
                   {
  -                    // TODO: exception handling
  -                    System.err.println("Exception storing site: " + e);
  +                    publishStatusMessage(request, "SSODetails", "status", e, 
"Could not remove credentials");
                   }
               }
               else if (add != null)
  @@ -215,13 +220,11 @@
                       }
                       catch (SSOException e)
                       {
  -                        // TODO: exception handling
  -                        System.err.println("Exception storing site: " + e);
  +                        publishStatusMessage(request, "SSODetails", 
"status", e, "Could not add credentials");
                       }
                       catch (SecurityException se)
                       {
  -                        // TODO: exception handling
  -                        System.err.println("Exception storing site: " + se);
  +                        publishStatusMessage(request, "SSODetails", 
"status", se, "Could not add credentials");
                       }                    
                   }
               }            
  
  
  
  1.8       +10 -6     
jakarta-jetspeed-2/applications/security/src/java/org/apache/jetspeed/portlets/security/sso/SSOBrowser.java
  
  Index: SSOBrowser.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-jetspeed-2/applications/security/src/java/org/apache/jetspeed/portlets/security/sso/SSOBrowser.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- SSOBrowser.java   14 Jan 2005 18:31:53 -0000      1.7
  +++ SSOBrowser.java   21 Jan 2005 22:09:22 -0000      1.8
  @@ -35,6 +35,7 @@
   import org.apache.portals.gems.browser.BrowserIterator;
   import org.apache.portals.gems.browser.DatabaseBrowserIterator;
   import org.apache.portals.gems.browser.BrowserPortlet;
  +import org.apache.portals.gems.util.StatusMessage;
   import org.apache.portals.messaging.PortletMessaging;
   import org.apache.velocity.context.Context;
   
  @@ -82,7 +83,6 @@
   
               //subPopulate(rundata, qResult, repo, folder, null);
   
  -            // TODO: need to try to normalize List/Collection/Iterators
               List list = new ArrayList();
               while (sites.hasNext())
               {
  @@ -117,6 +117,12 @@
               String selectedName = (String)PortletMessaging.receive(request, 
"site", "selectedName");
               context.put("currentName", selectedName);            
           }
  +        StatusMessage msg = (StatusMessage)PortletMessaging.consume(request, 
"SSOBrowser", "status");
  +        if (msg != null)
  +        {
  +            this.getContext(request).put("statusMsg", msg);            
  +        }
  +        
           super.doView(request, response);
       }
       
  @@ -166,8 +172,7 @@
                   }
                   catch (SSOException e)
                   {
  -                    // TODO: exception handling
  -                    System.err.println("Exception storing site: " + e);
  +                    publishStatusMessage(request, "SSOBrowser", "status", e, 
"Could not remove site");
                   }
               }
               else if (save != null)
  @@ -205,8 +210,7 @@
                       }
                       catch (SSOException e)
                       {
  -                        // TODO: exception handling
  -                        System.err.println("Exception storing site: " + e);
  +                        publishStatusMessage(request, "SSOBrowser", 
"status", e, "Could not store site");
                       }
                   }
               }            
  
  
  
  1.1                  
jakarta-jetspeed-2/applications/security/src/java/org/apache/jetspeed/portlets/security/groups/GroupBrowser.java
  
  Index: GroupBrowser.java
  ===================================================================
  /* Copyright 2004 Apache Software Foundation
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
  *     http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
  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.Iterator;
  import java.util.List;
  
  import javax.portlet.ActionRequest;
  import javax.portlet.ActionResponse;
  import javax.portlet.PortletConfig;
  import javax.portlet.PortletException;
  import javax.portlet.PortletMode;
  import javax.portlet.RenderRequest;
  import javax.portlet.RenderResponse;
  
  import org.apache.jetspeed.portlets.security.SecurityResources;
  import org.apache.jetspeed.security.Group;
  import org.apache.jetspeed.security.GroupManager;
  import org.apache.jetspeed.security.SecurityException;
  import org.apache.portals.gems.browser.BrowserIterator;
  import org.apache.portals.gems.browser.DatabaseBrowserIterator;
  import org.apache.portals.gems.browser.BrowserPortlet;
  import org.apache.portals.gems.util.StatusMessage;
  import org.apache.portals.messaging.PortletMessaging;
  import org.apache.velocity.context.Context;
  
  /**
   * Group Browser - flat non-hierarchical view
   * 
   * @author <a href="mailto:[EMAIL PROTECTED]">David Sean Taylor</a>
   * @version $Id: GroupBrowser.java,v 1.1 2005/01/21 22:09:22 taylor Exp $
   */
  public class GroupBrowser extends BrowserPortlet
  {
      private GroupManager groupManager;
      
      public void init(PortletConfig config)
      throws PortletException 
      {
          super.init(config);
          groupManager = (GroupManager) 
              
getPortletContext().getAttribute(SecurityResources.CPS_GROUP_MANAGER_COMPONENT);
          if (null == groupManager)
          {
              throw new PortletException("Failed to find the Group Manager on 
portlet initialization");
          }
      }
             
      public void getRows(RenderRequest request, String sql, int windowSize)
      throws Exception
      {
          List resultSetTitleList = new ArrayList();
          List resultSetTypeList = new ArrayList();
          try
          {
              Iterator groups = groupManager.getGroups("");
                          
              
              resultSetTypeList.add(String.valueOf(Types.VARCHAR));
              resultSetTitleList.add("Group");
  
              List list = new ArrayList();
              while (groups.hasNext())
              {
                  Group group = (Group)groups.next();
                  
                  Principal principal = group.getPrincipal();                
                  list.add(principal.getName());
              }            
              
              BrowserIterator iterator = new DatabaseBrowserIterator(
                      list, resultSetTitleList, resultSetTypeList,
                      windowSize);
              setBrowserIterator(request, iterator);
              iterator.sort("Group");
          }
          catch (Exception e)
          {
              //log.error("Exception in CMSBrowserAction.getRows: ", e);
              e.printStackTrace();
              throw e;
          }        
      }
         
      public void doView(RenderRequest request, RenderResponse response)
      throws PortletException, IOException
      {
          String selected = (String)PortletMessaging.receive(request, "group", 
"selected");
          if (selected != null)
          {        
              Context context = this.getContext(request);
              context.put("selected", selected);
          }
          StatusMessage msg = (StatusMessage)PortletMessaging.consume(request, 
"GroupBrowser", "status");
          if (msg != null)
          {
              this.getContext(request).put("statusMsg", msg);            
          }
          
          super.doView(request, response);
      }
  
      public void processAction(ActionRequest request, ActionResponse response)
      throws PortletException, IOException
      {
          if (request.getPortletMode() == PortletMode.VIEW)
          {
              String selected = request.getParameter("group");
              if (selected != null)
              {
                  Group group = lookupGroup(selected);
                  if (group != null)
                  {
                      PortletMessaging.publish(request, "group", "selected", 
selected);
                      PortletMessaging.publish(request, "group", "change", 
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");
                      }
                  }
                  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);
                          }
                      }
                      catch (Exception e)
                      {
                          publishStatusMessage(request, "GroupBrowser", 
"status", e, "Could not store group");
                      }
                  }
              }            
          }
          super.processAction(request, response);
              
      }
  
      private Group lookupGroup(String groupName)
      {
          try
          {
              return groupManager.getGroup(groupName);
          }
          catch (SecurityException e)
          {
              return null;
          }
      }
      
      private boolean isEmpty(String s)
      {
          if (s == null) return true;
          
          if (s.trim().equals("")) return true;
          
          return false;
      }
      
  }
  
  
  
  1.14      +60 -0     
jakarta-jetspeed-2/applications/security/src/webapp/WEB-INF/portlet.xml
  
  Index: portlet.xml
  ===================================================================
  RCS file: 
/home/cvs/jakarta-jetspeed-2/applications/security/src/webapp/WEB-INF/portlet.xml,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- portlet.xml       20 Jan 2005 01:44:44 -0000      1.13
  +++ portlet.xml       21 Jan 2005 22:09:22 -0000      1.14
  @@ -290,5 +290,65 @@
       </portlet-info>
   </portlet>
   
  +<portlet id="GroupBrowser">
  +    <init-param>
  +     <description>This parameter sets the template used in view 
mode.</description>
  +             <name>ViewPage</name>
  +                     <value>/WEB-INF/security/groups/groups-view.vm</value>
  +     </init-param>   
  +    <portlet-name>GroupBrowserPortlet</portlet-name>
  +    <display-name>Group Admin</display-name>
  +    <description>Group Browser Portlet</description>
  +    
<portlet-class>org.apache.jetspeed.portlets.security.groups.GroupBrowser</portlet-class>
  +    <expiration-cache>-1</expiration-cache>
  +    <supports>
  +      <mime-type>text/html</mime-type>
  +      <portlet-mode>VIEW</portlet-mode>
  +    </supports>
  +    <supported-locale>en</supported-locale>
  +    
<resource-bundle>org.apache.jetspeed.portlets.security.resources.SecurityResources</resource-bundle>
            
  +    <portlet-preferences>
  +      <preference>                            
  +        <name>WindowSize</name>                    
  +        <value>1000</value>    
  +      </preference>                                              
  +    </portlet-preferences>                
  +    <portlet-info>
  +      <title>Group admin</title>
  +      <short-title>Groups</short-title>
  +      <keywords>admin,security,groups</keywords>
  +    </portlet-info>
  +</portlet>
  +
  +<portlet id="RoleBrowser">
  +    <init-param>
  +     <description>This parameter sets the template used in view 
mode.</description>
  +             <name>ViewPage</name>
  +                     <value>/WEB-INF/security/roles/roles-view.vm</value>
  +     </init-param>   
  +    <portlet-name>RoleBrowserPortlet</portlet-name>
  +    <display-name>Role Admin</display-name>
  +    <description>Role Browser Portlet</description>
  +    
<portlet-class>org.apache.jetspeed.portlets.security.roles.RoleBrowser</portlet-class>
  +    <expiration-cache>-1</expiration-cache>
  +    <supports>
  +      <mime-type>text/html</mime-type>
  +      <portlet-mode>VIEW</portlet-mode>
  +    </supports>
  +    <supported-locale>en</supported-locale>
  +    
<resource-bundle>org.apache.jetspeed.portlets.security.resources.SecurityResources</resource-bundle>
            
  +    <portlet-preferences>
  +      <preference>                            
  +        <name>WindowSize</name>                    
  +        <value>1000</value>    
  +      </preference>                                              
  +    </portlet-preferences>                
  +    <portlet-info>
  +      <title>Role admin</title>
  +      <short-title>Roles</short-title>
  +      <keywords>admin,security,roles</keywords>
  +    </portlet-info>
  +</portlet>
  +
   </portlet-app>
   
  
  
  
  1.1                  
jakarta-jetspeed-2/applications/security/src/webapp/WEB-INF/security/groups/groups-view.vm
  
  Index: groups-view.vm
  ===================================================================
  #*
  Copyright 2004 The Apache Software Foundation
  
  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at
  
      http://www.apache.org/licenses/LICENSE-2.0
  
  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
  *#
  
  #**
  
  @author <a href="mailto:[EMAIL PROTECTED]">David Sean Taylor</a>
  @version $Id: groups-view.vm,v 1.1 2005/01/21 22:09:22 taylor Exp $
  
  *#
  
  <script language='JavaScript' 
src='/security/scripts/jetspeed-security.js'></script>
  
  #set ($MESSAGES = $portletConfig.getResourceBundle($renderRequest.Locale))
  
  #if ($statusMsg)
  #parse ('/WEB-INF/view/status-include.vm')
  #end
  
  <table cellpadding=0 cellspacing=1 border=0 width='100%' >
    <tr>
      <td width='12' class="jetdbHeadNoLink"></td>      
      #set ($column = $title.get(0))
          #set ($columnLink = $renderResponse.createRenderURL())
          $columnLink.setParameter("js_dbcolumn",$column)
  ##      <td align='center' class="jetdbHeadNoLink" width="40%" nowrap 
onClick="window.location.href='$columnLink'">
        <td align='center' class="jetdbHeadNoLink" width="40%" nowrap>
          $column
        </td>
      <td width='24' class="jetdbHeadNoLink">&nbsp;</td>    
      <td class=""></td>        
    </tr>
    #foreach ( $group in $table )
    <tr>
       #if ($selected == $group)
         #set ($rowstyle = "jetdbLight")
         <td class="$rowstyle" nowrap width='12'>
           <img src="/security/images/selected.gif" width="7" height="12" 
border="0" vspace="2"/>
         </td>
         #else
        #set ($rowstyle = "jetdbOdd")
         <td class="$rowstyle" nowrap width='12'>
           &nbsp;
         </td>      
         #end            
        <td class="$rowstyle" nowrap width="40%">
          #set ($action = $renderResponse.createActionURL())
          $action.setParameter('group', $group)
          <div align="center"><a href='$action'>$group</a></div>
        </td>    
         <td class="$rowstyle" nowrap width='24' align='center'>
           <a href="javascript:YesNoPopup('Confirm to Delete Group:','Confirm 
Delete','groupForm','groupDelete','$group','YesNoReturnMethod()');">
             <img src="/security/images/waste_bin.gif" width="20" height="15" 
border="0"/>            
           </a>
         </td>      
      <td class="">&nbsp;</td>               
     </tr>
    #end
    <tr>
      <td width='12' class="jetdbHeadNoLink"></td>      
        <td align='center' class="jetdbHeadNoLink" width="75%" nowrap>
        </td>
      <td width='24' class="jetdbHeadNoLink">&nbsp;</td>    
      <td class=""></td>        
    </tr>
  </table>
  <br/>
  <form name='groupForm' action="$renderResponse.createActionURL()" 
method="post">
  <table>
    <tr colspan="2" align="right">
      <td nowrap class="portlet-section-alternate" align="right">Group 
Name:&nbsp;</td>
      <td class="portlet-section-body" align="left">
        <input type="text" name="group.name" size="40" value="$!selected" 
class="portlet-form-field-label">
      </td>
    </tr>
  </table>
  <br/>
  <input name='groupDelete' type='hidden' value=''/>
  <input name='group.save' type="submit" 
value="$MESSAGES.getString('security.save')" class="portlet-form-button"/>
  <input name='group.refresh' class="portlet-form-button" type="submit" 
value="$MESSAGES.getString('security.refresh')" />
  <input name='group.new' class="portlet-form-button" type="submit" 
value="$MESSAGES.getString('security.new')" />
  
  </form>             
  
  
  
  

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

Reply via email to