• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License").
5  * You may not use this file except in compliance with the License.
6  * A copy of the License is located at
7  *
8  *  http://aws.amazon.com/apache2.0
9  *
10  * or in the "license" file accompanying this file. This file is distributed
11  * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12  * express or implied. See the License for the specific language governing
13  * permissions and limitations under the License.
14  */
15 
16 package software.amazon.awssdk.http.auth.spi.scheme;
17 
18 import software.amazon.awssdk.annotations.SdkPublicApi;
19 import software.amazon.awssdk.http.auth.spi.internal.scheme.DefaultAuthSchemeOption;
20 import software.amazon.awssdk.http.auth.spi.signer.SignerProperty;
21 import software.amazon.awssdk.identity.spi.IdentityProperty;
22 import software.amazon.awssdk.utils.builder.CopyableBuilder;
23 import software.amazon.awssdk.utils.builder.ToCopyableBuilder;
24 
25 /**
26  * An authentication scheme option, composed of the scheme ID and properties for use when resolving the identity and signing
27  * the request.
28  * <p>
29  * This is used in the output from the auth scheme resolver. The resolver returns a list of these, in the order the auth scheme
30  * resolver wishes to use them.
31  *
32  * @see AuthScheme
33  */
34 @SdkPublicApi
35 public interface AuthSchemeOption extends ToCopyableBuilder<AuthSchemeOption.Builder, AuthSchemeOption> {
36 
37     /**
38      * Get a new builder for creating a {@link AuthSchemeOption}.
39      */
builder()40     static Builder builder() {
41         return DefaultAuthSchemeOption.builder();
42     }
43 
44     /**
45      * Retrieve the scheme ID, a unique identifier for the authentication scheme (aws.auth#sigv4, smithy.api#httpBearerAuth).
46      */
schemeId()47     String schemeId();
48 
49     /**
50      * Retrieve the value of an {@link IdentityProperty}.
51      * @param property The IdentityProperty to retrieve the value of.
52      * @param <T> The type of the IdentityProperty.
53      */
identityProperty(IdentityProperty<T> property)54     <T> T identityProperty(IdentityProperty<T> property);
55 
56     /**
57      * Retrieve the value of an {@link SignerProperty}.
58      * @param property The SignerProperty to retrieve the value of.
59      * @param <T> The type of the SignerProperty.
60      */
signerProperty(SignerProperty<T> property)61     <T> T signerProperty(SignerProperty<T> property);
62 
63     /**
64      * A method to operate on all {@link IdentityProperty} values of this AuthSchemeOption.
65      * @param consumer The method to apply to each IdentityProperty.
66      */
forEachIdentityProperty(IdentityPropertyConsumer consumer)67     void forEachIdentityProperty(IdentityPropertyConsumer consumer);
68 
69     /**
70      * A method to operate on all {@link SignerProperty} values of this AuthSchemeOption.
71      * @param consumer The method to apply to each SignerProperty.
72      */
forEachSignerProperty(SignerPropertyConsumer consumer)73     void forEachSignerProperty(SignerPropertyConsumer consumer);
74 
75     /**
76      * Interface for operating on an {@link IdentityProperty} value.
77      */
78     @FunctionalInterface
79     interface IdentityPropertyConsumer {
80         /**
81          * A method to operate on an {@link IdentityProperty} and it's value.
82          * @param propertyKey The IdentityProperty.
83          * @param propertyValue The value of the IdentityProperty.
84          * @param <T> The type of the IdentityProperty.
85          */
accept(IdentityProperty<T> propertyKey, T propertyValue)86         <T> void accept(IdentityProperty<T> propertyKey, T propertyValue);
87     }
88 
89     /**
90      * Interface for operating on an {@link SignerProperty} value.
91      */
92     @FunctionalInterface
93     interface SignerPropertyConsumer {
94         /**
95          * A method to operate on a {@link SignerProperty} and it's value.
96          * @param propertyKey The SignerProperty.
97          * @param propertyValue The value of the SignerProperty.
98          * @param <T> The type of the SignerProperty.
99          */
accept(SignerProperty<T> propertyKey, T propertyValue)100         <T> void accept(SignerProperty<T> propertyKey, T propertyValue);
101     }
102 
103     /**
104      * A builder for a {@link AuthSchemeOption}.
105      */
106     interface Builder extends CopyableBuilder<Builder, AuthSchemeOption> {
107 
108         /**
109          * Set the scheme ID.
110          */
schemeId(String schemeId)111         Builder schemeId(String schemeId);
112 
113         /**
114          * Update or add the provided property value.
115          */
putIdentityProperty(IdentityProperty<T> key, T value)116         <T> Builder putIdentityProperty(IdentityProperty<T> key, T value);
117 
118         /**
119          * Add the provided property value if the property does not already exist.
120          */
putIdentityPropertyIfAbsent(IdentityProperty<T> key, T value)121         <T> Builder putIdentityPropertyIfAbsent(IdentityProperty<T> key, T value);
122 
123         /**
124          * Update or add the provided property value.
125          */
putSignerProperty(SignerProperty<T> key, T value)126         <T> Builder putSignerProperty(SignerProperty<T> key, T value);
127 
128         /**
129          * Add the provided property value if the property does not already exist.
130          */
putSignerPropertyIfAbsent(SignerProperty<T> key, T value)131         <T> Builder putSignerPropertyIfAbsent(SignerProperty<T> key, T value);
132     }
133 }
134