object policy
This commit is contained in:
parent
8a3a2d62db
commit
ec78f304ee
5 changed files with 64 additions and 4 deletions
|
@ -22,7 +22,7 @@ public class BucketPolicy extends AppCompatActivity {
|
|||
S3ClientOptions s3ClientOptions;
|
||||
AWSCredentials myCredentials;
|
||||
AmazonS3 s3client;
|
||||
boolean style;
|
||||
boolean style, publicbucket;
|
||||
ProgressBar simpleProgressBar;
|
||||
TextView permission;
|
||||
Button setpublic, setprivate;
|
||||
|
@ -60,6 +60,7 @@ public class BucketPolicy extends AppCompatActivity {
|
|||
try {
|
||||
//Your code goes here
|
||||
String policy = s3client.getBucketPolicy(bucket).getPolicyText();
|
||||
publicbucket = policy.contains("arn:aws:s3:::"+bucket+"/*") && policy.contains("s3:GetObject");
|
||||
//System.out.println(policy);
|
||||
|
||||
runOnUiThread(new Runnable() {
|
||||
|
@ -67,7 +68,7 @@ public class BucketPolicy extends AppCompatActivity {
|
|||
@Override
|
||||
public void run() {
|
||||
//Your code goes here
|
||||
if(policy.contains("\"Resource\":[\"arn:aws:s3:::"+bucket+"/*") || policy.contains("\"Resource\":\"arn:aws:s3:::"+bucket+"/*")){
|
||||
if(publicbucket){
|
||||
permission.setText(getResources().getString(R.string.public_bucket));
|
||||
} else {
|
||||
permission.setText(getResources().getString(R.string.custom_policy));
|
||||
|
|
|
@ -2,6 +2,7 @@ package asgardius.page.s3manager;
|
|||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
|
@ -20,7 +21,7 @@ public class ObjectPolicy extends AppCompatActivity {
|
|||
S3ClientOptions s3ClientOptions;
|
||||
AWSCredentials myCredentials;
|
||||
AmazonS3 s3client;
|
||||
boolean style;
|
||||
boolean style, publicbucket, publicobject;
|
||||
ProgressBar simpleProgressBar;
|
||||
TextView permission;
|
||||
Button setpublic, setprivate;
|
||||
|
@ -53,5 +54,59 @@ public class ObjectPolicy extends AppCompatActivity {
|
|||
s3client.setS3ClientOptions(s3ClientOptions);
|
||||
setprivate = (Button)findViewById(R.id.set_private);
|
||||
setpublic = (Button)findViewById(R.id.set_public);
|
||||
Thread getPolicy = new Thread(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
//Your code goes here
|
||||
String policy = s3client.getBucketPolicy(bucket).getPolicyText();
|
||||
publicbucket = policy.contains("arn:aws:s3:::"+bucket+"/*") && policy.contains("s3:GetObject");
|
||||
publicobject = false;
|
||||
if(!publicbucket) {
|
||||
publicobject = (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");
|
||||
}
|
||||
System.out.println(policy);
|
||||
|
||||
runOnUiThread(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
//Your code goes here
|
||||
if(publicbucket){
|
||||
permission.setText(getResources().getString(R.string.public_bucket));
|
||||
}else if(publicobject) {
|
||||
permission.setText(getResources().getString(R.string.public_object));
|
||||
}else {
|
||||
permission.setText(getResources().getString(R.string.custom_policy));
|
||||
setpublic.setVisibility(View.VISIBLE);
|
||||
}
|
||||
setprivate.setVisibility(View.VISIBLE);
|
||||
simpleProgressBar.setVisibility(View.INVISIBLE);
|
||||
}
|
||||
});
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
runOnUiThread(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if(e.toString().contains("NoSuchBucketPolicy")) {
|
||||
permission.setText(getResources().getString(R.string.private_bucket));
|
||||
setpublic.setVisibility(View.VISIBLE);
|
||||
simpleProgressBar.setVisibility(View.INVISIBLE);
|
||||
}
|
||||
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();
|
||||
}
|
||||
}
|
||||
});
|
||||
getPolicy.start();
|
||||
}
|
||||
}
|
|
@ -134,7 +134,7 @@ public class Share extends AppCompatActivity {
|
|||
@Override
|
||||
public void run() {
|
||||
//Your code goes here
|
||||
if(policy.contains("\"Resource\":[\"arn:aws:s3:::"+bucket+"/*") || policy.contains("\"Resource\":\"arn:aws:s3:::"+bucket+"/*")){
|
||||
if(policy.contains("arn:aws:s3:::"+bucket+"/*") && policy.contains("s3:GetObject")){
|
||||
publicbucket = true;
|
||||
expirationtext.setText(getResources().getString(R.string.expiration_not_required));
|
||||
|
||||
|
|
|
@ -118,6 +118,8 @@
|
|||
<string name="bucket_policy">Permisos de acceso</string>
|
||||
<string name="public_bucket">Bucket público</string>
|
||||
<string name="private_bucket">Bucket privado</string>
|
||||
<string name="public_object">Objeto público</string>
|
||||
<string name="private_object">Objeto privado</string>
|
||||
<string name="custom_policy">Política personalizada</string>
|
||||
<string name="set_public_bucket">Establecer bucket como público</string>
|
||||
<string name="set_private_bucket">Establecer bucket como privado</string>
|
||||
|
|
|
@ -122,6 +122,8 @@
|
|||
<string name="bucket_policy">Access permissions</string>
|
||||
<string name="public_bucket">Public bucket</string>
|
||||
<string name="private_bucket">Private bucket</string>
|
||||
<string name="public_object">Public object</string>
|
||||
<string name="private_object">Private object</string>
|
||||
<string name="custom_policy">Custom policy</string>
|
||||
<string name="set_public_bucket">Set bucket as public</string>
|
||||
<string name="set_private_bucket">Set bucket as private</string>
|
||||
|
|
Loading…
Reference in a new issue