Unsolved

This post is more than 5 years old

1048

June 6th, 2020 02:00

How to delete bucket policy using Java SDK ecs-object-client-java

Hello,

I am creating Bucket policies in my application using following java code snippet:

(I am using EMC Java SDK ecs-object-client-java)

>>>

List < BucketPolicyStatement > stmts = new ArrayList <>();
 
stmts . add ( new BucketPolicyStatement ()
. withSid ( "Grant permission to " + userId + " for objects" )
. withEffect ( Effect . Allow )
. withPrincipal ( userId )
. withResource ( bucketName + "/*" )
. withActions ( BucketPolicyAction . GetObject ,
BucketPolicyAction . GetObjectVersion ,
BucketPolicyAction . GetObjectAcl ,
BucketPolicyAction . GetObjectVersionAcl
)
);
stmts . add ( new BucketPolicyStatement ()
. withSid ( "Grant permission to " + userId + " for bucket" )
. withEffect ( Effect . Allow )
. withPrincipal ( userId )
. withResource ( bucketName )
. withActions ( BucketPolicyAction . ListBucket ,
BucketPolicyAction . ListBucketVersions ,
BucketPolicyAction . GetLifecycleConfiguration ,
BucketPolicyAction . GetBucketAcl ,
BucketPolicyAction . GetBucketVersioning ,
BucketPolicyAction . GetBucketPolicy
)
);
 
BucketPolicy bucketPolicy = new BucketPolicy ()
. withVersion ( "2012-10-17" )
. withId ( "new-policy-1" )
. withStatements ( stmts );
 
s3Client . setBucketPolicy ( bucketName , bucketPolicy );

<<<

Everything is working fine. But my question is how do I DELETE (remove) the Bucket policy programatically once it is set as above.

Any help / pointer would be highly appreciated. 

Thanks

Moderator

 • 

7.9K Posts

 • 

135 Points

June 8th, 2020 11:00

Hello UdayBidikar,

Here is a link to a KB that maybe of assistance.  You will need to login with your EMC account. https://dell.to/3f0I57h

Please let us know if you have any other questions.

June 12th, 2020 01:00

Hello Dell-Sam L,

Thank you for the quick response, but my question was about deleting the Bucket policy using S3 object client interface. Anyway mean while I figured out how to do it. I extended the ""S3JerseyClient" object in ecs-object-client-java SDK as follows. It works just fine now:

public class ECSs3Client extends S3JerseyClient {

public ECSs3Client ( S3Config s3Config ) {
super ( s3Config );
}
 
public void deleteBucketPolicy ( String bucketName ) {

try {
executeAndClose ( client , new GenericBucketRequest ( Method . DELETE , bucketName , "policy" ));
return ;
} catch ( S3Exception e ) {
switch ( e . getHttpCode ()) {
case RestUtil . STATUS_REDIRECT :
return ;
// case RestUtil.STATUS_UNAUTHORIZED:
// return;
// case RestUtil.STATUS_NOT_FOUND:
// return;
default:
throw e ;
}
}
}

}

 

No Events found!

Top