All Downloads are FREE. Search and download functionalities are using the official Maven repository.

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 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 getter(Function g) { return obj -> g.apply((IsAuthorizedWithTokenResponse) obj); } private static BiConsumer setter(BiConsumer s) { return (obj, val) -> s.accept((Builder) obj, val); } public interface Builder extends VerifiedPermissionsResponse.Builder, SdkPojo, CopyableBuilder { /** *

* An authorization decision that indicates if the authorization request should be allowed or denied. *

* * @param decision * An authorization decision that indicates if the authorization request should be allowed or denied. * @see Decision * @return Returns a reference to this object so that method calls can be chained together. * @see Decision */ Builder decision(String decision); /** *

* An authorization decision that indicates if the authorization request should be allowed or denied. *

* * @param decision * An authorization decision that indicates if the authorization request should be allowed or denied. * @see Decision * @return Returns a reference to this object so that method calls can be chained together. * @see Decision */ Builder decision(Decision decision); /** *

* 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. *

* * @param determiningPolicies * 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. * @return Returns a reference to this object so that method calls can be chained together. */ Builder determiningPolicies(Collection determiningPolicies); /** *

* 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. *

* * @param determiningPolicies * 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. * @return Returns a reference to this object so that method calls can be chained together. */ Builder determiningPolicies(DeterminingPolicyItem... determiningPolicies); /** *

* 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. *

* This is a convenience method that creates an instance of the * {@link software.amazon.awssdk.services.verifiedpermissions.model.DeterminingPolicyItem.Builder} avoiding the * need to create one manually via * {@link software.amazon.awssdk.services.verifiedpermissions.model.DeterminingPolicyItem#builder()}. * *

* When the {@link Consumer} completes, * {@link software.amazon.awssdk.services.verifiedpermissions.model.DeterminingPolicyItem.Builder#build()} is * called immediately and its result is passed to {@link #determiningPolicies(List)}. * * @param determiningPolicies * a consumer that will call methods on * {@link software.amazon.awssdk.services.verifiedpermissions.model.DeterminingPolicyItem.Builder} * @return Returns a reference to this object so that method calls can be chained together. * @see #determiningPolicies(java.util.Collection) */ Builder determiningPolicies(Consumer... determiningPolicies); /** *

* 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. *

* * @param errors * 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. * @return Returns a reference to this object so that method calls can be chained together. */ Builder errors(Collection errors); /** *

* 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. *

* * @param errors * 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. * @return Returns a reference to this object so that method calls can be chained together. */ Builder errors(EvaluationErrorItem... errors); /** *

* 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. *

* This is a convenience method that creates an instance of the * {@link software.amazon.awssdk.services.verifiedpermissions.model.EvaluationErrorItem.Builder} avoiding the * need to create one manually via * {@link software.amazon.awssdk.services.verifiedpermissions.model.EvaluationErrorItem#builder()}. * *

* When the {@link Consumer} completes, * {@link software.amazon.awssdk.services.verifiedpermissions.model.EvaluationErrorItem.Builder#build()} is * called immediately and its result is passed to {@link #errors(List)}. * * @param errors * a consumer that will call methods on * {@link software.amazon.awssdk.services.verifiedpermissions.model.EvaluationErrorItem.Builder} * @return Returns a reference to this object so that method calls can be chained together. * @see #errors(java.util.Collection) */ Builder errors(Consumer... errors); } static final class BuilderImpl extends VerifiedPermissionsResponse.BuilderImpl implements Builder { private String decision; private List determiningPolicies = DefaultSdkAutoConstructList.getInstance(); private List errors = DefaultSdkAutoConstructList.getInstance(); private BuilderImpl() { } private BuilderImpl(IsAuthorizedWithTokenResponse model) { super(model); decision(model.decision); determiningPolicies(model.determiningPolicies); errors(model.errors); } public final String getDecision() { return decision; } public final void setDecision(String decision) { this.decision = decision; } @Override public final Builder decision(String decision) { this.decision = decision; return this; } @Override public final Builder decision(Decision decision) { this.decision(decision == null ? null : decision.toString()); return this; } public final List getDeterminingPolicies() { List result = DeterminingPolicyListCopier.copyToBuilder(this.determiningPolicies); if (result instanceof SdkAutoConstructList) { return null; } return result; } public final void setDeterminingPolicies(Collection determiningPolicies) { this.determiningPolicies = DeterminingPolicyListCopier.copyFromBuilder(determiningPolicies); } @Override public final Builder determiningPolicies(Collection determiningPolicies) { this.determiningPolicies = DeterminingPolicyListCopier.copy(determiningPolicies); return this; } @Override @SafeVarargs public final Builder determiningPolicies(DeterminingPolicyItem... determiningPolicies) { determiningPolicies(Arrays.asList(determiningPolicies)); return this; } @Override @SafeVarargs public final Builder determiningPolicies(Consumer... determiningPolicies) { determiningPolicies(Stream.of(determiningPolicies).map(c -> DeterminingPolicyItem.builder().applyMutation(c).build()) .collect(Collectors.toList())); return this; } public final List getErrors() { List result = EvaluationErrorListCopier.copyToBuilder(this.errors); if (result instanceof SdkAutoConstructList) { return null; } return result; } public final void setErrors(Collection errors) { this.errors = EvaluationErrorListCopier.copyFromBuilder(errors); } @Override public final Builder errors(Collection errors) { this.errors = EvaluationErrorListCopier.copy(errors); return this; } @Override @SafeVarargs public final Builder errors(EvaluationErrorItem... errors) { errors(Arrays.asList(errors)); return this; } @Override @SafeVarargs public final Builder errors(Consumer... errors) { errors(Stream.of(errors).map(c -> EvaluationErrorItem.builder().applyMutation(c).build()) .collect(Collectors.toList())); return this; } @Override public IsAuthorizedWithTokenResponse build() { return new IsAuthorizedWithTokenResponse(this); } @Override public List> sdkFields() { return SDK_FIELDS; } } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy