16
16
17
17
package com .adobe .testing .s3mock ;
18
18
19
+ import static com .adobe .testing .s3mock .BucketNameFilter .BUCKET_ATTRIBUTE ;
19
20
import static com .adobe .testing .s3mock .util .AwsHttpHeaders .X_AMZ_BUCKET_OBJECT_LOCK_ENABLED ;
20
21
import static com .adobe .testing .s3mock .util .AwsHttpParameters .CONTINUATION_TOKEN ;
21
22
import static com .adobe .testing .s3mock .util .AwsHttpParameters .ENCODING_TYPE ;
33
34
import static org .springframework .http .MediaType .APPLICATION_XML_VALUE ;
34
35
35
36
import com .adobe .testing .s3mock .dto .BucketLifecycleConfiguration ;
37
+ import com .adobe .testing .s3mock .dto .BucketName ;
36
38
import com .adobe .testing .s3mock .dto .ListAllMyBucketsResult ;
37
39
import com .adobe .testing .s3mock .dto .ListBucketResult ;
38
40
import com .adobe .testing .s3mock .dto .ListBucketResultV2 ;
42
44
import org .springframework .http .ResponseEntity ;
43
45
import org .springframework .web .bind .annotation .CrossOrigin ;
44
46
import org .springframework .web .bind .annotation .PathVariable ;
47
+ import org .springframework .web .bind .annotation .RequestAttribute ;
45
48
import org .springframework .web .bind .annotation .RequestBody ;
46
49
import org .springframework .web .bind .annotation .RequestHeader ;
47
50
import org .springframework .web .bind .annotation .RequestMapping ;
@@ -110,7 +113,10 @@ public ResponseEntity<ListAllMyBucketsResult> listBuckets() {
110
113
)
111
114
public ResponseEntity <Void > createBucket (@ PathVariable final String bucketName ,
112
115
@ RequestHeader (value = X_AMZ_BUCKET_OBJECT_LOCK_ENABLED ,
113
- required = false , defaultValue = "false" ) boolean objectLockEnabled ) {
116
+ required = false , defaultValue = "false" ) boolean objectLockEnabled ,
117
+ @ RequestAttribute (BUCKET_ATTRIBUTE ) BucketName bucket ) {
118
+ //TODO: does subdomain access work for #createBucket in S3?
119
+ assert bucketName .equals (bucket .getName ());
114
120
bucketService .verifyBucketNameIsAllowed (bucketName );
115
121
bucketService .verifyBucketDoesNotExist (bucketName );
116
122
bucketService .createBucket (bucketName , objectLockEnabled );
@@ -129,7 +135,9 @@ public ResponseEntity<Void> createBucket(@PathVariable final String bucketName,
129
135
value = "/{bucketName:.+}" ,
130
136
method = RequestMethod .HEAD
131
137
)
132
- public ResponseEntity <Void > headBucket (@ PathVariable final String bucketName ) {
138
+ public ResponseEntity <Void > headBucket (@ PathVariable final String bucketName ,
139
+ @ RequestAttribute (BUCKET_ATTRIBUTE ) BucketName bucket ) {
140
+ assert bucketName .equals (bucket .getName ());
133
141
bucketService .verifyBucketExists (bucketName );
134
142
return ResponseEntity .ok ().build ();
135
143
}
@@ -149,7 +157,9 @@ public ResponseEntity<Void> headBucket(@PathVariable final String bucketName) {
149
157
},
150
158
method = RequestMethod .DELETE
151
159
)
152
- public ResponseEntity <Void > deleteBucket (@ PathVariable String bucketName ) {
160
+ public ResponseEntity <Void > deleteBucket (@ PathVariable String bucketName ,
161
+ @ RequestAttribute (BUCKET_ATTRIBUTE ) BucketName bucket ) {
162
+ assert bucketName .equals (bucket .getName ());
153
163
bucketService .verifyBucketExists (bucketName );
154
164
bucketService .verifyBucketIsEmpty (bucketName );
155
165
bucketService .deleteBucket (bucketName );
@@ -176,7 +186,9 @@ public ResponseEntity<Void> deleteBucket(@PathVariable String bucketName) {
176
186
}
177
187
)
178
188
public ResponseEntity <ObjectLockConfiguration > getObjectLockConfiguration (
179
- @ PathVariable String bucketName ) {
189
+ @ PathVariable String bucketName ,
190
+ @ RequestAttribute (BUCKET_ATTRIBUTE ) BucketName bucket ) {
191
+ assert bucketName .equals (bucket .getName ());
180
192
bucketService .verifyBucketExists (bucketName );
181
193
ObjectLockConfiguration configuration = bucketService .getObjectLockConfiguration (bucketName );
182
194
return ResponseEntity .ok (configuration );
@@ -200,7 +212,9 @@ public ResponseEntity<ObjectLockConfiguration> getObjectLockConfiguration(
200
212
)
201
213
public ResponseEntity <Void > putObjectLockConfiguration (
202
214
@ PathVariable String bucketName ,
203
- @ RequestBody ObjectLockConfiguration configuration ) {
215
+ @ RequestBody ObjectLockConfiguration configuration ,
216
+ @ RequestAttribute (BUCKET_ATTRIBUTE ) BucketName bucket ) {
217
+ assert bucketName .equals (bucket .getName ());
204
218
bucketService .verifyBucketExists (bucketName );
205
219
bucketService .setObjectLockConfiguration (bucketName , configuration );
206
220
return ResponseEntity .ok ().build ();
@@ -226,7 +240,9 @@ public ResponseEntity<Void> putObjectLockConfiguration(
226
240
}
227
241
)
228
242
public ResponseEntity <BucketLifecycleConfiguration > getBucketLifecycleConfiguration (
229
- @ PathVariable String bucketName ) {
243
+ @ PathVariable String bucketName ,
244
+ @ RequestAttribute (BUCKET_ATTRIBUTE ) BucketName bucket ) {
245
+ assert bucketName .equals (bucket .getName ());
230
246
bucketService .verifyBucketExists (bucketName );
231
247
BucketLifecycleConfiguration configuration =
232
248
bucketService .getBucketLifecycleConfiguration (bucketName );
@@ -251,7 +267,9 @@ public ResponseEntity<BucketLifecycleConfiguration> getBucketLifecycleConfigurat
251
267
)
252
268
public ResponseEntity <Void > putBucketLifecycleConfiguration (
253
269
@ PathVariable String bucketName ,
254
- @ RequestBody BucketLifecycleConfiguration configuration ) {
270
+ @ RequestBody BucketLifecycleConfiguration configuration ,
271
+ @ RequestAttribute (BUCKET_ATTRIBUTE ) BucketName bucket ) {
272
+ assert bucketName .equals (bucket .getName ());
255
273
bucketService .verifyBucketExists (bucketName );
256
274
bucketService .setBucketLifecycleConfiguration (bucketName , configuration );
257
275
return ResponseEntity .ok ().build ();
@@ -273,7 +291,9 @@ public ResponseEntity<Void> putBucketLifecycleConfiguration(
273
291
method = RequestMethod .DELETE
274
292
)
275
293
public ResponseEntity <Void > deleteBucketLifecycleConfiguration (
276
- @ PathVariable String bucketName ) {
294
+ @ PathVariable String bucketName ,
295
+ @ RequestAttribute (BUCKET_ATTRIBUTE ) BucketName bucket ) {
296
+ assert bucketName .equals (bucket .getName ());
277
297
bucketService .verifyBucketExists (bucketName );
278
298
bucketService .deleteBucketLifecycleConfiguration (bucketName );
279
299
return ResponseEntity .noContent ().build ();
@@ -332,7 +352,9 @@ public ResponseEntity<ListBucketResult> listObjects(
332
352
@ RequestParam (required = false ) String delimiter ,
333
353
@ RequestParam (required = false ) String marker ,
334
354
@ RequestParam (name = ENCODING_TYPE , required = false ) String encodingType ,
335
- @ RequestParam (name = MAX_KEYS , defaultValue = "1000" , required = false ) Integer maxKeys ) {
355
+ @ RequestParam (name = MAX_KEYS , defaultValue = "1000" , required = false ) Integer maxKeys ,
356
+ @ RequestAttribute (BUCKET_ATTRIBUTE ) BucketName bucket ) {
357
+ assert bucketName .equals (bucket .getName ());
336
358
bucketService .verifyBucketExists (bucketName );
337
359
bucketService .verifyMaxKeys (maxKeys );
338
360
bucketService .verifyEncodingType (encodingType );
@@ -370,7 +392,9 @@ public ResponseEntity<ListBucketResultV2> listObjectsV2(
370
392
@ RequestParam (name = ENCODING_TYPE , required = false ) String encodingType ,
371
393
@ RequestParam (name = START_AFTER , required = false ) String startAfter ,
372
394
@ RequestParam (name = MAX_KEYS , defaultValue = "1000" , required = false ) Integer maxKeys ,
373
- @ RequestParam (name = CONTINUATION_TOKEN , required = false ) String continuationToken ) {
395
+ @ RequestParam (name = CONTINUATION_TOKEN , required = false ) String continuationToken ,
396
+ @ RequestAttribute (BUCKET_ATTRIBUTE ) BucketName bucket ) {
397
+ assert bucketName .equals (bucket .getName ());
374
398
bucketService .verifyBucketExists (bucketName );
375
399
bucketService .verifyMaxKeys (maxKeys );
376
400
bucketService .verifyEncodingType (encodingType );
0 commit comments