001/*
002 * (C) Copyright 2006-2007 Nuxeo SA (http://nuxeo.com/) and others.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 *
016 * Contributors:
017 *     Nuxeo - initial API and implementation
018 *
019 * $Id$
020 */
021
022package org.nuxeo.ecm.webapp.security;
023
024import static org.jboss.seam.ScopeType.SESSION;
025
026import java.io.Serializable;
027import java.util.ArrayList;
028import java.util.List;
029
030import javax.faces.model.SelectItem;
031
032import org.jboss.seam.annotations.In;
033import org.jboss.seam.annotations.Name;
034import org.jboss.seam.annotations.Scope;
035import org.nuxeo.common.utils.i18n.Labeler;
036import org.nuxeo.ecm.core.api.CoreSession;
037import org.nuxeo.ecm.webapp.helpers.ResourcesAccessor;
038
039/**
040 * Lists the available permission actions. Hardcoded. ATM Grant/Deny supported.
041 *
042 * @author Razvan Caraghin
043 */
044@Name("permissionActionListManager")
045@Scope(SESSION)
046public class PermissionActionListManager implements Serializable {
047
048    private static final long serialVersionUID = -327848199566592785L;
049
050    private static final Labeler labeler = new Labeler("label.security");
051
052    protected String selectedGrant = "Grant";
053
054    @In(create = true)
055    private transient ResourcesAccessor resourcesAccessor;
056
057    @In(create = true, required = false)
058    protected transient CoreSession documentManager;
059
060    /**
061     * Returns true if negative ACLs are allowed.
062     *
063     * @since 6.0
064     */
065    public boolean getAllowNegativeACL() {
066        return documentManager == null ? false : documentManager.isNegativeAclAllowed();
067    }
068
069    public SelectItem[] getPermissionActionItems() {
070        List<String> permissionActions = new ArrayList<String>();
071        List<SelectItem> jsfModelList = new ArrayList<SelectItem>();
072
073        permissionActions.add("Grant");
074
075        if (getAllowNegativeACL()) {
076            permissionActions.add("Deny");
077        }
078
079        for (String permissionAction : permissionActions) {
080            String label = labeler.makeLabel(permissionAction);
081            SelectItem it = new SelectItem(permissionAction, resourcesAccessor.getMessages().get(label));
082            jsfModelList.add(it);
083        }
084
085        SelectItem[] permissionActionItems = jsfModelList.toArray(new SelectItem[0]);
086        return permissionActionItems;
087    }
088
089    public String getSelectedGrant() {
090        return selectedGrant;
091    }
092
093    public void setSelectedGrant(String selectedPermission) {
094        selectedGrant = selectedPermission;
095    }
096
097}