Polish @CrossOrigin
- origin --> origins - method --> methods - constants are now actually constant (i.e., static final)
This commit is contained in:
parent
60cdfa535e
commit
2b339db53b
|
@ -39,19 +39,19 @@ import org.springframework.core.annotation.AliasFor;
|
|||
@Documented
|
||||
public @interface CrossOrigin {
|
||||
|
||||
String[] DEFAULT_ORIGIN = { "*" };
|
||||
static final String[] DEFAULT_ORIGIN = { "*" };
|
||||
|
||||
String[] DEFAULT_ALLOWED_HEADERS = { "*" };
|
||||
static final String[] DEFAULT_ALLOWED_HEADERS = { "*" };
|
||||
|
||||
boolean DEFAULT_ALLOW_CREDENTIALS = true;
|
||||
static final boolean DEFAULT_ALLOW_CREDENTIALS = true;
|
||||
|
||||
long DEFAULT_MAX_AGE = 1800;
|
||||
static final long DEFAULT_MAX_AGE = 1800;
|
||||
|
||||
|
||||
/**
|
||||
* Alias for {@link #origin}.
|
||||
* Alias for {@link #origins}.
|
||||
*/
|
||||
@AliasFor(attribute = "origin")
|
||||
@AliasFor(attribute = "origins")
|
||||
String[] value() default {};
|
||||
|
||||
/**
|
||||
|
@ -63,7 +63,7 @@ public @interface CrossOrigin {
|
|||
* @see #value
|
||||
*/
|
||||
@AliasFor(attribute = "value")
|
||||
String[] origin() default {};
|
||||
String[] origins() default {};
|
||||
|
||||
/**
|
||||
* List of request headers that can be used during the actual request.
|
||||
|
@ -88,7 +88,7 @@ public @interface CrossOrigin {
|
|||
* <p>If undefined, methods defined by {@link RequestMapping} annotation
|
||||
* are used.
|
||||
*/
|
||||
RequestMethod[] method() default {};
|
||||
RequestMethod[] methods() default {};
|
||||
|
||||
/**
|
||||
* Whether the browser should include any cookies associated with the
|
||||
|
|
|
@ -36,7 +36,6 @@ import org.springframework.web.cors.CorsConfiguration;
|
|||
import org.springframework.web.method.HandlerMethod;
|
||||
import org.springframework.web.servlet.mvc.condition.AbstractRequestCondition;
|
||||
import org.springframework.web.servlet.mvc.condition.CompositeRequestCondition;
|
||||
import org.springframework.web.servlet.mvc.condition.NameValueExpression;
|
||||
import org.springframework.web.servlet.mvc.condition.RequestCondition;
|
||||
import org.springframework.web.servlet.mvc.method.RequestMappingInfo;
|
||||
import org.springframework.web.servlet.mvc.method.RequestMappingInfoHandlerMapping;
|
||||
|
@ -228,7 +227,6 @@ public class RequestMappingHandlerMapping extends RequestMappingInfoHandlerMappi
|
|||
* @param handlerType the handler type for which to create the condition
|
||||
* @return the condition, or {@code null}
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
protected RequestCondition<?> getCustomTypeCondition(Class<?> handlerType) {
|
||||
return null;
|
||||
}
|
||||
|
@ -244,7 +242,6 @@ public class RequestMappingHandlerMapping extends RequestMappingInfoHandlerMappi
|
|||
* @param method the handler method for which to create the condition
|
||||
* @return the condition, or {@code null}
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
protected RequestCondition<?> getCustomMethodCondition(Method method) {
|
||||
return null;
|
||||
}
|
||||
|
@ -326,10 +323,10 @@ public class RequestMappingHandlerMapping extends RequestMappingInfoHandlerMappi
|
|||
if (annotation == null) {
|
||||
return;
|
||||
}
|
||||
for (String origin : annotation.origin()) {
|
||||
for (String origin : annotation.origins()) {
|
||||
config.addAllowedOrigin(origin);
|
||||
}
|
||||
for (RequestMethod method : annotation.method()) {
|
||||
for (RequestMethod method : annotation.methods()) {
|
||||
config.addAllowedMethod(method.name());
|
||||
}
|
||||
for (String header : annotation.allowedHeaders()) {
|
||||
|
|
|
@ -56,8 +56,9 @@ import static org.junit.Assert.*;
|
|||
*/
|
||||
public class CrossOriginTests {
|
||||
|
||||
private TestRequestMappingInfoHandlerMapping handlerMapping;
|
||||
private MockHttpServletRequest request;
|
||||
private final TestRequestMappingInfoHandlerMapping handlerMapping = new TestRequestMappingInfoHandlerMapping();
|
||||
|
||||
private final MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
|
||||
@Rule
|
||||
public ExpectedException exception = ExpectedException.none();
|
||||
|
@ -65,11 +66,10 @@ public class CrossOriginTests {
|
|||
|
||||
@Before
|
||||
public void setUp() {
|
||||
this.handlerMapping = new TestRequestMappingInfoHandlerMapping();
|
||||
this.handlerMapping.setRemoveSemicolonContent(false);
|
||||
this.handlerMapping.setApplicationContext(new StaticWebApplicationContext());
|
||||
this.handlerMapping.afterPropertiesSet();
|
||||
this.request = new MockHttpServletRequest();
|
||||
|
||||
this.request.setMethod("GET");
|
||||
this.request.addHeader(HttpHeaders.ORIGIN, "http://domain.com/");
|
||||
}
|
||||
|
@ -304,8 +304,8 @@ public class CrossOriginTests {
|
|||
return "{}";
|
||||
}
|
||||
|
||||
@CrossOrigin(origin = { "http://site1.com", "http://site2.com" }, allowedHeaders = { "header1", "header2" },
|
||||
exposedHeaders = { "header3", "header4" }, method = RequestMethod.DELETE, maxAge = 123, allowCredentials = "false")
|
||||
@CrossOrigin(origins = { "http://site1.com", "http://site2.com" }, allowedHeaders = { "header1", "header2" },
|
||||
exposedHeaders = { "header3", "header4" }, methods = RequestMethod.DELETE, maxAge = 123, allowCredentials = "false")
|
||||
@RequestMapping(path = "/customized", method = { RequestMethod.GET, RequestMethod.POST })
|
||||
public void customized() {
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue