001/*
002 * (C) Copyright 2006-2007 Nuxeo SAS (http://nuxeo.com/) and contributors.
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the GNU Lesser General Public License
006 * (LGPL) version 2.1 which accompanies this distribution, and is available at
007 * http://www.gnu.org/licenses/lgpl.html
008 *
009 * This library is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012 * Lesser General Public License for more details.
013 *
014 * Contributors:
015 *     Nuxeo - initial API and implementation
016 *
017 * $Id$
018 */
019
020package org.nuxeo.ecm.webapp.security;
021
022import static org.jboss.seam.ScopeType.SESSION;
023
024import java.io.Serializable;
025import java.util.ArrayList;
026import java.util.List;
027
028import javax.faces.model.SelectItem;
029
030import org.jboss.seam.annotations.In;
031import org.jboss.seam.annotations.Name;
032import org.jboss.seam.annotations.Scope;
033import org.nuxeo.common.utils.i18n.Labeler;
034import org.nuxeo.ecm.core.api.CoreSession;
035import org.nuxeo.ecm.webapp.helpers.ResourcesAccessor;
036
037/**
038 * Lists the available permission actions. Hardcoded. ATM Grant/Deny supported.
039 *
040 * @author Razvan Caraghin
041 */
042@Name("permissionActionListManager")
043@Scope(SESSION)
044public class PermissionActionListManager implements Serializable {
045
046    private static final long serialVersionUID = -327848199566592785L;
047
048    private static final Labeler labeler = new Labeler("label.security");
049
050    protected String selectedGrant = "Grant";
051
052    @In(create = true)
053    private transient ResourcesAccessor resourcesAccessor;
054
055    @In(create = true, required = false)
056    protected transient CoreSession documentManager;
057
058    /**
059     * Returns true if negative ACLs are allowed.
060     *
061     * @since 6.0
062     */
063    public boolean getAllowNegativeACL() {
064        return documentManager == null ? false : documentManager.isNegativeAclAllowed();
065    }
066
067    public SelectItem[] getPermissionActionItems() {
068        List<String> permissionActions = new ArrayList<String>();
069        List<SelectItem> jsfModelList = new ArrayList<SelectItem>();
070
071        permissionActions.add("Grant");
072
073        if (getAllowNegativeACL()) {
074            permissionActions.add("Deny");
075        }
076
077        for (String permissionAction : permissionActions) {
078            String label = labeler.makeLabel(permissionAction);
079            SelectItem it = new SelectItem(permissionAction, resourcesAccessor.getMessages().get(label));
080            jsfModelList.add(it);
081        }
082
083        SelectItem[] permissionActionItems = jsfModelList.toArray(new SelectItem[0]);
084        return permissionActionItems;
085    }
086
087    public String getSelectedGrant() {
088        return selectedGrant;
089    }
090
091    public void setSelectedGrant(String selectedPermission) {
092        selectedGrant = selectedPermission;
093    }
094
095}