portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vku...@apache.org
Subject svn commit: r774696 - in /portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/security: JetspeedPrincipalManagementPortlet.java PrincipaDataProvider.java
Date Thu, 14 May 2009 09:12:12 GMT
Author: vkumar
Date: Thu May 14 09:12:12 2009
New Revision: 774696

URL: http://svn.apache.org/viewvc?rev=774696&view=rev
Log:
Introducing security delegation support in jetspeedPrincipal Portlet

Modified:
    portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/security/JetspeedPrincipalManagementPortlet.java
    portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/security/PrincipaDataProvider.java

Modified: portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/security/JetspeedPrincipalManagementPortlet.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/security/JetspeedPrincipalManagementPortlet.java?rev=774696&r1=774695&r2=774696&view=diff
==============================================================================
--- portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/security/JetspeedPrincipalManagementPortlet.java
(original)
+++ portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/security/JetspeedPrincipalManagementPortlet.java
Thu May 14 09:12:12 2009
@@ -143,11 +143,22 @@
         principalType = getServiceLocator()
                 .getJetspeedPrincipalManagerProvider().getPrincipalType(
                         principalParam);
+       
+        String filteredRole = getPreference("filteredRole", "");
+        if (principalParam.equals(JetspeedPrincipalType.USER))
+        {
+            principalDataProvider = new PrincipaDataProvider(getManager(), getRoleManager(),
getSearchString(), filteredRole, true);
+        }
+        else
+        {
+            principalDataProvider = new PrincipaDataProvider(getManager(), getSearchString());
+        }
+        
         ITab tab = null;
         tabs = new ArrayList();
         group = new WebMarkupContainer("group");
         group.setOutputMarkupId(true);
-        principalDataProvider = new PrincipaDataProvider(getManager(),getSearchString());
+
         
         final DataView<JetspeedPrincipal> principalView = new DataView<JetspeedPrincipal>("entries",
principalDataProvider)
         {
@@ -236,7 +247,7 @@
     public void setSearchString(String searchString)
     {
         this.searchString = (searchString == null ? "" : searchString.trim());        
-        principalDataProvider.refresh(getManager(),searchString);
+        principalDataProvider.refresh(getManager(),getRoleManager(),searchString);
         setPrincipal(null);
         controlPannels(false);
     }
@@ -319,7 +330,7 @@
                         getPrincipal().setEnabled(isUserEnabled());
                         getManager().updatePrincipal(principal);
                         setPrincipal(principal);
-                        principalDataProvider.refresh(getManager(),getSearchString());
+                        principalDataProvider.refresh(getManager(),getRoleManager(),getSearchString());
                     }
                     catch (SecurityException jSx)
                     {
@@ -338,7 +349,7 @@
                         getManager().removePrincipal(principal.getName());
                         setPrincipal(null);
                         controlPannels(false);
-                        principalDataProvider.refresh(getManager(),getSearchString());
+                        principalDataProvider.refresh(getManager(),getRoleManager(),getSearchString());
                     }
                     catch (SecurityException e)
                     {
@@ -770,7 +781,7 @@
                     {
                         log.error("Failed to update user.", jSx);
                     }
-                    principalDataProvider.refresh(getManager(),getSearchString());
+                    principalDataProvider.refresh(getManager(),getRoleManager(),getSearchString());
                 }
             };
             userForm.add(newUser);
@@ -1986,4 +1997,9 @@
         }
         super.onBeforeRender();
     }
+
+    private JetspeedPrincipalManager getRoleManager()
+    {
+        return (JetspeedPrincipalManager) getServiceLocator().getRoleManager();
+    }
 }

Modified: portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/security/PrincipaDataProvider.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/security/PrincipaDataProvider.java?rev=774696&r1=774695&r2=774696&view=diff
==============================================================================
--- portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/security/PrincipaDataProvider.java
(original)
+++ portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/security/PrincipaDataProvider.java
Thu May 14 09:12:12 2009
@@ -7,8 +7,12 @@
 import java.util.Iterator;
 import java.util.List;
 
+import org.apache.commons.lang.StringUtils;
 import org.apache.jetspeed.security.JetspeedPrincipal;
 import org.apache.jetspeed.security.JetspeedPrincipalManager;
+import org.apache.jetspeed.security.Role;
+import org.apache.jetspeed.security.RoleManager;
+import org.apache.jetspeed.security.SecurityException;
 import org.apache.wicket.extensions.markup.html.repeater.util.SortableDataProvider;
 import org.apache.wicket.markup.repeater.data.IDataProvider;
 import org.apache.wicket.model.IModel;
@@ -16,15 +20,31 @@
 
 public class PrincipaDataProvider extends SortableDataProvider<JetspeedPrincipal> implements
IDataProvider<JetspeedPrincipal>
 {
-    public enum OrderBy { NAME_ASC, NAME_DESC }
+    
+    private static final long serialVersionUID = -5676288154198656171L;
+
+    public enum OrderBy
+    {
+        NAME_ASC, NAME_DESC
+    }
+
     private OrderBy order = OrderBy.NAME_ASC;
     private List<JetspeedPrincipal> principalList = new ArrayList<JetspeedPrincipal>();
-    
-    public PrincipaDataProvider(JetspeedPrincipalManager manager,String search)
+    private boolean roleFilter = false;
+    private String filteredRole;
+
+    public PrincipaDataProvider(JetspeedPrincipalManager manager, String search)
     {
-        refresh(manager,search);
+        refresh(manager, search);
     }
-    
+
+    public PrincipaDataProvider(JetspeedPrincipalManager manager, JetspeedPrincipalManager
roleManager, String search, String filteredRole, boolean roleFlter)
+    {
+        this.filteredRole = filteredRole;
+        this.roleFilter = roleFlter;
+        refresh(manager, roleManager, search);
+    }
+
     public Iterator<? extends JetspeedPrincipal> iterator(int first, int count)
     {
         int last = first + count;
@@ -44,41 +64,81 @@
     {
         return principalList.size();
     }
+
     public OrderBy getOrderBy()
     {
         return order;
     }
-    
+
     public void setOrderBy(OrderBy orderBy)
     {
         this.order = orderBy;
-    }  
-    
+    }
+
     public void sort()
     {
         Collections.sort(principalList, new PrincipalComparator(getOrderBy()));
     }
-    
+
     public void refresh(JetspeedPrincipalManager manager, String searchString)
     {
         principalList = (List<JetspeedPrincipal>) manager.getPrincipals(searchString);
     }
-    
+
+    public void refresh(JetspeedPrincipalManager manager, JetspeedPrincipalManager roleManager,
String searchString)
+    {
+        if (roleFilter && !StringUtils.isEmpty(filteredRole))
+        {
+            if (roleManager.getPrincipal(filteredRole) == null)
+            {
+                principalList = Collections.EMPTY_LIST;
+            }
+            else
+            {
+                List<JetspeedPrincipal> localList = (List<JetspeedPrincipal>)
manager.getPrincipals(searchString);
+                for (JetspeedPrincipal principal : localList)
+                {
+                    try
+                    {
+                        List<Role> roles = ((RoleManager) roleManager).getRolesForUser(principal.getName());
+                        for (Role role : roles)
+                        {
+                            if (role.getName().equals(filteredRole))
+                            {
+                                principalList.add(principal);
+                            }
+                        }
+                    }
+                    catch (SecurityException e)
+                    {
+                        principalList = Collections.EMPTY_LIST;
+                    }
+                }
+            }
+        }
+        else
+        {
+            principalList = (List<JetspeedPrincipal>) manager.getPrincipals(searchString);
+        }
+    }
+
     public class PrincipalComparator implements Comparator<JetspeedPrincipal>
     {
         OrderBy orderBy;
-        
+
         public PrincipalComparator(OrderBy order)
         {
             this.orderBy = order;
         }
-        
+
         public int compare(JetspeedPrincipal principal, JetspeedPrincipal otherPrincipal)
         {
-            if(orderBy == OrderBy.NAME_ASC)
+            if (orderBy == OrderBy.NAME_ASC)
+            {
+                return principal.getName().compareToIgnoreCase(otherPrincipal.getName());
+            }
+            else
             {
-                return principal.getName().compareToIgnoreCase(otherPrincipal.getName());
   
-            }else{
                 return otherPrincipal.getName().compareToIgnoreCase(principal.getName());
             }
         }



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


Mime
View raw message