diff --git a/README.md b/README.md
index 1859c07..91154af 100644
--- a/README.md
+++ b/README.md
@@ -26,6 +26,7 @@ Current feature list
* get bucket info
* Set CORS policy
* Set bucket as public or private
+* Set object as public or private
Planned feature list
diff --git a/app/build.gradle b/app/build.gradle
index dc2a7e3..e7fb96c 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -9,8 +9,8 @@ android {
applicationId "asgardius.page.s3manager"
minSdk 23
targetSdk 33
- versionCode 72
- versionName "0.8.1"
+ versionCode 73
+ versionName "0.8.2"
setProperty("archivesBaseName", "s3-manager-$versionName")
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
diff --git a/app/src/main/java/asgardius/page/s3manager/ObjectPolicy.java b/app/src/main/java/asgardius/page/s3manager/ObjectPolicy.java
index 283cb36..a97c947 100644
--- a/app/src/main/java/asgardius/page/s3manager/ObjectPolicy.java
+++ b/app/src/main/java/asgardius/page/s3manager/ObjectPolicy.java
@@ -21,7 +21,7 @@ public class ObjectPolicy extends AppCompatActivity {
S3ClientOptions s3ClientOptions;
AWSCredentials myCredentials;
AmazonS3 s3client;
- boolean style, publicbucket, publicobject;
+ boolean style, publicbucket, publicobject, parent;
ProgressBar simpleProgressBar;
TextView permission;
Button setpublic, setprivate;
@@ -63,9 +63,11 @@ public class ObjectPolicy extends AppCompatActivity {
policy = s3client.getBucketPolicy(bucket).getPolicyText();
publicbucket = policy.contains("arn:aws:s3:::"+bucket+"/*") && policy.contains("s3:GetObject");
publicobject = false;
+ parent = true;
if(!publicbucket && policy.contains("s3:GetObject")) {
if((policy.contains("\"arn:aws:s3:::"+bucket+"/"+filename+"\"") || policy.contains("\"arn:aws:s3:::"+bucket+"/"+filename+"*\"") || policy.contains("\"arn:aws:s3:::"+bucket+"/"+filename+"**\"")) && policy.contains("s3:GetObject")) {
publicobject = true;
+ parent = false;
} else {
String[] path = filename.split("/");
String filepath = "";
@@ -88,10 +90,16 @@ public class ObjectPolicy extends AppCompatActivity {
//Your code goes here
if(publicbucket){
permission.setText(getResources().getString(R.string.public_object));
- //setprivate.setVisibility(View.VISIBLE);
+ setprivate.setEnabled(false);
+ setprivate.setText(getResources().getString(R.string.parent_policy));
+ setprivate.setVisibility(View.VISIBLE);
}else if(publicobject) {
permission.setText(getResources().getString(R.string.public_object));
- //setprivate.setVisibility(View.VISIBLE);
+ if(parent) {
+ setprivate.setEnabled(false);
+ setprivate.setText(getResources().getString(R.string.parent_policy));
+ }
+ setprivate.setVisibility(View.VISIBLE);
}else {
permission.setText(getResources().getString(R.string.private_object));
setpublic.setVisibility(View.VISIBLE);
@@ -130,6 +138,14 @@ public class ObjectPolicy extends AppCompatActivity {
setPublic();
}
});
+ setprivate.setOnClickListener(new View.OnClickListener(){
+ @Override
+ public void onClick(View view) {
+ //buttonaction
+ simpleProgressBar.setVisibility(View.VISIBLE);
+ setPrivate();
+ }
+ });
}
private void setPublic() {
@@ -185,4 +201,60 @@ public class ObjectPolicy extends AppCompatActivity {
});
setPublic.start();
}
+
+ private void setPrivate() {
+ Thread setPrivate = new Thread(new Runnable() {
+
+ @Override
+ public void run() {
+ try {
+ //Your code goes here
+ String newpolicy = null;
+ if(policy.contains(",\"arn:aws:s3:::"+bucket+"/"+filename+"*\"")) {
+ newpolicy = policy.replace(",\"arn:aws:s3:::"+bucket+"/"+filename+"*\"", "");
+ s3client.setBucketPolicy(bucket, newpolicy);
+ } else if(policy.contains(",\"arn:aws:s3:::"+bucket+"/"+filename+"**\"")) {
+ newpolicy = policy.replace(",\"arn:aws:s3:::"+bucket+"/"+filename+"**\"", "");
+ s3client.setBucketPolicy(bucket, newpolicy);
+ } else if(policy.contains(",\"arn:aws:s3:::"+bucket+"/"+filename+"\"")) {
+ newpolicy = policy.replace(",\"arn:aws:s3:::"+bucket+"/"+filename+"\"", "");
+ s3client.setBucketPolicy(bucket, newpolicy);
+ } else if(policy.contains("\"arn:aws:s3:::"+bucket+"/"+filename+"*\",")) {
+ newpolicy = policy.replace("\"arn:aws:s3:::"+bucket+"/"+filename+"*\",", "");
+ s3client.setBucketPolicy(bucket, newpolicy);
+ } else if(policy.contains("\"arn:aws:s3:::"+bucket+"/"+filename+"**\",")) {
+ newpolicy = policy.replace("\"arn:aws:s3:::"+bucket+"/"+filename+"**\",", "");
+ s3client.setBucketPolicy(bucket, newpolicy);
+ } else if(policy.contains("\"arn:aws:s3:::"+bucket+"/"+filename+"\",")) {
+ newpolicy = policy.replace("\"arn:aws:s3:::"+bucket+"/"+filename+"\",", "");
+ s3client.setBucketPolicy(bucket, newpolicy);
+ } else {
+ s3client.deleteBucketPolicy(bucket);
+ }
+
+ runOnUiThread(new Runnable() {
+
+ @Override
+ public void run() {
+ Toast.makeText(getApplicationContext(),getResources().getString(R.string.policy_ok), Toast.LENGTH_SHORT).show();
+ finish();
+ }
+ });
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ runOnUiThread(new Runnable() {
+
+ @Override
+ public void run() {
+ simpleProgressBar.setVisibility(View.INVISIBLE);
+ Toast.makeText(getApplicationContext(),getResources().getString(R.string.policy_error), Toast.LENGTH_SHORT).show();
+ }
+ });
+ //Toast.makeText(getApplicationContext(),getResources().getString(R.string.media_list_fail), Toast.LENGTH_SHORT).show();
+ }
+ }
+ });
+ setPrivate.start();
+ }
}
\ No newline at end of file
diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml
index d156e15..f7e41d0 100644
--- a/app/src/main/res/values-es/strings.xml
+++ b/app/src/main/res/values-es/strings.xml
@@ -123,5 +123,6 @@