001/*
002 *  Copyright 2013 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.core.ui;
017
018import java.lang.annotation.ElementType;
019import java.lang.annotation.Retention;
020import java.lang.annotation.RetentionPolicy;
021import java.lang.annotation.Target;
022
023import org.apache.commons.lang.StringUtils;
024
025import org.ametys.core.right.RightAssignmentContext;
026
027/**
028 * Mark the annotated method as callable by a client-side component.
029 */
030@Retention(RetentionPolicy.RUNTIME)
031@Target(ElementType.METHOD)
032public @interface Callable 
033{
034    /** Constant to use to ask explicitly the system to not check rights, as they will be checked by the method itself */
035    public static final String CHECKED_BY_IMPLEMENTATION = StringUtils.EMPTY;
036    
037    /** Constant to use to explicitly indicate that this method could be called by anyone (anonymous users included or not depending on {@link #allowAnonymous()}) */
038    public static final String NO_CHECK_REQUIRED = "*";
039    
040    /** Constant to check read access */
041    public static final String READ_ACCESS = "__READ_ACCESS";
042    
043    /**
044     * Indicate how to check multiple rights
045     */
046    public enum RightMode
047    {
048        /** All the right must be allowed */
049        AND,
050        /** At least one right must be allowed */
051        OR
052    }
053    
054    /** 
055     * The ids of rights to be checked
056     * @return The ids or empty if there is no right protection
057     */
058    public String[] rights();
059    
060    /**
061     * The mode to use to check multiple rights
062     * @return The mode to use
063     */
064    public RightMode rightMode() default RightMode.OR;
065    
066    /**
067     * Determines if the method can be accessed by a anonymous user
068     * @return true if anonymous user is allowed
069     */
070    public boolean allowAnonymous() default false;
071    
072    /**
073     * The context to check the right. Defaults to '/${WorkspaceName}'
074     * @return The context
075     */
076    public String context() default "/${WorkspaceName}";
077    
078    /**
079     * The id of a type of the {@link RightAssignmentContext} to use to convert JS object into into a Java object
080     * @return The id of the {@link RightAssignmentContext}
081     */
082    public String rightContext() default "";
083    
084    /**
085     * The index of method's argument holding the context value to be converted by {@link RightAssignmentContext}
086     * @return The parameter's index
087     */
088    public int paramIndex() default -1;
089}