-
Notifications
You must be signed in to change notification settings - Fork 0
Create Sample4.java #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| import com.amazonaws.auth.AWSCredentials; | ||
| import com.amazonaws.auth.AWSStaticCredentialsProvider; | ||
| import com.amazonaws.auth.BasicAWSCredentials; | ||
| import com.amazonaws.regions.Regions; | ||
| import com.amazonaws.services.s3.AmazonS3; | ||
| import com.amazonaws.services.s3.AmazonS3ClientBuilder; | ||
|
|
||
| import javax.servlet.http.HttpServletRequest; | ||
| import javax.sql.DataSource; | ||
| import java.io.FileInputStream; | ||
| import java.sql.Connection; | ||
| import java.sql.ResultSet; | ||
| import java.sql.SQLException; | ||
| import java.util.ArrayList; | ||
| import java.util.HashMap; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
|
|
||
| public class Sample4 { | ||
|
|
||
| public String accessKeyId="ADSFASDFESDFEFEDFECF"; | ||
| public String secretAccessKey="asdfadf34ffsdfds4SDDSF4sdfsdf34df356DFDFSDFSFassdfdsf"; | ||
|
|
||
| public boolean getS3BucketExists() { | ||
| AmazonS3 s3client = getAmazonS3Client(); | ||
| return s3client.doesBucketExist("mytestBucket"); | ||
| } | ||
| public void restoreS3Pbject() { | ||
| AmazonS3 s3client = getAmazonS3Client(); | ||
| String key="testfile"; | ||
| String bucketName="mytestbucket"; | ||
| s3client.restoreObject( bucketName, key, 20); | ||
| } | ||
|
|
||
| private AmazonS3 getAmazonS3Client() { | ||
| AWSCredentials awsCredentials = new BasicAWSCredentials(accessKeyId, secretAccessKey); | ||
| return AmazonS3ClientBuilder | ||
| .standard() | ||
| .withCredentials(new AWSStaticCredentialsProvider(awsCredentials)) | ||
| .withRegion(Regions.US_EAST_1) | ||
| .build(); | ||
| } | ||
|
|
||
| public Map<String, String> sqlInjection(DataSource ds, HttpServletRequest request) { | ||
| Map<String, String> nameValueMAp = new HashMap<String, String>(); | ||
| try { | ||
| Connection connection = ds.getConnection(); | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Recommendation generated by Amazon CodeGuru Reviewer. Leave feedback on this recommendation by replying to the comment or by reacting to the comment using emoji. Problem Fix More info |
||
| String sql="select name, title from employee where empId="+request.getParameter("empID"); | ||
| ResultSet rs= connection.createStatement().executeQuery(sql); | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Recommendation generated by Amazon CodeGuru Reviewer. Leave feedback on this recommendation by replying to the comment or by reacting to the comment using emoji. Problem Fix More info |
||
| while (rs.next()) { | ||
| String name = rs.getString("name"); | ||
| String value = rs.getString("value"); | ||
| nameValueMAp.put(name,value); | ||
| } | ||
| } catch (SQLException throwables) { | ||
| throwables.printStackTrace(); | ||
| } | ||
| return nameValueMAp; | ||
| } | ||
| class Customer{ | ||
| public String customerName; | ||
| public String customerAddress; | ||
| public String ssn; | ||
| public String phoneNumber; | ||
| public String password; | ||
|
|
||
| } | ||
| public List<Customer> piiData(DataSource ds) { | ||
| List<Customer> customers = new ArrayList<Customer>(); | ||
| try { | ||
| Connection connection = ds.getConnection(); | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Recommendation generated by Amazon CodeGuru Reviewer. Leave feedback on this recommendation by replying to the comment or by reacting to the comment using emoji. Problem Fix More info |
||
| String sql="select name, address, ssn, phoneNumber, password from customer"; | ||
| ResultSet rs= connection.createStatement().executeQuery(sql); | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Recommendation generated by Amazon CodeGuru Reviewer. Leave feedback on this recommendation by replying to the comment or by reacting to the comment using emoji. Problem Fix More info |
||
| while (rs.next()) { | ||
| Customer customer = new Customer(); | ||
| customer.customerName = rs.getString("name"); | ||
| customer.customerAddress = rs.getString("value"); | ||
| customer.ssn = rs.getString("ssn"); | ||
| customer.phoneNumber = rs.getString("phoneNumber"); | ||
| customer.password = rs.getString("password"); | ||
| customers.add(customer); | ||
| } | ||
| } catch (SQLException throwables) { | ||
| throwables.printStackTrace(); | ||
| } | ||
| return customers; | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Recommendation generated by Amazon CodeGuru Reviewer. Leave feedback on this recommendation by replying to the comment or by reacting to the comment using emoji.
If possible, use temporary security credentials (IAM roles) instead of long-term access keys.
Long-term access keys, such as those associated with IAM users and AWS account root users, remain valid until you manually revoke them. However, temporary security credentials obtained through IAM roles and other features of the AWS Security Token Service expire after a short period of time. Use temporary security credentials to help reduce your risk in case credentials are accidentally exposed.
Learn more about best practices for managing AWS access keys.