Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ jobs:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2
- name: Build and analyze
- name: Build #and analyze
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: mvn -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=jonathanvila_java-security-demo
run: mvn -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=autocoderoversg_java-security-demo
13 changes: 6 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<sonar.organization>jonathanvila</sonar.organization>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<sonar.organization>autocoderoversg</sonar.organization>
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
<dummy>one</dummy>
</properties>
Expand Down Expand Up @@ -76,9 +76,8 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>21</source>
<target>21</target>
<compilerArgs>--enable-preview</compilerArgs>
<source>17</source>
<target>17</target>
</configuration>
</plugin>
</plugins>
Expand All @@ -87,7 +86,7 @@
<plugin>
<groupId>org.sonarsource.scanner.maven</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>3.9.1.2184</version>
<version>4.0.0.4121</version>
</plugin>
</plugins>
</pluginManagement>
Expand Down
47 changes: 2 additions & 45 deletions src/main/java/demo/security/util/DBUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ public DBUtils() throws SQLException {
}

public void newConnect() throws SQLException {
String myJDBCPasswd = "myJDBCPasswd";
connection = DriverManager.getConnection(
"mYJDBCUrl", "myJDBCUser", "myJDBCPasswd");
"mYJDBCUrl", "myJDBCUser", myJDBCPasswd);

Check failure

Code scanning / SonarCloud

Credentials should not be hard-coded

<!--SONAR_ISSUE_KEY:AZvmahNCtvKpHQXPw_7--->Revoke and change this password, as it is compromised. <p>See more on <a href="https://sonarcloud.io/project/issues?id=jonathanvila_java-security-demo&issues=AZvmahNCtvKpHQXPw_7-&open=AZvmahNCtvKpHQXPw_7-&pullRequest=7">SonarQube Cloud</a></p>

Check failure

Code scanning / SonarCloud

Credentials should not be hard-coded High

Revoke and change this password, as it is compromised. See more on SonarQube Cloud

ArrayList<String> list = new ArrayList<>();
list.add("hola");
Expand All @@ -62,16 +63,6 @@ public List<String> findUsers(String user) throws Exception {
return users;
}

public List<String> findItem(String itemId) throws Exception {
String query = "SELECT item_id FROM items WHERE item_id = '" + itemId + "'";
Statement statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery(query);
List<String> items = new ArrayList<String>();
while (resultSet.next()) {
items.add(resultSet.getString(0));
}
return items;
}

public void sumNumbers(int max) {
int count, sum = 0;
Expand All @@ -96,39 +87,5 @@ public void sumNumbers(int max) {
System.out.println("The Sum of numbers is: " + sum);
}

/**
* Connects to the given external URL 1000 times using threads.
* Each thread performs a single connection and logs the response code.
*
* @param urlString the external URL to connect to
*/
public static void connectToExternalUrlConcurrently(String urlString) {
final int THREAD_COUNT = 1000;
Thread[] threads = new Thread[THREAD_COUNT];
for (int i = 0; i < THREAD_COUNT; i++) {
threads[i] = Thread.ofVirtual().unstarted(() -> {
try {
URL url = new URL(urlString);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.setConnectTimeout(5000);
conn.setReadTimeout(5000);
int responseCode = conn.getResponseCode();
conn.disconnect();
} catch (Exception e) {
}
});
}
for (Thread thread : threads) {
thread.start();
}
for (Thread thread : threads) {
try {
thread.join();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
}

}
1 change: 1 addition & 0 deletions src/main/java/demo/security/util/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public static void executeJs(String input) throws ScriptException {

public void demo() {
List<String> mylist = List.of("a", "b", "c");
List<String> mylist2 = new ArrayList<>();
String element;
try {
element = mylist.get(4);
Expand Down