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 ;
31
32
import static org .springframework .http .MediaType .APPLICATION_XML_VALUE ;
32
33
33
34
import com .adobe .testing .s3mock .dto .BucketLifecycleConfiguration ;
35
+ import com .adobe .testing .s3mock .dto .BucketName ;
34
36
import com .adobe .testing .s3mock .dto .ListAllMyBucketsResult ;
35
37
import com .adobe .testing .s3mock .dto .ListBucketResult ;
36
38
import com .adobe .testing .s3mock .dto .ListBucketResultV2 ;
39
41
import org .springframework .http .ResponseEntity ;
40
42
import org .springframework .web .bind .annotation .CrossOrigin ;
41
43
import org .springframework .web .bind .annotation .PathVariable ;
44
+ import org .springframework .web .bind .annotation .RequestAttribute ;
42
45
import org .springframework .web .bind .annotation .RequestBody ;
43
46
import org .springframework .web .bind .annotation .RequestHeader ;
44
47
import org .springframework .web .bind .annotation .RequestMapping ;
@@ -105,7 +108,10 @@ public ResponseEntity<ListAllMyBucketsResult> listBuckets() {
105
108
)
106
109
public ResponseEntity <Void > createBucket (@ PathVariable final String bucketName ,
107
110
@ RequestHeader (value = X_AMZ_BUCKET_OBJECT_LOCK_ENABLED ,
108
- required = false , defaultValue = "false" ) boolean objectLockEnabled ) {
111
+ required = false , defaultValue = "false" ) boolean objectLockEnabled ,
112
+ @ RequestAttribute (BUCKET_ATTRIBUTE ) BucketName bucket ) {
113
+ //TODO: does subdomain access work for #createBucket in S3?
114
+ assert bucketName .equals (bucket .getName ());
109
115
bucketService .verifyBucketNameIsAllowed (bucketName );
110
116
bucketService .verifyBucketDoesNotExist (bucketName );
111
117
bucketService .createBucket (bucketName , objectLockEnabled );
@@ -124,7 +130,9 @@ public ResponseEntity<Void> createBucket(@PathVariable final String bucketName,
124
130
value = "/{bucketName:[a-z0-9.-]+}" ,
125
131
method = RequestMethod .HEAD
126
132
)
127
- public ResponseEntity <Void > headBucket (@ PathVariable final String bucketName ) {
133
+ public ResponseEntity <Void > headBucket (@ PathVariable final String bucketName ,
134
+ @ RequestAttribute (BUCKET_ATTRIBUTE ) BucketName bucket ) {
135
+ assert bucketName .equals (bucket .getName ());
128
136
bucketService .verifyBucketExists (bucketName );
129
137
return ResponseEntity .ok ().build ();
130
138
}
@@ -144,7 +152,9 @@ public ResponseEntity<Void> headBucket(@PathVariable final String bucketName) {
144
152
},
145
153
method = RequestMethod .DELETE
146
154
)
147
- public ResponseEntity <Void > deleteBucket (@ PathVariable String bucketName ) {
155
+ public ResponseEntity <Void > deleteBucket (@ PathVariable String bucketName ,
156
+ @ RequestAttribute (BUCKET_ATTRIBUTE ) BucketName bucket ) {
157
+ assert bucketName .equals (bucket .getName ());
148
158
bucketService .verifyBucketExists (bucketName );
149
159
bucketService .verifyBucketIsEmpty (bucketName );
150
160
bucketService .deleteBucket (bucketName );
@@ -171,7 +181,9 @@ public ResponseEntity<Void> deleteBucket(@PathVariable String bucketName) {
171
181
}
172
182
)
173
183
public ResponseEntity <ObjectLockConfiguration > getObjectLockConfiguration (
174
- @ PathVariable String bucketName ) {
184
+ @ PathVariable String bucketName ,
185
+ @ RequestAttribute (BUCKET_ATTRIBUTE ) BucketName bucket ) {
186
+ assert bucketName .equals (bucket .getName ());
175
187
bucketService .verifyBucketExists (bucketName );
176
188
ObjectLockConfiguration configuration = bucketService .getObjectLockConfiguration (bucketName );
177
189
return ResponseEntity .ok (configuration );
@@ -195,7 +207,9 @@ public ResponseEntity<ObjectLockConfiguration> getObjectLockConfiguration(
195
207
)
196
208
public ResponseEntity <Void > putObjectLockConfiguration (
197
209
@ PathVariable String bucketName ,
198
- @ RequestBody ObjectLockConfiguration configuration ) {
210
+ @ RequestBody ObjectLockConfiguration configuration ,
211
+ @ RequestAttribute (BUCKET_ATTRIBUTE ) BucketName bucket ) {
212
+ assert bucketName .equals (bucket .getName ());
199
213
bucketService .verifyBucketExists (bucketName );
200
214
bucketService .setObjectLockConfiguration (bucketName , configuration );
201
215
return ResponseEntity .ok ().build ();
@@ -221,7 +235,9 @@ public ResponseEntity<Void> putObjectLockConfiguration(
221
235
}
222
236
)
223
237
public ResponseEntity <BucketLifecycleConfiguration > getBucketLifecycleConfiguration (
224
- @ PathVariable String bucketName ) {
238
+ @ PathVariable String bucketName ,
239
+ @ RequestAttribute (BUCKET_ATTRIBUTE ) BucketName bucket ) {
240
+ assert bucketName .equals (bucket .getName ());
225
241
bucketService .verifyBucketExists (bucketName );
226
242
BucketLifecycleConfiguration configuration =
227
243
bucketService .getBucketLifecycleConfiguration (bucketName );
@@ -246,7 +262,9 @@ public ResponseEntity<BucketLifecycleConfiguration> getBucketLifecycleConfigurat
246
262
)
247
263
public ResponseEntity <Void > putBucketLifecycleConfiguration (
248
264
@ PathVariable String bucketName ,
249
- @ RequestBody BucketLifecycleConfiguration configuration ) {
265
+ @ RequestBody BucketLifecycleConfiguration configuration ,
266
+ @ RequestAttribute (BUCKET_ATTRIBUTE ) BucketName bucket ) {
267
+ assert bucketName .equals (bucket .getName ());
250
268
bucketService .verifyBucketExists (bucketName );
251
269
bucketService .setBucketLifecycleConfiguration (bucketName , configuration );
252
270
return ResponseEntity .ok ().build ();
@@ -268,7 +286,9 @@ public ResponseEntity<Void> putBucketLifecycleConfiguration(
268
286
method = RequestMethod .DELETE
269
287
)
270
288
public ResponseEntity <Void > deleteBucketLifecycleConfiguration (
271
- @ PathVariable String bucketName ) {
289
+ @ PathVariable String bucketName ,
290
+ @ RequestAttribute (BUCKET_ATTRIBUTE ) BucketName bucket ) {
291
+ assert bucketName .equals (bucket .getName ());
272
292
bucketService .verifyBucketExists (bucketName );
273
293
bucketService .deleteBucketLifecycleConfiguration (bucketName );
274
294
return ResponseEntity .noContent ().build ();
@@ -305,7 +325,9 @@ public ResponseEntity<ListBucketResult> listObjects(
305
325
@ RequestParam (required = false ) String delimiter ,
306
326
@ RequestParam (required = false ) String marker ,
307
327
@ RequestParam (name = ENCODING_TYPE , required = false ) String encodingType ,
308
- @ RequestParam (name = MAX_KEYS , defaultValue = "1000" , required = false ) Integer maxKeys ) {
328
+ @ RequestParam (name = MAX_KEYS , defaultValue = "1000" , required = false ) Integer maxKeys ,
329
+ @ RequestAttribute (BUCKET_ATTRIBUTE ) BucketName bucket ) {
330
+ assert bucketName .equals (bucket .getName ());
309
331
bucketService .verifyBucketExists (bucketName );
310
332
bucketService .verifyMaxKeys (maxKeys );
311
333
bucketService .verifyEncodingType (encodingType );
@@ -343,7 +365,9 @@ public ResponseEntity<ListBucketResultV2> listObjectsV2(
343
365
@ RequestParam (name = ENCODING_TYPE , required = false ) String encodingType ,
344
366
@ RequestParam (name = START_AFTER , required = false ) String startAfter ,
345
367
@ RequestParam (name = MAX_KEYS , defaultValue = "1000" , required = false ) Integer maxKeys ,
346
- @ RequestParam (name = CONTINUATION_TOKEN , required = false ) String continuationToken ) {
368
+ @ RequestParam (name = CONTINUATION_TOKEN , required = false ) String continuationToken ,
369
+ @ RequestAttribute (BUCKET_ATTRIBUTE ) BucketName bucket ) {
370
+ assert bucketName .equals (bucket .getName ());
347
371
bucketService .verifyBucketExists (bucketName );
348
372
bucketService .verifyMaxKeys (maxKeys );
349
373
bucketService .verifyEncodingType (encodingType );
0 commit comments