Removed depcrecated package com/arsdigita/cms/ui/permissions from ccm-cms

pull/28/head
Jens Pelzetter 2022-03-17 19:10:56 +01:00
parent b9dc94e48b
commit 9d16918052
20 changed files with 22 additions and 3428 deletions

View File

@ -19,7 +19,6 @@
package com.arsdigita.cms.ui;
import com.arsdigita.bebop.ActionLink;
import com.arsdigita.bebop.Form;
import com.arsdigita.bebop.FormProcessException;
import com.arsdigita.bebop.Label;
import com.arsdigita.bebop.Page;
@ -35,8 +34,6 @@ import com.arsdigita.bebop.event.ChangeListener;
import com.arsdigita.bebop.event.FormProcessListener;
import com.arsdigita.bebop.event.FormSectionEvent;
import com.arsdigita.bebop.event.FormSubmissionListener;
import com.arsdigita.bebop.event.PrintEvent;
import com.arsdigita.bebop.event.PrintListener;
import com.arsdigita.bebop.parameters.LongParameter;
import com.arsdigita.bebop.parameters.StringParameter;
import com.arsdigita.cms.CMS;
@ -51,7 +48,6 @@ import com.arsdigita.cms.ui.folder.FolderManipulator;
import com.arsdigita.cms.ui.folder.FolderPath;
import com.arsdigita.cms.ui.folder.FolderRequestLocal;
import com.arsdigita.cms.ui.folder.FolderSelectionModel;
import com.arsdigita.cms.ui.permissions.CMSPermissionsPane;
import com.arsdigita.globalization.GlobalizedMessage;
import com.arsdigita.toolbox.ui.ActionGroup;
@ -82,31 +78,45 @@ public class FlatItemList extends SegmentedPanel implements FormProcessListener,
ActionListener {
private static final String CONTENT_TYPE_ID = "ct";
// The folder selectors
private final FolderSelectionModel folderSelectionModel;
private final FolderRequestLocal folderRequestLocal;
private final NewItemForm newItemForm;
private final SingleSelectionModel<Long> typeSelectionModel;
private final CreationSelector creationSelector;
private final FolderManipulator folderManipulator;
private final FolderCreateForm folderCreator;
// private final ActionLink m_setHomeFolderAction;
// private final ActionLink m_removeHomeFolderAction;
private final ActionLink createFolderAction;
// private final ActionLink togglePrivateAction;
// private final Label m_homeFolderLabel;
private final Segment browseSegment;
private final Segment newItemSegment;
private final Segment newFolderSegment;
private final Segment editFolderSegment;
private final Segment permissionsSegment;
private final CMSPermissionsPane permissionsPane;
// Folder edit/rename functionality.
private final ActionLink editFolderAction;
private final FolderEditorForm folderEditor;
private final Label contentLabel;
private final FolderPath folderPath;
private final Label chooseLabel;
private final StringParameter selectedLanguageParam;
/**
@ -180,8 +190,9 @@ public class FlatItemList extends SegmentedPanel implements FormProcessListener,
permissionsSegment.addHeader(new Label(new GlobalizedMessage(
"cms.ui.permissions", CmsConstants.CMS_BUNDLE)));
selectedLanguageParam = new StringParameter(ContentItemPage.SELECTED_LANGUAGE);
selectedLanguageParam = new StringParameter(
ContentItemPage.SELECTED_LANGUAGE);
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final PermissionManager permissionManager = cdiUtil.findBean(
PermissionManager.class);
@ -190,12 +201,6 @@ public class FlatItemList extends SegmentedPanel implements FormProcessListener,
final Map<String, String> privNameMap = new HashMap<>();
privileges.forEach(privilege -> privNameMap.put(privilege, privilege));
permissionsPane = new CMSPermissionsPane(
privileges.toArray(new String[]{}),
privNameMap,
(CcmObjectSelectionModel) folderSelectionModel);
permissionActions.setSubject(permissionsPane);
newItemSegment.addHeader(new Label(globalize("cms.ui.new_item")));
typeSelectionModel = new ParameterSingleSelectionModel<>(
new LongParameter(CONTENT_TYPE_ID));
@ -408,8 +413,6 @@ public class FlatItemList extends SegmentedPanel implements FormProcessListener,
PermissionChecker.class);
permissionChecker.checkPermission(ItemPrivileges.ADMINISTER,
currentFolder);
permissionsPane.reset(state);
}
@Override
@ -419,17 +422,12 @@ public class FlatItemList extends SegmentedPanel implements FormProcessListener,
// switching between folders used to keep showing the permission pane
// in the same perm mode (direct or inherited) regardless
// of the folder status
permissionsPane.reset(state);
}
public final FolderManipulator getManipulator() {
return folderManipulator;
}
public final CMSPermissionsPane getPermissionsPane() {
return permissionsPane;
}
public void setPermissionLinkVis(final PageState state) {
// final Folder currentFolder = folderRequestLocal.getFolder(state);
// final CdiUtil cdiUtil = CdiUtil.createCdiUtil();

View File

@ -1,69 +0,0 @@
/*
* Copyright (C) 2017 LibreCCM Foundation.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
package com.arsdigita.cms.ui.permissions;
/**
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
class CMSDirectPermissionsTableRow {
private long granteeKey;
private String granteeName;
private boolean permitted;
private UserPrivilegeKey userPrivilegeKey;
public long getGranteeKey() {
return granteeKey;
}
protected void setGranteeKey(final long granteeKey) {
this.granteeKey = granteeKey;
}
public String getGranteeName() {
return granteeName;
}
protected void setGranteeName(final String granteeName) {
this.granteeName = granteeName;
}
public boolean isPermitted() {
return permitted;
}
protected void setPermitted(final boolean permitted) {
this.permitted = permitted;
}
public UserPrivilegeKey getUserPrivilegeKey() {
return userPrivilegeKey;
}
protected void setUserPrivilegeKey(final UserPrivilegeKey userPrivilegeKey) {
this.userPrivilegeKey = userPrivilegeKey;
}
}

View File

@ -1,167 +0,0 @@
/*
* Copyright (C) 2002-2004 Red Hat Inc. All Rights Reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
package com.arsdigita.cms.ui.permissions;
import com.arsdigita.globalization.GlobalizedMessage;
import org.librecms.contentsection.privileges.ItemPrivileges;
/**
* This interface is used to centralise constants and labels used in the
* Permissions UI package.
*
* @author Stefan Deusch (stefan@arsdigita.com)
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
class CMSPermissionsConstants {
private CMSPermissionsConstants() {
//Nothing
}
/**
* These are our five default privileges.
*/
public static final String[] DEFAULT_PRIVILEGES = new String[]{
ItemPrivileges.VIEW_PUBLISHED,
ItemPrivileges.EDIT,
ItemPrivileges.CREATE_NEW,
ItemPrivileges.DELETE,};
public static final String BUNDLE_NAME
= "com.arsdigita.ui.permissions.PermissionsResources";
public static final GlobalizedMessage SEARCH_LABEL = new GlobalizedMessage(
"permissions.userSearchForm.label", BUNDLE_NAME);
public static final GlobalizedMessage SEARCH_BUTTON = new GlobalizedMessage(
"permissions.button.search", BUNDLE_NAME);
public static final GlobalizedMessage SAVE_BUTTON = new GlobalizedMessage(
"permissions.button.save", BUNDLE_NAME);
public static final GlobalizedMessage NO_RESULTS = new GlobalizedMessage(
"permissions.userSearchForm.noResults", BUNDLE_NAME);
// Direct / Indirect permissions
public static final GlobalizedMessage PERM_TABLE_DIRECT_HEADING
= new GlobalizedMessage(
"permissions.directPermissions.heading", BUNDLE_NAME);
public static final GlobalizedMessage PERM_TABLE_DIRECT_EXPLANATION
= new GlobalizedMessage(
"permissions.directPermissions.explanation", BUNDLE_NAME);
public static final GlobalizedMessage PERM_TABLE_INDIRECT_HEADING
= new GlobalizedMessage(
"permissions.indirectPermissions.heading", BUNDLE_NAME);
public static final GlobalizedMessage PERM_TABLE_INDIRECT_EXPLANATION
= new GlobalizedMessage(
"permissions.indirectPermissions.explanation", BUNDLE_NAME);
public static final GlobalizedMessage PERM_TABLE_INDIRECT_CONTEXT
= new GlobalizedMessage(
"permissions.indirectPermissions.context", BUNDLE_NAME);
public static final GlobalizedMessage PERM_TABLE_GRANTEE
= new GlobalizedMessage(
"permissions.table.grantee", BUNDLE_NAME);
public static final GlobalizedMessage PERM_TABLE_ACTIONS
= new GlobalizedMessage(
"permissions.table.actions", BUNDLE_NAME);
public static final GlobalizedMessage REMOVE_ALL_CONFIRM
= new GlobalizedMessage(
"permissions.table.actions.removeAll", BUNDLE_NAME);
public static final GlobalizedMessage PERM_TABLE_INHERITED
= new GlobalizedMessage(
"permissions.table.inherited", BUNDLE_NAME);
public static final GlobalizedMessage PERM_TABLE_NO_PARENT_CONTEXT
= new GlobalizedMessage(
"permissions.table.parent.context.null", BUNDLE_NAME);
// Permissions header
public static final GlobalizedMessage PAGE_TITLE = new GlobalizedMessage(
"permissions.one.title", BUNDLE_NAME);
public static final GlobalizedMessage MAIN_SITE = new GlobalizedMessage(
"permissions.main.site", BUNDLE_NAME);
public static final GlobalizedMessage PERSONAL_SITE = new GlobalizedMessage(
"permissions.personal.site", BUNDLE_NAME);
public static final GlobalizedMessage PERMISSIONS_INDEX
= new GlobalizedMessage(
"permissions.index.title", BUNDLE_NAME);
public static final GlobalizedMessage PERMISSIONS_INDEX_NAVBAR
= new GlobalizedMessage(
"permissions.index.navbarItem", BUNDLE_NAME);
// Permissions grant form
public static final GlobalizedMessage PAGE_GRANT_TITLE
= new GlobalizedMessage(
"permissions.one.grant.title", BUNDLE_NAME);
public static final GlobalizedMessage PAGE_GRANT_LEFT
= new GlobalizedMessage(
"permissions.one.grant.explanation.left", BUNDLE_NAME);
public static final GlobalizedMessage PAGE_GRANT_RIGHT
= new GlobalizedMessage(
"permissions.one.grant.explanation.right", BUNDLE_NAME);
// Access denied page
public static final GlobalizedMessage PAGE_DENIED_TITLE
= new GlobalizedMessage(
"permissions.denied.title", BUNDLE_NAME);
// Index page
public static final GlobalizedMessage PAGE_OBJECT_INDEX
= new GlobalizedMessage(
"permissions.index.adminObjects", BUNDLE_NAME);
public static final GlobalizedMessage PAGE_OBJECT_PANEL_TITLE
= new GlobalizedMessage(
"permissions.index.panelTitle", BUNDLE_NAME);
public static final GlobalizedMessage PAGE_OBJECT_NONE
= new GlobalizedMessage(
"permissions.index.noAdminObjects", BUNDLE_NAME);
// Flats for permission types
public static final int DIRECT = 0;
public static final int INHERITED = 1;
// Form constants
public static final String OBJECT_ID = "po_id";
public static final String DIRECT_PERMISSIONS = "direct";
public static final String INDIRECT_PERMISSIONS = "indirect";
public static final String SEARCH_QUERY = "query";
public static final String PRIV_SET = "privs_set";
// shared query
public static final String RETRIEVE_USERS
= "com.arsdigita.kernel.RetrieveUsers";
}

View File

@ -1,212 +0,0 @@
/*
* Copyright (C) 2002-2004 Red Hat Inc. All Rights Reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
package com.arsdigita.cms.ui.permissions;
import com.arsdigita.bebop.BoxPanel;
import com.arsdigita.bebop.Form;
import com.arsdigita.bebop.FormData;
import com.arsdigita.bebop.FormProcessException;
import com.arsdigita.bebop.Label;
import com.arsdigita.bebop.PageState;
import com.arsdigita.bebop.SegmentedPanel;
import com.arsdigita.bebop.Text;
import com.arsdigita.bebop.event.FormSectionEvent;
import com.arsdigita.bebop.event.FormSubmissionListener;
import com.arsdigita.bebop.event.PrintEvent;
import com.arsdigita.bebop.event.PrintListener;
import com.arsdigita.bebop.form.CheckboxGroup;
import com.arsdigita.bebop.form.Option;
import com.arsdigita.bebop.form.OptionGroup;
import com.arsdigita.bebop.form.Submit;
import com.arsdigita.bebop.parameters.ArrayParameter;
import com.arsdigita.bebop.parameters.StringParameter;
import com.arsdigita.util.StringUtils;
import com.arsdigita.util.UncheckedWrapperException;
import org.libreccm.cdi.utils.CdiUtil;
import org.libreccm.security.PermissionManager;
import org.libreccm.security.Role;
import org.libreccm.security.RoleRepository;
import java.util.List;
import java.util.TooManyListenersException;
import static com.arsdigita.cms.ui.permissions.CMSPermissionsConstants.*;
/**
* Permissions Grant container for permissions assignment. Widgets are currently
* organised on a bebop SegmentedPanel.
*
* @author Stefan Deusch (sdeusch@arsdigita.com)
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
class CMSPermissionsGrant {
private final static String PARTIES_CBG = "parties_cbg";
private final static String PRIVILEGES_CBG = "privs_cbg";
// data keys
private static final String USER_ID = "userID";
private static final String SCREEN_NAME = "screenName";
private static final String FIRST_NAME = "firstName";
private static final String LAST_NAME = "lastName";
private final CMSPermissionsPane parent;
private final SegmentedPanel grantPanel;
private CheckboxGroup partiesCheckboxGroup;
private CheckboxGroup privilegesCheckboxGroup;
private Form form;
private Submit saveSubmit;
/**
* Creates a PermissionsGrant object that will be contained with another
* component. This is currently used inside the permissions pane.
*
* @param parent the enclosing container
*/
public CMSPermissionsGrant(final CMSPermissionsPane parent) {
this.parent = parent;
makeForm();
grantPanel = new SegmentedPanel();
grantPanel.addSegment(new Label(PAGE_GRANT_TITLE), form);
}
/**
* Builds the form used to grant pivileges to users and groups.
*/
private void makeForm() {
form = new Form("GrantPrivileges", new BoxPanel());
form.setMethod(Form.POST);
form.addSubmissionListener(new GrantFormSubmissionListener());
form.add(new Label(PAGE_GRANT_LEFT));
partiesCheckboxGroup = new CheckboxGroup(PARTIES_CBG);
try {
partiesCheckboxGroup.addPrintListener(new UserSearchPrintListener());
} catch (TooManyListenersException e) {
throw new UncheckedWrapperException("TooManyListeners: " + e
.getMessage(), e);
}
form.add(partiesCheckboxGroup);
form.add(new Label(PAGE_GRANT_RIGHT));
privilegesCheckboxGroup = new CheckboxGroup(PRIVILEGES_CBG);
try {
privilegesCheckboxGroup.addPrintListener(
new PrivilegePrintListener());
} catch (TooManyListenersException e) {
throw new UncheckedWrapperException("TooManyListeners: " + e
.getMessage(), e);
}
form.add(privilegesCheckboxGroup);
saveSubmit = new Submit("save", SAVE_BUTTON);
form.add(saveSubmit);
}
/**
* Returns the SegmentedPanel with the permissions grant Form
*
* @return the SegmentedPanel with the permissions grant form
*/
public SegmentedPanel getPanel() {
return grantPanel;
}
private class GrantFormSubmissionListener
implements FormSubmissionListener {
@Override
public void submitted(FormSectionEvent event) throws
FormProcessException {
final PageState state = event.getPageState();
final FormData data = event.getFormData();
final String[] gids = (String[]) data.get(PARTIES_CBG);
final String[] privs = (String[]) data.get(PRIVILEGES_CBG);
if (privs != null && gids != null) {
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final PermissionManager permissionManager = cdiUtil.findBean(
PermissionManager.class);
final Long oID = parent.getObject(state).getObjectId();
for (String gid : gids) {
final Long gID = Long.parseLong(gid);
final CMSUserObjectStruct userObjectStruct
= new CMSUserObjectStruct(gID,
oID);
for (String priv : privs) {
permissionManager.grantPrivilege(
priv,
userObjectStruct.getRole(),
userObjectStruct.getObject());
}
}
}
// parent.showAdmin(state);
}
}
private class UserSearchPrintListener implements PrintListener {
@Override
public void prepare(final PrintEvent event) {
final PageState state = event.getPageState();
final OptionGroup target = (OptionGroup) event.getTarget();
// get query string
final String search = StringUtils.stripWhiteSpace((String) state.
getValue(new StringParameter(SEARCH_QUERY)));
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final RoleRepository roleRepo = cdiUtil.findBean(
RoleRepository.class);
final List<Role> roles = roleRepo.searchByName(search);
roles.forEach(role -> target.addOption(new Option(
Long.toString(role.getRoleId()),
new Text(role.getName()))));
}
}
private class PrivilegePrintListener implements PrintListener {
@Override
public void prepare(final PrintEvent event) {
final PageState state = event.getPageState();
final OptionGroup target = (OptionGroup) event.getTarget();
// get privileges from page state
final Object[] privileges = (Object[]) state.getValue(
new ArrayParameter(
PRIV_SET));
// print ceckbox group with privileges
for (Object privilege : privileges) {
target.addOption(new Option((String) privilege,
new Text(parent.getPrivilegeName(
(String) privilege))));
}
}
}
}

View File

@ -1,99 +0,0 @@
/*
* Copyright (C) 2002-2004 Red Hat Inc. All Rights Reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
package com.arsdigita.cms.ui.permissions;
import com.arsdigita.bebop.BoxPanel;
import com.arsdigita.bebop.DimensionalNavbar;
import com.arsdigita.bebop.Label;
import com.arsdigita.bebop.Link;
import com.arsdigita.bebop.PageState;
import com.arsdigita.bebop.event.PrintEvent;
import com.arsdigita.bebop.event.PrintListener;
import org.libreccm.core.CcmObject;
import static com.arsdigita.cms.ui.permissions.CMSPermissionsConstants.*;
/**
*
* Component that Renders the Header of the Permissions Admin pages
*
* @author sdeusch@arsdigita.com
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
class CMSPermissionsHeader extends BoxPanel {
private final CMSPermissionsPane parent;
private final Label title;
/**
* Constructor
*/
CMSPermissionsHeader(final CMSPermissionsPane parent) {
this.parent = parent;
title = new Label();
title.addPrintListener(new PrintListener() {
@Override
public void prepare(final PrintEvent event) {
final Label target = (Label) event.getTarget();
target.setLabel(PAGE_TITLE);
}
});
title.setClassAttr("heading");
add(title);
// Used to render the object name in the navbar
final Label objectName = new Label();
objectName.addPrintListener(new PrintListener() {
public void prepare(final PrintEvent event) {
final Label target = (Label) event.getTarget();
target.setLabel(getObjectName(event));
}
});
final DimensionalNavbar navbar = new DimensionalNavbar();
navbar.add(new Link(new Label(PERSONAL_SITE), "/pvt/home"));
navbar.add(new Link(new Label(MAIN_SITE), "/"));
navbar.add(new Link(new Label(PERMISSIONS_INDEX), "/permissions/"));
navbar.add(objectName);
navbar.setClassAttr("permNavBar");
add(navbar);
}
private String getObjectName(final PrintEvent event) {
final PageState state = event.getPageState();
final CcmObject object = parent.getObject(state);
final String objectName = String.format("%s (ID %d)",
object.getDisplayName(),
object.getObjectId());
return objectName;
}
/**
* Returns the object used to render the title of the panel.
*/
Label getTitle() {
return title;
}
}

View File

@ -1,686 +0,0 @@
/*
* Copyright (C) 2002-2004 Red Hat Inc. All Rights Reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
package com.arsdigita.cms.ui.permissions;
import com.arsdigita.bebop.BoxPanel;
import com.arsdigita.bebop.Component;
import com.arsdigita.bebop.ControlLink;
import com.arsdigita.bebop.Form;
import com.arsdigita.bebop.FormProcessException;
import com.arsdigita.bebop.Label;
import com.arsdigita.bebop.Page;
import com.arsdigita.bebop.PageState;
import com.arsdigita.bebop.RequestLocal;
import com.arsdigita.bebop.Resettable;
import com.arsdigita.bebop.SegmentedPanel;
import com.arsdigita.bebop.SimpleComponent;
import com.arsdigita.bebop.SimpleContainer;
import com.arsdigita.bebop.Table;
import com.arsdigita.bebop.Text;
import com.arsdigita.bebop.event.ActionEvent;
import com.arsdigita.bebop.event.ActionListener;
import com.arsdigita.bebop.event.RequestEvent;
import com.arsdigita.bebop.event.RequestListener;
import com.arsdigita.bebop.event.TableActionEvent;
import com.arsdigita.bebop.event.TableActionListener;
import com.arsdigita.bebop.parameters.ArrayParameter;
import com.arsdigita.bebop.parameters.ParameterModel;
import com.arsdigita.bebop.parameters.StringParameter;
import com.arsdigita.bebop.table.TableCellRenderer;
import com.arsdigita.dispatcher.DispatcherHelper;
import com.arsdigita.globalization.GlobalizedMessage;
import com.arsdigita.ui.CcmObjectSelectionModel;
import com.arsdigita.util.UncheckedWrapperException;
import org.libreccm.cdi.utils.CdiUtil;
import org.libreccm.core.CcmObject;
import org.libreccm.core.UnexpectedErrorException;
import org.libreccm.security.PermissionChecker;
import org.libreccm.security.PermissionManager;
import org.libreccm.security.Role;
import org.libreccm.security.RoleRepository;
import org.librecms.CmsConstants;
import org.librecms.contentsection.privileges.ItemPrivileges;
import java.io.IOException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
/**
* A pane used to administer the permissions of one {@link
* ACSObject}. This is a reusable component that can be embedded into a page to
* provide a generic UI. The page must have the "?po_id=" parameter to supply to
* ACSObject id of the item one is managing permissions for.
*
* @author sdeusch@arsdigita.com
* @authro <a href="jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
public class CMSPermissionsPane extends SimpleContainer implements Resettable,
ActionListener,
RequestListener {
// non-shared parameter models; leave package scope for access from its members.
private ParameterModel searchString = new StringParameter(
CMSPermissionsConstants.SEARCH_QUERY);
private ParameterModel privilegeArray = new ArrayParameter(
CMSPermissionsConstants.PRIV_SET);
private String[] privileges;
private Map<String, String> privilegeNameMap;
private SimpleContainer permissionsTable;
private CMSPermissionsTables allPermissions;
private CMSPermissionsHeader PermissionsHeader;
private SimpleContainer directPermissions;
private Form roleSearchForm;
private SimpleContainer inheritedPermissions;
private SimpleComponent contextPanel;
private SimpleContainer permissionsGrantPanel;
private SimpleContainer noResultsPanel;
private ObjectAdminListing adminListing;
private CcmObjectSelectionModel<CcmObject> selectionModel;
private RequestLocal userObjectInfo;
/**
* Default constructor creates components that show the default privileges
* as defined in PermissionsConstants interface
*
* @param model
*/
public CMSPermissionsPane(final CcmObjectSelectionModel<CcmObject> model) {
this(CMSPermissionsConstants.DEFAULT_PRIVILEGES, new HashMap<>(), model);
privilegeNameMap.put("read", "Read");
privilegeNameMap.put("write", "Write");
privilegeNameMap.put("create", "Create");
privilegeNameMap.put("delete", "Delete");
privilegeNameMap.put("admin", "Admin");
}
/**
* Creates a PermissionsPane with components showing the privileges that are
* passed in as argument.
*
* @param privileges
* @param privilegeNameMap
* @param selectionModel
*/
public CMSPermissionsPane(
final String[] privileges,
final Map<String, String> privilegeNameMap,
final CcmObjectSelectionModel<CcmObject> selectionModel) {
userObjectInfo = new RequestLocal() {
@Override
protected Object initialValue(final PageState state) {
return new CMSUserObjectStruct(state, selectionModel);
}
};
this.privileges = privileges;
this.selectionModel = selectionModel;
this.privilegeNameMap = privilegeNameMap;
}
public CMSPermissionsPane(
final Class<?> privilegesClass,
final CcmObjectSelectionModel<CcmObject> selectionModel) {
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final PermissionManager permissionManager = cdiUtil.findBean(
PermissionManager.class);
final List<String> privilegesFromClass = permissionManager
.listDefiniedPrivileges(privilegesClass);
final Map<String, String> nameMap = new HashMap<>();
for(final String privilege: privilegesFromClass) {
nameMap.put(privilege, privilege);
}
this.privileges = privilegesFromClass.toArray(new String[]{});
this.selectionModel = selectionModel;
this.privilegeNameMap = nameMap;
}
/**
* Overwrite this method to construct your default Permissions Pane with the
* components you need. You can subclass anonymously overwriting just the
* register method. Note: the getXXX methods are lazy instantiators, i.e.
* they produce the components only if not already there. (You can even
* overwrite the getXXX components with your own implementation, e.g., if
* you want to show a List instead of a Table for the direct permissions,
* but still use a Table for the inherited permissions.
*
* @param page
*/
@Override
public void register(final Page page) {
super.register(page);
// add permissions components to this specific implementation
// add(getPermissionsHeader());
// add(getContextPanel());
add(getPermissionsTable());
// add(getDirectPermissionsPanel());
// add(getUserSearchForm())
// add(getInheritedPermissionsPanel());
// add(getPermissionGrantPanel());
// add(getNoSearchResultPanel());
// add(getAdminListingPanel());
// set initial visibility of components
// p.setVisibleDefault(getPermissionsHeader(), true);
page.setVisibleDefault(getPermissionsTable(), true);
// page.setVisibleDefault(getDirectPermissionsPanel(), true);
// page.setVisibleDefault(getUserSearchForm(), true);
// page.setVisibleDefault(getInheritedPermissionsPanel(), true);
// page.setVisibleDefault(getContextPanel(), true);
// page.setVisibleDefault(getPermissionGrantPanel(), false);
// page.setVisibleDefault(getNoSearchResultPanel(), false);
// page.setVisibleDefault(getAdminListingPanel(), false);
// p.addActionListener(this);
// p.addRequestListener(this);
// add state parameters
page.addGlobalStateParam(searchString);
page.addGlobalStateParam(privilegeArray);
}
/**
* Implementation of interface bebop.Resettable. Use {@code reset} to reset
* permissions component to initial state, e.g. if you embed it into another
* container.
*/
@Override
public void reset(final PageState state) {
// showAdmin(state);
}
/**
* Utility method to get the authenticated user or group
*
* @param state
*
* @return
*/
public Role getRequestingRole(final PageState state) {
return ((CMSUserObjectStruct) userObjectInfo.get(state)).getRole();
}
/**
* Utility method to get the ACSObject from the page state
*
* @param state
*
* @return
*/
public CcmObject getObject(final PageState state) {
return ((CMSUserObjectStruct) userObjectInfo.get(state)).getObject();
}
/**
* Returns the title "Permissions on object articles", e.g.
*
* @return
*/
public Label getTitle() {
return ((CMSPermissionsHeader) getPermissionsHeader()).getTitle();
}
/**
* Returns a string array of privilege names as defined in the constructor
*
* @return
*/
public String[] getPrivileges() {
return Arrays.copyOf(privileges, privileges.length);
}
private SimpleContainer getPermissionsTable() {
if (permissionsTable != null) {
return permissionsTable;
}
final BoxPanel panel = new BoxPanel(BoxPanel.VERTICAL);
final Label header = new Label(new GlobalizedMessage(
"cms.ui.permissions.table.header",
CmsConstants.CMS_BUNDLE));
panel.add(header);
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final PermissionManager permissionManager = cdiUtil.findBean(
PermissionManager.class);
// final List<String> privileges = permissionManager
// .listDefiniedPrivileges(ItemPrivileges.class);
// final List<Label> headerLabels = privileges.stream()
final List<Label> headerLabels = Arrays.stream(privileges)
.map(privilege -> generatePrivilegeColumnHeader(privilege))
.collect(Collectors.toList());
headerLabels.add(0,
new Label(new GlobalizedMessage(
"cms.ui.permissions.table.role_header",
CmsConstants.CMS_BUNDLE)));
headerLabels.add(new Label(new GlobalizedMessage(
"cms.ui.permissions.table.remove_all.header",
CmsConstants.CMS_BUNDLE)));
final Table table = new Table(new CMSPermissionsTableModelBuilder(this),
headerLabels.toArray());
table.setClassAttr("dataTable");
for (int j = 1; j < table.getColumnModel().size() - 1; j++) {
// table.getColumn(j).setKey(privileges.get(j - 1));
// table.getColumn(j).setKey(privileges[j - 1]);
table.getColumn(j).setCellRenderer(new TableCellRenderer() {
@Override
public Component getComponent(final Table table,
final PageState state,
final Object value,
final boolean isSelected,
final Object key,
final int row,
final int column) {
final ControlLink link = new ControlLink("");
final CMSPermissionsTableColumn col
= (CMSPermissionsTableColumn) value;
if (col.isPermitted()) {
link.setClassAttr("checkBoxChecked");
} else {
link.setClassAttr("checkBoxUnchecked");
}
return link;
}
});
}
table.getColumn(table.getColumnModel().size() - 1).setCellRenderer(
new TableCellRenderer() {
@Override
public Component getComponent(final Table table,
final PageState state,
final Object value,
final boolean isSelected,
final Object key,
final int row,
final int column) {
final ControlLink link = new ControlLink(new Label(
new GlobalizedMessage(
"cms.ui.permissions.table.actions.remove_all",
CmsConstants.CMS_BUNDLE)));
link.setConfirmation(new GlobalizedMessage(
"cms.ui.permissions.table.actions.remove_all.confirm",
CmsConstants.CMS_BUNDLE));
return link;
}
});
table.addTableActionListener(new TableActionListener() {
@Override
public void cellSelected(final TableActionEvent event)
throws FormProcessException {
final PageState state = event.getPageState();
final int columnIndex = event.getColumn();
if (event.getRowKey() == null) {
return;
}
final String roleName = (String) event.getRowKey();
final Table table = (Table) event.getSource();
final int columnCount = table.getColumnModel().size();
final int lastColumnIndex = columnCount - 1;
final CcmObject object = getObject(state);
final RoleRepository roleRepo = cdiUtil.findBean(
RoleRepository.class);
final Optional<Role> role = roleRepo.findByName(roleName);
if (!role.isPresent()) {
throw new UnexpectedErrorException(String.format(
"Role \"%s\" was not found inthe database, but was in "
+ "the permissions table.",
roleName));
}
final PermissionChecker permissionChecker = cdiUtil.findBean(
PermissionChecker.class);
if (columnIndex > 0 && columnIndex < lastColumnIndex) {
// final String privilege = table
// .getColumn(columnIndex)
// .getKey();
final String privilege = privileges[columnIndex - 1];
if (permissionChecker.isPermitted(privilege,
object,
role.get())) {
permissionManager.revokePrivilege(privilege,
role.get(),
object);
} else {
permissionManager.grantPrivilege(privilege,
role.get(),
object);
}
} else if (columnIndex == lastColumnIndex) {
final List<String> privileges = permissionManager
.listDefiniedPrivileges(ItemPrivileges.class);
privileges.forEach(privilege -> permissionManager
.revokePrivilege(privilege, role.get(), object));
}
}
@Override
public void headSelected(final TableActionEvent event) {
//Nothing
}
});
panel.add(table);
permissionsTable = panel;
return panel;
}
private Label generatePrivilegeColumnHeader(final String privilege) {
return new Label(new GlobalizedMessage(
String.format("cms.ui.permissions.table.privilege.headers.%s",
privilege),
CmsConstants.CMS_BUNDLE));
}
// /**
// * Produces the direct and inherited permission tables to the privileges
// * defined in the constructor.
// *
// * @see #getDirectPermissionsPanel(), getInheritedPermissionsPanel()
// */
// private CMSPermissionsTables getPermissionsTables() {
// if (allPermissions == null) {
// allPermissions = new CMSPermissionsTables(privileges, this);
// }
// return allPermissions;
// }
//
// /**
// * Returns the bebop component with a table for the direct permission on the
// * privileges defined in the constructor
// *
// * @return
// *
// * @see #getInheritedPermissionsPanel()
// */
// public SimpleContainer getDirectPermissionsPanel() {
// directPermissions = getPermissionsTables().getPermissions(
// CMSPermissionsConstants.DIRECT);
// return directPermissions;
// }
//
// /**
// * Returns the bebop component with a table for the inherited permission on
// * the privileges defined in the constructor. The table is non-editable.
// *
// * @return
// *
// * @see #getDirectPermissionsPanel()
// */
// public SimpleContainer getInheritedPermissionsPanel() {
// inheritedPermissions = getPermissionsTables()
// .getPermissions(CMSPermissionsConstants.INHERITED);
// return inheritedPermissions;
// }
public SimpleContainer getAdminListingPanel() {
if (adminListing == null) {
adminListing = new ObjectAdminListing(selectionModel);
}
return adminListing;
}
/**
* This is an outstanding item.
*
* @return
*/
public SegmentedPanel getUniversalPermissionsPanel() {
throw new UnsupportedOperationException();
}
/**
* Returns a bebop form for user and group search.
*
* @return
*/
public Form getUserSearchForm() {
if (roleSearchForm == null) {
roleSearchForm = new CMSUserSearchForm(this);
}
return roleSearchForm;
}
/**
* Returns a panel with a form with 2 checkbox groups, one for parties to
* choose, one for privileges to assign.
*
* @return
*/
public SimpleContainer getPermissionGrantPanel() {
if (permissionsGrantPanel == null) {
CMSPermissionsGrant permGrant = new CMSPermissionsGrant(this);
permissionsGrantPanel = permGrant.getPanel();
}
return permissionsGrantPanel;
}
/**
* Returns a bebop container with the title to this object and a navigation
* bar, specific for the UI at /permissions/.
*
* @return
*/
public SimpleContainer getPermissionsHeader() {
if (PermissionsHeader == null) {
PermissionsHeader = new CMSPermissionsHeader(this);
}
return PermissionsHeader;
}
/**
* Returns a bebop panel indicating that the user search yielded no results.
* It is customised in the xsl stylesheet.
*
* @return
*/
public SimpleContainer getNoSearchResultPanel() {
if (noResultsPanel == null) {
final Label errorMsg = new Label(CMSPermissionsConstants.NO_RESULTS);
errorMsg.setClassAttr("errorBullet");
final BoxPanel panel = new BoxPanel();
panel.add(errorMsg);
panel.add(new CMSUserSearchForm(this));
noResultsPanel = new SegmentedPanel().addSegment(new Text(" "),
panel);
}
return noResultsPanel;
}
// /**
// * Returns a bebop panel with a link to the permissions administration page
// * of the object's direct ancestor (parent).
// *
// * @return
// */
// public SimpleComponent getContextPanel() {
// if (contextPanel == null) {
// contextPanel = getPermissionsTables().makeContextPanel();
// }
// return contextPanel;
// }
ParameterModel getSearchString() {
return searchString;
}
ParameterModel getPrivilegeParam() {
return privilegeArray;
}
CcmObjectSelectionModel<CcmObject> getSelectionModel() {
return selectionModel;
}
// /**
// * Shows panel with no results to user search.
// *
// * @param state
// */
// public void showNoResults(final PageState state) {
// getDirectPermissionsPanel().setVisible(state, false);
// getInheritedPermissionsPanel().setVisible(state, false);
// getContextPanel().setVisible(state, false);
// getUserSearchForm().setVisible(state, false);
// getPermissionGrantPanel().setVisible(state, false);
// getNoSearchResultPanel().setVisible(state, true);
// }
// /**
// * Show the Grant privileges panel
// *
// * @param state
// */
// public void showGrant(final PageState state) {
// getDirectPermissionsPanel().setVisible(state, false);
// getInheritedPermissionsPanel().setVisible(state, false);
// getContextPanel().setVisible(state, false);
// getUserSearchForm().setVisible(state, false);
// getNoSearchResultPanel().setVisible(state, false);
// getPermissionGrantPanel().setVisible(state, true);
// }
// /**
// * Shows the administration page of permissions to one object.
// *
// * @param state
// */
// public void showAdmin(final PageState state) {
// final CcmObject object = getObject(state);
// final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
// final PermissionChecker permissionChecker = cdiUtil.findBean(
// PermissionChecker.class);
//
// final boolean canAccess;
// if (object == null) {
// throw new UncheckedWrapperException(
// "Unexpected null value for object.");
// } else if (object instanceof ContentItem) {
// canAccess = permissionChecker.isPermitted(ItemPrivileges.ADMINISTER,
// object);
// } else if (object instanceof Folder) {
// canAccess = permissionChecker.isPermitted(ItemPrivileges.ADMINISTER,
// object);
// } else {
// throw new UncheckedWrapperException(String.format(
// "The object is of type \"%s\" which is not supported here.",
// object.getClass().getName()));
// }
//
// if (canAccess) {
// showCustom(state, true);
//
//// showCustom(state, false);
// getContextPanel().setVisible(state, true);
//
// } else {
// // do not have permission to set permissions, so don't show them
// getDirectPermissionsPanel().setVisible(state, false);
// getInheritedPermissionsPanel().setVisible(state, false);
// getUserSearchForm().setVisible(state, false);
// getContextPanel().setVisible(state, false);
// }
//
// getPermissionGrantPanel().setVisible(state, false);
// }
@Override
public void actionPerformed(final ActionEvent event) {
final PageState state = event.getPageState();
/**
* check if viewing user has admin privilege on this Object, after
* Action Event fires everytime the component is visible.
*
*/
if (this.isVisible(state)) {
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final PermissionChecker permissionChecker = cdiUtil.findBean(
PermissionChecker.class);
if (!permissionChecker.isPermitted(ItemPrivileges.ADMINISTER,
getObject(state))) {
try {
DispatcherHelper.sendRedirect(state.getRequest(),
state.getResponse(),
"/permissions/denied");
} catch (IOException ex) {
throw new UncheckedWrapperException(ex);
}
}
}
}
// public void showCustom(final PageState state, final boolean custom) {
// if (custom) {
// getDirectPermissionsPanel().setVisible(state, true);
// getInheritedPermissionsPanel().setVisible(state, false);
// getUserSearchForm().setVisible(state, true);
// getAdminListingPanel().setVisible(state, true);
// } else {
// getDirectPermissionsPanel().setVisible(state, false);
// getInheritedPermissionsPanel().setVisible(state, true);
// getUserSearchForm().setVisible(state, false);
// getAdminListingPanel().setVisible(state, false);
// }
// }
public String getPrivilegeName(final String privilege) {
return privilegeNameMap.get(privilege);
}
@Override
public void pageRequested(final RequestEvent event) {
// PageState s = e.getPageState();
// ACSObject object = getObject(s);
// if (object != null) {
// DataObject context = PermissionService.getContext(object);
// if (context != null) {
// showCustom(s, false);
// } else {
// showCustom(s, true);
// }
// } else {
// throw new IllegalStateException( (String) GlobalizationUtil.globalize("cms.ui.permissions.current_object_is_null").localize());
// }
}
}

View File

@ -1,99 +0,0 @@
/*
* Copyright (C) 2017 LibreCCM Foundation.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
package com.arsdigita.cms.ui.permissions;
import java.util.Objects;
/**
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
class CMSPermissionsTableColumn {
private String privilege;
private boolean permitted;
public String getPrivilege() {
return privilege;
}
protected void setPrivilege(final String privilege) {
this.privilege = privilege;
}
public boolean isPermitted() {
return permitted;
}
protected void setPermitted(final boolean permitted) {
this.permitted = permitted;
}
@Override
public int hashCode() {
int hash = 7;
hash = 83 * hash + Objects.hashCode(privilege);
hash = 83 * hash + (permitted ? 1 : 0);
return hash;
}
@Override
public boolean equals(final Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (!(obj instanceof CMSPermissionsTableColumn)) {
return false;
}
final CMSPermissionsTableColumn other
= (CMSPermissionsTableColumn) obj;
if (!other.canEqual(this)) {
return false;
}
if (permitted != other.isPermitted()) {
return false;
}
return Objects.equals(privilege, other.getPrivilege());
}
public boolean canEqual(final Object obj) {
return obj instanceof CMSPermissionsTableColumn;
}
@Override
public final String toString() {
return toString("");
}
public String toString(final String data) {
return String.format("%s{ "
+ "privilege = \"%s\", "
+ "permitted = %b%s"
+ " }",
super.toString(),
privilege,
permitted,
data);
}
}

View File

@ -1,120 +0,0 @@
/*
* Copyright (C) 2017 LibreCCM Foundation.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
package com.arsdigita.cms.ui.permissions;
import com.arsdigita.cms.CMS;
import org.libreccm.core.CcmObject;
import org.libreccm.core.UnexpectedErrorException;
import org.libreccm.security.PermissionChecker;
import org.libreccm.security.PermissionManager;
import org.libreccm.security.Role;
import org.librecms.contentsection.ContentSection;
import org.librecms.contentsection.ContentSectionRepository;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collectors;
import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
import javax.transaction.Transactional;
/**
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
@RequestScoped
class CMSPermissionsTableController {
@Inject
private ContentSectionRepository sectionRepo;
@Inject
private PermissionManager permissionManager;
@Inject
private PermissionChecker permissionChecker;
@Transactional(Transactional.TxType.REQUIRED)
public List<CMSPermissionsTableRow> buildDirectPermissionsRows(
final CcmObject object, final String[] privileges) {
final Optional<ContentSection> section = sectionRepo.findById(CMS
.getContext().getContentSection().getObjectId());
final List<Role> roles = section
.orElseThrow(() -> new UnexpectedErrorException(String.format(
"The content section %s from the CMS context was not found in"
+ "the database.",
Objects.toString(CMS.getContext().getContentSection()))))
.getRoles();
return roles.stream()
.map(role -> buildRow(role, object, privileges))
.sorted((row1, row2) -> {
return row1.getRoleName().compareTo(row2.getRoleName());
})
.collect(Collectors.toList());
}
private CMSPermissionsTableRow buildRow(final Role role,
final CcmObject object,
final String[] privileges) {
final List<CMSPermissionsTableColumn> columns = Arrays
.stream(privileges)
.map(privilege -> buildColumn(role, object, privilege))
.collect(Collectors.toList());
final CMSPermissionsTableRow row = new CMSPermissionsTableRow();
row.setObject(object);
row.setRoleName(role.getName());
row.setColumns(columns);
return row;
}
private CMSPermissionsTableColumn buildColumn(final Role role,
final CcmObject object,
final String privilege) {
final CMSPermissionsTableColumn column = new CMSPermissionsTableColumn();
column.setPrivilege(privilege);
column.setPermitted(permissionChecker.isPermitted(privilege,
object,
role));
return column;
}
@Transactional(Transactional.TxType.REQUIRED)
public void togglePermission(final CcmObject object,
final String privilege,
final Role role) {
if (permissionChecker.isPermitted(privilege, object, role)) {
permissionManager.revokePrivilege(privilege, role, object);
} else {
permissionManager.grantPrivilege(privilege, role, object);
}
}
}

View File

@ -1,101 +0,0 @@
/*
* Copyright (C) 2017 LibreCCM Foundation.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
package com.arsdigita.cms.ui.permissions;
import com.arsdigita.bebop.table.TableModel;
import org.libreccm.cdi.utils.CdiUtil;
import org.libreccm.core.CcmObject;
import java.util.Iterator;
/**
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
class CMSPermissionsTableModel implements TableModel {
private final String[] privileges;
private final Iterator<CMSPermissionsTableRow> iterator;
private CMSPermissionsTableRow currentRow;
public CMSPermissionsTableModel(final CcmObject object,
final String[] privileges) {
this.privileges = privileges;
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final CMSPermissionsTableController controller = cdiUtil.findBean(
CMSPermissionsTableController.class);
iterator = controller
.buildDirectPermissionsRows(object,privileges)
.iterator();
}
@Override
public int getColumnCount() {
return privileges.length + 2;
}
@Override
public boolean nextRow() {
if (iterator.hasNext()) {
currentRow = iterator.next();
return true;
} else {
return false;
}
}
@Override
public Object getElementAt(final int columnIndex) {
if (columnIndex == 0) {
return currentRow.getRoleName();
} else if (columnIndex == getColumnCount() - 1) {
return "Remove all";
} else {
return currentRow.getColumns().get(columnIndex - 1);
}
}
@Override
public Object getKeyAt(final int columnIndex) {
return currentRow.getRoleName();
// if (columnIndex == 0) {
// return String.format("%s-%s-role",
// currentRow.getObject().getUuid(),
// currentRow.getRoleName());
// } else if (columnIndex >= currentRow.getColumns().size() - 1) {
// return String.format("%s-%s-remove-all",
// currentRow.getObject().getUuid(),
// currentRow.getRoleName());
// } else {
// return String.format(
// "%s-%s-%s",
// currentRow.getObject().getUuid(),
// currentRow.getRoleName(),
// currentRow.getColumns().get(columnIndex - 1).getPrivilege()
// );
// }
}
}

View File

@ -1,48 +0,0 @@
/*
* Copyright (C) 2017 LibreCCM Foundation.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
package com.arsdigita.cms.ui.permissions;
import com.arsdigita.bebop.PageState;
import com.arsdigita.bebop.Table;
import com.arsdigita.bebop.table.TableModel;
import com.arsdigita.bebop.table.TableModelBuilder;
import com.arsdigita.util.LockableImpl;
import org.libreccm.core.CcmObject;
/**
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
class CMSPermissionsTableModelBuilder extends LockableImpl
implements TableModelBuilder {
private final CMSPermissionsPane parent;
public CMSPermissionsTableModelBuilder(final CMSPermissionsPane parent) {
this.parent = parent;
}
@Override
public TableModel makeModel(final Table table, final PageState state) {
final CcmObject object = parent.getObject(state);
return new CMSPermissionsTableModel(object, parent.getPrivileges());
}
}

View File

@ -1,116 +0,0 @@
/*
* Copyright (C) 2017 LibreCCM Foundation.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
package com.arsdigita.cms.ui.permissions;
import org.libreccm.core.CcmObject;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
/**
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
class CMSPermissionsTableRow {
private CcmObject object;
private String roleName;
private List<CMSPermissionsTableColumn> columns;
public CcmObject getObject() {
return object;
}
public void setObject(final CcmObject object) {
this.object = object;
}
public String getRoleName() {
return roleName;
}
protected void setRoleName(final String roleName) {
this.roleName = roleName;
}
public List<CMSPermissionsTableColumn> getColumns() {
return Collections.unmodifiableList(columns);
}
protected void setColumns(final List<CMSPermissionsTableColumn> columns) {
this.columns = columns;
}
@Override
public int hashCode() {
int hash = 3;
hash = 79 * hash + Objects.hashCode(roleName);
hash = 79 * hash + Objects.hashCode(columns);
return hash;
}
@Override
public boolean equals(final Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (!(obj instanceof CMSPermissionsTableRow)) {
return false;
}
final CMSPermissionsTableRow other = (CMSPermissionsTableRow) obj;
if (!other.canEqual(this)) {
return false;
}
if (!Objects.equals(roleName, other.getRoleName())) {
return false;
}
if (Objects.equals(columns, other.getColumns())) {
} else {
return false;
}
return true;
}
public boolean canEqual(final Object obj) {
return obj instanceof CMSPermissionsTableRow;
}
@Override
public final String toString() {
return toString("");
}
public String toString(final String data) {
return String.format("%s{ "
+ "roleName = \"%s\", "
+ "columns = %s%s"
+ " }",
super.toString(),
roleName,
Objects.toString(columns),
data);
}
}

View File

@ -1,545 +0,0 @@
/*
* Copyright (C) 2002-2004 Red Hat Inc. All Rights Reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
package com.arsdigita.cms.ui.permissions;
import com.arsdigita.bebop.ActionLink;
import com.arsdigita.bebop.Component;
import com.arsdigita.bebop.ControlLink;
import com.arsdigita.bebop.GridPanel;
import com.arsdigita.bebop.Label;
import com.arsdigita.bebop.PageState;
import com.arsdigita.bebop.SimpleComponent;
import com.arsdigita.bebop.SimpleContainer;
import com.arsdigita.bebop.Table;
import com.arsdigita.bebop.event.PrintEvent;
import com.arsdigita.bebop.event.PrintListener;
import com.arsdigita.bebop.event.TableActionEvent;
import com.arsdigita.bebop.event.TableActionListener;
import com.arsdigita.bebop.table.TableCellRenderer;
import com.arsdigita.bebop.table.TableModel;
import com.arsdigita.bebop.table.TableModelBuilder;
import com.arsdigita.globalization.GlobalizedMessage;
import com.arsdigita.util.LockableImpl;
import com.arsdigita.util.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.libreccm.cdi.utils.CdiUtil;
import org.libreccm.core.CcmObject;
import org.libreccm.security.Permission;
import org.libreccm.security.PermissionManager;
import org.libreccm.security.Role;
import org.librecms.CmsConstants;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import static com.arsdigita.cms.ui.permissions.CMSPermissionsConstants.*;
/**
* Class to represent direct and inherited permissions of an CcmObject. This
* class provides two SegmentPanels with the direct and the inherited
* permissions tables, respectively. The expected pageState contains a variable
* "id=123" of which the permissions are rendered. The viewing user must be
* authenticated. The permissions representations can be swapped , e.g. with a
* List, if scalability warrants.
*
* @author Stefan Deusch
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
class CMSPermissionsTables {
private static Logger LOGGER = LogManager.getLogger(
CMSPermissionsTables.class);
private CMSPermissionsPane parent;
private String[] privileges;
private final GridPanel permissionsPanel[] = new GridPanel[2];
private final int[] tableColumns = new int[2];
/**
* Default constructor uses the DEFAULT_PRIVILEGES as defined in
* PermissionsConstants.
*/
CMSPermissionsTables(final CMSPermissionsPane parent) {
this(DEFAULT_PRIVILEGES, parent);
}
/**
* Constructor that takes an array of PrivilegeDescriptors and builds the
* grantee - privilege matrix. <strong>The permissions tables contain the
* set of privileges that are passed into this constructor.</strong>
*
* @param privileges the array of PrivilegeDesrciptors with which go into
* table
* @param parent the Bebop parent container
*/
CMSPermissionsTables(final String[] privileges,
final CMSPermissionsPane parent) {
this.parent = parent;
// fixed table information
this.privileges = privileges;
tableColumns[DIRECT] = privileges.length + 2;
tableColumns[INHERITED] = privileges.length + 1;
// Construct Direct Permissions Panel
permissionsPanel[DIRECT] = new GridPanel(1);
final Table directTable = new Table(
new PermissionsTableModelBuilder(DIRECT),
getHeaders(DIRECT));
directTable.setClassAttr("dataTable");
setCellRenderers(directTable, DIRECT);
directTable.addTableActionListener(
new DirectPermissionsTableActionListener());
permissionsPanel[DIRECT].add(new Label(new GlobalizedMessage(
"cms.ui.permissions.these_are_the_custom_permissions"
+ "_that_have_been_granted_on_this_object",
CmsConstants.CMS_BUNDLE)));
permissionsPanel[DIRECT].add(directTable);
// Construct Inherited Permissions Panel
permissionsPanel[INHERITED] = new GridPanel(1);
final Table inheritedTable = new Table(
new PermissionsTableModelBuilder(INHERITED),
getHeaders(INHERITED));
inheritedTable.setClassAttr("dataTable");
setCellRenderers(inheritedTable, INHERITED);
permissionsPanel[INHERITED].add(new Label(new GlobalizedMessage(
"cms.ui.permissions.these_are_the_current_permissions_for_this_folder",
CmsConstants.CMS_BUNDLE)));
permissionsPanel[INHERITED].add(inheritedTable);
//m_permPanel[INHERITED].addSegment(new Label(PERM_TABLE_INDIRECT_HEADING),
// boxpanel);
}
/**
* Returns the SegmentedPanel with either the direct or the indirect
* permissions table.
*
* @param use PermissionsContants.DIRECT or PermissionsContants.INHERITED
*/
GridPanel getPermissions(int type) {
return permissionsPanel[type];
}
/**
* Returns the set of privileges of the permission tables as a String array.
*/
String[] getPrivileges() {
return Arrays.copyOf(privileges, privileges.length);
}
SimpleComponent makeContextPanel() {
final SimpleContainer contextPanel = new SimpleContainer();
final Label contextLabel1 = new Label();
contextLabel1.addPrintListener(new PrintListener() {
@Override
public void prepare(final PrintEvent event) {
final PageState state = event.getPageState();
final Label label = (Label) event.getTarget();
final CcmObject context = getContext(state);
if (context != null) {
label.setLabel(PERM_TABLE_INDIRECT_CONTEXT);
contextLabel1.setVisible(state, true);
} else {
label.setLabel(PERM_TABLE_NO_PARENT_CONTEXT);
contextLabel1.setVisible(state, false);
}
}
});
final Label contextLabel2 = new Label();
contextLabel2.addPrintListener(new PrintListener() {
@Override
public void prepare(final PrintEvent event) {
final PageState state = event.getPageState();
final Label label = (Label) event.getTarget();
final CcmObject context = getContext(state);
if (context != null) {
label.setLabel(context.getDisplayName());
}
}
});
contextLabel2.setFontWeight(Label.BOLD);
contextPanel.add(contextLabel1);
contextPanel.add(contextLabel2);
return contextPanel;
}
CcmObject getContext(final PageState state) {
return null;
}
private String[] getHeaders(final int type) {
String[] headers = new String[tableColumns[type]];
headers[0] = PERM_TABLE_GRANTEE.localize() + "";
for (int j = 0; j < privileges.length; j++) {
headers[j + 1] = parent.getPrivilegeName(privileges[j]);
}
if (type == DIRECT) {
headers[privileges.length + 1] = PERM_TABLE_ACTIONS.localize()
+ "";
}
return headers;
}
private void setCellRenderers(final Table table, final int type) {
int j;
if (type == DIRECT) {
for (j = 1; j < table.getColumnModel().size() - 1; j++) {
table.getColumn(j).setCellRenderer(
new PermissionToggleRenderer());
}
table.getColumn(j).setCellRenderer(new LinkRenderer());
} else {
for (j = 1; j < table.getColumnModel().size(); j++) {
table.getColumn(j).setCellRenderer(
new PermissionStatusRenderer());
}
}
}
private class DirectPermissionsTableActionListener
implements TableActionListener {
@Override
public void cellSelected(TableActionEvent event) {
final PageState state = event.getPageState();
final int col = event.getColumn();
final String rowkey = (String) event.getRowKey();
if (rowkey == null) {
return;
}
final Table table = (Table) event.getSource();
final int no_cols = table.getColumnModel().size();
final int lastCol = no_cols - 1;
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final PermissionManager permissionManager = cdiUtil.findBean(
PermissionManager.class);
if (col > 0 && col < lastCol) {
final PermissionStatus pmds = UserPrivilegeKey
.undescribe(rowkey);
LOGGER.debug("Do perm toggle on {} for {} of {}",
pmds.getObject().getObjectId(),
pmds.getRole().getName(),
pmds.getPrivilege());
if (pmds.isGranted()) {
LOGGER.debug("Do revoke permission");
permissionManager.revokePrivilege(pmds.getPrivilege(),
pmds.getRole(),
pmds.getObject());
} else {
LOGGER.debug("Do grant permission");
permissionManager.grantPrivilege(pmds.getPrivilege(),
pmds.getRole(),
pmds.getObject());
}
} else if (col == lastCol) {
// Process Remove All Link
final String[] tokens = StringUtils.split(rowkey, '.');
final Long pID = Long.parseLong(tokens[0]);
/*
* Remove all indicated privileges from user
* enumerated in tokens array
*/
final CcmObject obj = parent.getObject(state);
final Role role = CMSUserObjectStruct.loadRole(pID);
LOGGER.debug("Revoke all on {} for {}.",
obj.getObjectId(),
role.getName());
for (final String token : tokens) {
permissionManager.revokePrivilege(token, role, obj);
}
}
}
@Override
public void headSelected(final TableActionEvent event) {
throw new UnsupportedOperationException();
}
}
private final class PermissionsTableModelBuilder
extends LockableImpl implements TableModelBuilder {
private final int m_type;
PermissionsTableModelBuilder(final int type) {
m_type = type;
}
/*
* this can be optimized to run the query only
* once for both tables
*/
@Override
public TableModel makeModel(final Table table,
final PageState state) {
final CcmObject object = parent.getObject(state);
switch (m_type) {
case DIRECT:
return new DirectPermissionsTableModel(object);
case INHERITED:
return new DirectPermissionsTableModel(
object);
default:
return null;
}
}
}
private class DirectPermissionsTableModel implements TableModel {
private final List<String> userPrivileges = new ArrayList<>();
private Iterator<Permission> iterator;
private Permission currentPermission;
public DirectPermissionsTableModel(final CcmObject object) {
// this.iterator = permissions.iterator();
}
@Override
public int getColumnCount() {
return tableColumns[DIRECT];
}
@Override
public Object getElementAt(final int columnIndex) {
if (columnIndex == 0) {
// the Grantee column
return currentPermission.getGrantee().getName();
} else if (columnIndex == getColumnCount() - 1) {
// the Action column
return "Remove All";
} else {
if (userHasPermission(columnIndex - 1)) {
return Boolean.TRUE;
} else {
return Boolean.FALSE;
}
}
}
@Override
public Object getKeyAt(final int columnIndex) {
if (columnIndex == 0) {
// the key for the grantee
return currentPermission.getGrantee().getRoleId();
} else if (columnIndex == getColumnCount() - 1) {
// key for 'Remove All' link
return makeRemoveAllKey();
} else {
// key for a user privilege
return (new UserPrivilegeKey(
currentPermission.getObject().getObjectId(),
currentPermission.getGrantee().getRoleId(),
privileges[columnIndex - 1],
userHasPermission(columnIndex - 1)))
.toString();
}
}
@Override
public boolean nextRow() {
if (iterator.hasNext()) {
currentPermission = iterator.next();
return true;
} else {
return false;
}
}
boolean userHasPermission(final int idx) {
return userPrivileges.contains(privileges[idx]);
}
private String makeRemoveAllKey() {
final StringBuffer buffer = new StringBuffer();
buffer.append(Long.toString(currentPermission.getGrantee()
.getRoleId()));
for (int i = 0; i < privileges.length; i++) {
if (userHasPermission(i)) {
buffer.append(".").append(privileges[i]);
}
}
return buffer.toString();
}
void addPrivilege(final String privilege) {
for (String current : privileges) {
if (current.equals(current)) {
userPrivileges.add(current);
break;
}
}
}
protected Permission getCurrentPermission() {
return currentPermission;
}
}
/**
* Extension of DirectPermissionsTableModel to accomodate Inherited
* permissions table model.
*/
private final class InheritedPermissionsTableModel
extends DirectPermissionsTableModel {
public InheritedPermissionsTableModel(final CcmObject object) {
super(object);
}
@Override
public int getColumnCount() {
return tableColumns[INHERITED];
}
@Override
public Object getElementAt(final int columnIndex) {
if (columnIndex == 0) {
// the Grantee column
return getCurrentPermission().getGrantee().getName();
} else {
if (userHasPermission(columnIndex - 1)) {
return Boolean.TRUE;
} else {
return Boolean.FALSE;
}
}
}
@Override
public Object getKeyAt(final int columnIndex) {
if (columnIndex == 0) {
// the key for the grantee
return getCurrentPermission().getGrantee().getRoleId();
}
// no keys for inherited permissions
return null;
}
}
private final class PermissionToggleRenderer implements TableCellRenderer {
@Override
public Component getComponent(final Table table,
final PageState state,
final Object value,
final boolean isSelected,
final Object key,
final int row,
final int column) {
final ControlLink link = new ControlLink("");
if (((Boolean) value)) {
link.setClassAttr("checkBoxChecked");
} else {
link.setClassAttr("checkBoxUnchecked");
}
return link;
}
}
private final class PermissionStatusRenderer implements TableCellRenderer {
@Override
public Component getComponent(final Table table,
final PageState state,
final Object value,
final boolean isSelected,
final Object key,
final int row,
final int column) {
final Label link = new Label();
if (((Boolean) value)) {
link.setClassAttr("checkBoxGreyChecked");
} else {
link.setClassAttr("checkBoxGreyUnchecked");
}
return link;
}
}
private final class LinkRenderer implements TableCellRenderer {
@Override
public Component getComponent(final Table table,
final PageState state,
final Object value,
final boolean isSelected,
final Object key,
final int row,
final int column) {
final ControlLink link = new ControlLink((String) value);
link.setConfirmation(REMOVE_ALL_CONFIRM);
return link;
}
}
}

View File

@ -1,114 +0,0 @@
/*
* Copyright (C) 2002-2004 Red Hat Inc. All Rights Reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
package com.arsdigita.cms.ui.permissions;
import com.arsdigita.bebop.PageState;
import com.arsdigita.ui.CcmObjectSelectionModel;
import com.arsdigita.util.UncheckedWrapperException;
import org.libreccm.cdi.utils.CdiUtil;
import org.libreccm.core.CcmObject;
import org.libreccm.core.CcmObjectRepository;
import org.libreccm.security.Role;
import org.libreccm.security.RoleRepository;
import java.util.Optional;
/**
* This class is mainly instantiated from a PageState It is very context
* specific for permissions. It tries to read the object_id and load the
* corresponding ACSObject, as well as the party_id and the corresponding
* entity.
*
* @author Stefan Deusch (sdeusch@arsdigita.com)
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
class CMSUserObjectStruct {
private final Role role;
private final CcmObject object;
CMSUserObjectStruct(final PageState state,
final CcmObjectSelectionModel selectionModel) {
this(getRole(state), getObject(state, selectionModel));
}
CMSUserObjectStruct(final Long partyId,
final Long objectId) {
this(loadRole(partyId), loadObject(objectId));
}
CMSUserObjectStruct(final Role role, final CcmObject object) {
this.role = role;
this.object = object;
}
Role getRole() {
return role;
}
CcmObject getObject() {
return object;
}
// Utility factory methods
static CcmObject loadObject(final Long objectId) {
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final CcmObjectRepository objectRepo = cdiUtil.findBean(
CcmObjectRepository.class);
final Optional<CcmObject> ccmObject = objectRepo.findById(objectId);
if (!ccmObject.isPresent()) {
throw new UncheckedWrapperException(String.format(
"Failed to find object with ID %d.", objectId));
}
return ccmObject.get();
}
// use in package
static Role loadRole(final Long roleId) {
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final RoleRepository roleRepo = cdiUtil
.findBean(RoleRepository.class);
final Optional<Role> role = roleRepo.findById(roleId);
if (!role.isPresent()) {
throw new UncheckedWrapperException(String.format(
"Failed to find party with ID %d.", roleId));
}
return role.get();
}
public static Role getRole(final PageState state) {
// final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
// final Shiro shiro = cdiUtil.findBean(Shiro.class);
//
// return shiro.getUser();
return null;
}
public static CcmObject getObject(
final PageState state, final CcmObjectSelectionModel selectionModel) {
return selectionModel.getSelectedObject(state);
}
}

View File

@ -1,136 +0,0 @@
/*
* Copyright (C) 2002-2004 Red Hat Inc. All Rights Reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
package com.arsdigita.cms.ui.permissions;
import com.arsdigita.bebop.ColumnPanel;
import com.arsdigita.bebop.Form;
import com.arsdigita.bebop.FormData;
import com.arsdigita.bebop.FormProcessException;
import com.arsdigita.bebop.Label;
import com.arsdigita.bebop.PageState;
import com.arsdigita.bebop.SimpleContainer;
import com.arsdigita.bebop.event.FormProcessListener;
import com.arsdigita.bebop.event.FormSectionEvent;
import com.arsdigita.bebop.form.Submit;
import com.arsdigita.bebop.form.TextField;
import com.arsdigita.bebop.parameters.NotEmptyValidationListener;
import com.arsdigita.bebop.parameters.ParameterModel;
import com.arsdigita.bebop.parameters.StringParameter;
import com.arsdigita.util.StringUtils;
import org.libreccm.cdi.utils.CdiUtil;
import org.libreccm.security.Party;
import org.libreccm.security.Role;
import org.libreccm.security.RoleRepository;
import java.util.List;
import static com.arsdigita.cms.ui.permissions.CMSPermissionsConstants.*;
/**
* User Search Form for permissions.
*
* @author Stefan Deusch (stefan@arsdigita.com)
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
public class CMSUserSearchForm extends Form implements FormProcessListener {
private CMSPermissionsPane parent;
private TextField searchField;
public CMSUserSearchForm(CMSPermissionsPane parent) {
this(DEFAULT_PRIVILEGES, parent);
}
public CMSUserSearchForm(final String[] privileges,
final CMSPermissionsPane parent) {
super("RoleSearchUsers", new SimpleContainer());
this.parent = parent;
setMethod(Form.POST);
addProcessListener(this);
add(new Label(SEARCH_LABEL));
add(new Label("&nbsp;", false));
final StringParameter searchParam = new StringParameter(SEARCH_QUERY);
searchField = new TextField(searchParam);
searchField.addValidationListener(new NotEmptyValidationListener());
searchField.setSize(20);
add(searchField, ColumnPanel.RIGHT);
final Submit submit = new Submit(SEARCH_BUTTON);
add(submit, ColumnPanel.LEFT);
}
@Override
public void process(final FormSectionEvent event) throws
FormProcessException {
final PageState state = event.getPageState();
final FormData data = event.getFormData();
final String search = StringUtils.stripWhiteSpace((String) data.get(
SEARCH_QUERY));
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final RoleRepository roleRepo = cdiUtil.findBean(RoleRepository.class);
final List<Role> roles = roleRepo.searchByName(search);
if (roles.isEmpty()) {
// parent.showNoResults(state);
} else {
// put search string into Page
state.setValue(getSearchString(), data.get(SEARCH_QUERY));
// put privileges into Page
state.setValue(getPrivilegeModel(), getPrivileges());
// parent.showGrant(state);
}
}
/**
* Hide Delegate pattern, if parent's implementation changes.
*/
private ParameterModel getSearchString() {
return parent.getSearchString();
}
/**
* Detto
*/
private ParameterModel getPrivilegeModel() {
return parent.getPrivilegeParam();
}
/**
* Detto
*/
private Object[] getPrivileges() {
return parent.getPrivileges();
}
public TextField getSearchWidget() {
return searchField;
}
}

View File

@ -1,80 +0,0 @@
/*
* Copyright (C) 2018 LibreCCM Foundation.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
package com.arsdigita.cms.ui.permissions;
import com.arsdigita.bebop.BoxPanel;
import com.arsdigita.bebop.parameters.StringParameter;
import com.arsdigita.cms.CMS;
import com.arsdigita.cms.ItemSelectionModel;
import com.arsdigita.cms.ui.authoring.AuthoringKitWizard;
import com.arsdigita.cms.ui.authoring.ResettableContainer;
import com.arsdigita.ui.CcmObjectSelectionModel;
import org.libreccm.cdi.utils.CdiUtil;
import org.libreccm.core.CcmObject;
import org.libreccm.security.PermissionManager;
import org.librecms.CmsConstants;
import org.librecms.contentsection.privileges.ItemPrivileges;
import org.librecms.ui.authoring.ContentItemAuthoringStep;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
@ContentItemAuthoringStep(
labelBundle = CmsConstants.CMS_BUNDLE,
labelKey = "item_permissions_step.label",
descriptionBundle = CmsConstants.CMS_BUNDLE,
descriptionKey = "item_permissions_step.description"
)
public class ItemPermissionsStep extends ResettableContainer {
public ItemPermissionsStep(final ItemSelectionModel itemSelectionModel,
final AuthoringKitWizard authoringKitWizard,
final StringParameter selectedLanguage) {
super("cms:permissionsStep", CMS.CMS_XML_NS);
final BoxPanel panel = new BoxPanel(BoxPanel.VERTICAL);
super.add(panel);
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final PermissionManager permissionManager = cdiUtil.findBean(
PermissionManager.class);
final List<String> privileges = permissionManager
.listDefiniedPrivileges(ItemPrivileges.class);
final Map<String, String> privNameMap = new HashMap<>();
privileges.forEach(privilege -> privNameMap.put(privilege, privilege));
final CcmObjectSelectionModel<CcmObject> objSelectionModel
= new CcmObjectSelectionModel<>(
itemSelectionModel.getStateParameter().getName());
final CMSPermissionsPane permissionsPane = new CMSPermissionsPane(
privileges.toArray(new String[]{}),
privNameMap,
objSelectionModel);
panel.add(permissionsPane);
}
}

View File

@ -1,287 +0,0 @@
/*
* Copyright (C) 2002-2004 Red Hat Inc. All Rights Reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
package com.arsdigita.cms.ui.permissions;
import com.arsdigita.bebop.ColumnPanel;
import com.arsdigita.bebop.Form;
import com.arsdigita.bebop.FormData;
import com.arsdigita.bebop.FormProcessException;
import com.arsdigita.bebop.Label;
import com.arsdigita.bebop.PageState;
import com.arsdigita.bebop.RequestLocal;
import com.arsdigita.bebop.SimpleContainer;
import com.arsdigita.bebop.Text;
import com.arsdigita.bebop.event.FormProcessListener;
import com.arsdigita.bebop.event.FormSectionEvent;
import com.arsdigita.bebop.event.PrintEvent;
import com.arsdigita.bebop.event.PrintListener;
import com.arsdigita.bebop.form.CheckboxGroup;
import com.arsdigita.bebop.form.Hidden;
import com.arsdigita.bebop.form.Option;
import com.arsdigita.bebop.form.OptionGroup;
import com.arsdigita.bebop.form.Submit;
import com.arsdigita.bebop.form.TextField;
import com.arsdigita.bebop.form.Widget;
import com.arsdigita.bebop.parameters.NotNullValidationListener;
import com.arsdigita.cms.ui.CMSContainer;
import com.arsdigita.cms.ui.CMSForm;
import com.arsdigita.globalization.GlobalizedMessage;
import com.arsdigita.ui.CcmObjectSelectionModel;
import org.libreccm.core.CcmObject;
import org.libreccm.security.User;
import com.arsdigita.util.Assert;
import org.libreccm.cdi.utils.CdiUtil;
import org.libreccm.security.PermissionChecker;
import org.libreccm.security.PermissionManager;
import org.libreccm.security.Role;
import org.libreccm.security.RoleRepository;
import org.libreccm.security.UserRepository;
import org.librecms.CmsConstants;
import org.librecms.contentsection.privileges.ItemPrivileges;
import java.util.List;
import java.util.Optional;
import java.util.TooManyListenersException;
/**
* <p>
* This component is a form for adding object administrators
*
* @author Michael Pih (pihman@arsdigita.com)
* @author Uday Mathur (umathur@arsdigita.com)
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
public class ObjectAddAdmin extends SimpleContainer
implements FormProcessListener {
private final static String SEARCH_QUERY = "searchQuery";
private final static String USERS = "roles";
private final static String SUBMIT = "addSubmit";
private final static String CANCEL = "addCancel";
private Widget searchWidget;
private final RequestLocal queryRequestLocal;
private String labelText;
private String m_submitText;
private final CMSContainer noMatchesContainer;
private final CMSContainer matchesContainer;
private final Form form;
private Hidden searchQuery;
private CheckboxGroup rolesCheckboxGroup;
private Submit submit;
private Submit cancel;
private final CcmObjectSelectionModel<CcmObject> objectSelectionModel;
public ObjectAddAdmin(
final CcmObjectSelectionModel<CcmObject> objectSelectionModel,
final TextField search) {
// super(search, "ObjectAddAdmin");
labelText = "Check the box next to the name of the person(s) to assign.";
m_submitText = "Add Members";
searchWidget = search;
queryRequestLocal = new RequestLocal() {
@Override
protected Object initialValue(final PageState state) {
return makeQuery(state);
}
};
this.objectSelectionModel = objectSelectionModel;
form = makeForm("ObjectAddAdmin");
final Label title = new Label(new GlobalizedMessage("cms.ui.matches",
CmsConstants.CMS_BUNDLE));
title.setFontWeight(Label.BOLD);
final Label label = new Label(new GlobalizedMessage(
"cms.ui.there_was_no_one_matching_the_search_criteria",
CmsConstants.CMS_BUNDLE));
label.setFontWeight("em");
noMatchesContainer = new CMSContainer();
noMatchesContainer.add(title);
noMatchesContainer.add(label);
add(noMatchesContainer);
matchesContainer = new CMSContainer();
matchesContainer.add(title);
matchesContainer.add(form);
add(matchesContainer);
}
/**
* Build the form used to add roles.
*
* @param name
*
* @return The form
*/
protected Form makeForm(final String name) {
final CMSForm form = new CMSForm(name) {
public final boolean isCancelled(final PageState state) {
return cancel.isSelected(state);
}
};
// This hidden field will store the search query. A hidden widget is
// used instead of a request local variable because the search query
// should only be updated when the search form is submitted.
searchQuery = new Hidden(SEARCH_QUERY);
form.add(searchQuery, ColumnPanel.FULL_WIDTH);
final Text label = new Text(labelText);
form.add(label, ColumnPanel.FULL_WIDTH);
// Add the list of roles that can be added.
rolesCheckboxGroup = new CheckboxGroup(USERS);
rolesCheckboxGroup
.addValidationListener(new NotNullValidationListener());
try {
rolesCheckboxGroup.addPrintListener(new PrintListener() {
@Override
public void prepare(PrintEvent event) {
final CheckboxGroup target = (CheckboxGroup) event
.getTarget();
final PageState state = event.getPageState();
// Ensures that the init listener gets fired before the
// print listeners.
addRoles(state, target);
}
});
} catch (TooManyListenersException ex) {
throw new RuntimeException(ex);
}
form.add(rolesCheckboxGroup, ColumnPanel.FULL_WIDTH);
// Submit and Cancel buttons.
final SimpleContainer container = new SimpleContainer();
submit = new Submit(SUBMIT, m_submitText);
container.add(submit);
cancel = new Submit(CANCEL, "Cancel");
container.add(cancel);
form.add(container, ColumnPanel.FULL_WIDTH | ColumnPanel.CENTER);
form.addProcessListener(this);
return form;
}
/**
* Fetches the form for adding users.
*
* @return The "add user" form
*/
public Form getForm() {
return form;
}
/**
* Fetches the widget that contains the search string.
*
* @return The widget that contains the search string
*/
protected Widget getSearchWidget() {
return searchQuery;
}
/**
* Adds roles to the option group.
*
* @param state The page state
* @param target The option group
*
* @pre ( state != null && target != null )
*/
protected void addRoles(final PageState state, final OptionGroup target) {
@SuppressWarnings("unchecked")
final List<Role> roles = (List<Role>) queryRequestLocal.get(state);
roles.forEach(role -> target.addOption(
new Option(Long.toString(role.getRoleId()), role.getName())));
}
protected List<User> makeQuery(final PageState state) {
Assert.isTrue(objectSelectionModel.isSelected(state));
final CcmObject object = (CcmObject) objectSelectionModel
.getSelectedObject(state);
final String searchQuery = (String) getSearchWidget().getValue(state);
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final UserRepository userRepo = cdiUtil.findBean(UserRepository.class);
return userRepo.filtered(searchQuery);
}
@Override
public void process(final FormSectionEvent event) throws
FormProcessException {
final FormData data = event.getFormData();
final PageState state = event.getPageState();
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final PermissionChecker permissionChecker = cdiUtil.findBean(
PermissionChecker.class);
final PermissionManager permissionManager = cdiUtil.findBean(
PermissionManager.class);
final RoleRepository roleRepo = cdiUtil.findBean(RoleRepository.class);
final CcmObject object = objectSelectionModel.getSelectedObject(state);
permissionChecker.checkPermission(ItemPrivileges.ADMINISTER, object);
final String[] roleIds = (String[]) data.get("roles");
if (roleIds != null) {
// Add each checked user to the object
for (final String roleId : roleIds) {
final Optional<Role> role = roleRepo.findById(Long.parseLong(roleId));
if (!role.isPresent()) {
throw new FormProcessException(new GlobalizedMessage(
"cms.ui.permissions.cannot_add_user",
CmsConstants.CMS_BUNDLE));
}
permissionManager.grantPrivilege(ItemPrivileges.ADMINISTER,
role.get(),
object);
}
} else {
throw new FormProcessException(new GlobalizedMessage(
"cms.ui.permissions.no_roles_were_selected",
CmsConstants.CMS_BUNDLE));
}
fireCompletionEvent(state);
}
}

View File

@ -1,118 +0,0 @@
/*
* Copyright (C) 2002-2004 Red Hat Inc. All Rights Reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
package com.arsdigita.cms.ui.permissions;
import com.arsdigita.bebop.ActionLink;
import com.arsdigita.bebop.FormData;
import com.arsdigita.bebop.PageState;
import com.arsdigita.bebop.SimpleContainer;
import com.arsdigita.bebop.event.ActionEvent;
import com.arsdigita.bebop.event.ActionListener;
import com.arsdigita.cms.ui.UserSearchForm;
import com.arsdigita.globalization.GlobalizedMessage;
import com.arsdigita.ui.CcmObjectSelectionModel;
import com.arsdigita.xml.Element;
import org.libreccm.core.CcmObject;
import org.librecms.CmsConstants;
/**
* <p>
* This panel allows a staff administrator to search for users and add them to a
* staff role for the content section.</p>
*
* @author Michael Pih (pihman@arsdigita.com)
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
public class ObjectAddSearchAdmin extends SimpleContainer {
private final CcmObjectSelectionModel<CcmObject> objectSelectionModel;
private final UserSearchForm searchForm;
private final ObjectAddAdmin addPanel;
private final ActionLink returnLink;
public ObjectAddSearchAdmin(
final CcmObjectSelectionModel<CcmObject> objectSelectionModel) {
super();
this.objectSelectionModel = objectSelectionModel;
searchForm = new UserSearchForm("ObjectAdminSearch");
add(searchForm);
addPanel = getObjectAddAdmin(objectSelectionModel, searchForm);
add(addPanel);
addPanel.addCompletionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent event) {
fireCompletionEvent(event.getPageState());
}
});
returnLink = new ActionLink(new GlobalizedMessage(
"cms.ui.permissions.return_to_object_info", CmsConstants.CMS_BUNDLE));
returnLink.setClassAttr("actionLink");
returnLink.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent event) {
fireCompletionEvent(event.getPageState());
}
});
add(returnLink);
}
/**
* Displays the appropriate form(s).
*
* @param parent
*/
@Override
public void generateXML(final PageState state, final Element parent) {
final FormData data = searchForm.getFormData(state);
final FormData data2 = addPanel.getForm().getFormData(state);
if (data != null && (data.isSubmission() || data2.isSubmission())) {
addPanel.setVisible(state, true);
} else {
addPanel.setVisible(state, false);
}
super.generateXML(state, parent);
}
/**
* This returns the form for adding object administrators
*
* @param model
* @param searchForm
* @return
*/
protected ObjectAddAdmin getObjectAddAdmin(
final CcmObjectSelectionModel<CcmObject> model,
final UserSearchForm searchForm) {
return new ObjectAddAdmin(model, searchForm.getSearchWidget());
}
}

View File

@ -1,256 +0,0 @@
/*
* Copyright (C) 2002-2004 Red Hat Inc. All Rights Reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
package com.arsdigita.cms.ui.permissions;
import com.arsdigita.bebop.ActionLink;
import com.arsdigita.bebop.Component;
import com.arsdigita.bebop.ControlLink;
import com.arsdigita.bebop.Label;
import com.arsdigita.bebop.Page;
import com.arsdigita.bebop.PageState;
import com.arsdigita.bebop.SimpleContainer;
import com.arsdigita.bebop.Table;
import com.arsdigita.bebop.Text;
import com.arsdigita.bebop.event.ActionEvent;
import com.arsdigita.bebop.event.ActionListener;
import com.arsdigita.bebop.event.TableActionEvent;
import com.arsdigita.bebop.event.TableActionListener;
import com.arsdigita.bebop.table.TableCellRenderer;
import com.arsdigita.bebop.table.TableModel;
import com.arsdigita.bebop.table.TableModelBuilder;
import com.arsdigita.cms.CMS;
import com.arsdigita.globalization.GlobalizedMessage;
import com.arsdigita.ui.CcmObjectSelectionModel;
import com.arsdigita.util.LockableImpl;
import com.arsdigita.util.UncheckedWrapperException;
import org.libreccm.cdi.utils.CdiUtil;
import org.libreccm.core.CcmObject;
import org.libreccm.security.PermissionChecker;
import org.libreccm.security.PermissionManager;
import org.libreccm.security.Role;
import org.libreccm.security.RoleRepository;
import org.librecms.CmsConstants;
import org.librecms.contentsection.privileges.ItemPrivileges;
import java.util.Iterator;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
public class ObjectAdminListing extends SimpleContainer {
private final Table adminTable;
private ActionLink addUserLink;
private final CcmObjectSelectionModel<CcmObject> objectSelectionModel;
private ObjectAddSearchAdmin objectAddSearchAdmin;
public ObjectAdminListing(
final CcmObjectSelectionModel<CcmObject> objectSelectionModel) {
super("cms:roleAdmin", CMS.CMS_XML_NS);
this.objectSelectionModel = objectSelectionModel;
adminTable = new Table(getTableModelBuilder(objectSelectionModel),
new String[]{"Member", "Action"});
adminTable.setDefaultCellRenderer(new ObjectAdminTableRenderer());
adminTable.setEmptyView(new Label(
"There are no administrators for this object"));
adminTable.setClassAttr("dataTable");
adminTable.addTableActionListener(new ObjectAdminActionListener());
addUserLink = new ActionLink(new GlobalizedMessage(
"cms.ui.permissions.add_administrator", CmsConstants.CMS_BUNDLE));
addUserLink.setClassAttr("actionLink");
objectAddSearchAdmin = getObjectAddSearchAdmin(objectSelectionModel);
addUserLink.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent event) {
objectAddSearchAdmin.setVisible(event.getPageState(), true);
addUserLink.setVisible(event.getPageState(), false);
}
});
objectAddSearchAdmin.addCompletionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent event) {
objectAddSearchAdmin.setVisible(event.getPageState(), false);
addUserLink.setVisible(event.getPageState(), true);
}
});
add(adminTable);
add(addUserLink);
add(objectAddSearchAdmin);
}
@Override
public void register(final Page page) {
super.register(page);
page.setVisibleDefault(objectAddSearchAdmin, false);
}
// This returns the add search admin form to use for this object
protected ObjectAddSearchAdmin getObjectAddSearchAdmin(
CcmObjectSelectionModel<CcmObject> model) {
return new ObjectAddSearchAdmin(model);
}
private class ObjectAdminActionListener implements TableActionListener {
@Override
public void cellSelected(final TableActionEvent event) {
if (event.getColumn() == 1) {
final PageState state = event.getPageState();
final CcmObject object = objectSelectionModel.getSelectedObject(
state);
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final PermissionChecker permissionChecker = cdiUtil.findBean(
PermissionChecker.class);
final PermissionManager permissionManager = cdiUtil.findBean(
PermissionManager.class);
final RoleRepository roleRepo = cdiUtil.findBean(
RoleRepository.class);
permissionChecker.checkPermission(
ItemPrivileges.ADMINISTER, object);
final String roleId = (String) event.getRowKey();
final Optional<Role> role = roleRepo.findById(Long.parseLong(roleId));
if (!role.isPresent()) {
throw new UncheckedWrapperException(String.format(
"No role with id %s found.", roleId));
}
permissionManager.revokePrivilege(ItemPrivileges.ADMINISTER,
role.get(),
object);
}
}
@Override
public void headSelected(final TableActionEvent event) {
}
}
protected TableModelBuilder getTableModelBuilder(
final CcmObjectSelectionModel<CcmObject> model) {
return new ObjectTableModelBuilder(model);
}
private class ObjectTableModelBuilder extends LockableImpl
implements TableModelBuilder {
private final CcmObjectSelectionModel<CcmObject> model;
ObjectTableModelBuilder(final CcmObjectSelectionModel<CcmObject> model) {
this.model = model;
}
@Override
public TableModel makeModel(final Table table, final PageState state) {
final CcmObject object = model.getSelectedObject(state);
final List<Role> roles = object.getPermissions().stream()
.filter(permission -> ItemPrivileges.ADMINISTER.equals(
permission.getGrantedPrivilege()))
.map(permission -> permission.getGrantee())
.collect(Collectors.toList());
return new ObjectAdminTableModel(roles);
}
}
private class ObjectAdminTableModel implements TableModel {
private final Iterator<Role> roles;
private Role currentRole;
public ObjectAdminTableModel(final List<Role> roles) {
this.roles = roles.iterator();
}
@Override
public int getColumnCount() {
return 2;
}
@Override
public boolean nextRow() {
if (roles.hasNext()) {
currentRole = roles.next();
return true;
} else {
return false;
}
}
@Override
public Object getElementAt(final int column) {
return currentRole;
}
@Override
public Object getKeyAt(final int column) {
return currentRole.getRoleId();
}
}
private class ObjectAdminTableRenderer implements TableCellRenderer {
@Override
public Component getComponent(final Table list,
final PageState state,
final Object value,
final boolean isSelected,
final Object key,
final int row,
final int column) {
final Role role = (Role) value;
switch (column) {
case 0:
return new Text(role.getName());
case 1:
return new ControlLink(new Text("remove"));
default:
throw new IllegalArgumentException("Column index " + column
+ " out of bounds 0..1");
}
}
}
}

View File

@ -1,67 +0,0 @@
/*
* Copyright (C) 2017 LibreCCM Foundation.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
package com.arsdigita.cms.ui.permissions;
import org.libreccm.core.CcmObject;
import org.libreccm.security.Role;
/**
*
* Structure to hold a permission and its current grant state
*
*
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
final class PermissionStatus {
private final boolean granted;
private final CcmObject object;
private final Role role;
private final String privilege;
PermissionStatus(final String privilege,
final CcmObject object,
final Role role,
final boolean granted) {
this.granted = granted;
this.object = object;
this.role = role;
this.privilege = privilege;
}
boolean isGranted() {
return granted;
}
CcmObject getObject() {
return object;
}
Role getRole() {
return role;
}
String getPrivilege() {
return privilege;
}
}

View File

@ -1,84 +0,0 @@
/*
* Copyright (C) 2017 LibreCCM Foundation.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
package com.arsdigita.cms.ui.permissions;
/**
* Utility class to encode a user privilege in the bebop table.
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
final class UserPrivilegeKey {
private final String objectId;
private final String granteeId;
private final String privilege;
private final boolean granted;
public UserPrivilegeKey(final Long objectId,
final Long granteeId,
final String privilege,
final boolean granted) {
this.objectId = objectId.toString();
this.granteeId = granteeId.toString();
this.privilege = privilege;
this.granted = granted;
}
@Override
public String toString() {
return String.format("%s{ %s }",
super.toString(),
String.join(".", privilege,
objectId,
granteeId,
Boolean.toString(granted)));
}
/**
* Decodes the information in a key into the helper class
*
* @see PermissionStatus
*/
static PermissionStatus undescribe(final String key) {
final int i = key.indexOf(".");
final int j = key.indexOf(".", i + 1);
final int k = key.lastIndexOf(".");
final String privilege = key.substring(0, i);
final Long oID = Long.parseLong(key.substring(i + 1, j));
final Long gID = Long.parseLong(key.substring(j + 1, k));
boolean granted = false;
final CMSUserObjectStruct uos;
try {
granted = Boolean.parseBoolean(key.substring(k + 1, k + 2));
uos = new CMSUserObjectStruct(gID, oID);
} catch (NumberFormatException ex) {
// cannot decode
throw new IllegalArgumentException(ex.getMessage());
}
return new PermissionStatus(privilege,
uos.getObject(),
uos.getRole(),
granted);
}
}