001/* 002 * Copyright 2024 Anyware Services 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 */ 016package org.ametys.plugins.repository.rights; 017 018import java.util.List; 019import java.util.Map; 020import java.util.Set; 021 022import org.apache.avalon.framework.service.ServiceException; 023import org.apache.avalon.framework.service.ServiceManager; 024import org.apache.avalon.framework.service.Serviceable; 025 026import org.ametys.core.right.RightAssignmentContext; 027import org.ametys.plugins.repository.ACLAmetysObject; 028import org.ametys.plugins.repository.AmetysObject; 029import org.ametys.plugins.repository.AmetysObjectResolver; 030import org.ametys.runtime.plugin.component.PluginAware; 031 032/** 033 * Private {@link RightAssignmentContext} for {@link ACLAmetysObject}.<br> 034 * This implementation can be used to get a {@link ACLAmetysObject} from a JS context.<br> 035 * It is not supposed to be available to get or set assignments. 036 */ 037public class ACLAmetysObjectRightAssignmentContext implements RightAssignmentContext, Serviceable, PluginAware 038{ 039 /** The id of this right context */ 040 public static final String ID = "right.assignment.context.ametysobject"; 041 042 /** The Ametys object resolver */ 043 protected AmetysObjectResolver _resolver; 044 045 private String _pluginName; 046 047 private String _id; 048 049 @Override 050 public void service(ServiceManager smanager) throws ServiceException 051 { 052 _resolver = (AmetysObjectResolver) smanager.lookup(AmetysObjectResolver.ROLE); 053 } 054 055 @Override 056 public void setPluginInfo(String pluginName, String featureName, String id) 057 { 058 _id = id; 059 _pluginName = pluginName; 060 } 061 062 public String getId() 063 { 064 return _id; 065 } 066 067 public boolean isPrivate() 068 { 069 return true; 070 } 071 072 public Object convertJSContext(Object jsContext) 073 { 074 if (jsContext instanceof String) 075 { 076 AmetysObject ao = _resolver.resolveById((String) jsContext); 077 if (ao instanceof ACLAmetysObject) 078 { 079 return ao; 080 } 081 } 082 return null; 083 } 084 085 public String getContextIdentifier(Object context) 086 { 087 return ((AmetysObject) context).getId(); 088 } 089 090 public Set<Object> getParentContexts(Object context) 091 { 092 return null; 093 } 094 095 public List<Object> getRootContexts(Map<String, Object> contextParameters) 096 { 097 return List.of(); 098 } 099 100 public List<Script> getScripts(Map<String, Object> contextParameters) 101 { 102 return List.of(); 103 } 104 105 public List<Script> getScripts(boolean ignoreRights, Map<String, Object> contextParameters) 106 { 107 return List.of(); 108 } 109 110 public Map<String, String> getRights(Map<String, Object> contextParameters) 111 { 112 return Map.of(); 113 } 114 115 public String getPluginName() 116 { 117 return _pluginName; 118 } 119 120 public Map<String, List<String>> getDependencies() 121 { 122 return Map.of(); 123 } 124 125}