diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 4bc8657..4556074 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -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 diff --git a/pom.xml b/pom.xml index 5904828..e976ffa 100644 --- a/pom.xml +++ b/pom.xml @@ -10,9 +10,9 @@ http://maven.apache.org UTF-8 - 21 - 21 - jonathanvila + 17 + 17 + autocoderoversg https://sonarcloud.io one @@ -76,9 +76,8 @@ org.apache.maven.plugins maven-compiler-plugin - 21 - 21 - --enable-preview + 17 + 17 @@ -87,7 +86,7 @@ org.sonarsource.scanner.maven sonar-maven-plugin - 3.9.1.2184 + 4.0.0.4121 diff --git a/src/main/java/demo/security/util/DBUtils.java b/src/main/java/demo/security/util/DBUtils.java index 2f1aca6..079e2d7 100644 --- a/src/main/java/demo/security/util/DBUtils.java +++ b/src/main/java/demo/security/util/DBUtils.java @@ -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); ArrayList list = new ArrayList<>(); list.add("hola"); @@ -62,16 +63,6 @@ public List findUsers(String user) throws Exception { return users; } - public List 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 items = new ArrayList(); - while (resultSet.next()) { - items.add(resultSet.getString(0)); - } - return items; - } public void sumNumbers(int max) { int count, sum = 0; @@ -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(); - } - } - } } diff --git a/src/main/java/demo/security/util/Utils.java b/src/main/java/demo/security/util/Utils.java index 200026f..bda9fe7 100644 --- a/src/main/java/demo/security/util/Utils.java +++ b/src/main/java/demo/security/util/Utils.java @@ -47,6 +47,7 @@ public static void executeJs(String input) throws ScriptException { public void demo() { List mylist = List.of("a", "b", "c"); + List mylist2 = new ArrayList<>(); String element; try { element = mylist.get(4);