package act.security;
/*-
* #%L
* ACT Framework
* %%
* Copyright (C) 2014 - 2017 ActFramework
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
import static org.osgl.http.H.Header.Names.*;
import act.Act;
import act.app.ActionContext;
import org.osgl.$;
import org.osgl.http.H;
import org.osgl.inject.BeanSpec;
import org.osgl.util.C;
import org.osgl.util.E;
import org.osgl.util.S;
import java.lang.annotation.*;
import java.lang.reflect.Method;
import java.lang.reflect.Type;
import java.util.Collection;
/**
* Provice CORS header manipulation methods
*/
public class CORS {
/**
* Mark a controller class or action handler method that
* must not add any CORS headers irregarding to the
* global CORS setting
*/
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD, ElementType.TYPE})
public @interface Disable {
}
/**
* Mark a controller class or action handler method that
* needs to add `Access-Control-Allow-Origin` header
*/
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD, ElementType.TYPE})
public @interface AllowOrigin {
/**
* The value set to the `Access-Control-Allow-Origin` header
* @return the value
*/
String value() default "*";
}
/**
* Mark a controller class or action handler method that
* needs to add `Access-Control-Allow-Headers` header
*/
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD, ElementType.TYPE})
public @interface AllowHeaders {
/**
* The value set to the `Access-Control-Allow-Headers` header
* @return the value
*/
String value() default "*";
}
/**
* Mark a controller class or action handler method that
* needs to add `Access-Control-Expose-Headers` header
*/
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD, ElementType.TYPE})
public @interface ExposeHeaders {
/**
* The value set to the `Access-Control-Expose-Headers` header
* @return the value
*/
String value() default "*";
}
/**
* Mark a controller class or action handler method that
* needs to add `Access-Control-Allow-Credentials` header
* and set the value to `false`
*/
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD, ElementType.TYPE})
public @interface DisallowCredentials {
}
/**
* Mark a controller class or action handler method that
* needs to add `Access-Control-Allow-Credentials` header
* and set the value to `true`
*/
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD, ElementType.TYPE})
public @interface AllowCredentials {
}
/**
* Mark a controller class or action handler method that
* needs to add `Access-Control-Max-Age` header
*/
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD, ElementType.TYPE})
public @interface MaxAge {
/**
* The value set to the `Access-Control-Max-Age` header
* @return the value
*/
int value() default 30 * 60;
}
public static Spec spec(Collection