Removed depcrecated package com/arsdigita/cms/ui/role from ccm-cms
parent
5efeef8136
commit
980f958bae
|
|
@ -39,7 +39,6 @@ import com.arsdigita.cms.ui.category.CategoryAdminPane;
|
|||
import com.arsdigita.cms.ui.cse.ContentSoonExpiredPane;
|
||||
import com.arsdigita.cms.ui.folder.FolderAdminPane;
|
||||
import com.arsdigita.cms.ui.lifecycle.LifecycleAdminPane;
|
||||
import com.arsdigita.cms.ui.role.RoleAdminPane;
|
||||
import com.arsdigita.cms.ui.workflow.WorkflowAdminPane;
|
||||
import com.arsdigita.globalization.GlobalizedMessage;
|
||||
import com.arsdigita.toolbox.ui.LayoutPanel;
|
||||
|
|
@ -134,8 +133,6 @@ public class ContentSectionPage extends CMSPage implements ActionListener {
|
|||
|
||||
private ItemSearch m_searchPane;
|
||||
|
||||
private RoleAdminPane m_rolePane;
|
||||
|
||||
private WorkflowAdminPane m_workflowPane;
|
||||
|
||||
private LifecycleAdminPane m_lifecyclePane;
|
||||
|
|
@ -160,7 +157,6 @@ public class ContentSectionPage extends CMSPage implements ActionListener {
|
|||
m_folderPane = getFolderAdminPane();
|
||||
m_browsePane = getBrowsePane();
|
||||
m_searchPane = getSearchPane();
|
||||
m_rolePane = getRoleAdminPane();
|
||||
m_workflowPane = getWorkflowAdminPane();
|
||||
m_lifecyclePane = getLifecycleAdminPane();
|
||||
m_categoryPane = getCategoryAdminPane();
|
||||
|
|
@ -205,11 +201,6 @@ public class ContentSectionPage extends CMSPage implements ActionListener {
|
|||
permissionChecker.isPermitted(
|
||||
AdminPrivileges.ADMINISTER_LIFECYLES));
|
||||
|
||||
m_tabbedPane.setTabVisible(
|
||||
state,
|
||||
m_rolePane,
|
||||
permissionChecker.isPermitted(
|
||||
AdminPrivileges.ADMINISTER_ROLES));
|
||||
// csePane: should check permission
|
||||
m_tabbedPane.setTabVisible(state, m_csePane, true);
|
||||
// TODO Check for reportPane as well
|
||||
|
|
@ -261,27 +252,6 @@ public class ContentSectionPage extends CMSPage implements ActionListener {
|
|||
return m_searchPane;
|
||||
}
|
||||
|
||||
// protected AssetPane getAssetPane() {
|
||||
// if (m_assetPane == null) {
|
||||
// m_assetPane = new AssetPane();
|
||||
// }
|
||||
//
|
||||
// return m_assetPane;
|
||||
// }
|
||||
// ToDo NG
|
||||
// protected ImagesPane getImagesPane() {
|
||||
// if (m_imagesPane == null) {
|
||||
// m_imagesPane = new ImagesPane();
|
||||
// }
|
||||
// return m_imagesPane;
|
||||
// }
|
||||
protected RoleAdminPane getRoleAdminPane() {
|
||||
if (m_rolePane == null) {
|
||||
m_rolePane = new RoleAdminPane();
|
||||
}
|
||||
return m_rolePane;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates, and then caches, the workflow administration pane. Overriding
|
||||
* this method to return null will prevent this tab from appearing.
|
||||
|
|
@ -365,11 +335,8 @@ public class ContentSectionPage extends CMSPage implements ActionListener {
|
|||
protected TabbedPane createTabbedPane() {
|
||||
final TabbedPane pane = new TabbedPane();
|
||||
|
||||
//tab(pane, "cms.ui.folders", getFolderAdminPane());
|
||||
tab(pane, "cms.ui.browse", getBrowsePane());
|
||||
tab(pane, "cms.ui.search", getSearchPane());
|
||||
// ToDo NG replace with media tab tab(pane, "cms.ui.images", getImagesPane());
|
||||
tab(pane, "cms.ui.roles", getRoleAdminPane());
|
||||
tab(pane, "cms.ui.workflows", getWorkflowAdminPane());
|
||||
tab(pane, "cms.ui.lifecycles", getLifecycleAdminPane());
|
||||
tab(pane, "cms.ui.categories", getCategoryAdminPane());
|
||||
|
|
|
|||
|
|
@ -1,168 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2003-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.role;
|
||||
|
||||
import com.arsdigita.bebop.FormProcessException;
|
||||
import com.arsdigita.bebop.Label;
|
||||
import com.arsdigita.bebop.PageState;
|
||||
import com.arsdigita.bebop.event.ParameterEvent;
|
||||
import com.arsdigita.bebop.event.ParameterListener;
|
||||
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.cms.CMS;
|
||||
import com.arsdigita.cms.ui.BaseForm;
|
||||
import com.arsdigita.globalization.GlobalizedMessage;
|
||||
import com.arsdigita.ui.admin.GlobalizationUtil;
|
||||
import com.arsdigita.util.UncheckedWrapperException;
|
||||
|
||||
import org.libreccm.cdi.utils.CdiUtil;
|
||||
import org.libreccm.security.PermissionManager;
|
||||
import org.libreccm.security.Role;
|
||||
import org.librecms.CmsConstants;
|
||||
import org.librecms.contentsection.ContentSection;
|
||||
import org.librecms.contentsection.privileges.AdminPrivileges;
|
||||
import org.librecms.contentsection.privileges.AssetPrivileges;
|
||||
import org.librecms.contentsection.privileges.ItemPrivileges;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.TooManyListenersException;
|
||||
|
||||
/**
|
||||
* For more detailed information see {@link com.arsdigita.bebop.Form}.
|
||||
*
|
||||
* @author <a href="mailto:yannick.buelter@yabue.de">Yannick Bülter</a>
|
||||
* @author Justin Ross <jross@redhat.com>
|
||||
*
|
||||
*/
|
||||
class BaseRoleForm extends BaseForm {
|
||||
|
||||
private final Name roleName;
|
||||
private final Description roleDescription;
|
||||
private CheckboxGroup privileges;
|
||||
|
||||
BaseRoleForm(final String key,
|
||||
final GlobalizedMessage message) {
|
||||
super(key, message);
|
||||
|
||||
roleName = new Name("label", 200, true);
|
||||
addField(gz("cms.ui.role.name"), roleName);
|
||||
|
||||
roleDescription = new Description("description", 4000, false);
|
||||
addField(gz("cms.ui.role.description"), roleDescription);
|
||||
|
||||
privileges = new CheckboxGroup("privileges");
|
||||
addField(gz("cms.ui.role.privileges"), privileges);
|
||||
|
||||
try {
|
||||
privileges.addPrintListener(new PrivilegePrinter());
|
||||
} catch (TooManyListenersException tmle) {
|
||||
throw new UncheckedWrapperException(tmle);
|
||||
}
|
||||
|
||||
addAction(new Finish());
|
||||
addAction(new Cancel());
|
||||
|
||||
addSecurityListener(AdminPrivileges.ADMINISTER_ROLES);
|
||||
}
|
||||
|
||||
protected Name getRoleName() {
|
||||
return roleName;
|
||||
}
|
||||
|
||||
protected Description getRoleDescription() {
|
||||
return roleDescription;
|
||||
}
|
||||
|
||||
protected CheckboxGroup getPrivileges() {
|
||||
return privileges;
|
||||
}
|
||||
|
||||
private class PrivilegePrinter implements PrintListener {
|
||||
|
||||
@Override
|
||||
public final void prepare(final PrintEvent event) {
|
||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||
final PermissionManager permissionManager = cdiUtil.findBean(
|
||||
PermissionManager.class);
|
||||
|
||||
final CheckboxGroup target = (CheckboxGroup) event.getTarget();
|
||||
target.clearOptions();
|
||||
|
||||
final List<String> adminPrivileges = permissionManager
|
||||
.listDefiniedPrivileges(AdminPrivileges.class);
|
||||
final List<String> itemPrivileges = permissionManager
|
||||
.listDefiniedPrivileges(ItemPrivileges.class);
|
||||
final List<String> assetPrivileges = permissionManager
|
||||
.listDefiniedPrivileges(AssetPrivileges.class);
|
||||
|
||||
final List<String> possiblePrivileges = new ArrayList<>();
|
||||
possiblePrivileges.addAll(adminPrivileges);
|
||||
possiblePrivileges.addAll(itemPrivileges);
|
||||
possiblePrivileges.addAll(assetPrivileges);
|
||||
|
||||
for (final String privilege : possiblePrivileges) {
|
||||
target.addOption(new Option(
|
||||
privilege,
|
||||
new Label(new GlobalizedMessage(privilege,
|
||||
CmsConstants.CMS_BUNDLE))));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class NameUniqueListener implements ParameterListener {
|
||||
|
||||
private final RoleRequestLocal roleRequestLocal;
|
||||
|
||||
NameUniqueListener(final RoleRequestLocal role) {
|
||||
roleRequestLocal = role;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates that there are no duplicates between the names of roles.
|
||||
*/
|
||||
@Override
|
||||
public final void validate(final ParameterEvent event)
|
||||
throws FormProcessException {
|
||||
|
||||
final PageState state = event.getPageState();
|
||||
final String name = (String) roleName.getValue(state);
|
||||
|
||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||
final RoleAdminPaneController controller = cdiUtil.findBean(
|
||||
RoleAdminPaneController.class);
|
||||
final Role selectedRole;
|
||||
if (roleRequestLocal == null) {
|
||||
selectedRole = null;
|
||||
} else {
|
||||
selectedRole = roleRequestLocal.getRole(state);
|
||||
}
|
||||
|
||||
if (!controller.validateRoleNameUniqueness(name, selectedRole)) {
|
||||
throw new FormProcessException(GlobalizationUtil.globalize(
|
||||
"cms.ui.role.name_not_unique"));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,273 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2003-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.role;
|
||||
|
||||
import com.arsdigita.bebop.ActionLink;
|
||||
import com.arsdigita.bebop.FormProcessException;
|
||||
import com.arsdigita.bebop.Label;
|
||||
import com.arsdigita.bebop.PageState;
|
||||
import com.arsdigita.bebop.SimpleContainer;
|
||||
import com.arsdigita.bebop.SingleSelectionModel;
|
||||
import com.arsdigita.bebop.Table;
|
||||
import com.arsdigita.bebop.event.TableActionAdapter;
|
||||
import com.arsdigita.bebop.event.TableActionEvent;
|
||||
import com.arsdigita.bebop.table.DefaultTableCellRenderer;
|
||||
import com.arsdigita.bebop.table.TableColumn;
|
||||
import com.arsdigita.bebop.table.TableColumnModel;
|
||||
import com.arsdigita.cms.CMS;
|
||||
import com.arsdigita.cms.ui.BaseItemPane;
|
||||
import com.arsdigita.cms.ui.PartySearchForm;
|
||||
import com.arsdigita.cms.ui.VisibilityComponent;
|
||||
import com.arsdigita.globalization.GlobalizedMessage;
|
||||
import com.arsdigita.toolbox.ui.ActionGroup;
|
||||
import com.arsdigita.toolbox.ui.Property;
|
||||
import com.arsdigita.toolbox.ui.PropertyList;
|
||||
import com.arsdigita.toolbox.ui.Section;
|
||||
|
||||
import org.libreccm.cdi.utils.CdiUtil;
|
||||
import org.libreccm.security.Party;
|
||||
import org.libreccm.security.PartyRepository;
|
||||
import org.libreccm.security.PermissionChecker;
|
||||
import org.libreccm.security.Role;
|
||||
import org.libreccm.security.RoleManager;
|
||||
import org.librecms.CmsConstants;
|
||||
import org.librecms.contentsection.privileges.AdminPrivileges;
|
||||
|
||||
/**
|
||||
* This pane is for showing the properties of a {@link Role}. That includes
|
||||
* name, description, permissions and members. The last one is a list of
|
||||
* {@link Party parties} to which the role corresponds to.
|
||||
*
|
||||
* NOTE: There was an AdminTable besides the MemberTable. Since this function
|
||||
* was/is never used, it was deemed deprecated and was removed.
|
||||
*
|
||||
*
|
||||
* @author Justin Ross <jross@redhat.com>
|
||||
* @author <a href="mailto:yannick.buelter@yabue.de">Yannick Bülter</a>
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
class BaseRoleItemPane extends BaseItemPane {
|
||||
|
||||
private final RoleRequestLocal roleRequestLocal;
|
||||
|
||||
private final MemberTable membersTable;
|
||||
|
||||
BaseRoleItemPane(final SingleSelectionModel<String> model,
|
||||
final RoleRequestLocal role,
|
||||
final ActionLink editLink,
|
||||
final ActionLink deleteLink) {
|
||||
roleRequestLocal = role;
|
||||
|
||||
membersTable = new MemberTable();
|
||||
|
||||
final ActionLink memberAddLink = new ActionLink(new Label(gz(
|
||||
"cms.ui.role.member.add")));
|
||||
|
||||
final SimpleContainer m_detailPane = new SimpleContainer();
|
||||
add(m_detailPane);
|
||||
setDefault(m_detailPane);
|
||||
|
||||
m_detailPane.add(new SummarySection(editLink, deleteLink));
|
||||
m_detailPane.add(new MemberSection(memberAddLink));
|
||||
|
||||
final PartySearchForm memberSearchForm = new PartySearchForm();
|
||||
add(memberSearchForm);
|
||||
|
||||
final RolePartyAddForm memberAddForm = new RolePartyAddForm(
|
||||
model, memberSearchForm.getSearchWidget());
|
||||
add(memberAddForm);
|
||||
|
||||
connect(memberAddLink, memberSearchForm);
|
||||
connect(memberSearchForm, memberAddForm);
|
||||
memberAddForm.getForm().addSubmissionListener(new CancelListener(
|
||||
memberAddForm.getForm()));
|
||||
resume(memberAddForm.getForm(), m_detailPane);
|
||||
}
|
||||
|
||||
private class SummarySection extends Section {
|
||||
|
||||
SummarySection(final ActionLink editLink,
|
||||
final ActionLink deleteLink) {
|
||||
setHeading(gz("cms.ui.role.details"));
|
||||
|
||||
final ActionGroup group = new ActionGroup();
|
||||
setBody(group);
|
||||
|
||||
group.setSubject(new Properties());
|
||||
group.addAction(
|
||||
new VisibilityComponent(editLink,
|
||||
AdminPrivileges.ADMINISTER_ROLES),
|
||||
ActionGroup.DELETE);
|
||||
group.addAction(
|
||||
new VisibilityComponent(deleteLink,
|
||||
AdminPrivileges.ADMINISTER_ROLES),
|
||||
ActionGroup.DELETE);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private class Properties extends PropertyList {
|
||||
|
||||
@Override
|
||||
protected final java.util.List<Property> properties(
|
||||
final PageState state
|
||||
) {
|
||||
|
||||
final java.util.List<Property> properties = super.properties(
|
||||
state
|
||||
);
|
||||
|
||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||
final RoleAdminPaneController controller = cdiUtil
|
||||
.findBean(RoleAdminPaneController.class);
|
||||
|
||||
final Role role = roleRequestLocal.getRole(state);
|
||||
|
||||
properties.add(
|
||||
new Property(lz("cms.ui.role.name"), role.getName())
|
||||
);
|
||||
|
||||
// Right now just loads the default locale description.
|
||||
properties.add(
|
||||
new Property(
|
||||
lz("cms.ui.role.description"),
|
||||
controller.getRoleDescription(role)
|
||||
)
|
||||
);
|
||||
|
||||
// Since Permissions don't seem to have a "pretty" form, the
|
||||
// granted privilege is used.
|
||||
final String permissions = controller
|
||||
.generateGrantedPermissionsString(
|
||||
role,
|
||||
CMS.getContext().getContentSection()
|
||||
);
|
||||
|
||||
if (permissions.length() > 0) {
|
||||
properties.add(
|
||||
new Property(
|
||||
lz("cms.ui.role.privileges"),
|
||||
permissions
|
||||
)
|
||||
);
|
||||
} else {
|
||||
properties.add(
|
||||
new Property(
|
||||
lz("cms.ui.role.privileges"),
|
||||
lz("cms.ui.role.privilege.none")
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
return properties;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private class MemberSection extends Section {
|
||||
|
||||
MemberSection(final ActionLink memberAddLink) {
|
||||
setHeading(gz("cms.ui.role.members"));
|
||||
|
||||
final ActionGroup group = new ActionGroup();
|
||||
setBody(group);
|
||||
|
||||
group.setSubject(membersTable);
|
||||
group.addAction(
|
||||
new VisibilityComponent(memberAddLink,
|
||||
AdminPrivileges.ADMINISTER_ROLES),
|
||||
ActionGroup.ADD);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private class MemberTable extends Table {
|
||||
|
||||
private static final int COL_NAME = 0;
|
||||
|
||||
private static final int COL_EMAIL = 1;
|
||||
|
||||
private static final int COL_REMOVE = 2;
|
||||
|
||||
MemberTable() {
|
||||
super();
|
||||
|
||||
final TableColumnModel columnModel = getColumnModel();
|
||||
columnModel.add(new TableColumn(
|
||||
COL_NAME,
|
||||
new Label(new GlobalizedMessage("cms.ui.name",
|
||||
CmsConstants.CMS_BUNDLE))));
|
||||
columnModel.add(new TableColumn(
|
||||
COL_EMAIL,
|
||||
new Label(new GlobalizedMessage("cms.ui.role.member.email",
|
||||
CmsConstants.CMS_BUNDLE))));
|
||||
columnModel.add(new TableColumn(
|
||||
COL_REMOVE,
|
||||
new Label(new GlobalizedMessage("cms.ui.role.member.remove",
|
||||
CmsConstants.CMS_BUNDLE))));
|
||||
|
||||
setEmptyView(new Label(gz("cms.ui.role.member.none")));
|
||||
|
||||
setModelBuilder(new MemberTableModelBuilder(roleRequestLocal));
|
||||
|
||||
getColumn(2).setCellRenderer(new DefaultTableCellRenderer(true));
|
||||
|
||||
addTableActionListener(new Listener());
|
||||
}
|
||||
|
||||
private class Listener extends TableActionAdapter {
|
||||
|
||||
@Override
|
||||
public final void cellSelected(final TableActionEvent e) throws
|
||||
FormProcessException {
|
||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||
final PageState state = e.getPageState();
|
||||
final PermissionChecker permissionChecker = cdiUtil.findBean(
|
||||
PermissionChecker.class);
|
||||
|
||||
if (!permissionChecker.isPermitted(
|
||||
AdminPrivileges.ADMINISTER_ROLES)) {
|
||||
throw new FormProcessException(
|
||||
new GlobalizedMessage(
|
||||
"cms.ui.role.insufficient_privileges",
|
||||
CmsConstants.CMS_BUNDLE));
|
||||
}
|
||||
|
||||
if (e.getColumn() == 2) {
|
||||
final Role role = roleRequestLocal.getRole(state);
|
||||
long itemId = Long.parseLong(e.getRowKey().toString());
|
||||
|
||||
final PartyRepository partyRepository = cdiUtil.findBean(
|
||||
PartyRepository.class);
|
||||
final RoleManager roleManager = cdiUtil.findBean(
|
||||
RoleManager.class);
|
||||
final Party party = partyRepository.findById(itemId).get();
|
||||
|
||||
roleManager.removeRoleFromParty(role, party);
|
||||
|
||||
getRowSelectionModel().clearSelection(state);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,120 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2003-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.role;
|
||||
|
||||
import com.arsdigita.bebop.PageState;
|
||||
import com.arsdigita.bebop.Table;
|
||||
import com.arsdigita.bebop.table.AbstractTableModelBuilder;
|
||||
import com.arsdigita.bebop.table.TableModel;
|
||||
import com.arsdigita.ui.admin.GlobalizationUtil;
|
||||
|
||||
import org.libreccm.cdi.utils.CdiUtil;
|
||||
import org.libreccm.security.Party;
|
||||
import org.libreccm.security.PartyRepository;
|
||||
import org.libreccm.security.Role;
|
||||
import org.libreccm.security.RoleManager;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Creates a table model based on the {@link Party parties} of the given
|
||||
* {@link Role role}.
|
||||
*
|
||||
* @author <a href="mailto:yannick.buelter@yabue.de">Yannick Bülter</a>
|
||||
* @author Justin Ross <jross@redhat.com>
|
||||
* @version $Id: MemberTableModelBuilder.java 287 2005-02-22 00:29:02Z sskracic
|
||||
* $
|
||||
*/
|
||||
class MemberTableModelBuilder extends AbstractTableModelBuilder {
|
||||
|
||||
private final RoleRequestLocal roleRequestLocal;
|
||||
|
||||
MemberTableModelBuilder(final RoleRequestLocal role) {
|
||||
roleRequestLocal = role;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final TableModel makeModel(final Table table,
|
||||
final PageState state) {
|
||||
final Role role = roleRequestLocal.getRole(state);
|
||||
|
||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||
final RoleAdminPaneController controller = cdiUtil.findBean(
|
||||
RoleAdminPaneController.class);
|
||||
final List<Party> members = controller.createRoleMemberList(role);
|
||||
|
||||
return new Model(members);
|
||||
}
|
||||
|
||||
private static class Model implements TableModel {
|
||||
|
||||
private Party m_party;
|
||||
private final Collection<Party> m_parties;
|
||||
private final Iterator<Party> iterator;
|
||||
|
||||
Model(final Collection<Party> parties) {
|
||||
m_parties = parties;
|
||||
iterator = m_parties.iterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final int getColumnCount() {
|
||||
return 3;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean nextRow() {
|
||||
if (iterator.hasNext()) {
|
||||
m_party = iterator.next();
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Object getKeyAt(final int column) {
|
||||
return m_party.getPartyId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Object getElementAt(final int column) {
|
||||
switch (column) {
|
||||
case 0:
|
||||
return m_party.getName();
|
||||
case 1:
|
||||
return lz("cms.ui.none");
|
||||
case 2:
|
||||
return lz("cms.ui.role.member.remove");
|
||||
default:
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected static String lz(final String key) {
|
||||
return (String) GlobalizationUtil.globalize(key).localize();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,87 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2003-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.role;
|
||||
|
||||
import com.arsdigita.bebop.FormProcessException;
|
||||
import com.arsdigita.bebop.PageState;
|
||||
import com.arsdigita.bebop.SingleSelectionModel;
|
||||
import com.arsdigita.bebop.event.FormProcessListener;
|
||||
import com.arsdigita.bebop.event.FormSectionEvent;
|
||||
|
||||
import org.libreccm.cdi.utils.CdiUtil;
|
||||
import org.libreccm.security.Role;
|
||||
|
||||
/**
|
||||
* Provides a {@link com.arsdigita.bebop.Form} for adding {@link Role roles}.
|
||||
*
|
||||
*
|
||||
* @author Michael Pih
|
||||
* @author Justin Ross <jross@redhat.com>
|
||||
* @author <a href="mailto:yannick.buelter@yabue.de">Yannick Bülter</a>
|
||||
*/
|
||||
final class RoleAddForm extends BaseRoleForm {
|
||||
|
||||
private final SingleSelectionModel<String> selectionModel;
|
||||
|
||||
RoleAddForm(final SingleSelectionModel<String> selectionModel) {
|
||||
super("AddStaffRole", gz("cms.ui.role.add"));
|
||||
|
||||
this.selectionModel = selectionModel;
|
||||
|
||||
getRoleName().addValidationListener(new NameUniqueListener(null));
|
||||
|
||||
addProcessListener(new ProcessListener());
|
||||
}
|
||||
|
||||
/**
|
||||
* The {@link Role} gets saved to the database and permissions are granted
|
||||
* as needed.
|
||||
*
|
||||
* NOTE: The part about granting and revoking privileges is mostly Copy &
|
||||
* Paste from {@link RoleEditForm}. If you find any bugs or errors in this
|
||||
* code, be sure to change it there accordingly.
|
||||
*/
|
||||
private class ProcessListener implements FormProcessListener {
|
||||
|
||||
@Override
|
||||
public final void process(final FormSectionEvent event)
|
||||
throws FormProcessException {
|
||||
|
||||
final PageState state = event.getPageState();
|
||||
final String roleName = (String) getRoleName().getValue(state);
|
||||
final String roleDesc = (String) getRoleDescription()
|
||||
.getValue(state);
|
||||
final String[] selectedPrivileges = (String[]) getPrivileges()
|
||||
.getValue(state);
|
||||
|
||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||
final RoleAdminPaneController controller = cdiUtil.findBean(
|
||||
RoleAdminPaneController.class);
|
||||
|
||||
final Role role = controller.addRole(roleName,
|
||||
roleDesc,
|
||||
selectedPrivileges);
|
||||
|
||||
selectionModel
|
||||
.setSelectedKey(state, Long.toString(role.getRoleId()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,215 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2003-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.role;
|
||||
|
||||
import com.arsdigita.bebop.ActionLink;
|
||||
import com.arsdigita.bebop.FormProcessException;
|
||||
import com.arsdigita.bebop.Label;
|
||||
import com.arsdigita.bebop.List;
|
||||
import com.arsdigita.bebop.PageState;
|
||||
import com.arsdigita.bebop.ParameterSingleSelectionModel;
|
||||
import com.arsdigita.bebop.SimpleContainer;
|
||||
import com.arsdigita.bebop.SingleSelectionModel;
|
||||
import com.arsdigita.bebop.event.ChangeEvent;
|
||||
import com.arsdigita.bebop.event.ChangeListener;
|
||||
import com.arsdigita.bebop.event.FormSectionEvent;
|
||||
import com.arsdigita.bebop.list.ListModel;
|
||||
import com.arsdigita.bebop.list.ListModelBuilder;
|
||||
import com.arsdigita.bebop.parameters.StringParameter;
|
||||
import com.arsdigita.cms.CMS;
|
||||
import com.arsdigita.cms.ui.BaseAdminPane;
|
||||
import com.arsdigita.cms.ui.BaseDeleteForm;
|
||||
import com.arsdigita.cms.ui.VisibilityComponent;
|
||||
import com.arsdigita.toolbox.ui.ActionGroup;
|
||||
import com.arsdigita.toolbox.ui.Section;
|
||||
import com.arsdigita.util.LockableImpl;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.libreccm.cdi.utils.CdiUtil;
|
||||
import org.libreccm.security.Role;
|
||||
import org.libreccm.security.RoleRepository;
|
||||
import org.librecms.contentsection.ContentSection;
|
||||
import org.librecms.contentsection.privileges.AdminPrivileges;
|
||||
|
||||
/**
|
||||
* Provides the logic to administer {@link Role roles}.
|
||||
*
|
||||
* NOTE: Prior, this class managed two {@link ListModelBuilder}. The reason
|
||||
* being, that roles where differentiated between Viewer and Member groups.
|
||||
* Since this is no longer the case, there exists only the
|
||||
* {@link RoleListModelBuilder} now.
|
||||
*
|
||||
*
|
||||
* @author Justin Ross <jross@redhat.com>
|
||||
* @author <a href="mailto:yannick.buelter@yabue.de">Yannick Bülter</a>
|
||||
* @author <a href="mailto:jens.pelzetter@googemail.com">Jens Pelzetter</a>
|
||||
*
|
||||
*/
|
||||
public class RoleAdminPane extends BaseAdminPane<String> {
|
||||
|
||||
private static final Logger LOGGER = LogManager.getLogger(
|
||||
RoleAdminPane.class);
|
||||
|
||||
private final SingleSelectionModel<String> selectionModel;
|
||||
|
||||
private final List rolesList;
|
||||
|
||||
public RoleAdminPane() {
|
||||
selectionModel = new ParameterSingleSelectionModel<>(
|
||||
new StringParameter(List.SELECTED));
|
||||
setSelectionModel(selectionModel);
|
||||
|
||||
selectionModel.addChangeListener(new SelectionListener());
|
||||
|
||||
RoleRequestLocal m_role = new SelectionRequestLocal();
|
||||
|
||||
rolesList = new List(new RoleListModelBuilder());
|
||||
rolesList.setSelectionModel(selectionModel);
|
||||
|
||||
final SimpleContainer left = new SimpleContainer();
|
||||
setLeft(left);
|
||||
|
||||
final RoleSection roleSection = new RoleSection();
|
||||
left.add(roleSection);
|
||||
|
||||
setEdit(gz("cms.ui.role.edit"), new RoleEditForm(m_role));
|
||||
setDelete(gz("cms.ui.role.delete"), new DeleteForm());
|
||||
|
||||
setIntroPane(new Label(gz("cms.ui.role.intro")));
|
||||
setItemPane(new BaseRoleItemPane(selectionModel, m_role,
|
||||
getEditLink(), getDeleteLink()));
|
||||
}
|
||||
|
||||
private class RoleSection extends Section {
|
||||
|
||||
RoleSection() {
|
||||
setHeading(gz("cms.ui.role.staff"));
|
||||
|
||||
final ActionGroup group = new ActionGroup();
|
||||
setBody(group);
|
||||
|
||||
group.setSubject(rolesList);
|
||||
|
||||
final ActionLink link = new ActionLink(new Label(gz(
|
||||
"cms.ui.role.staff.add")));
|
||||
|
||||
group.addAction(
|
||||
new VisibilityComponent(link,
|
||||
AdminPrivileges.ADMINISTER_ROLES),
|
||||
ActionGroup.ADD);
|
||||
|
||||
final RoleAddForm form = new RoleAddForm(selectionModel);
|
||||
getBody().add(form);
|
||||
getBody().connect(link, form);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private class SelectionListener implements ChangeListener {
|
||||
|
||||
@Override
|
||||
public final void stateChanged(final ChangeEvent event) {
|
||||
LOGGER.debug("Selection state changed; I may change "
|
||||
+ "the body's visible pane");
|
||||
|
||||
final PageState state = event.getPageState();
|
||||
|
||||
getBody().reset(state);
|
||||
|
||||
if (selectionModel.isSelected(state)) {
|
||||
LOGGER.debug("The selection model is selected; displaying "
|
||||
+ "the item pane");
|
||||
|
||||
getBody().push(state, getItemPane());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private class SelectionRequestLocal extends RoleRequestLocal {
|
||||
|
||||
@Override
|
||||
protected final Object initialValue(final PageState state) {
|
||||
final Long id = Long.parseLong(selectionModel.getSelectedKey(state));
|
||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||
final RoleRepository roleRepository = cdiUtil.findBean(
|
||||
RoleRepository.class);
|
||||
|
||||
return roleRepository.findById(id);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* This builder provides a list model of the {@link Role roles} which
|
||||
* correspond to the {@link ContentSection} in this context.
|
||||
*/
|
||||
private static class RoleListModelBuilder extends LockableImpl implements
|
||||
ListModelBuilder {
|
||||
|
||||
RoleListModelBuilder() {
|
||||
super();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final ListModel makeModel(final List list, final PageState state) {
|
||||
final ContentSection section = CMS.getContext().getContentSection();
|
||||
|
||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||
final RoleAdminPaneController controller = cdiUtil
|
||||
.findBean(RoleAdminPaneController.class);
|
||||
final java.util.List<Role> roles = controller
|
||||
.findRolesForContentSection(section);
|
||||
|
||||
return new RoleListModel(roles);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides a simple delete form to remove a {@link Role}.
|
||||
*/
|
||||
private class DeleteForm extends BaseDeleteForm {
|
||||
|
||||
DeleteForm() {
|
||||
super(gz("cms.ui.role.delete_prompt"));
|
||||
|
||||
addSecurityListener(AdminPrivileges.ADMINISTER_ROLES);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void process(final FormSectionEvent event)
|
||||
throws FormProcessException {
|
||||
|
||||
final PageState state = event.getPageState();
|
||||
|
||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||
final RoleAdminPaneController controller = cdiUtil.findBean(
|
||||
RoleAdminPaneController.class);
|
||||
|
||||
controller.deleteRole(CMS.getContext().getContentSection(),
|
||||
selectionModel.getSelectedKey(state));
|
||||
|
||||
selectionModel.clearSelection(state);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,402 +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.role;
|
||||
|
||||
import com.arsdigita.cms.CMS;
|
||||
import com.arsdigita.kernel.KernelConfig;
|
||||
|
||||
import org.libreccm.configuration.ConfigurationManager;
|
||||
import org.libreccm.security.Party;
|
||||
import org.libreccm.security.PartyRepository;
|
||||
import org.libreccm.security.Permission;
|
||||
import org.libreccm.security.PermissionManager;
|
||||
import org.libreccm.security.Role;
|
||||
import org.libreccm.security.RoleManager;
|
||||
import org.libreccm.security.RoleRepository;
|
||||
import org.librecms.contentsection.ContentSection;
|
||||
import org.librecms.contentsection.ContentSectionManager;
|
||||
import org.librecms.contentsection.ContentSectionRepository;
|
||||
import org.librecms.contentsection.Folder;
|
||||
import org.librecms.contentsection.privileges.AdminPrivileges;
|
||||
import org.librecms.contentsection.privileges.AssetPrivileges;
|
||||
import org.librecms.contentsection.privileges.ItemPrivileges;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
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 RoleAdminPaneController {
|
||||
|
||||
@Inject
|
||||
private ConfigurationManager confManager;
|
||||
|
||||
@Inject
|
||||
private PartyRepository partyRepo;
|
||||
|
||||
@Inject
|
||||
private PermissionManager permissionManager;
|
||||
|
||||
@Inject
|
||||
private RoleManager roleManager;
|
||||
|
||||
@Inject
|
||||
private RoleRepository roleRepo;
|
||||
|
||||
@Inject
|
||||
private ContentSectionManager sectionManager;
|
||||
|
||||
@Inject
|
||||
private ContentSectionRepository sectionRepo;
|
||||
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
public List<Role> findRolesForContentSection(final ContentSection section) {
|
||||
final ContentSection contentSection = sectionRepo
|
||||
.findById(section.getObjectId())
|
||||
.orElseThrow(() -> new IllegalArgumentException(String.format(
|
||||
"No ContentSection with id %d in the database. "
|
||||
+ "Where did that ID come from?",
|
||||
section.getObjectId())));
|
||||
|
||||
return new ArrayList<>(contentSection.getRoles());
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public String getRoleDescription(final Role ofRole) {
|
||||
final Role role = roleRepo
|
||||
.findById(ofRole.getRoleId())
|
||||
.orElseThrow(
|
||||
() -> new IllegalArgumentException(
|
||||
String.format(
|
||||
"No role with ID %d found.", ofRole.getRoleId()
|
||||
)
|
||||
)
|
||||
);
|
||||
final KernelConfig config = confManager
|
||||
.findConfiguration(KernelConfig.class);
|
||||
return role.getDescription().getValue(config.getDefaultLocale());
|
||||
}
|
||||
|
||||
public String[] getGrantedPrivileges(final Role role,
|
||||
final ContentSection section) {
|
||||
final List<Permission> sectionPermissions = permissionManager
|
||||
.findPermissionsForRoleAndObject(role, section);
|
||||
final List<Permission> itemPermissions = permissionManager
|
||||
.findPermissionsForRoleAndObject(role,
|
||||
section.getRootDocumentsFolder());
|
||||
final List<Permission> assetPermissions = permissionManager
|
||||
.findPermissionsForRoleAndObject(role,
|
||||
section.getRootAssetsFolder());
|
||||
final List<Permission> permissions = new ArrayList<>();
|
||||
permissions.addAll(sectionPermissions);
|
||||
permissions.addAll(itemPermissions);
|
||||
permissions.addAll(assetPermissions);
|
||||
final List<String> privileges = permissions.stream()
|
||||
.map(Permission::getGrantedPrivilege)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
return privileges.toArray(new String[]{});
|
||||
}
|
||||
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
public String generateGrantedPermissionsString(final Role role,
|
||||
final ContentSection section) {
|
||||
|
||||
final List<Permission> sectionPermissions = permissionManager
|
||||
.findPermissionsForRoleAndObject(role, section);
|
||||
final List<Permission> itemPermissions = permissionManager
|
||||
.findPermissionsForRoleAndObject(role,
|
||||
section.getRootDocumentsFolder());
|
||||
final List<Permission> assetPermissions = permissionManager
|
||||
.findPermissionsForRoleAndObject(role,
|
||||
section.getRootAssetsFolder());
|
||||
final List<Permission> permissions = new ArrayList<>();
|
||||
permissions.addAll(sectionPermissions);
|
||||
permissions.addAll(itemPermissions);
|
||||
permissions.addAll(assetPermissions);
|
||||
|
||||
return permissions.stream()
|
||||
.map(Permission::getGrantedPrivilege)
|
||||
.collect(Collectors.joining("; "));
|
||||
|
||||
}
|
||||
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
public List<Party> createRoleMemberList(final Role role) {
|
||||
|
||||
final Role theRole = roleRepo
|
||||
.findById(role.getRoleId())
|
||||
.orElseThrow(() -> new IllegalArgumentException(String.format(
|
||||
"No role with ID %d in the database. Where did that Id come from?",
|
||||
role.getRoleId())));
|
||||
|
||||
return theRole.getMemberships()
|
||||
.stream()
|
||||
.map(membership -> membership.getMember())
|
||||
.sorted((member1, member2) -> {
|
||||
return member1.getName().compareTo(member2.getName());
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
public void deleteRole(final ContentSection section,
|
||||
final String roleId) {
|
||||
|
||||
final Role role = roleRepo.findById(Long.parseLong(roleId))
|
||||
.orElseThrow(() -> new IllegalArgumentException(String.format(
|
||||
"No Role with ID %s in the database. Where did that ID come from?",
|
||||
roleId)));
|
||||
final ContentSection contentSection = sectionRepo
|
||||
.findById(section.getObjectId())
|
||||
.orElseThrow(() -> new IllegalArgumentException(String.format(
|
||||
"No ContentSection with ID %d in the database. "
|
||||
+ "Where did that ID come from?",
|
||||
section.getObjectId())));
|
||||
|
||||
sectionManager.removeRoleFromContentSection(contentSection, role);
|
||||
roleRepo.delete(role);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param name
|
||||
* @param selectedRole
|
||||
*
|
||||
* @return {@code true} if name is unique, {@code false} otherwise.
|
||||
*/
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
public boolean validateRoleNameUniqueness(final String name,
|
||||
final Role selectedRole) {
|
||||
|
||||
final ContentSection section = CMS.getContext().getContentSection();
|
||||
|
||||
final ContentSection contentSection = sectionRepo
|
||||
.findById(section.getObjectId())
|
||||
.orElseThrow(() -> new IllegalArgumentException(String.format(
|
||||
"No ContentSection with ID %d in the database."
|
||||
+ " Where did that ID come from?",
|
||||
section.getObjectId())));
|
||||
|
||||
final Collection<Role> roles = contentSection.getRoles();
|
||||
boolean result = true;
|
||||
for (final Role role : roles) {
|
||||
if (role.getName().equalsIgnoreCase(name)
|
||||
&& (selectedRole == null
|
||||
|| selectedRole.getRoleId() != role.getRoleId())) {
|
||||
result = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public void saveRole(final Role role,
|
||||
final String roleName,
|
||||
final String roleDescription,
|
||||
final String[] selectedPermissions) {
|
||||
|
||||
final Role roleToSave = roleRepo.findById(role.getRoleId())
|
||||
.orElseThrow(() -> new IllegalArgumentException(String.format(
|
||||
"No Role with ID %d in the database. Where did that ID come from?",
|
||||
role.getRoleId())));
|
||||
|
||||
final KernelConfig kernelConfig = confManager.findConfiguration(
|
||||
KernelConfig.class);
|
||||
final Locale defaultLocale = kernelConfig.getDefaultLocale();
|
||||
|
||||
roleToSave.setName(roleName);
|
||||
roleToSave.getDescription().putValue(defaultLocale, roleDescription);
|
||||
|
||||
roleRepo.save(roleToSave);
|
||||
|
||||
final ContentSection contentSection = sectionRepo.findById(
|
||||
CMS.getContext().getContentSection().getObjectId())
|
||||
.orElseThrow(() -> new IllegalArgumentException(String.format(
|
||||
"No ContentSection with ID %d in the database."
|
||||
+ "Where did that ID come from?",
|
||||
CMS.getContext().getContentSection().getObjectId())));
|
||||
|
||||
final List<String> adminPrivileges = permissionManager
|
||||
.listDefiniedPrivileges(AdminPrivileges.class);
|
||||
final List<String> itemPrivileges = permissionManager
|
||||
.listDefiniedPrivileges(ItemPrivileges.class);
|
||||
final List<String> assetPrivileges = permissionManager
|
||||
.listDefiniedPrivileges(AssetPrivileges.class);
|
||||
|
||||
final Folder rootDocumentsFolder = contentSection
|
||||
.getRootDocumentsFolder();
|
||||
final Folder rootAssetsFolder = contentSection.getRootAssetsFolder();
|
||||
|
||||
final List<Permission> currentPermissionsSection = permissionManager
|
||||
.findPermissionsForRoleAndObject(roleToSave, contentSection);
|
||||
final List<Permission> currentPermissionsDocuments = permissionManager
|
||||
.findPermissionsForRoleAndObject(roleToSave, rootDocumentsFolder);
|
||||
final List<Permission> currentPermissionsAssets = permissionManager
|
||||
.findPermissionsForRoleAndObject(roleToSave, rootAssetsFolder);
|
||||
|
||||
//Revoke permissions not in selectedPermissions
|
||||
revokeNotSelectedPrivileges(selectedPermissions,
|
||||
roleToSave,
|
||||
currentPermissionsSection);
|
||||
revokeNotSelectedPrivileges(selectedPermissions,
|
||||
roleToSave,
|
||||
currentPermissionsDocuments);
|
||||
revokeNotSelectedPrivileges(selectedPermissions,
|
||||
roleToSave,
|
||||
currentPermissionsAssets);
|
||||
|
||||
// Grant selected privileges
|
||||
for (final String privilege : adminPrivileges) {
|
||||
if (isPrivilegeSelected(selectedPermissions, privilege)) {
|
||||
permissionManager.grantPrivilege(privilege,
|
||||
roleToSave,
|
||||
contentSection);
|
||||
}
|
||||
}
|
||||
|
||||
for (final String privilege : itemPrivileges) {
|
||||
if (isPrivilegeSelected(selectedPermissions, privilege)) {
|
||||
permissionManager.grantPrivilege(privilege,
|
||||
roleToSave,
|
||||
rootDocumentsFolder);
|
||||
}
|
||||
}
|
||||
|
||||
for (final String privilege : assetPrivileges) {
|
||||
if (isPrivilegeSelected(selectedPermissions, privilege)) {
|
||||
permissionManager.grantPrivilege(privilege,
|
||||
roleToSave,
|
||||
rootAssetsFolder);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void revokeNotSelectedPrivileges(final String[] selectedPrivileges,
|
||||
final Role role,
|
||||
final List<Permission> permissions) {
|
||||
for (final Permission permission : permissions) {
|
||||
if (!isPrivilegeSelected(selectedPrivileges,
|
||||
permission.getGrantedPrivilege())) {
|
||||
permissionManager.revokePrivilege(
|
||||
permission.getGrantedPrivilege(),
|
||||
role,
|
||||
permission.getObject());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isPrivilegeSelected(
|
||||
final String[] selectedPrivileges, final String privilege) {
|
||||
|
||||
return Arrays.stream(selectedPrivileges)
|
||||
.anyMatch(current -> current.equals(privilege));
|
||||
|
||||
}
|
||||
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
public Role addRole(final String name,
|
||||
final String description,
|
||||
final String[] selectedPrivileges) {
|
||||
|
||||
final KernelConfig kernelConfig = confManager.findConfiguration(
|
||||
KernelConfig.class);
|
||||
final Locale defaultLocale = kernelConfig.getDefaultLocale();
|
||||
|
||||
final Role role = new Role();
|
||||
role.setName(name);
|
||||
role.getDescription().putValue(defaultLocale, description);
|
||||
|
||||
roleRepo.save(role);
|
||||
|
||||
final List<String> adminPrivileges = permissionManager
|
||||
.listDefiniedPrivileges(AdminPrivileges.class);
|
||||
final List<String> itemPrivileges = permissionManager
|
||||
.listDefiniedPrivileges(ItemPrivileges.class);
|
||||
final List<String> assetPrivileges = permissionManager
|
||||
.listDefiniedPrivileges(AssetPrivileges.class);
|
||||
|
||||
final ContentSection contentSection = sectionRepo.findById(
|
||||
CMS.getContext().getContentSection().getObjectId())
|
||||
.orElseThrow(() -> new IllegalArgumentException(String.format(
|
||||
"No ContentSection with ID %d in the database."
|
||||
+ "Where did that ID come from?",
|
||||
CMS.getContext().getContentSection().getObjectId())));
|
||||
sectionManager.addRoleToContentSection(role, contentSection);
|
||||
final Folder rootDocumentsFolder = contentSection
|
||||
.getRootDocumentsFolder();
|
||||
final Folder rootAssetsFolder = contentSection.getRootAssetsFolder();
|
||||
|
||||
for (final String privilege : adminPrivileges) {
|
||||
if (isPrivilegeSelected(selectedPrivileges, privilege)) {
|
||||
permissionManager.grantPrivilege(privilege,
|
||||
role,
|
||||
contentSection);
|
||||
}
|
||||
}
|
||||
|
||||
for (final String privilege : itemPrivileges) {
|
||||
if (isPrivilegeSelected(selectedPrivileges, privilege)) {
|
||||
permissionManager.grantPrivilege(privilege,
|
||||
role,
|
||||
rootDocumentsFolder);
|
||||
}
|
||||
}
|
||||
|
||||
for (final String privilege : assetPrivileges) {
|
||||
if (isPrivilegeSelected(selectedPrivileges, privilege)) {
|
||||
permissionManager.grantPrivilege(privilege,
|
||||
role,
|
||||
rootAssetsFolder);
|
||||
}
|
||||
}
|
||||
|
||||
return role;
|
||||
}
|
||||
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
public void assignRoleToParty(final long roleId, final long partyId) {
|
||||
|
||||
final Role role = roleRepo
|
||||
.findById(roleId)
|
||||
.orElseThrow(() -> new IllegalArgumentException(String
|
||||
.format("No role with ID %d in the database.",
|
||||
roleId)));
|
||||
final Party party = partyRepo
|
||||
.findById(partyId)
|
||||
.orElseThrow(() -> new IllegalArgumentException(String
|
||||
.format("No party with ID %d in the database.",
|
||||
partyId)));
|
||||
|
||||
roleManager.assignRoleToParty(role, party);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,115 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2003-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.role;
|
||||
|
||||
import com.arsdigita.bebop.FormProcessException;
|
||||
import com.arsdigita.bebop.PageState;
|
||||
import com.arsdigita.bebop.event.FormInitListener;
|
||||
import com.arsdigita.bebop.event.FormProcessListener;
|
||||
import com.arsdigita.bebop.event.FormSectionEvent;
|
||||
import com.arsdigita.cms.CMS;
|
||||
|
||||
import org.libreccm.cdi.utils.CdiUtil;
|
||||
import org.libreccm.security.PermissionManager;
|
||||
import org.libreccm.security.Role;
|
||||
|
||||
/**
|
||||
* Represents a {@link com.arsdigita.bebop.Form Form} to edit
|
||||
* {@link Role roles}.
|
||||
*
|
||||
*
|
||||
* @author Michael Pih
|
||||
* @author Justin Ross <jross@redhat.com>
|
||||
* @author <a href="mailto:yannick.buelter@yabue.de">Yannick Bülter</a>
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
final class RoleEditForm extends BaseRoleForm {
|
||||
|
||||
private final RoleRequestLocal roleRequestLocal;
|
||||
|
||||
RoleEditForm(final RoleRequestLocal role) {
|
||||
super("EditStaffRole", gz("cms.ui.role.edit"));
|
||||
|
||||
roleRequestLocal = role;
|
||||
|
||||
getRoleName().addValidationListener(new NameUniqueListener(
|
||||
roleRequestLocal));
|
||||
|
||||
addInitListener(new InitListener());
|
||||
addProcessListener(new ProcessListener());
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the initial values of a {@link Role} which were received from the
|
||||
* database.
|
||||
*/
|
||||
private class InitListener implements FormInitListener {
|
||||
|
||||
@Override
|
||||
public final void init(final FormSectionEvent event) {
|
||||
final PageState state = event.getPageState();
|
||||
final Role role = roleRequestLocal.getRole(state);
|
||||
|
||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||
final RoleAdminPaneController controller = cdiUtil.findBean(
|
||||
RoleAdminPaneController.class);
|
||||
|
||||
getRoleName().setValue(state, role.getName());
|
||||
getRoleDescription().setValue(
|
||||
state,
|
||||
controller.getRoleDescription(role)
|
||||
);
|
||||
|
||||
final String[] permissions = controller.getGrantedPrivileges(
|
||||
role, CMS.getContext().getContentSection());
|
||||
|
||||
getPrivileges().setValue(state, permissions);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates a role and it's permissions. It uses the
|
||||
* {@link PermissionManager} to grant and revoke permissions as needed.
|
||||
*
|
||||
*/
|
||||
private class ProcessListener implements FormProcessListener {
|
||||
|
||||
@Override
|
||||
public final void process(final FormSectionEvent event)
|
||||
throws FormProcessException {
|
||||
|
||||
final PageState state = event.getPageState();
|
||||
final String roleName = (String) getRoleName().getValue(state);
|
||||
final String roleDesc = (String) getRoleDescription()
|
||||
.getValue(state);
|
||||
final String[] selectedPermissions = (String[]) getPrivileges()
|
||||
.getValue(state);
|
||||
final Role role = roleRequestLocal.getRole(state);
|
||||
|
||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||
final RoleAdminPaneController controller = cdiUtil.findBean(
|
||||
RoleAdminPaneController.class);
|
||||
|
||||
controller.saveRole(role, roleName, roleDesc, selectedPermissions);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,84 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2003-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.role;
|
||||
|
||||
import com.arsdigita.bebop.list.ListModel;
|
||||
|
||||
import org.libreccm.security.Role;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Provides a {@link ListModel} implementation for Collections of Roles. This
|
||||
* class is usable like an iterator, with an exception. The {@link #next()}
|
||||
* method only moves the iterator forward. To get elements you need to first use
|
||||
* {@link #next()} and afterwards {@link #getRole()}, {@link #getElement()} or
|
||||
* {@link #getKey()}.
|
||||
*
|
||||
* Also remember that the iterator does not move unless {@link #next()} is
|
||||
* called.
|
||||
*
|
||||
* @author <a href="mailto:yannick.buelter@yabue.de">Yannick Bülter</a>
|
||||
*/
|
||||
class RoleListModel implements ListModel {
|
||||
|
||||
private final List<Role> m_roles;
|
||||
private Iterator<Role> iterator;
|
||||
private Role currentRole;
|
||||
|
||||
RoleListModel(final List<Role> roles) {
|
||||
m_roles = roles;
|
||||
iterator = roles.iterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean next() {
|
||||
if (iterator.hasNext()) {
|
||||
currentRole = iterator.next();
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Object getElement() {
|
||||
return currentRole.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String getKey() {
|
||||
return Long.toString(currentRole.getRoleId());
|
||||
}
|
||||
|
||||
public final boolean isEmpty() {
|
||||
return m_roles.isEmpty();
|
||||
}
|
||||
|
||||
public final Role getRole() {
|
||||
return currentRole;
|
||||
}
|
||||
|
||||
public final void reset() {
|
||||
iterator = m_roles.iterator();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,131 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2003-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.role;
|
||||
|
||||
import com.arsdigita.bebop.FormData;
|
||||
import com.arsdigita.bebop.FormProcessException;
|
||||
import com.arsdigita.bebop.PageState;
|
||||
import com.arsdigita.bebop.SingleSelectionModel;
|
||||
import com.arsdigita.bebop.event.FormSectionEvent;
|
||||
import com.arsdigita.bebop.form.TextField;
|
||||
import com.arsdigita.cms.ui.FormSecurityListener;
|
||||
import com.arsdigita.cms.ui.PartyAddForm;
|
||||
import com.arsdigita.ui.admin.GlobalizationUtil;
|
||||
import com.arsdigita.util.Assert;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.libreccm.cdi.utils.CdiUtil;
|
||||
|
||||
import org.libreccm.security.Party;
|
||||
import org.libreccm.security.PartyRepository;
|
||||
import org.libreccm.security.Role;
|
||||
import org.libreccm.security.RoleManager;
|
||||
import org.libreccm.security.RoleRepository;
|
||||
import org.libreccm.security.User;
|
||||
import org.librecms.contentsection.privileges.AdminPrivileges;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Adds a form which can add {@link Party parties} to {@link Role roles}. Also
|
||||
* enables searching for parties.
|
||||
*
|
||||
* NOTE: In earlier versions it was also possible to filter parties using
|
||||
* {@link User} attributes such as username, name, last name, etc. This feature
|
||||
* may be added later if still needed.
|
||||
*
|
||||
*
|
||||
* @author Michael Pih
|
||||
* @author Uday Mathur
|
||||
* @author <a href="mailto:yannick.buelter@yabue.de">Yannick Bülter</a>
|
||||
*/
|
||||
class RolePartyAddForm extends PartyAddForm {
|
||||
|
||||
private static final Logger LOGGER = LogManager
|
||||
.getLogger(RolePartyAddForm.class);
|
||||
|
||||
private final SingleSelectionModel<String> roleSelectionModel;
|
||||
|
||||
RolePartyAddForm(final SingleSelectionModel<String> roleSelectionModel,
|
||||
final TextField search) {
|
||||
|
||||
super(search);
|
||||
|
||||
this.roleSelectionModel = roleSelectionModel;
|
||||
|
||||
super
|
||||
.getForm()
|
||||
.addSubmissionListener(
|
||||
new FormSecurityListener(AdminPrivileges.ADMINISTER_ROLES));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<Party> makeQuery(final PageState state) {
|
||||
|
||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||
final PartyRepository partyRepository = cdiUtil.findBean(
|
||||
PartyRepository.class);
|
||||
|
||||
final String searchQuery = (String) getSearchWidget().getValue(state);
|
||||
|
||||
return partyRepository.searchByName(searchQuery);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void process(FormSectionEvent event) throws FormProcessException {
|
||||
|
||||
final FormData data = event.getFormData();
|
||||
final PageState state = event.getPageState();
|
||||
|
||||
final String[] parties = (String[]) data.get("parties");
|
||||
LOGGER.debug("PARTIES = " + Arrays.toString(parties));
|
||||
if (parties == null) {
|
||||
throw new FormProcessException(GlobalizationUtil.globalize(
|
||||
"cms.ui.role.no_party_selected"));
|
||||
}
|
||||
|
||||
final Long roleId = Long
|
||||
.parseLong(roleSelectionModel.getSelectedKey(state));
|
||||
|
||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||
// final RoleRepository roleRepository = cdiUtil.findBean(
|
||||
// RoleRepository.class);
|
||||
// final PartyRepository partyRepository = cdiUtil.findBean(
|
||||
// PartyRepository.class);
|
||||
// final RoleManager roleManager = cdiUtil.findBean(RoleManager.class);
|
||||
final RoleAdminPaneController controller = cdiUtil
|
||||
.findBean(RoleAdminPaneController.class);
|
||||
|
||||
// final Role role = roleRepository.findById(roleId).get();
|
||||
|
||||
// Add each checked party to the role
|
||||
// Party party;
|
||||
for (int i = 0; i < parties.length; i++) {
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
LOGGER.debug("parties[" + i + "] = " + parties[i]);
|
||||
}
|
||||
// party = partyRepository.findById(Long.parseLong(parties[i])).get();
|
||||
// roleManager.assignRoleToParty(role, party);
|
||||
controller.assignRoleToParty(roleId, Long.parseLong(parties[i]));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,42 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2003-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.role;
|
||||
|
||||
import com.arsdigita.bebop.PageState;
|
||||
import com.arsdigita.bebop.RequestLocal;
|
||||
|
||||
import org.libreccm.security.Role;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* See {@link RequestLocal} for more information.
|
||||
*
|
||||
* @author <a href="mailto:yannick.buelter@yabue.de">Yannick Bülter</a>
|
||||
*/
|
||||
abstract class RoleRequestLocal extends RequestLocal {
|
||||
|
||||
final Role getRole(final PageState state) {
|
||||
@SuppressWarnings("unchecked")
|
||||
final Optional<Role> role = (Optional<Role>) get(state);
|
||||
|
||||
return role.get();
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue