portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tay...@apache.org
Subject svn commit: r1731003 [1/2] - in /portals/jetspeed-2/applications/j2-admin/trunk/src/main: java/org/apache/jetspeed/portlets/ java/org/apache/jetspeed/portlets/security/ java/org/apache/jetspeed/portlets/wicket/ resources/org/apache/jetspeed/portlets/se...
Date Thu, 18 Feb 2016 04:32:59 GMT
Author: taylor
Date: Thu Feb 18 04:32:58 2016
New Revision: 1731003

URL: http://svn.apache.org/viewvc?rev=1731003&view=rev
Log:
JS2-1349: Add ability to filter by groups in the user manager. Add filterRoles and filterGroups
drop downs to Edit Mode configuration

Added:
    portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/security/ExtendedWicketPortlet.java
Modified:
    portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/AdminPortletWebPage.java
    portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/security/JetspeedPrincipalManagementEditPortlet.java
    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/PrincipalDataProvider.java
    portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/wicket/AbstractAdminWebApplication.java
    portals/jetspeed-2/applications/j2-admin/trunk/src/main/resources/org/apache/jetspeed/portlets/security/JetspeedPrincipalManagementEditPortlet.html
    portals/jetspeed-2/applications/j2-admin/trunk/src/main/resources/org/apache/jetspeed/portlets/security/resources/JetspeedPrincipalManagement.properties
    portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/WEB-INF/jetspeed-portlet.xml
    portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/WEB-INF/portlet.xml

Modified: portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/AdminPortletWebPage.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/AdminPortletWebPage.java?rev=1731003&r1=1731002&r2=1731003&view=diff
==============================================================================
--- portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/AdminPortletWebPage.java
(original)
+++ portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/AdminPortletWebPage.java
Thu Feb 18 04:32:58 2016
@@ -17,12 +17,6 @@
 
 package org.apache.jetspeed.portlets;
 
-import java.util.Enumeration;
-
-import javax.portlet.PortletPreferences;
-import javax.portlet.PortletRequest;
-import javax.portlet.PortletResponse;
-
 import org.apache.commons.lang.BooleanUtils;
 import org.apache.jetspeed.portlets.wicket.AbstractAdminWebApplication;
 import org.apache.jetspeed.request.RequestContext;
@@ -32,6 +26,11 @@ import org.apache.wicket.PageParameters;
 import org.apache.wicket.markup.html.WebPage;
 import org.apache.wicket.model.IModel;
 
+import javax.portlet.PortletPreferences;
+import javax.portlet.PortletRequest;
+import javax.portlet.PortletResponse;
+import java.util.Enumeration;
+
 
 /**
  * General Portlet functionality provided to Admin Portlets via inheritance in an abstract
class.
@@ -149,6 +148,11 @@ public abstract class AdminPortletWebPag
         return ((AbstractAdminWebApplication) getApplication()).getPreferenceValueAsInteger(key);
     }
 
+    public int getPreferenceAsInteger(String key, int defaultValue)
+    {
+        return ((AbstractAdminWebApplication) getApplication()).getPreferenceValueAsInteger(key,
defaultValue);
+    }
+
     /**
      * Delegates the invocation to {@link AbstractAdminWebApplication#getPreferenceValueAsBoolean(String)}.
      * Please use the corresponding method of {@link AbstractAdminWebApplication} directly.

Added: portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/security/ExtendedWicketPortlet.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/security/ExtendedWicketPortlet.java?rev=1731003&view=auto
==============================================================================
--- portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/security/ExtendedWicketPortlet.java
(added)
+++ portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/security/ExtendedWicketPortlet.java
Thu Feb 18 04:32:58 2016
@@ -0,0 +1,35 @@
+package org.apache.jetspeed.portlets.security;
+
+import org.apache.jetspeed.JetspeedActions;
+import org.apache.wicket.protocol.http.portlet.WicketPortlet;
+
+import javax.portlet.PortletException;
+import javax.portlet.PortletMode;
+import javax.portlet.RenderRequest;
+import javax.portlet.RenderResponse;
+import javax.portlet.WindowState;
+import java.io.IOException;
+
+/**
+ * Created by dtaylor on 2/16/16.
+ */
+public class ExtendedWicketPortlet extends WicketPortlet {
+
+    protected void doDispatch(RenderRequest request, RenderResponse response) throws PortletException,
IOException
+    {
+        if ( !request.getWindowState().equals(WindowState.MINIMIZED))
+        {
+            PortletMode curMode = request.getPortletMode();
+            if (JetspeedActions.EDIT_DEFAULTS_MODE.equals(curMode))
+            {
+                //request.setAttribute(PARAM_EDIT_PAGE, DEFAULT_EDIT_DEFAULTS_PAGE);
+                doEdit(request, response);
+            }
+            else
+            {
+                super.doDispatch(request, response);
+            }
+        }
+
+    }
+}

Modified: portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/security/JetspeedPrincipalManagementEditPortlet.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/security/JetspeedPrincipalManagementEditPortlet.java?rev=1731003&r1=1731002&r2=1731003&view=diff
==============================================================================
--- portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/security/JetspeedPrincipalManagementEditPortlet.java
(original)
+++ portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/security/JetspeedPrincipalManagementEditPortlet.java
Thu Feb 18 04:32:58 2016
@@ -29,7 +29,6 @@ import org.apache.wicket.markup.html.bas
 import org.apache.wicket.markup.html.form.Button;
 import org.apache.wicket.markup.html.form.DropDownChoice;
 import org.apache.wicket.markup.html.form.Form;
-import org.apache.wicket.markup.html.form.RequiredTextField;
 import org.apache.wicket.markup.html.form.TextField;
 import org.apache.wicket.markup.html.panel.FeedbackPanel;
 import org.apache.wicket.model.IModel;
@@ -53,11 +52,16 @@ import java.util.List;
  */
 public class JetspeedPrincipalManagementEditPortlet extends AdminPortletWebPage
 {
-    private String subite;
+    private String subsite;
     private String profile;
     private String role;
+    private String requiredRole;
+    private String requiredGroup;
+    private String filteredRole;
+    private String filteredGroup;
     private String templateDir;
     private String subSiteRoot;
+    private Integer rowsPerPage;
     private Logger log = LoggerFactory.getLogger(JetspeedPrincipalManagementEditPortlet.class);
     IModel getProfileList = new LoadableDetachableModel()
     {
@@ -73,6 +77,45 @@ public class JetspeedPrincipalManagement
             return getRoles();
         }
     };
+    IModel getRoleNamesAndEmpty = new LoadableDetachableModel()
+    {
+        protected Object load()
+        {
+            List<String> roles = new ArrayList<>();
+            roles.add("");
+            roles.addAll(getRoles());
+            return roles;
+        }
+    };
+    IModel getGroupNames = new LoadableDetachableModel()
+    {
+        protected Object load()
+        {
+            return getGroups();
+        }
+    };
+    IModel getGroupNamesAndEmpty = new LoadableDetachableModel()
+    {
+        protected Object load()
+        {
+            List<String> groups = new ArrayList<>();
+            groups.add("");
+            groups.addAll(getGroups());
+            return groups;
+        }
+    };
+    IModel getGroupNamesAndManagerPrefix = new LoadableDetachableModel()
+    {
+        protected Object load()
+        {
+            List<String> groups = new ArrayList<>();
+            groups.add("");
+            groups.add(JetspeedPrincipalManagementPortlet.GROUP_MANAGER_PREFIX_FLAG);
+            groups.addAll(getGroups());
+            return groups;
+        }
+    };
+
     IModel getSubSites = new LoadableDetachableModel()
     {
         protected Object load()
@@ -84,23 +127,42 @@ public class JetspeedPrincipalManagement
     public JetspeedPrincipalManagementEditPortlet()
     {
         PortletRequest request = ((AbstractAdminWebApplication) getApplication()).getPortletRequest();
-        subite = request.getPreferences().getValue(JetspeedPrincipalManagementPortlet.DEFAULT_SUBSITE,
"");
+        subsite = request.getPreferences().getValue(JetspeedPrincipalManagementPortlet.DEFAULT_SUBSITE,
"");
         profile = request.getPreferences().getValue(JetspeedPrincipalManagementPortlet.DEFAULT_PROFILE,
"");
         role = request.getPreferences().getValue(JetspeedPrincipalManagementPortlet.DEFAULT_ROLE,
"");
+        requiredRole = request.getPreferences().getValue(JetspeedPrincipalManagementPortlet.REQUIRED_ROLE,
"");
+        requiredGroup = request.getPreferences().getValue(JetspeedPrincipalManagementPortlet.REQUIRED_GROUP,
"");
+        filteredRole = request.getPreferences().getValue(JetspeedPrincipalManagementPortlet.FILTERED_ROLE,
"");
+        filteredGroup = request.getPreferences().getValue(JetspeedPrincipalManagementPortlet.FILTERED_GROUP,
"");
         templateDir = request.getPreferences().getValue(JetspeedPrincipalManagementPortlet.NEW_USER_TEMPLATE_DIR,
"");
         subSiteRoot = request.getPreferences().getValue(JetspeedPrincipalManagementPortlet.SUB_SITE_ROOT,
"");
+        rowsPerPage = Integer.parseInt(request.getPreferences().getValue(JetspeedPrincipalManagementPortlet.ROWS_PER_PAGE,
"10"));
         add(new FeedbackPanel("feedback"));
         Form userPrefernces = new Form("userPrefernces");
         userPrefernces.add(new Label("subsiterootLabel", new ResourceModel("subsiteroot")));
         userPrefernces.add(new TextField("subsiteroot", new PropertyModel(this, "subSiteRoot")));
       
         userPrefernces.add(new Label("subsiteLabel", new ResourceModel("default.subsite")));
-        userPrefernces.add(new DropDownChoice("defaultSubSite", new PropertyModel(this, "subite"),getSubSites));
+        userPrefernces.add(new DropDownChoice("defaultSubSite", new PropertyModel(this, "subsite"),getSubSites));
         userPrefernces.add(new Label("templateDirLabel", new ResourceModel("templatedir")));
-        userPrefernces.add(new RequiredTextField("templateDir", new PropertyModel(this, "templateDir")));
+        //userPrefernces.add(new RequiredTextField("templateDir", new PropertyModel(this,
"templateDir")));
+        userPrefernces.add(new TextField("templateDir", new PropertyModel(this, "templateDir")));
         userPrefernces.add(new Label("profileLabel", new ResourceModel("default.profile")));
         userPrefernces.add(new DropDownChoice("profile", new PropertyModel(this, "profile"),
getProfileList));
         userPrefernces.add(new Label("roleLabel", new ResourceModel("default.role")));
         userPrefernces.add(new DropDownChoice("role", new PropertyModel(this, "role"), getRoleNames));
+
+        userPrefernces.add(new Label("requiredRoleLabel", new ResourceModel("required.role")));
+        userPrefernces.add(new DropDownChoice("requiredRole", new PropertyModel(this, "requiredRole"),
getRoleNamesAndEmpty));
+        userPrefernces.add(new Label("requiredGroupLabel", new ResourceModel("required.group")));
+        userPrefernces.add(new DropDownChoice("requiredGroup", new PropertyModel(this, "requiredGroup"),
getGroupNamesAndEmpty));
+
+        userPrefernces.add(new Label("filteredRoleLabel", new ResourceModel("filtered.role")));
+        userPrefernces.add(new DropDownChoice("filteredRole", new PropertyModel(this, "filteredRole"),
getRoleNamesAndEmpty));
+        userPrefernces.add(new Label("filteredGroupLabel", new ResourceModel("filtered.group")));
+        userPrefernces.add(new DropDownChoice("filteredGroup", new PropertyModel(this, "filteredGroup"),
getGroupNamesAndManagerPrefix));
+
+        userPrefernces.add(new Label("rowsPerPageLabel", new ResourceModel("rowsPerPage")));
+        userPrefernces.add(new TextField("rowsPerPage", new PropertyModel(this, "rowsPerPage")));
         userPrefernces.add(new Button("addUserPrefernces", new ResourceModel("common.save"))
         {
             @Override
@@ -112,14 +174,25 @@ public class JetspeedPrincipalManagement
                     if (log.isDebugEnabled())
                     {
                         log.debug("Setting default role as " + getRole());
-                        log.debug("Setting default subsite as " + getSubite());
-                        log.debug("Setting default profile as " + getSubite());
+                        log.debug("Setting default subsite as " + getSubsite());
+                        log.debug("Setting default profile as " + getSubsite());
                     }
                     request.getPreferences().setValue(JetspeedPrincipalManagementPortlet.DEFAULT_ROLE,
getRole());
-                    request.getPreferences().setValue(JetspeedPrincipalManagementPortlet.DEFAULT_SUBSITE,
getSubite());
+                    request.getPreferences().setValue(JetspeedPrincipalManagementPortlet.DEFAULT_SUBSITE,
getSubsite());
                     request.getPreferences().setValue(JetspeedPrincipalManagementPortlet.DEFAULT_PROFILE,
getProfile());
                     request.getPreferences().setValue(JetspeedPrincipalManagementPortlet.NEW_USER_TEMPLATE_DIR,
getTemplateDir());
                     request.getPreferences().setValue(JetspeedPrincipalManagementPortlet.SUB_SITE_ROOT,
getSubSiteRoot());
+
+                    request.getPreferences().setValue(JetspeedPrincipalManagementPortlet.REQUIRED_ROLE,
getRequiredRole());
+                    request.getPreferences().setValue(JetspeedPrincipalManagementPortlet.REQUIRED_GROUP,
getRequiredGroup());
+                    request.getPreferences().setValue(JetspeedPrincipalManagementPortlet.FILTERED_ROLE,
getFilteredRole());
+                    request.getPreferences().setValue(JetspeedPrincipalManagementPortlet.FILTERED_GROUP,
getFilteredGroup());
+
+                    int rows = getRowsPerPage();
+                    if (rows < 1) {
+                        rows = 10;
+                    }
+                    request.getPreferences().setValue(JetspeedPrincipalManagementPortlet.ROWS_PER_PAGE,
Integer.toString(rows));
                     request.getPreferences().store();
                     if (log.isDebugEnabled())
                     {
@@ -156,20 +229,20 @@ public class JetspeedPrincipalManagement
     }
 
     /**
-     * @return the subite
+     * @return the subsite
      */
-    public String getSubite()
+    public String getSubsite()
     {
-        return subite;
+        return subsite;
     }
 
     /**
-     * @param subite
-     *            the subite to set
+     * @param subsite
+     *            the subsite to set
      */
-    public void setSubite(String subite)
+    public void setSubsite(String subsite)
     {
-        this.subite = subite;
+        this.subsite = subsite;
     }
 
     /**
@@ -223,6 +296,38 @@ public class JetspeedPrincipalManagement
         this.templateDir = templateDir;
     }
 
+    public String getRequiredRole() {
+        return requiredRole;
+    }
+
+    public void setRequiredRole(String requiredRole) {
+        this.requiredRole = requiredRole;
+    }
+
+    public String getRequiredGroup() {
+        return requiredGroup;
+    }
+
+    public void setRequiredGroup(String requiredGroup) {
+        this.requiredGroup = requiredGroup;
+    }
+
+    public String getFilteredRole() {
+        return filteredRole;
+    }
+
+    public void setFilteredRole(String filteredRole) {
+        this.filteredRole = filteredRole;
+    }
+
+    public String getFilteredGroup() {
+        return filteredGroup;
+    }
+
+    public void setFilteredGroup(String filteredGroup) {
+        this.filteredGroup = filteredGroup;
+    }
+
     /**
      * @return the subSiteRootr
      */
@@ -265,6 +370,20 @@ public class JetspeedPrincipalManagement
         return roleNames;
     }
 
+    private List<String> getGroups()
+    {
+        List<String> groupNames = Collections.EMPTY_LIST;
+        try
+        {
+            groupNames = ((AbstractAdminWebApplication) getApplication()).getServiceLocator().getGroupManager().getGroupNames("");
+        }
+        catch (SecurityException e)
+        {
+            error(e.getMessage());
+        }
+        return groupNames;
+    }
+
     private List<String> getSubSites()
     {
         List<String> subsites = new ArrayList<String>();
@@ -296,4 +415,13 @@ public class JetspeedPrincipalManagement
         }
         return subsites;
     }
+
+    public Integer getRowsPerPage() {
+        return rowsPerPage;
+    }
+
+    public void setRowsPerPage(Integer rowsPerPage) {
+        this.rowsPerPage = rowsPerPage;
+    }
+
 }

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=1731003&r1=1731002&r2=1731003&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 Feb 18 04:32:58 2016
@@ -32,6 +32,7 @@ import org.apache.jetspeed.portlets.wick
 import org.apache.jetspeed.profiler.Profiler;
 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.InvalidNewPasswordException;
 import org.apache.jetspeed.security.InvalidPasswordException;
 import org.apache.jetspeed.security.JetspeedPrincipal;
@@ -40,6 +41,7 @@ import org.apache.jetspeed.security.Jets
 import org.apache.jetspeed.security.JetspeedPrincipalType;
 import org.apache.jetspeed.security.PasswordAlreadyUsedException;
 import org.apache.jetspeed.security.PasswordCredential;
+import org.apache.jetspeed.security.Role;
 import org.apache.jetspeed.security.RoleManager;
 import org.apache.jetspeed.security.SecurityAttribute;
 import org.apache.jetspeed.security.SecurityException;
@@ -116,10 +118,15 @@ public class JetspeedPrincipalManagement
     public static final String DEFAULT_SUBSITE = "defaultSubsite";
     public static final String DEFAULT_ROLE = "defaultRole";
     public static final String REQUIRED_ROLE = "requiredRole";
+    public static final String REQUIRED_GROUP = "requiredGroup";
     public static final String DEFAULT_PROFILE = "defaultProfile";
     public static final String NEW_USER_TEMPLATE_DIR = "newUserTemplateDirectory";
     public static final String SUB_SITE_ROOT = "subsiteRootFolder";
-
+    public static final String FILTERED_ROLE = "filteredRole";
+    public static final String FILTERED_GROUP = "filteredGroup";
+    public static final String ROWS_PER_PAGE = "rowsPerPage";
+    public static final String GROUP_MANAGER_PREFIX_FLAG = "mgr-*";
+    public static final String GROUP_MANAGER_PREFIX = "mgr-";
     private static final java.sql.Date MAX_DATE = java.sql.Date.valueOf("2099-01-01");
 
     private String principalParam;
@@ -150,16 +157,22 @@ public class JetspeedPrincipalManagement
                 .getJetspeedPrincipalManagerProvider().getPrincipalType(
                         principalParam);
        
-        String filteredRole = getPreference("filteredRole", "");
+        String filteredRole = getPreference(FILTERED_ROLE, "");
+        String filteredGroup = getPreference(FILTERED_GROUP, "");
+        UserSubjectPrincipal currentUser = (UserSubjectPrincipal)getPortletRequest().getUserPrincipal();
         if (principalParam.equals(JetspeedPrincipalType.USER))
         {
-            principalDataProvider = new PrincipalDataProvider(getManager(), getRoleManager(),
getSearchString(), filteredRole, true);
+            if (!StringUtils.isEmpty(filteredGroup)) {
+                principalDataProvider = new PrincipalDataProvider(currentUser, getManager(),
getGroupManager(), getSearchString(), filteredGroup, false, (RoleManager)getRoleManager());
+            }
+            else {
+                principalDataProvider = new PrincipalDataProvider(currentUser, getManager(),
getRoleManager(), getSearchString(), filteredRole, true, (RoleManager)getRoleManager());
+            }
         }
         else
         {
-            principalDataProvider = new PrincipalDataProvider(getManager(), getSearchString());
+            principalDataProvider = new PrincipalDataProvider(currentUser, getManager(),
getSearchString());
         }
-        
         ITab tab = null;
         tabs = new ArrayList();
         group = new WebMarkupContainer("group");
@@ -186,7 +199,9 @@ public class JetspeedPrincipalManagement
                 item.add(editLink);
             }
         };
-        principalView.setItemsPerPage(10);
+        Integer rowsPerPage = getPreferenceAsInteger(ROWS_PER_PAGE, 10);
+
+        principalView.setItemsPerPage(rowsPerPage);
         group.add(principalView);
 
         OrderByLink orderLink = new OrderByLink("nameOrderLink", "name", principalDataProvider,VoidCssProvider.getInstance())
@@ -252,8 +267,14 @@ public class JetspeedPrincipalManagement
 
     public void setSearchString(String searchString)
     {
-        this.searchString = (searchString == null ? "" : searchString.trim());        
-        principalDataProvider.refresh(getManager(),getRoleManager(),searchString);
+        this.searchString = (searchString == null ? "" : searchString.trim());
+        String filteredGroup = getPreference(FILTERED_GROUP, "");
+        if (!StringUtils.isEmpty(filteredGroup)) {
+            principalDataProvider.refresh(getManager(), getGroupManager(), searchString,
(RoleManager)getRoleManager());
+        }
+        else {
+            principalDataProvider.refresh(getManager(), getRoleManager(), searchString, (RoleManager)getRoleManager());
+        }
         setPrincipal(null);
         controlPannels(false);
     }
@@ -336,7 +357,13 @@ public class JetspeedPrincipalManagement
                         getPrincipal().setEnabled(isUserEnabled());
                         getManager().updatePrincipal(principal);
                         setPrincipal(principal);
-                        principalDataProvider.refresh(getManager(),getRoleManager(),getSearchString());
+                        String filteredGroup = getPreference(FILTERED_GROUP, "");
+                        if (!StringUtils.isEmpty(filteredGroup)) {
+                            principalDataProvider.refresh(getManager(), getGroupManager(),
getSearchString(), (RoleManager)getRoleManager());
+                        }
+                        else {
+                            principalDataProvider.refresh(getManager(), getRoleManager(),
getSearchString(), (RoleManager)getRoleManager());
+                        }
                     }
                     catch (SecurityException jSx)
                     {
@@ -355,7 +382,13 @@ public class JetspeedPrincipalManagement
                         getManager().removePrincipal(principal.getName());
                         setPrincipal(null);
                         controlPannels(false);
-                        principalDataProvider.refresh(getManager(),getRoleManager(),getSearchString());
+                        String filteredGroup = getPreference(FILTERED_GROUP, "");
+                        if (!StringUtils.isEmpty(filteredGroup)) {
+                            principalDataProvider.refresh(getManager(), getGroupManager(),
getSearchString(), (RoleManager)getRoleManager());
+                        }
+                        else {
+                            principalDataProvider.refresh(getManager(), getRoleManager(),
getSearchString(), (RoleManager)getRoleManager());
+                        }
                     }
                     catch (SecurityException e)
                     {
@@ -687,10 +720,13 @@ public class JetspeedPrincipalManagement
             
             final String defaultRole = preferences.getValue(DEFAULT_ROLE ,"");
             final String requiredRole = preferences.getValue(REQUIRED_ROLE, "");
+            final String requiredGroup = preferences.getValue(REQUIRED_GROUP, "");
             final String defaultProfile = preferences.getValue(DEFAULT_PROFILE ,"");
             final String defaultSubsite = preferences.getValue(DEFAULT_SUBSITE ,"");
             final String templateFolder = preferences.getValue(NEW_USER_TEMPLATE_DIR, "");
             final String subsiteRoot = preferences.getValue(SUB_SITE_ROOT,"");
+            final String filteredGroup = preferences.getValue(JetspeedPrincipalManagementPortlet.FILTERED_GROUP,
"");
+
             profilingRule = defaultProfile.toString();
             
             add(new FeedbackPanel("feedback"));
@@ -722,6 +758,7 @@ public class JetspeedPrincipalManagement
                     JetspeedPrincipal principal = getManager().newPrincipal(
                             getUserName(), false);
                     RoleManager roleManager = ((AbstractAdminWebApplication)getApplication()).getServiceLocator().getRoleManager();
+                    GroupManager groupManager = ((AbstractAdminWebApplication)getApplication()).getServiceLocator().getGroupManager();
                     PageManager pageManager = ((AbstractAdminWebApplication) getApplication()).getServiceLocator().getPageManager();
                     try
                     {
@@ -736,7 +773,26 @@ public class JetspeedPrincipalManagement
                         {
                             roleManager.addRoleToUser(getUserName(), requiredRole);
                         }
-                        
+
+                        // if using mgr-* filteredGroup, always add the * part of the convention
+                        // for example, if filteredGroup == mgr-engineering, then the 'engineering'
group will be auto-added
+                        if (!StringUtils.isEmpty(filteredGroup) && filteredGroup.equals(GROUP_MANAGER_PREFIX_FLAG))
{
+                            UserSubjectPrincipal currentUser = (UserSubjectPrincipal)getPortletRequest().getUserPrincipal();
+                            List<Role> roles = roleManager.getRolesForUser(currentUser.getName());
+                            for (Role role : roles)
+                            {
+                                if (role.getName().startsWith(JetspeedPrincipalManagementPortlet.GROUP_MANAGER_PREFIX))
+                                {
+                                    String targetGroup = role.getName().substring(JetspeedPrincipalManagementPortlet.GROUP_MANAGER_PREFIX.length());
+                                    groupManager.addUserToGroup(getUserName(), targetGroup);
+                                }
+                            }
+                        }
+                        if(!StringUtils.isEmpty(requiredGroup))
+                        {
+                            groupManager.addUserToGroup(getUserName(), requiredGroup);
+                        }
+
                         Profiler profiler = getServiceLocator().getProfiler();
                         
                         if (!StringUtils.isEmpty(getProfilingRule()))
@@ -828,7 +884,13 @@ public class JetspeedPrincipalManagement
                     {
                         log.error("Failed to update user.", jSx);
                     }
-                    principalDataProvider.refresh(getManager(),getRoleManager(),getSearchString());
+                    String filteredGroup = getPreference(FILTERED_GROUP, "");
+                    if (!StringUtils.isEmpty(filteredGroup)) {
+                        principalDataProvider.refresh(getManager(), getGroupManager(), getSearchString(),
(RoleManager)getRoleManager());
+                    }
+                    else {
+                        principalDataProvider.refresh(getManager(), getRoleManager(), getSearchString(),
(RoleManager)getRoleManager());
+                    }
                 }
             };
             userForm.add(newUser);
@@ -2061,13 +2123,13 @@ public class JetspeedPrincipalManagement
         return nameList;
     }
 
-    private void controlPannels(boolean userSelecteed)
+    private void controlPannels(boolean userSelected)
     {
         TabbedPanel panel = (TabbedPanel) get("tabs");
         ITab tab;
         panel.getTabs().clear();
         boolean guestUserSelected;
-        if (userSelecteed)
+        if (userSelected)
         {
             if (principalType.getName().equals(JetspeedPrincipalType.USER))
             {
@@ -2214,7 +2276,12 @@ public class JetspeedPrincipalManagement
     {
         return (JetspeedPrincipalManager) getServiceLocator().getRoleManager();
     }
-    
+
+    private JetspeedPrincipalManager getGroupManager()
+    {
+        return (JetspeedPrincipalManager) getServiceLocator().getGroupManager();
+    }
+
     private static boolean hasPrincipal(Subject subject, JetspeedPrincipal jp)
     {
         Iterator<Principal> principals = subject.getPrincipals().iterator();

Modified: portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/security/PrincipalDataProvider.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/security/PrincipalDataProvider.java?rev=1731003&r1=1731002&r2=1731003&view=diff
==============================================================================
--- portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/security/PrincipalDataProvider.java
(original)
+++ portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/security/PrincipalDataProvider.java
Thu Feb 18 04:32:58 2016
@@ -16,24 +16,27 @@
  */
 package org.apache.jetspeed.portlets.security;
 
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.Iterator;
-import java.util.List;
-
 import org.apache.commons.lang.StringUtils;
+import org.apache.jetspeed.security.Group;
+import org.apache.jetspeed.security.GroupManager;
 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.jetspeed.security.UserSubjectPrincipal;
 import org.apache.wicket.extensions.markup.html.repeater.util.SortableDataProvider;
 import org.apache.wicket.markup.repeater.data.IDataProvider;
 import org.apache.wicket.model.IModel;
 import org.apache.wicket.model.Model;
 
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.List;
+
 public class PrincipalDataProvider extends SortableDataProvider<JetspeedPrincipal>
implements IDataProvider<JetspeedPrincipal>
 {
     
@@ -47,18 +50,33 @@ public class PrincipalDataProvider exten
     private OrderBy order = OrderBy.NAME_ASC;
     private List<JetspeedPrincipal> principalList = new ArrayList<JetspeedPrincipal>();
     private boolean roleFilter = false;
+    private boolean groupFilter = false;
     private String filteredRole;
+    private String filteredGroup;
+    private UserSubjectPrincipal currentUser;
 
-    public PrincipalDataProvider(JetspeedPrincipalManager manager, String search)
+    public PrincipalDataProvider(UserSubjectPrincipal currentUser, JetspeedPrincipalManager
manager, String search)
     {
+        this.currentUser = currentUser;
         refresh(manager, search);
     }
 
-    public PrincipalDataProvider(JetspeedPrincipalManager manager, JetspeedPrincipalManager
roleManager, String search, String filteredRole, boolean roleFlter)
+    public PrincipalDataProvider(UserSubjectPrincipal currentUser, JetspeedPrincipalManager
manager, JetspeedPrincipalManager roleOrGroupManager, String search, String filteredRoleOrGroup,
boolean isRoleFilter, RoleManager roleManager)
     {
-        this.filteredRole = filteredRole;
-        this.roleFilter = roleFlter;
-        refresh(manager, roleManager, search);
+        this.currentUser = currentUser;
+        if (isRoleFilter) { // can be either role or group filter
+            this.filteredRole = filteredRoleOrGroup;
+            this.filteredGroup = "";
+            this.roleFilter = true;
+            this.groupFilter = false;
+        }
+        else {
+            this.filteredGroup = filteredRoleOrGroup;
+            this.filteredRole = "";
+            this.roleFilter = false;
+            this.groupFilter = true;
+        }
+        refresh(manager, roleOrGroupManager, search, roleManager);
     }
 
     public Iterator<? extends JetspeedPrincipal> iterator(int first, int count)
@@ -101,11 +119,11 @@ public class PrincipalDataProvider exten
         principalList = (List<JetspeedPrincipal>) manager.getPrincipals(searchString);
     }
 
-    public void refresh(JetspeedPrincipalManager manager, JetspeedPrincipalManager roleManager,
String searchString)
+    public void refresh(JetspeedPrincipalManager manager, JetspeedPrincipalManager assocManager,
String searchString, RoleManager roleManager)
     {
         if (roleFilter && !StringUtils.isEmpty(filteredRole))
         {
-            if (roleManager.getPrincipal(filteredRole) == null)
+            if (assocManager.getPrincipal(filteredRole) == null)
             {
                 principalList = new ArrayList<JetspeedPrincipal>();
             }
@@ -117,7 +135,7 @@ public class PrincipalDataProvider exten
                 {
                     try
                     {
-                        List<Role> roles = ((RoleManager) roleManager).getRolesForUser(principal.getName());
+                        List<Role> roles = ((RoleManager) assocManager).getRolesForUser(principal.getName());
                         for (Role role : roles)
                         {
                             if (role.getName().equals(filteredRole))
@@ -133,6 +151,58 @@ public class PrincipalDataProvider exten
                     }
                 }
             }
+        }
+        else if (groupFilter && !StringUtils.isEmpty(filteredGroup))
+        {
+            if (!filteredGroup.equals(JetspeedPrincipalManagementPortlet.GROUP_MANAGER_PREFIX_FLAG)
&& assocManager.getPrincipal(filteredGroup) == null)
+            {
+                principalList = new ArrayList<JetspeedPrincipal>();
+            }
+            else
+            {
+                principalList = new ArrayList<JetspeedPrincipal>();
+                if (filteredGroup.equals(JetspeedPrincipalManagementPortlet.GROUP_MANAGER_PREFIX_FLAG)
&& roleManager != null) {
+                    try {
+                        List<Role> roles = roleManager.getRolesForUser(currentUser.getName());
+                        for (Role role : roles)
+                        {
+                            if (role.getName().startsWith(JetspeedPrincipalManagementPortlet.GROUP_MANAGER_PREFIX))
+                            {
+                                String targetGroup = role.getName().substring(JetspeedPrincipalManagementPortlet.GROUP_MANAGER_PREFIX.length());
+                                // filter users by target group
+                                List<JetspeedPrincipal> localList = (List<JetspeedPrincipal>)
manager.getPrincipals(searchString);
+                                for (JetspeedPrincipal principal : localList) {
+                                    List<Group> groups = ((GroupManager) assocManager).getGroupsForUser(principal.getName());
+                                    for (Group group : groups) {
+                                        if (group.getName().equals(targetGroup)) {
+                                            principalList.add(principal);
+                                            break;
+                                        }
+                                    }
+                                }
+                            }
+                        }
+                    } catch (SecurityException e) {
+                        principalList = new ArrayList<JetspeedPrincipal>();
+                    }
+                }
+                else {
+                    List<JetspeedPrincipal> localList = (List<JetspeedPrincipal>)
manager.getPrincipals(searchString);
+                    for (JetspeedPrincipal principal : localList) {
+                        try {
+                            List<Group> groups = ((GroupManager) assocManager).getGroupsForUser(principal.getName());
+                            for (Group group : groups) {
+                                if (group.getName().equals(filteredGroup)) {
+                                    principalList.add(principal);
+                                    break;
+                                }
+                            }
+                        } catch (SecurityException e) {
+                            principalList = new ArrayList<JetspeedPrincipal>();
+                        }
+                    }
+                }
+            }
         }
         else
         {

Modified: portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/wicket/AbstractAdminWebApplication.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/wicket/AbstractAdminWebApplication.java?rev=1731003&r1=1731002&r2=1731003&view=diff
==============================================================================
--- portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/wicket/AbstractAdminWebApplication.java
(original)
+++ portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/wicket/AbstractAdminWebApplication.java
Thu Feb 18 04:32:58 2016
@@ -16,16 +16,6 @@
  */
 package org.apache.jetspeed.portlets.wicket;
 
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.security.Principal;
-
-import javax.portlet.PortletConfig;
-import javax.portlet.PortletPreferences;
-import javax.portlet.PortletRequest;
-import javax.portlet.PortletResponse;
-import javax.portlet.RenderResponse;
-
 import org.apache.jetspeed.portlets.JetspeedServiceLocator;
 import org.apache.wicket.RequestContext;
 import org.apache.wicket.WicketRuntimeException;
@@ -35,6 +25,15 @@ import org.apache.wicket.util.resource.I
 import org.apache.wicket.util.resource.UrlResourceStream;
 import org.apache.wicket.util.resource.locator.ResourceStreamLocator;
 
+import javax.portlet.PortletConfig;
+import javax.portlet.PortletPreferences;
+import javax.portlet.PortletRequest;
+import javax.portlet.PortletResponse;
+import javax.portlet.RenderResponse;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.security.Principal;
+
 /**
  * Abstract Admin Wicket Application
  * <P>
@@ -215,6 +214,12 @@ public abstract class AbstractAdminWebAp
         return (preferenceValue != null ? Integer.parseInt(preferenceValue) : 0);
     }
 
+    public int getPreferenceValueAsInteger(String key, int defaultValue)
+    {
+        String preferenceValue = getPreferenceValue(key);
+        return (preferenceValue != null ? Integer.parseInt(preferenceValue) : defaultValue);
+    }
+
     public boolean getPreferenceValueAsBoolean(String key)
     {
         String preferenceValue = getPreferenceValue(key);

Modified: portals/jetspeed-2/applications/j2-admin/trunk/src/main/resources/org/apache/jetspeed/portlets/security/JetspeedPrincipalManagementEditPortlet.html
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/applications/j2-admin/trunk/src/main/resources/org/apache/jetspeed/portlets/security/JetspeedPrincipalManagementEditPortlet.html?rev=1731003&r1=1731002&r2=1731003&view=diff
==============================================================================
--- portals/jetspeed-2/applications/j2-admin/trunk/src/main/resources/org/apache/jetspeed/portlets/security/JetspeedPrincipalManagementEditPortlet.html
(original)
+++ portals/jetspeed-2/applications/j2-admin/trunk/src/main/resources/org/apache/jetspeed/portlets/security/JetspeedPrincipalManagementEditPortlet.html
Thu Feb 18 04:32:58 2016
@@ -1,4 +1,5 @@
-<!-- 
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
   Licensed to the Apache Software Foundation (ASF) under one or more
   contributor license agreements.  See the NOTICE file distributed with
   this work for additional information regarding copyright ownership.
@@ -16,15 +17,13 @@
   
   Author <a href="mailto:vkumar@apache.org">Vivek Kumar</a>
  -->
-<?xml version="1.0" encoding="UTF-8"?>
-
 <html xmlns="http://www.w3.org/1999/xhtml" >
 	<div wicket:id="feedback"></div>
     <form wicket:id="userPrefernces">
-        <table  cellpadding="0" cellspacing="1" border="1" width="300px">
+        <table  cellpadding="0" cellspacing="1" border="1" >
             <tr>
                 <td><span wicket:id="subsiterootLabel"/></td>
-                <td><input type="text" wicket:id="subsiteroot" class="portlet-form-field-label"
/></td>				            
+                <td><input type="text" wicket:id="subsiteroot" size="50" class="portlet-form-field-label"
/></td>
             </tr>
             <tr>
                 <td><span wicket:id="subsiteLabel"/></td>
@@ -33,7 +32,7 @@
             
             <tr>
                 <td><span wicket:id="templateDirLabel"/></td>
-                <td><input type="text" wicket:id="templateDir" class="portlet-form-field-label"
/></td>				
+                <td><input type="text" wicket:id="templateDir" size="50" class="portlet-form-field-label"
/></td>
             </tr>            
             <tr>
                 <td><span wicket:id="profileLabel"/></td>
@@ -44,7 +43,23 @@
                 <td><select wicket:id="role"></select></td>				
             </tr>
             <tr>
-                <td colspan="2"><input type="submit" wicket:id="addUserPrefernces"
/></td>			
+                <td><span wicket:id="requiredRoleLabel"/></td>
+                <td><select wicket:id="requiredRole"></select></td>
+            </tr>
+            <tr>
+                <td><span wicket:id="filteredRoleLabel"/></td>
+                <td><select wicket:id="filteredRole"></select></td>
+            </tr>
+            <tr>
+                <td><span wicket:id="filteredGroupLabel"/></td>
+                <td><select wicket:id="filteredGroup"></select></td>
+            </tr>
+            <tr>
+                <td><span wicket:id="rowsPerPageLabel"/></td>
+                <td><input wicket:id="rowsPerPage" size="10"/></td>
+            </tr>
+            <tr>
+                <td colspan="2"><input type="submit" wicket:id="addUserPrefernces"
/></td>
             </tr>
         </table>    
     </form>

Modified: portals/jetspeed-2/applications/j2-admin/trunk/src/main/resources/org/apache/jetspeed/portlets/security/resources/JetspeedPrincipalManagement.properties
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/applications/j2-admin/trunk/src/main/resources/org/apache/jetspeed/portlets/security/resources/JetspeedPrincipalManagement.properties?rev=1731003&r1=1731002&r2=1731003&view=diff
==============================================================================
--- portals/jetspeed-2/applications/j2-admin/trunk/src/main/resources/org/apache/jetspeed/portlets/security/resources/JetspeedPrincipalManagement.properties
(original)
+++ portals/jetspeed-2/applications/j2-admin/trunk/src/main/resources/org/apache/jetspeed/portlets/security/resources/JetspeedPrincipalManagement.properties
Thu Feb 18 04:32:58 2016
@@ -75,7 +75,10 @@ default.profile=Default profile
 default.subsite=Default sub-site
 subsiteroot =Sub site root
 templatedir =New User template directory
-
+rowsPerPage=Rows Per Page
+required.role=Required Role
+filtered.role=Filtered Role
+filtered.group=Filtered Group
 JetspeedPrincipalManagementPortlet$PrincipalNameValidator=User already exists, cannot add
new user
 chgpwd.error.invalidPassword=Current password invalid
 chgpwd.error.invalidNewPassword=Invalid new password

Modified: portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/WEB-INF/jetspeed-portlet.xml
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/WEB-INF/jetspeed-portlet.xml?rev=1731003&r1=1731002&r2=1731003&view=diff
==============================================================================
--- portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/WEB-INF/jetspeed-portlet.xml
(original)
+++ portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/WEB-INF/jetspeed-portlet.xml
Thu Feb 18 04:32:58 2016
@@ -25,7 +25,7 @@
   <dc:title xml:lang="en">Jetspeed-2 Administration
     Portlets</dc:title>
   <dc:creator>J2 Team</dc:creator>
-  <js:metadata name="pa-version">2.2</js:metadata>
+  <js:metadata name="pa-version">2.3.1</js:metadata>
 
   <portlet>
     <portlet-name>LoginPortlet</portlet-name>




---------------------------------------------------------------------
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