get object policy
This commit is contained in:
parent
ec78f304ee
commit
1b1dc39482
6 changed files with 52 additions and 21 deletions
|
@ -63,10 +63,23 @@ public class ObjectPolicy extends AppCompatActivity {
|
|||
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");
|
||||
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;
|
||||
} else {
|
||||
String[] path = filename.split("/");
|
||||
String filepath = "";
|
||||
for (int i = 0; i < path.length-1; i++) {
|
||||
filepath = filepath+path[i]+"/";
|
||||
//System.out.println(filepath);
|
||||
if(policy.contains("\"arn:aws:s3:::"+bucket+"/"+filepath+"*\"") || policy.contains("\"arn:aws:s3:::"+bucket+"/"+filepath+"**\"")) {
|
||||
publicobject = true;
|
||||
i = path.length;
|
||||
}
|
||||
System.out.println(policy);
|
||||
}
|
||||
}
|
||||
}
|
||||
//System.out.println(policy);
|
||||
|
||||
runOnUiThread(new Runnable() {
|
||||
|
||||
|
@ -75,13 +88,14 @@ public class ObjectPolicy extends AppCompatActivity {
|
|||
//Your code goes here
|
||||
if(publicbucket){
|
||||
permission.setText(getResources().getString(R.string.public_bucket));
|
||||
setprivate.setVisibility(View.VISIBLE);
|
||||
}else if(publicobject) {
|
||||
permission.setText(getResources().getString(R.string.public_object));
|
||||
setprivate.setVisibility(View.VISIBLE);
|
||||
}else {
|
||||
permission.setText(getResources().getString(R.string.custom_policy));
|
||||
permission.setText(getResources().getString(R.string.private_object));
|
||||
setpublic.setVisibility(View.VISIBLE);
|
||||
}
|
||||
setprivate.setVisibility(View.VISIBLE);
|
||||
simpleProgressBar.setVisibility(View.INVISIBLE);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -36,7 +36,7 @@ import java.util.List;
|
|||
|
||||
public class Share extends AppCompatActivity {
|
||||
String username, password, endpoint, bucket, object, location, title, objectlist;
|
||||
boolean mediafile, style, publicbucket;
|
||||
boolean mediafile, style, publicobject;
|
||||
TextView expirationtext;
|
||||
ProgressBar simpleProgressBar;
|
||||
Region region;
|
||||
|
@ -127,6 +127,25 @@ public class Share extends AppCompatActivity {
|
|||
try {
|
||||
//Your code goes here
|
||||
String policy = s3client.getBucketPolicy(bucket).getPolicyText();
|
||||
publicobject = false;
|
||||
if(policy.contains("arn:aws:s3:::"+bucket+"/*") && policy.contains("s3:GetObject")) {
|
||||
publicobject = true;
|
||||
} else if(policy.contains("s3:GetObject")) {
|
||||
if((policy.contains("\"arn:aws:s3:::"+bucket+"/"+object+"\"") || policy.contains("\"arn:aws:s3:::"+bucket+"/"+object+"*\"") || policy.contains("\"arn:aws:s3:::"+bucket+"/"+object+"**\"")) && policy.contains("s3:GetObject")) {
|
||||
publicobject = true;
|
||||
} else {
|
||||
String[] path = object.split("/");
|
||||
String filepath = "";
|
||||
for (int i = 0; i < path.length-1; i++) {
|
||||
filepath = filepath+path[i]+"/";
|
||||
//System.out.println(filepath);
|
||||
if(policy.contains("\"arn:aws:s3:::"+bucket+"/"+filepath+"*\"") || policy.contains("\"arn:aws:s3:::"+bucket+"/"+filepath+"**\"")) {
|
||||
publicobject = true;
|
||||
i = path.length;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//System.out.println(policy);
|
||||
|
||||
runOnUiThread(new Runnable() {
|
||||
|
@ -134,12 +153,10 @@ public class Share extends AppCompatActivity {
|
|||
@Override
|
||||
public void run() {
|
||||
//Your code goes here
|
||||
if(policy.contains("arn:aws:s3:::"+bucket+"/*") && policy.contains("s3:GetObject")){
|
||||
publicbucket = true;
|
||||
if(publicobject){
|
||||
expirationtext.setText(getResources().getString(R.string.expiration_not_required));
|
||||
|
||||
} else {
|
||||
publicbucket = false;
|
||||
datepick.setEnabled(true);
|
||||
hourpick.setEnabled(true);
|
||||
minutepick.setEnabled(true);
|
||||
|
@ -162,7 +179,7 @@ public class Share extends AppCompatActivity {
|
|||
|
||||
@Override
|
||||
public void run() {
|
||||
publicbucket = false;
|
||||
publicobject = false;
|
||||
datepick.setEnabled(true);
|
||||
hourpick.setEnabled(true);
|
||||
minutepick.setEnabled(true);
|
||||
|
@ -354,7 +371,7 @@ public class Share extends AppCompatActivity {
|
|||
objectlist = "";
|
||||
List<S3ObjectSummary> objects = result.getObjectSummaries();
|
||||
for (S3ObjectSummary os : objects) {
|
||||
if(publicbucket) {
|
||||
if(publicobject) {
|
||||
objectlist = objectlist+s3client.getUrl(bucket, os.getKey()).toString()+"\n";
|
||||
} else {
|
||||
request = new GeneratePresignedUrlRequest(bucket, os.getKey()).withExpiration(expiration);
|
||||
|
@ -365,7 +382,7 @@ public class Share extends AppCompatActivity {
|
|||
result = s3client.listNextBatchOfObjects (result);
|
||||
objects = result.getObjectSummaries();
|
||||
for (S3ObjectSummary os : objects) {
|
||||
if(publicbucket) {
|
||||
if(publicobject) {
|
||||
objectlist = objectlist+s3client.getUrl(bucket, os.getKey()).toString()+"\n";
|
||||
} else {
|
||||
request = new GeneratePresignedUrlRequest(bucket, os.getKey()).withExpiration(expiration);
|
||||
|
@ -377,7 +394,7 @@ public class Share extends AppCompatActivity {
|
|||
}
|
||||
|
||||
private void sharefile() {
|
||||
if(publicbucket) {
|
||||
if(publicobject) {
|
||||
objectURL = s3client.getUrl(bucket, object);
|
||||
} else {
|
||||
if (datepick.getText().toString().equals("")) {
|
||||
|
|
|
@ -27,14 +27,14 @@
|
|||
android:id="@+id/set_public"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="70dp"
|
||||
android:text="@string/set_public_bucket"
|
||||
android:text="@string/set_public"
|
||||
android:visibility="gone" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/set_private"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="70dp"
|
||||
android:text="@string/set_private_bucket"
|
||||
android:text="@string/set_private"
|
||||
android:visibility="gone" />
|
||||
|
||||
</LinearLayout>
|
||||
|
|
|
@ -28,14 +28,14 @@
|
|||
android:id="@+id/set_public"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="70dp"
|
||||
android:text="@string/set_public_bucket"
|
||||
android:text="@string/set_public"
|
||||
android:visibility="gone" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/set_private"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="70dp"
|
||||
android:text="@string/set_private_bucket"
|
||||
android:text="@string/set_private"
|
||||
android:visibility="gone" />
|
||||
|
||||
</LinearLayout>
|
||||
|
|
|
@ -121,7 +121,7 @@
|
|||
<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>
|
||||
<string name="set_public">Establecer como público</string>
|
||||
<string name="set_private">Establecer como privado</string>
|
||||
<string name="expiration_not_required">Fecha de expiración no requerida</string>
|
||||
</resources>
|
|
@ -125,7 +125,7 @@
|
|||
<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>
|
||||
<string name="set_public">Set as public</string>
|
||||
<string name="set_private">Set as private</string>
|
||||
<string name="expiration_not_required">Expiration date not required</string>
|
||||
</resources>
|
Loading…
Add table
Add a link
Reference in a new issue