From 16fca27422ab118391fb1784776945aaa61773e3 Mon Sep 17 00:00:00 2001 From: Page Asgardius Date: Sun, 22 Jan 2023 05:36:20 -0700 Subject: [PATCH] check permissions --- .../page/s3manager/BucketPolicy.java | 29 ++++++++--- .../page/s3manager/BucketSelect.java | 2 +- .../res/layout/activity_bucket_policy.xml | 51 +++++++++++++++++++ app/src/main/res/menu/bucket_menu.xml | 2 +- app/src/main/res/values-es/strings.xml | 5 +- app/src/main/res/values/strings.xml | 5 +- 6 files changed, 84 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/asgardius/page/s3manager/BucketPolicy.java b/app/src/main/java/asgardius/page/s3manager/BucketPolicy.java index 3e1d18c..b6bca02 100644 --- a/app/src/main/java/asgardius/page/s3manager/BucketPolicy.java +++ b/app/src/main/java/asgardius/page/s3manager/BucketPolicy.java @@ -1,6 +1,9 @@ package asgardius.page.s3manager; import android.os.Bundle; +import android.view.View; +import android.widget.ProgressBar; +import android.widget.TextView; import android.widget.Toast; import androidx.appcompat.app.AppCompatActivity; @@ -19,11 +22,15 @@ public class BucketPolicy extends AppCompatActivity { AWSCredentials myCredentials; AmazonS3 s3client; boolean style; + ProgressBar simpleProgressBar; + TextView permission; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_bucket_policy); + simpleProgressBar = (ProgressBar) findViewById(R.id.simpleProgressBar); + permission = (TextView) findViewById(R.id.permission); endpoint = getIntent().getStringExtra("endpoint"); title = getIntent().getStringExtra("title"); username = getIntent().getStringExtra("username"); @@ -42,7 +49,7 @@ public class BucketPolicy extends AppCompatActivity { s3client.setEndpoint(endpoint); s3ClientOptions.setPathStyleAccess(style); s3client.setS3ClientOptions(s3ClientOptions); - Thread getAcl = new Thread(new Runnable() { + Thread getPolicy = new Thread(new Runnable() { @Override public void run() { @@ -56,6 +63,12 @@ public class BucketPolicy extends AppCompatActivity { @Override public void run() { //Your code goes here + if(policy.contains("\"Resource\":[\"arn:aws:s3:::"+bucket+"/*")){ + permission.setText(getResources().getString(R.string.public_bucket)); + } else { + permission.setText(getResources().getString(R.string.custom_policy)); + } + simpleProgressBar.setVisibility(View.INVISIBLE); } }); @@ -65,16 +78,20 @@ public class BucketPolicy extends AppCompatActivity { @Override public void run() { - Toast.makeText(getApplicationContext(),e.toString(), Toast.LENGTH_SHORT).show(); + if(e.toString().contains("NoSuchBucketPolicy")) { + simpleProgressBar.setVisibility(View.INVISIBLE); + permission.setText(getResources().getString(R.string.private_bucket)); + } + else { + Toast.makeText(getApplicationContext(),e.toString(), Toast.LENGTH_SHORT).show(); + finish(); + } } }); //Toast.makeText(getApplicationContext(),getResources().getString(R.string.media_list_fail), Toast.LENGTH_SHORT).show(); - if(!e.toString().contains("NoSuchBucketPolicy")) { - finish(); - } } } }); - getAcl.start(); + getPolicy.start(); } } \ No newline at end of file diff --git a/app/src/main/java/asgardius/page/s3manager/BucketSelect.java b/app/src/main/java/asgardius/page/s3manager/BucketSelect.java index f03cd44..cb1e3e7 100644 --- a/app/src/main/java/asgardius/page/s3manager/BucketSelect.java +++ b/app/src/main/java/asgardius/page/s3manager/BucketSelect.java @@ -189,7 +189,7 @@ public class BucketSelect extends AppCompatActivity { copyName(Name.get(position).toString()); } else if (menuItem.getTitle() == getResources().getString(R.string.cors_config)) { corsConfig(Name.get(position).toString()); - } else if (menuItem.getTitle() == getResources().getString(R.string.acl)) { + } else if (menuItem.getTitle() == getResources().getString(R.string.bucket_policy)) { aclConfig(Name.get(position).toString()); } else if (menuItem.getTitle() == getResources().getString(R.string.file_del)) { //Toast.makeText(BucketSelect.this, getResources().getString(R.string.pending_feature), Toast.LENGTH_SHORT).show(); diff --git a/app/src/main/res/layout/activity_bucket_policy.xml b/app/src/main/res/layout/activity_bucket_policy.xml index fd2879f..79188a6 100644 --- a/app/src/main/res/layout/activity_bucket_policy.xml +++ b/app/src/main/res/layout/activity_bucket_policy.xml @@ -6,4 +6,55 @@ android:layout_height="match_parent" tools:context=".BucketPolicy"> + + + + + + +