check permissions

This commit is contained in:
Page Asgardius 2023-01-22 05:36:20 -07:00
parent 960707d4e0
commit 16fca27422
6 changed files with 84 additions and 10 deletions

View file

@ -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();
}
}

View file

@ -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();

View file

@ -6,4 +6,55 @@
android:layout_height="match_parent"
tools:context=".BucketPolicy">
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:ignore="MissingConstraints">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/permission"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAlignment="center"
android:textSize="25sp"/>
<Button
android:id="@+id/allow_all"
android:layout_width="match_parent"
android:layout_height="70dp"
android:text="@string/allow_all"
android:visibility="gone" />
<Button
android:id="@+id/allow_pdf"
android:layout_width="match_parent"
android:layout_height="70dp"
android:text="@string/allow_pdf"
android:visibility="gone" />
<Button
android:id="@+id/delete_cors"
android:layout_width="match_parent"
android:layout_height="70dp"
android:text="@string/delete_cors"
android:visibility="gone" />
</LinearLayout>
</androidx.core.widget.NestedScrollView>
<ProgressBar
android:id="@+id/simpleProgressBar"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:max="100"
android:progress="50"
android:padding="20dp"
tools:ignore="MissingConstraints"
android:indeterminate="true" />
</androidx.constraintlayout.widget.ConstraintLayout>

View file

@ -35,7 +35,7 @@
<item
android:id="@+id/acl_config"
android:title="@string/acl" />
android:title="@string/bucket_policy" />
<item
android:id="@+id/deletefolder"

View file

@ -115,5 +115,8 @@
<string name="save_links">Guardar enlaces en archivo</string>
<string name="copy_links">Copiar enlaces al potapapeles</string>
<string name="save_ok">Archivo guardado exitosamente</string>
<string name="acl">Permisos de acceso</string>
<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="custom_policy">Política personalizada</string>
</resources>

View file

@ -119,5 +119,8 @@
<string name="save_links">Save links to file</string>
<string name="save_ok">File saved successfully</string>
<string name="copy_links">Copy links to clipboard</string>
<string name="acl">Access permissions</string>
<string name="bucket_policy">Access permissions</string>
<string name="public_bucket">Public bucket</string>
<string name="private_bucket">Private bucket</string>
<string name="custom_policy">Private bucket</string>
</resources>