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 * George Lefter 018 * 019 * $Id$ 020 */ 021 022package org.nuxeo.ecm.webapp.security; 023 024import java.util.HashMap; 025import java.util.Map; 026 027import org.apache.commons.logging.Log; 028import org.apache.commons.logging.LogFactory; 029import org.nuxeo.runtime.model.ComponentInstance; 030import org.nuxeo.runtime.model.DefaultComponent; 031 032/** 033 * A service that provided the UI visible permissions for different document types. 034 * 035 * @author <a href='mailto:[email protected]'>George Lefter</a> 036 * @deprecated use the PermissionProvider that is part of the core SecurityService instead 037 */ 038@Deprecated 039public class UIPermissionService extends DefaultComponent { 040 041 public static final String NAME = "org.nuxeo.ecm.webapp.security.UIPermissionService"; 042 043 private static final Log log = LogFactory.getLog(UIPermissionService.class); 044 045 private final Map<String, String[]> permissionMap = new HashMap<String, String[]>(); 046 047 private String[] defaultPermissionList = new String[0]; 048 049 @Override 050 public void registerContribution(Object contribution, String extensionPoint, ComponentInstance contributor) { 051 if (extensionPoint.equals("uiPermissions")) { 052 UIPermissionListDescriptor desc = (UIPermissionListDescriptor) contribution; 053 if (desc.isDefault) { 054 defaultPermissionList = desc.permissions; 055 } else { 056 permissionMap.put(desc.documentType, desc.permissions); 057 } 058 } else { 059 log.error("unknown extension point: " + extensionPoint); 060 } 061 } 062 063 @Override 064 public void unregisterContribution(Object contribution, String extensionPoint, ComponentInstance contributor) { 065 if (extensionPoint.equals("uiPermissions")) { 066 UIPermissionListDescriptor desc = (UIPermissionListDescriptor) contribution; 067 permissionMap.remove(desc.documentType); 068 } else { 069 log.error("unknown extension point: " + extensionPoint); 070 } 071 } 072 073 /** 074 * Retrieves the visible permissions for a document type. 075 * 076 * @param documentType the type of document for which to retrieve permissions, or null to retrieve the default 077 * permissions 078 * @return the list of permissions for the specified document type 079 */ 080 public String[] getUIPermissions(String documentType) { 081 String[] permissions = permissionMap.get(documentType); 082 if (documentType == null || permissions == null) { 083 return defaultPermissionList; 084 } else { 085 return permissions; 086 } 087 } 088 089}