001/* 002 * Copyright 2016 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.core.impl.right; 017 018import java.util.ArrayList; 019import java.util.List; 020import java.util.Map; 021import java.util.Set; 022 023import org.ametys.core.right.AbstractStaticRightAssignmentContext; 024import org.ametys.core.right.RightAssignmentContext; 025 026/** 027 * {@link RightAssignmentContext} for assign rights to a configured context 028 */ 029public class StringRightAssignmentContext extends AbstractStaticRightAssignmentContext 030{ 031 @Override 032 public Object convertJSContext(Object context) 033 { 034 if (context instanceof String) 035 { 036 return context; 037 } 038 return null; 039 } 040 041 @Override 042 public String getContextIdentifier(Object context) 043 { 044 if (context instanceof String) 045 { 046 return (String) context; 047 } 048 return null; 049 } 050 051 @Override 052 public Set<Object> getParentContexts(Object context) 053 { 054 return null; 055 } 056 057 @Override 058 public List<Object> getRootContexts(Map<String, Object> contextParameters) 059 { 060 List<Object> rootContexts = new ArrayList<>(); 061 062 if (matchWorkspace(contextParameters)) 063 { 064 rootContexts.add(_script.getParameters().get("context")); 065 } 066 return rootContexts; 067 } 068}