software.amazon.awssdk.services.verifiedpermissions.model.IsAuthorizedWithTokenResponse 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.verifiedpermissions.model;
import java.util.Arrays;
import java.util.Collection;
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 java.util.stream.Collectors;
import java.util.stream.Stream;
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.ListTrait;
import software.amazon.awssdk.core.traits.LocationTrait;
import software.amazon.awssdk.core.util.DefaultSdkAutoConstructList;
import software.amazon.awssdk.core.util.SdkAutoConstructList;
import software.amazon.awssdk.utils.ToString;
import software.amazon.awssdk.utils.builder.CopyableBuilder;
import software.amazon.awssdk.utils.builder.ToCopyableBuilder;
/**
*/
@Generated("software.amazon.awssdk:codegen")
public final class IsAuthorizedWithTokenResponse extends VerifiedPermissionsResponse implements
ToCopyableBuilder {
private static final SdkField DECISION_FIELD = SdkField. builder(MarshallingType.STRING)
.memberName("decision").getter(getter(IsAuthorizedWithTokenResponse::decisionAsString))
.setter(setter(Builder::decision))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("decision").build()).build();
private static final SdkField> DETERMINING_POLICIES_FIELD = SdkField
.> builder(MarshallingType.LIST)
.memberName("determiningPolicies")
.getter(getter(IsAuthorizedWithTokenResponse::determiningPolicies))
.setter(setter(Builder::determiningPolicies))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("determiningPolicies").build(),
ListTrait
.builder()
.memberLocationName(null)
.memberFieldInfo(
SdkField. builder(MarshallingType.SDK_POJO)
.constructor(DeterminingPolicyItem::builder)
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD)
.locationName("member").build()).build()).build()).build();
private static final SdkField> ERRORS_FIELD = SdkField
.> builder(MarshallingType.LIST)
.memberName("errors")
.getter(getter(IsAuthorizedWithTokenResponse::errors))
.setter(setter(Builder::errors))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("errors").build(),
ListTrait
.builder()
.memberLocationName(null)
.memberFieldInfo(
SdkField. builder(MarshallingType.SDK_POJO)
.constructor(EvaluationErrorItem::builder)
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD)
.locationName("member").build()).build()).build()).build();
private static final List> SDK_FIELDS = Collections.unmodifiableList(Arrays.asList(DECISION_FIELD,
DETERMINING_POLICIES_FIELD, ERRORS_FIELD));
private final String decision;
private final List determiningPolicies;
private final List errors;
private IsAuthorizedWithTokenResponse(BuilderImpl builder) {
super(builder);
this.decision = builder.decision;
this.determiningPolicies = builder.determiningPolicies;
this.errors = builder.errors;
}
/**
*
* An authorization decision that indicates if the authorization request should be allowed or denied.
*
*
* If the service returns an enum value that is not available in the current SDK version, {@link #decision} will
* return {@link Decision#UNKNOWN_TO_SDK_VERSION}. The raw value returned by the service is available from
* {@link #decisionAsString}.
*
*
* @return An authorization decision that indicates if the authorization request should be allowed or denied.
* @see Decision
*/
public final Decision decision() {
return Decision.fromValue(decision);
}
/**
*
* An authorization decision that indicates if the authorization request should be allowed or denied.
*
*
* If the service returns an enum value that is not available in the current SDK version, {@link #decision} will
* return {@link Decision#UNKNOWN_TO_SDK_VERSION}. The raw value returned by the service is available from
* {@link #decisionAsString}.
*
*
* @return An authorization decision that indicates if the authorization request should be allowed or denied.
* @see Decision
*/
public final String decisionAsString() {
return decision;
}
/**
* For responses, this returns true if the service returned a value for the DeterminingPolicies property. This DOES
* NOT check that the value is non-empty (for which, you should check the {@code isEmpty()} method on the property).
* This is useful because the SDK will never return a null collection or map, but you may need to differentiate
* between the service returning nothing (or null) and the service returning an empty collection or map. For
* requests, this returns true if a value for the property was specified in the request builder, and false if a
* value was not specified.
*/
public final boolean hasDeterminingPolicies() {
return determiningPolicies != null && !(determiningPolicies instanceof SdkAutoConstructList);
}
/**
*
* The list of determining policies used to make the authorization decision. For example, if there are multiple
* matching policies, where at least one is a forbid policy, then because forbid always overrides permit the forbid
* policies are the determining policies. If all matching policies are permit policies, then those policies are the
* determining policies. When no policies match and the response is the default DENY, there are no determining
* policies.
*
*
* Attempts to modify the collection returned by this method will result in an UnsupportedOperationException.
*
*
* This method will never return null. If you would like to know whether the service returned this field (so that
* you can differentiate between null and empty), you can use the {@link #hasDeterminingPolicies} method.
*
*
* @return The list of determining policies used to make the authorization decision. For example, if there are
* multiple matching policies, where at least one is a forbid policy, then because forbid always overrides
* permit the forbid policies are the determining policies. If all matching policies are permit policies,
* then those policies are the determining policies. When no policies match and the response is the default
* DENY, there are no determining policies.
*/
public final List determiningPolicies() {
return determiningPolicies;
}
/**
* For responses, this returns true if the service returned a value for the Errors property. This DOES NOT check
* that the value is non-empty (for which, you should check the {@code isEmpty()} method on the property). This is
* useful because the SDK will never return a null collection or map, but you may need to differentiate between the
* service returning nothing (or null) and the service returning an empty collection or map. For requests, this
* returns true if a value for the property was specified in the request builder, and false if a value was not
* specified.
*/
public final boolean hasErrors() {
return errors != null && !(errors instanceof SdkAutoConstructList);
}
/**
*
* Errors that occurred while making an authorization decision. For example, a policy references an entity or entity
* attribute that does not exist in the slice.
*
*
* Attempts to modify the collection returned by this method will result in an UnsupportedOperationException.
*
*
* This method will never return null. If you would like to know whether the service returned this field (so that
* you can differentiate between null and empty), you can use the {@link #hasErrors} method.
*
*
* @return Errors that occurred while making an authorization decision. For example, a policy references an entity
* or entity attribute that does not exist in the slice.
*/
public final List errors() {
return errors;
}
@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 final int hashCode() {
int hashCode = 1;
hashCode = 31 * hashCode + super.hashCode();
hashCode = 31 * hashCode + Objects.hashCode(decisionAsString());
hashCode = 31 * hashCode + Objects.hashCode(hasDeterminingPolicies() ? determiningPolicies() : null);
hashCode = 31 * hashCode + Objects.hashCode(hasErrors() ? errors() : null);
return hashCode;
}
@Override
public final boolean equals(Object obj) {
return super.equals(obj) && equalsBySdkFields(obj);
}
@Override
public final boolean equalsBySdkFields(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (!(obj instanceof IsAuthorizedWithTokenResponse)) {
return false;
}
IsAuthorizedWithTokenResponse other = (IsAuthorizedWithTokenResponse) obj;
return Objects.equals(decisionAsString(), other.decisionAsString())
&& hasDeterminingPolicies() == other.hasDeterminingPolicies()
&& Objects.equals(determiningPolicies(), other.determiningPolicies()) && hasErrors() == other.hasErrors()
&& Objects.equals(errors(), other.errors());
}
/**
* 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 final String toString() {
return ToString.builder("IsAuthorizedWithTokenResponse").add("Decision", decisionAsString())
.add("DeterminingPolicies", hasDeterminingPolicies() ? determiningPolicies() : null)
.add("Errors", errors() == null ? null : "*** Sensitive Data Redacted ***").build();
}
public final Optional getValueForField(String fieldName, Class clazz) {
switch (fieldName) {
case "decision":
return Optional.ofNullable(clazz.cast(decisionAsString()));
case "determiningPolicies":
return Optional.ofNullable(clazz.cast(determiningPolicies()));
case "errors":
return Optional.ofNullable(clazz.cast(errors()));
default:
return Optional.empty();
}
}
@Override
public final List> sdkFields() {
return SDK_FIELDS;
}
private static Function