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.apache.commons.logging.Log;
031import org.apache.commons.logging.LogFactory;
032import org.jboss.seam.annotations.In;
033import org.jboss.seam.annotations.Name;
034import org.jboss.seam.annotations.Scope;
035import org.nuxeo.ecm.core.api.CoreSession;
036
037/**
038 * POJO class that extracts and holds the list of the available permissions from backend.
039 *
040 * @author Razvan Caraghin
041 */
042@Name("permissionListManager")
043@Scope(SESSION)
044public class PermissionListManager implements Serializable {
045
046    private static final long serialVersionUID = -7288271409172281902L;
047
048    private static final Log log = LogFactory.getLog(PermissionListManager.class);
049
050    @In(create = true, required = false)
051    protected transient CoreSession documentManager;
052
053    protected SelectItem[] availablePermissions;
054
055    protected String selectedPermission;
056
057    public SelectItem[] getAvailablePermissions() {
058        if (null == availablePermissions) {
059            log.debug("Factory method called...");
060
061            List<SelectItem> jsfModelList = new ArrayList<SelectItem>();
062
063            List<String> permissions = documentManager.getAvailableSecurityPermissions();
064
065            for (String permission : permissions) {
066                SelectItem it = new SelectItem(permission);
067                jsfModelList.add(it);
068            }
069
070            availablePermissions = jsfModelList.toArray(new SelectItem[0]);
071        }
072
073        return availablePermissions;
074    }
075
076    public String getSelectedPermission() {
077        return selectedPermission;
078    }
079
080    public void setSelectedPermission(String selectedPermission) {
081        this.selectedPermission = selectedPermission;
082    }
083
084}