This commit is contained in:
Page Asgardius 2022-12-26 11:04:33 -07:00
parent b2de50b544
commit 458b622139
6 changed files with 147 additions and 5 deletions

View file

@ -178,7 +178,7 @@ public class AccountAdd extends AppCompatActivity {
@Override @Override
public void run() { public void run() {
Toast.makeText(getApplicationContext(),getResources().getString(R.string.media_list_fail), Toast.LENGTH_SHORT).show(); Toast.makeText(getApplicationContext(),e.toString(), Toast.LENGTH_SHORT).show();
} }
}); });
} }

View file

@ -123,7 +123,7 @@ public class BucketSelect extends AppCompatActivity {
@Override @Override
public void run() { public void run() {
Toast.makeText(getApplicationContext(),getResources().getString(R.string.media_list_fail), Toast.LENGTH_SHORT).show(); Toast.makeText(getApplicationContext(),e.toString(), Toast.LENGTH_SHORT).show();
} }
}); });
//Toast.makeText(getApplicationContext(),getResources().getString(R.string.media_list_fail), Toast.LENGTH_SHORT).show(); //Toast.makeText(getApplicationContext(),getResources().getString(R.string.media_list_fail), Toast.LENGTH_SHORT).show();

View file

@ -22,6 +22,7 @@ import com.amazonaws.services.s3.model.S3ObjectSummary;
import java.net.URI; import java.net.URI;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.List; import java.util.List;
public class CorsConfig extends AppCompatActivity { public class CorsConfig extends AppCompatActivity {
@ -36,6 +37,7 @@ public class CorsConfig extends AppCompatActivity {
boolean allorigins, pdfcompatible, found = false; boolean allorigins, pdfcompatible, found = false;
TextView origins; TextView origins;
Button allowall, allowpdf, deletecors; Button allowall, allowpdf, deletecors;
BucketCrossOriginConfiguration corsconfig;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@ -81,8 +83,8 @@ public class CorsConfig extends AppCompatActivity {
if (!corsRules.isEmpty()) { if (!corsRules.isEmpty()) {
found = true; found = true;
for (CORSRule rule: corsRules) { for (CORSRule rule: corsRules) {
System.out.println("allowOrigins: "+rule.getAllowedOrigins()); //System.out.println("allowOrigins: "+rule.getAllowedOrigins());
System.out.println("AllowedMethod: "+rule.getAllowedMethods()); //System.out.println("AllowedMethod: "+rule.getAllowedMethods());
if (rule.getAllowedOrigins().toString().equals("[*]")) { if (rule.getAllowedOrigins().toString().equals("[*]")) {
allorigins = true; allorigins = true;
} else if (rule.getAllowedOrigins().toString().contains("https://"+pdfendpoint.getHost())) { } else if (rule.getAllowedOrigins().toString().contains("https://"+pdfendpoint.getHost())) {
@ -106,6 +108,7 @@ public class CorsConfig extends AppCompatActivity {
} else if (found) { } else if (found) {
origins.setText(getResources().getString(R.string.cors_npdf)); origins.setText(getResources().getString(R.string.cors_npdf));
deletecors.setVisibility(View.VISIBLE); deletecors.setVisibility(View.VISIBLE);
allowpdf.setVisibility(View.VISIBLE);
allowall.setVisibility(View.VISIBLE); allowall.setVisibility(View.VISIBLE);
} else { } else {
origins.setText(getResources().getString(R.string.cors_none)); origins.setText(getResources().getString(R.string.cors_none));
@ -130,5 +133,140 @@ public class CorsConfig extends AppCompatActivity {
} }
}); });
getCors.start(); getCors.start();
allowall.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View view) {
//buttonaction
setAllowall();
}
});
allowpdf.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View view) {
//buttonaction
setAllowpdf();
}
});
deletecors.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View view) {
//buttonaction
setDeletecors();
}
});
}
public void setAllowall() {
Thread addAll = new Thread(new Runnable() {
@Override
public void run() {
try {
//Your code goes here
List<CORSRule.AllowedMethods> allowMethods = new ArrayList<>();
allowMethods.add(CORSRule.AllowedMethods.GET);
List<String> allowOrigins = new ArrayList<>();
allowOrigins.add("*");
CORSRule corsRules = new CORSRule().withAllowedMethods(allowMethods).withAllowedOrigins(allowOrigins);
corsconfig = new BucketCrossOriginConfiguration().withRules(corsRules);
s3client.setBucketCrossOriginConfiguration(bucket, corsconfig);
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(getApplicationContext(),getResources().getString(R.string.cors_ok), Toast.LENGTH_SHORT).show();
finish();
}
});
} catch (Exception e) {
e.printStackTrace();
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(getApplicationContext(),getResources().getString(R.string.cors_error), Toast.LENGTH_SHORT).show();
}
});
//Toast.makeText(getApplicationContext(),getResources().getString(R.string.media_list_fail), Toast.LENGTH_SHORT).show();
}
}
});
addAll.start();
}
public void setAllowpdf() {
Thread addPdf = new Thread(new Runnable() {
@Override
public void run() {
try {
//Your code goes here
List<CORSRule.AllowedMethods> allowMethods = new ArrayList<>();
allowMethods.add(CORSRule.AllowedMethods.GET);
List<String> allowOrigins = new ArrayList<>();
allowOrigins.add("https://"+pdfendpoint.getHost());
CORSRule corsRules = new CORSRule().withAllowedMethods(allowMethods).withAllowedOrigins(allowOrigins);
corsconfig = new BucketCrossOriginConfiguration().withRules(corsRules);
s3client.setBucketCrossOriginConfiguration(bucket, corsconfig);
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(getApplicationContext(),getResources().getString(R.string.cors_ok), Toast.LENGTH_SHORT).show();
finish();
}
});
} catch (Exception e) {
e.printStackTrace();
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(getApplicationContext(),getResources().getString(R.string.cors_error), Toast.LENGTH_SHORT).show();
}
});
//Toast.makeText(getApplicationContext(),getResources().getString(R.string.media_list_fail), Toast.LENGTH_SHORT).show();
}
}
});
addPdf.start();
}
public void setDeletecors() {
Thread delCors = new Thread(new Runnable() {
@Override
public void run() {
try {
//Your code goes here
s3client.deleteBucketCrossOriginConfiguration(bucket);
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(getApplicationContext(),getResources().getString(R.string.cors_ok), Toast.LENGTH_SHORT).show();
finish();
}
});
} catch (Exception e) {
e.printStackTrace();
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(getApplicationContext(),getResources().getString(R.string.cors_error), Toast.LENGTH_SHORT).show();
}
});
//Toast.makeText(getApplicationContext(),getResources().getString(R.string.media_list_fail), Toast.LENGTH_SHORT).show();
}
}
});
delCors.start();
} }
} }

View file

@ -237,7 +237,7 @@ public class ObjectSelect extends AppCompatActivity {
@Override @Override
public void run() { public void run() {
Toast.makeText(getApplicationContext(),getResources().getString(R.string.media_list_fail), Toast.LENGTH_SHORT).show(); Toast.makeText(getApplicationContext(),e.toString(), Toast.LENGTH_SHORT).show();
} }
}); });
//Toast.makeText(getApplicationContext(),getResources().getString(R.string.media_list_fail), Toast.LENGTH_SHORT).show(); //Toast.makeText(getApplicationContext(),getResources().getString(R.string.media_list_fail), Toast.LENGTH_SHORT).show();

View file

@ -104,4 +104,6 @@
<string name="allow_all">Permitir todo</string> <string name="allow_all">Permitir todo</string>
<string name="allow_pdf">Permitir pdf</string> <string name="allow_pdf">Permitir pdf</string>
<string name="delete_cors">Eliminar CORS</string> <string name="delete_cors">Eliminar CORS</string>
<string name="cors_error">No se pudo cambiar la política CORS</string>
<string name="cors_ok">Política CORS cambiada exitosamente</string>
</resources> </resources>

View file

@ -107,4 +107,6 @@
<string name="allow_all">Allow all</string> <string name="allow_all">Allow all</string>
<string name="allow_pdf">Allow pdf</string> <string name="allow_pdf">Allow pdf</string>
<string name="delete_cors">Delete CORS</string> <string name="delete_cors">Delete CORS</string>
<string name="cors_error">Cannot change CORS policy</string>
<string name="cors_ok">CORS policy changed successfully</string>
</resources> </resources>