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