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

software.amazon.awssdk.services.verifiedpermissions.model.TemplateLinkedPolicyDefinition 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.io.Serializable;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
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;

/**
 * 

* Contains information about a policy created by instantiating a policy template. *

*/ @Generated("software.amazon.awssdk:codegen") public final class TemplateLinkedPolicyDefinition implements SdkPojo, Serializable, ToCopyableBuilder { private static final SdkField POLICY_TEMPLATE_ID_FIELD = SdkField. builder(MarshallingType.STRING) .memberName("policyTemplateId").getter(getter(TemplateLinkedPolicyDefinition::policyTemplateId)) .setter(setter(Builder::policyTemplateId)) .traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("policyTemplateId").build()).build(); private static final SdkField PRINCIPAL_FIELD = SdkField . builder(MarshallingType.SDK_POJO).memberName("principal") .getter(getter(TemplateLinkedPolicyDefinition::principal)).setter(setter(Builder::principal)) .constructor(EntityIdentifier::builder) .traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("principal").build()).build(); private static final SdkField RESOURCE_FIELD = SdkField . builder(MarshallingType.SDK_POJO).memberName("resource") .getter(getter(TemplateLinkedPolicyDefinition::resource)).setter(setter(Builder::resource)) .constructor(EntityIdentifier::builder) .traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("resource").build()).build(); private static final List> SDK_FIELDS = Collections.unmodifiableList(Arrays.asList(POLICY_TEMPLATE_ID_FIELD, PRINCIPAL_FIELD, RESOURCE_FIELD)); private static final Map> SDK_NAME_TO_FIELD = memberNameToFieldInitializer(); private static final long serialVersionUID = 1L; private final String policyTemplateId; private final EntityIdentifier principal; private final EntityIdentifier resource; private TemplateLinkedPolicyDefinition(BuilderImpl builder) { this.policyTemplateId = builder.policyTemplateId; this.principal = builder.principal; this.resource = builder.resource; } /** *

* The unique identifier of the policy template used to create this policy. *

* * @return The unique identifier of the policy template used to create this policy. */ public final String policyTemplateId() { return policyTemplateId; } /** *

* The principal associated with this template-linked policy. Verified Permissions substitutes this principal for * the ?principal placeholder in the policy template when it evaluates an authorization request. *

* * @return The principal associated with this template-linked policy. Verified Permissions substitutes this * principal for the ?principal placeholder in the policy template when it evaluates an * authorization request. */ public final EntityIdentifier principal() { return principal; } /** *

* The resource associated with this template-linked policy. Verified Permissions substitutes this resource for the * ?resource placeholder in the policy template when it evaluates an authorization request. *

* * @return The resource associated with this template-linked policy. Verified Permissions substitutes this resource * for the ?resource placeholder in the policy template when it evaluates an authorization * request. */ public final EntityIdentifier resource() { return resource; } @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 + Objects.hashCode(policyTemplateId()); hashCode = 31 * hashCode + Objects.hashCode(principal()); hashCode = 31 * hashCode + Objects.hashCode(resource()); 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 TemplateLinkedPolicyDefinition)) { return false; } TemplateLinkedPolicyDefinition other = (TemplateLinkedPolicyDefinition) obj; return Objects.equals(policyTemplateId(), other.policyTemplateId()) && Objects.equals(principal(), other.principal()) && Objects.equals(resource(), other.resource()); } /** * 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("TemplateLinkedPolicyDefinition").add("PolicyTemplateId", policyTemplateId()) .add("Principal", principal()).add("Resource", resource()).build(); } public final Optional getValueForField(String fieldName, Class clazz) { switch (fieldName) { case "policyTemplateId": return Optional.ofNullable(clazz.cast(policyTemplateId())); case "principal": return Optional.ofNullable(clazz.cast(principal())); case "resource": return Optional.ofNullable(clazz.cast(resource())); default: return Optional.empty(); } } @Override public final List> sdkFields() { return SDK_FIELDS; } @Override public final Map> sdkFieldNameToField() { return SDK_NAME_TO_FIELD; } private static Map> memberNameToFieldInitializer() { Map> map = new HashMap<>(); map.put("policyTemplateId", POLICY_TEMPLATE_ID_FIELD); map.put("principal", PRINCIPAL_FIELD); map.put("resource", RESOURCE_FIELD); return Collections.unmodifiableMap(map); } private static Function getter(Function g) { return obj -> g.apply((TemplateLinkedPolicyDefinition) obj); } private static BiConsumer setter(BiConsumer s) { return (obj, val) -> s.accept((Builder) obj, val); } public interface Builder extends SdkPojo, CopyableBuilder { /** *

* The unique identifier of the policy template used to create this policy. *

* * @param policyTemplateId * The unique identifier of the policy template used to create this policy. * @return Returns a reference to this object so that method calls can be chained together. */ Builder policyTemplateId(String policyTemplateId); /** *

* The principal associated with this template-linked policy. Verified Permissions substitutes this principal * for the ?principal placeholder in the policy template when it evaluates an authorization * request. *

* * @param principal * The principal associated with this template-linked policy. Verified Permissions substitutes this * principal for the ?principal placeholder in the policy template when it evaluates an * authorization request. * @return Returns a reference to this object so that method calls can be chained together. */ Builder principal(EntityIdentifier principal); /** *

* The principal associated with this template-linked policy. Verified Permissions substitutes this principal * for the ?principal placeholder in the policy template when it evaluates an authorization * request. *

* This is a convenience method that creates an instance of the {@link EntityIdentifier.Builder} avoiding the * need to create one manually via {@link EntityIdentifier#builder()}. * *

* When the {@link Consumer} completes, {@link EntityIdentifier.Builder#build()} is called immediately and its * result is passed to {@link #principal(EntityIdentifier)}. * * @param principal * a consumer that will call methods on {@link EntityIdentifier.Builder} * @return Returns a reference to this object so that method calls can be chained together. * @see #principal(EntityIdentifier) */ default Builder principal(Consumer principal) { return principal(EntityIdentifier.builder().applyMutation(principal).build()); } /** *

* The resource associated with this template-linked policy. Verified Permissions substitutes this resource for * the ?resource placeholder in the policy template when it evaluates an authorization request. *

* * @param resource * The resource associated with this template-linked policy. Verified Permissions substitutes this * resource for the ?resource placeholder in the policy template when it evaluates an * authorization request. * @return Returns a reference to this object so that method calls can be chained together. */ Builder resource(EntityIdentifier resource); /** *

* The resource associated with this template-linked policy. Verified Permissions substitutes this resource for * the ?resource placeholder in the policy template when it evaluates an authorization request. *

* This is a convenience method that creates an instance of the {@link EntityIdentifier.Builder} avoiding the * need to create one manually via {@link EntityIdentifier#builder()}. * *

* When the {@link Consumer} completes, {@link EntityIdentifier.Builder#build()} is called immediately and its * result is passed to {@link #resource(EntityIdentifier)}. * * @param resource * a consumer that will call methods on {@link EntityIdentifier.Builder} * @return Returns a reference to this object so that method calls can be chained together. * @see #resource(EntityIdentifier) */ default Builder resource(Consumer resource) { return resource(EntityIdentifier.builder().applyMutation(resource).build()); } } static final class BuilderImpl implements Builder { private String policyTemplateId; private EntityIdentifier principal; private EntityIdentifier resource; private BuilderImpl() { } private BuilderImpl(TemplateLinkedPolicyDefinition model) { policyTemplateId(model.policyTemplateId); principal(model.principal); resource(model.resource); } public final String getPolicyTemplateId() { return policyTemplateId; } public final void setPolicyTemplateId(String policyTemplateId) { this.policyTemplateId = policyTemplateId; } @Override public final Builder policyTemplateId(String policyTemplateId) { this.policyTemplateId = policyTemplateId; return this; } public final EntityIdentifier.Builder getPrincipal() { return principal != null ? principal.toBuilder() : null; } public final void setPrincipal(EntityIdentifier.BuilderImpl principal) { this.principal = principal != null ? principal.build() : null; } @Override public final Builder principal(EntityIdentifier principal) { this.principal = principal; return this; } public final EntityIdentifier.Builder getResource() { return resource != null ? resource.toBuilder() : null; } public final void setResource(EntityIdentifier.BuilderImpl resource) { this.resource = resource != null ? resource.build() : null; } @Override public final Builder resource(EntityIdentifier resource) { this.resource = resource; return this; } @Override public TemplateLinkedPolicyDefinition build() { return new TemplateLinkedPolicyDefinition(this); } @Override public List> sdkFields() { return SDK_FIELDS; } @Override public Map> sdkFieldNameToField() { return SDK_NAME_TO_FIELD; } } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy