software.amazon.awssdk.services.iot.model.AuthResult Maven / Gradle / Ivy
Show all versions of iot Show documentation
/*
* 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.iot.model;
import java.io.Serializable;
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 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;
/**
*
* The authorizer result.
*
*/
@Generated("software.amazon.awssdk:codegen")
public final class AuthResult implements SdkPojo, Serializable, ToCopyableBuilder {
private static final SdkField AUTH_INFO_FIELD = SdkField. builder(MarshallingType.SDK_POJO)
.memberName("authInfo").getter(getter(AuthResult::authInfo)).setter(setter(Builder::authInfo))
.constructor(AuthInfo::builder)
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("authInfo").build()).build();
private static final SdkField ALLOWED_FIELD = SdkField. builder(MarshallingType.SDK_POJO)
.memberName("allowed").getter(getter(AuthResult::allowed)).setter(setter(Builder::allowed))
.constructor(Allowed::builder)
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("allowed").build()).build();
private static final SdkField DENIED_FIELD = SdkField. builder(MarshallingType.SDK_POJO).memberName("denied")
.getter(getter(AuthResult::denied)).setter(setter(Builder::denied)).constructor(Denied::builder)
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("denied").build()).build();
private static final SdkField AUTH_DECISION_FIELD = SdkField. builder(MarshallingType.STRING)
.memberName("authDecision").getter(getter(AuthResult::authDecisionAsString)).setter(setter(Builder::authDecision))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("authDecision").build()).build();
private static final SdkField> MISSING_CONTEXT_VALUES_FIELD = SdkField
.> builder(MarshallingType.LIST)
.memberName("missingContextValues")
.getter(getter(AuthResult::missingContextValues))
.setter(setter(Builder::missingContextValues))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("missingContextValues").build(),
ListTrait
.builder()
.memberLocationName(null)
.memberFieldInfo(
SdkField. builder(MarshallingType.STRING)
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD)
.locationName("member").build()).build()).build()).build();
private static final List> SDK_FIELDS = Collections.unmodifiableList(Arrays.asList(AUTH_INFO_FIELD,
ALLOWED_FIELD, DENIED_FIELD, AUTH_DECISION_FIELD, MISSING_CONTEXT_VALUES_FIELD));
private static final long serialVersionUID = 1L;
private final AuthInfo authInfo;
private final Allowed allowed;
private final Denied denied;
private final String authDecision;
private final List missingContextValues;
private AuthResult(BuilderImpl builder) {
this.authInfo = builder.authInfo;
this.allowed = builder.allowed;
this.denied = builder.denied;
this.authDecision = builder.authDecision;
this.missingContextValues = builder.missingContextValues;
}
/**
*
* Authorization information.
*
*
* @return Authorization information.
*/
public final AuthInfo authInfo() {
return authInfo;
}
/**
*
* The policies and statements that allowed the specified action.
*
*
* @return The policies and statements that allowed the specified action.
*/
public final Allowed allowed() {
return allowed;
}
/**
*
* The policies and statements that denied the specified action.
*
*
* @return The policies and statements that denied the specified action.
*/
public final Denied denied() {
return denied;
}
/**
*
* The final authorization decision of this scenario. Multiple statements are taken into account when determining
* the authorization decision. An explicit deny statement can override multiple allow statements.
*
*
* If the service returns an enum value that is not available in the current SDK version, {@link #authDecision} will
* return {@link AuthDecision#UNKNOWN_TO_SDK_VERSION}. The raw value returned by the service is available from
* {@link #authDecisionAsString}.
*
*
* @return The final authorization decision of this scenario. Multiple statements are taken into account when
* determining the authorization decision. An explicit deny statement can override multiple allow
* statements.
* @see AuthDecision
*/
public final AuthDecision authDecision() {
return AuthDecision.fromValue(authDecision);
}
/**
*
* The final authorization decision of this scenario. Multiple statements are taken into account when determining
* the authorization decision. An explicit deny statement can override multiple allow statements.
*
*
* If the service returns an enum value that is not available in the current SDK version, {@link #authDecision} will
* return {@link AuthDecision#UNKNOWN_TO_SDK_VERSION}. The raw value returned by the service is available from
* {@link #authDecisionAsString}.
*
*
* @return The final authorization decision of this scenario. Multiple statements are taken into account when
* determining the authorization decision. An explicit deny statement can override multiple allow
* statements.
* @see AuthDecision
*/
public final String authDecisionAsString() {
return authDecision;
}
/**
* For responses, this returns true if the service returned a value for the MissingContextValues 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 hasMissingContextValues() {
return missingContextValues != null && !(missingContextValues instanceof SdkAutoConstructList);
}
/**
*
* Contains any missing context values found while evaluating policy.
*
*
* 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 #hasMissingContextValues} method.
*
*
* @return Contains any missing context values found while evaluating policy.
*/
public final List missingContextValues() {
return missingContextValues;
}
@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 + Objects.hashCode(authInfo());
hashCode = 31 * hashCode + Objects.hashCode(allowed());
hashCode = 31 * hashCode + Objects.hashCode(denied());
hashCode = 31 * hashCode + Objects.hashCode(authDecisionAsString());
hashCode = 31 * hashCode + Objects.hashCode(hasMissingContextValues() ? missingContextValues() : null);
return hashCode;
}
@Override
public final boolean equals(Object obj) {
return equalsBySdkFields(obj);
}
@Override
public final boolean equalsBySdkFields(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (!(obj instanceof AuthResult)) {
return false;
}
AuthResult other = (AuthResult) obj;
return Objects.equals(authInfo(), other.authInfo()) && Objects.equals(allowed(), other.allowed())
&& Objects.equals(denied(), other.denied())
&& Objects.equals(authDecisionAsString(), other.authDecisionAsString())
&& hasMissingContextValues() == other.hasMissingContextValues()
&& Objects.equals(missingContextValues(), other.missingContextValues());
}
/**
* 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("AuthResult").add("AuthInfo", authInfo()).add("Allowed", allowed()).add("Denied", denied())
.add("AuthDecision", authDecisionAsString())
.add("MissingContextValues", hasMissingContextValues() ? missingContextValues() : null).build();
}
public final Optional getValueForField(String fieldName, Class clazz) {
switch (fieldName) {
case "authInfo":
return Optional.ofNullable(clazz.cast(authInfo()));
case "allowed":
return Optional.ofNullable(clazz.cast(allowed()));
case "denied":
return Optional.ofNullable(clazz.cast(denied()));
case "authDecision":
return Optional.ofNullable(clazz.cast(authDecisionAsString()));
case "missingContextValues":
return Optional.ofNullable(clazz.cast(missingContextValues()));
default:
return Optional.empty();
}
}
@Override
public final List> sdkFields() {
return SDK_FIELDS;
}
private static Function