
software.amazon.awssdk.services.wafv2.model.FieldToMatch Maven / Gradle / Ivy
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
* the License. A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file 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.
*/
package software.amazon.awssdk.services.wafv2.model;
import java.io.Serializable;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.util.function.Function;
import software.amazon.awssdk.annotations.Generated;
import software.amazon.awssdk.core.SdkField;
import software.amazon.awssdk.core.SdkPojo;
import software.amazon.awssdk.core.protocol.MarshallLocation;
import software.amazon.awssdk.core.protocol.MarshallingType;
import software.amazon.awssdk.core.traits.LocationTrait;
import software.amazon.awssdk.utils.ToString;
import software.amazon.awssdk.utils.builder.CopyableBuilder;
import software.amazon.awssdk.utils.builder.ToCopyableBuilder;
/**
*
*
* This is the latest version of AWS WAF, named AWS WAFV2, released in November, 2019. For information, including
* how to migrate your AWS WAF resources from the prior release, see the AWS WAF Developer Guide.
*
*
*
* The part of a web request that you want AWS WAF to inspect. Include the single FieldToMatch
type that
* you want to inspect, with additional specifications as needed, according to the type. You specify a single request
* component in FieldToMatch
for each rule statement that requires it. To inspect more than one component
* of a web request, create a separate rule statement for each component.
*
*/
@Generated("software.amazon.awssdk:codegen")
public final class FieldToMatch implements SdkPojo, Serializable, ToCopyableBuilder {
private static final SdkField SINGLE_HEADER_FIELD = SdkField. builder(MarshallingType.SDK_POJO)
.memberName("SingleHeader").getter(getter(FieldToMatch::singleHeader)).setter(setter(Builder::singleHeader))
.constructor(SingleHeader::builder)
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("SingleHeader").build()).build();
private static final SdkField SINGLE_QUERY_ARGUMENT_FIELD = SdkField
. builder(MarshallingType.SDK_POJO).memberName("SingleQueryArgument")
.getter(getter(FieldToMatch::singleQueryArgument)).setter(setter(Builder::singleQueryArgument))
.constructor(SingleQueryArgument::builder)
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("SingleQueryArgument").build())
.build();
private static final SdkField ALL_QUERY_ARGUMENTS_FIELD = SdkField
. builder(MarshallingType.SDK_POJO).memberName("AllQueryArguments")
.getter(getter(FieldToMatch::allQueryArguments)).setter(setter(Builder::allQueryArguments))
.constructor(AllQueryArguments::builder)
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("AllQueryArguments").build()).build();
private static final SdkField URI_PATH_FIELD = SdkField. builder(MarshallingType.SDK_POJO)
.memberName("UriPath").getter(getter(FieldToMatch::uriPath)).setter(setter(Builder::uriPath))
.constructor(UriPath::builder)
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("UriPath").build()).build();
private static final SdkField QUERY_STRING_FIELD = SdkField. builder(MarshallingType.SDK_POJO)
.memberName("QueryString").getter(getter(FieldToMatch::queryString)).setter(setter(Builder::queryString))
.constructor(QueryString::builder)
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("QueryString").build()).build();
private static final SdkField BODY_FIELD = SdkField. builder(MarshallingType.SDK_POJO).memberName("Body")
.getter(getter(FieldToMatch::body)).setter(setter(Builder::body)).constructor(Body::builder)
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("Body").build()).build();
private static final SdkField METHOD_FIELD = SdkField. builder(MarshallingType.SDK_POJO).memberName("Method")
.getter(getter(FieldToMatch::method)).setter(setter(Builder::method)).constructor(Method::builder)
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("Method").build()).build();
private static final List> SDK_FIELDS = Collections
.unmodifiableList(Arrays.asList(SINGLE_HEADER_FIELD, SINGLE_QUERY_ARGUMENT_FIELD, ALL_QUERY_ARGUMENTS_FIELD,
URI_PATH_FIELD, QUERY_STRING_FIELD, BODY_FIELD, METHOD_FIELD));
private static final long serialVersionUID = 1L;
private final SingleHeader singleHeader;
private final SingleQueryArgument singleQueryArgument;
private final AllQueryArguments allQueryArguments;
private final UriPath uriPath;
private final QueryString queryString;
private final Body body;
private final Method method;
private FieldToMatch(BuilderImpl builder) {
this.singleHeader = builder.singleHeader;
this.singleQueryArgument = builder.singleQueryArgument;
this.allQueryArguments = builder.allQueryArguments;
this.uriPath = builder.uriPath;
this.queryString = builder.queryString;
this.body = builder.body;
this.method = builder.method;
}
/**
*
* Inspect a single header. Provide the name of the header to inspect, for example, User-Agent
or
* Referer
. This setting isn't case sensitive.
*
*
* @return Inspect a single header. Provide the name of the header to inspect, for example, User-Agent
* or Referer
. This setting isn't case sensitive.
*/
public SingleHeader singleHeader() {
return singleHeader;
}
/**
*
* Inspect a single query argument. Provide the name of the query argument to inspect, such as UserName or
* SalesRegion. The name can be up to 30 characters long and isn't case sensitive.
*
*
* This is used only to indicate the web request component for AWS WAF to inspect, in the FieldToMatch
* specification.
*
*
* @return Inspect a single query argument. Provide the name of the query argument to inspect, such as
* UserName or SalesRegion. The name can be up to 30 characters long and isn't case sensitive.
*
*
* This is used only to indicate the web request component for AWS WAF to inspect, in the
* FieldToMatch specification.
*/
public SingleQueryArgument singleQueryArgument() {
return singleQueryArgument;
}
/**
*
* Inspect all query arguments.
*
*
* @return Inspect all query arguments.
*/
public AllQueryArguments allQueryArguments() {
return allQueryArguments;
}
/**
*
* Inspect the request URI path. This is the part of a web request that identifies a resource, for example,
* /images/daily-ad.jpg
.
*
*
* @return Inspect the request URI path. This is the part of a web request that identifies a resource, for example,
* /images/daily-ad.jpg
.
*/
public UriPath uriPath() {
return uriPath;
}
/**
*
* Inspect the query string. This is the part of a URL that appears after a ?
character, if any.
*
*
* @return Inspect the query string. This is the part of a URL that appears after a ?
character, if
* any.
*/
public QueryString queryString() {
return queryString;
}
/**
*
* Inspect the request body, which immediately follows the request headers. This is the part of a request that
* contains any additional data that you want to send to your web server as the HTTP request body, such as data from
* a form.
*
*
* Note that only the first 8 KB (8192 bytes) of the request body are forwarded to AWS WAF for inspection by the
* underlying host service. If you don't need to inspect more than 8 KB, you can guarantee that you don't allow
* additional bytes in by combining a statement that inspects the body of the web request, such as
* ByteMatchStatement or RegexPatternSetReferenceStatement, with a SizeConstraintStatement that
* enforces an 8 KB size limit on the body of the request. AWS WAF doesn't support inspecting the entire contents of
* web requests whose bodies exceed the 8 KB limit.
*
*
* @return Inspect the request body, which immediately follows the request headers. This is the part of a request
* that contains any additional data that you want to send to your web server as the HTTP request body, such
* as data from a form.
*
* Note that only the first 8 KB (8192 bytes) of the request body are forwarded to AWS WAF for inspection by
* the underlying host service. If you don't need to inspect more than 8 KB, you can guarantee that you
* don't allow additional bytes in by combining a statement that inspects the body of the web request, such
* as ByteMatchStatement or RegexPatternSetReferenceStatement, with a
* SizeConstraintStatement that enforces an 8 KB size limit on the body of the request. AWS WAF
* doesn't support inspecting the entire contents of web requests whose bodies exceed the 8 KB limit.
*/
public Body body() {
return body;
}
/**
*
* Inspect the HTTP method. The method indicates the type of operation that the request is asking the origin to
* perform.
*
*
* @return Inspect the HTTP method. The method indicates the type of operation that the request is asking the origin
* to perform.
*/
public Method method() {
return method;
}
@Override
public Builder toBuilder() {
return new BuilderImpl(this);
}
public static Builder builder() {
return new BuilderImpl();
}
public static Class extends Builder> serializableBuilderClass() {
return BuilderImpl.class;
}
@Override
public int hashCode() {
int hashCode = 1;
hashCode = 31 * hashCode + Objects.hashCode(singleHeader());
hashCode = 31 * hashCode + Objects.hashCode(singleQueryArgument());
hashCode = 31 * hashCode + Objects.hashCode(allQueryArguments());
hashCode = 31 * hashCode + Objects.hashCode(uriPath());
hashCode = 31 * hashCode + Objects.hashCode(queryString());
hashCode = 31 * hashCode + Objects.hashCode(body());
hashCode = 31 * hashCode + Objects.hashCode(method());
return hashCode;
}
@Override
public boolean equals(Object obj) {
return equalsBySdkFields(obj);
}
@Override
public boolean equalsBySdkFields(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (!(obj instanceof FieldToMatch)) {
return false;
}
FieldToMatch other = (FieldToMatch) obj;
return Objects.equals(singleHeader(), other.singleHeader())
&& Objects.equals(singleQueryArgument(), other.singleQueryArgument())
&& Objects.equals(allQueryArguments(), other.allQueryArguments()) && Objects.equals(uriPath(), other.uriPath())
&& Objects.equals(queryString(), other.queryString()) && Objects.equals(body(), other.body())
&& Objects.equals(method(), other.method());
}
/**
* Returns a string representation of this object. This is useful for testing and debugging. Sensitive data will be
* redacted from this string using a placeholder value.
*/
@Override
public String toString() {
return ToString.builder("FieldToMatch").add("SingleHeader", singleHeader())
.add("SingleQueryArgument", singleQueryArgument()).add("AllQueryArguments", allQueryArguments())
.add("UriPath", uriPath()).add("QueryString", queryString()).add("Body", body()).add("Method", method()).build();
}
public Optional getValueForField(String fieldName, Class clazz) {
switch (fieldName) {
case "SingleHeader":
return Optional.ofNullable(clazz.cast(singleHeader()));
case "SingleQueryArgument":
return Optional.ofNullable(clazz.cast(singleQueryArgument()));
case "AllQueryArguments":
return Optional.ofNullable(clazz.cast(allQueryArguments()));
case "UriPath":
return Optional.ofNullable(clazz.cast(uriPath()));
case "QueryString":
return Optional.ofNullable(clazz.cast(queryString()));
case "Body":
return Optional.ofNullable(clazz.cast(body()));
case "Method":
return Optional.ofNullable(clazz.cast(method()));
default:
return Optional.empty();
}
}
@Override
public List> sdkFields() {
return SDK_FIELDS;
}
private static Function