-
Notifications
You must be signed in to change notification settings - Fork 279
Expand file tree
/
Copy pathAwsRequestSignature.java
More file actions
201 lines (173 loc) · 5.66 KB
/
AwsRequestSignature.java
File metadata and controls
201 lines (173 loc) · 5.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
/*
* Copyright 2021 Google LLC
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of Google LLC nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.google.auth.oauth2;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import java.util.HashMap;
import java.util.Map;
/**
* Stores the AWS API request signature based on the AWS Signature Version 4 signing process, and
* the parameters used in the signing process.
*/
class AwsRequestSignature {
private AwsSecurityCredentials awsSecurityCredentials;
private Map<String, String> canonicalHeaders;
private String signature;
private String credentialScope;
private String url;
private String httpMethod;
private String date;
private String region;
private String authorizationHeader;
private AwsRequestSignature(
AwsSecurityCredentials awsSecurityCredentials,
Map<String, String> canonicalHeaders,
String signature,
String credentialScope,
String url,
String httpMethod,
String date,
String region,
String authorizationHeader) {
this.awsSecurityCredentials = awsSecurityCredentials;
this.canonicalHeaders = canonicalHeaders;
this.signature = signature;
this.credentialScope = credentialScope;
this.url = url;
this.httpMethod = httpMethod;
this.date = date;
this.region = region;
this.authorizationHeader = authorizationHeader;
}
/** Returns the request signature based on the AWS Signature Version 4 signing process. */
String getSignature() {
return signature;
}
/** Returns the credential scope. e.g. 20150830/us-east-1/iam/aws4_request */
String getCredentialScope() {
return credentialScope;
}
/** Returns the AWS security credentials. */
AwsSecurityCredentials getSecurityCredentials() {
return awsSecurityCredentials;
}
/** Returns the request URL. */
String getUrl() {
return url;
}
/** Returns the HTTP request method. */
String getHttpMethod() {
return httpMethod;
}
/** Returns the HTTP request canonical headers. */
Map<String, String> getCanonicalHeaders() {
return new HashMap<>(canonicalHeaders);
}
/** Returns the request date. */
String getDate() {
return date;
}
/** Returns the targeted region. */
String getRegion() {
return region;
}
/** Returns the authorization header. */
String getAuthorizationHeader() {
return authorizationHeader;
}
static class Builder {
private AwsSecurityCredentials awsSecurityCredentials;
private Map<String, String> canonicalHeaders;
private String signature;
private String credentialScope;
private String url;
private String httpMethod;
private String date;
private String region;
private String authorizationHeader;
@CanIgnoreReturnValue
Builder setSignature(String signature) {
this.signature = signature;
return this;
}
@CanIgnoreReturnValue
Builder setCredentialScope(String credentialScope) {
this.credentialScope = credentialScope;
return this;
}
@CanIgnoreReturnValue
Builder setSecurityCredentials(AwsSecurityCredentials awsSecurityCredentials) {
this.awsSecurityCredentials = awsSecurityCredentials;
return this;
}
@CanIgnoreReturnValue
Builder setUrl(String url) {
this.url = url;
return this;
}
@CanIgnoreReturnValue
Builder setHttpMethod(String httpMethod) {
this.httpMethod = httpMethod;
return this;
}
@CanIgnoreReturnValue
Builder setCanonicalHeaders(Map<String, String> canonicalHeaders) {
this.canonicalHeaders = new HashMap<>(canonicalHeaders);
return this;
}
@CanIgnoreReturnValue
Builder setDate(String date) {
this.date = date;
return this;
}
@CanIgnoreReturnValue
Builder setRegion(String region) {
this.region = region;
return this;
}
@CanIgnoreReturnValue
Builder setAuthorizationHeader(String authorizationHeader) {
this.authorizationHeader = authorizationHeader;
return this;
}
AwsRequestSignature build() {
return new AwsRequestSignature(
awsSecurityCredentials,
canonicalHeaders,
signature,
credentialScope,
url,
httpMethod,
date,
region,
authorizationHeader);
}
}
}