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    /** 
035     * Constant to use to explicitly do not check right
036     * @deprecated Use {@link #NO_CHECK_REQUIRED} or {@link #CHECKED_BY_IMPLEMENTATION} instead.
037     */
038    @Deprecated
039    public static final String SKIP_BUILTIN_CHECK = StringUtils.EMPTY;
040    
041    /** Constant to use to ask explicitly the system to not check rights, as they will be checked by the method itself */
042    public static final String CHECKED_BY_IMPLEMENTATION = StringUtils.EMPTY;
043    
044    /** Constant to use to explicitly indicate that this method could be called by anyone (anonymous users included or not depending on {@link #allowAnonymous()}) */
045    public static final String NO_CHECK_REQUIRED = "*";
046    
047    /** Constant to check read access */
048    public static final String READ_ACCESS = "__READ_ACCESS";
049    
050    /**
051     * Indicate how to check multiple rights
052     */
053    public enum RightMode
054    {
055        /** All the right must be allowed */
056        AND,
057        /** At least one right must be allowed */
058        OR
059    }
060    
061    /** 
062     * The ids of rights to be checked
063     * @return The ids or empty if there is no right protection
064     */
065    public String[] rights() default CHECKED_BY_IMPLEMENTATION;
066    
067    /**
068     * The mode to use to check multiple rights
069     * @return The mode to use
070     */
071    public RightMode rightMode() default RightMode.OR;
072    
073    /**
074     * Determines if the method can be accessed by a anonymous user
075     * @return true if anonymous user is allowed
076     */
077    public boolean allowAnonymous() default false;
078    
079    /**
080     * The context to check the right. Defaults to '/${WorkspaceName}'
081     * @return The context
082     */
083    public String context() default "/${WorkspaceName}";
084    
085    /**
086     * The id of a type of the {@link RightAssignmentContext} to use to convert JS object into into a Java object
087     * @return The id of the {@link RightAssignmentContext}
088     */
089    public String rightContext() default "";
090    
091    /**
092     * The index of method's argument holding the context value to be converted by {@link RightAssignmentContext}
093     * @return The parameter's index
094     */
095    public int paramIndex() default -1;
096}